December 14, 2011
On 12/14/2011 1:59 AM, Jacob Carlborg wrote:
> What happened to arrays in this release:
>
> void foo (Object[] a) {}
> class Foo {}
>
> void main ()
> {
> Foo[] b;
> foo(b);
> }
>
> The above code fails with the following message:
>
> main.d(54): Error: function main.foo (Object[] a) is not callable using argument
> types (Foo[])
> main.d(54): Error: cannot implicitly convert expression (b) of type Foo[] to
> Object[]
>
> Have I missed something, I can't find this in the changelog?

I don't remember if there was a bugzilla entry for it, but it's the object slicing problem. The thing is, main() expects b to be an array of Foo's. If foo() replaces one of the array elements with an Object, then b is no longer an array of Foo's, and can crash.

Note that if you write foo as:

    void foo(const(Object)[] a)

it will work.
December 14, 2011
On 12/14/11 1:44 AM, Walter Bright wrote:
> On 12/13/2011 11:18 PM, Jacob Carlborg wrote:
>> On 2011-12-14 08:09, Bernard Helyer wrote:
>>> Changelog isn't showing up for me.
>>
>> Same here, latest change log is 2.056, which is empty.
>>
>
> Andrei's working on uploading it. Sorry about the delay.

Yah, sorry.

Andrei
December 14, 2011
On 12/14/11 1:05 AM, Walter Bright wrote:
> Highlights are use of XMM floating point registers in 64 bit targets,
> and now supporting OS X 64 as a target.
>
> http://www.digitalmars.com/d/2.0/changelog.html
> http://ftp.digitalmars.com/dmd.2.057.zip
>
> A lot of people put a ton of effort into making this D's best release
> ever. Thanks!

Many thanks to all participants for this awesome release and in particular for the intense pace of the past few days!

Andrei
December 14, 2011
On 2011-12-14 11:10, Walter Bright wrote:
> On 12/14/2011 1:59 AM, Jacob Carlborg wrote:
>> What happened to arrays in this release:
>>
>> void foo (Object[] a) {}
>> class Foo {}
>>
>> void main ()
>> {
>> Foo[] b;
>> foo(b);
>> }
>>
>> The above code fails with the following message:
>>
>> main.d(54): Error: function main.foo (Object[] a) is not callable
>> using argument
>> types (Foo[])
>> main.d(54): Error: cannot implicitly convert expression (b) of type
>> Foo[] to
>> Object[]
>>
>> Have I missed something, I can't find this in the changelog?
>
> I don't remember if there was a bugzilla entry for it, but it's the
> object slicing problem. The thing is, main() expects b to be an array of
> Foo's. If foo() replaces one of the array elements with an Object, then
> b is no longer an array of Foo's, and can crash.

I think it would be good if it's in the changelog, even if there is no bugzilla entry for it.

> Note that if you write foo as:
>
> void foo(const(Object)[] a)
>
> it will work.

Ok, thanks.

-- 
/Jacob Carlborg
December 14, 2011
Jacob Carlborg:

> What happened to arrays in this release:

They have closed a significant D2 hole.

As Walter has explained, this code used to compile fine and then crash at runtime:

class Foo {
    void spam() {}
}
class Bar {}
void foo(Object[] a) {
    a[0] = new Bar;
}
void main() {
    Foo[] b = [new Foo];
    foo(b);
    b[0].spam(); // crash
}


Now instead it gives this at compile-time:
test.d(10): Error: function test.foo (Object[] a) is not callable using argument types (Foo[])
test.d(10): Error: cannot implicitly convert expression (b) of type Foo[] to Object[]


Now a modified foo is accepted if its 'a' argoment is constant, because you can't modify the array contents (unless you cast away const):


class Foo {
    void spam() {}
}
void foo(const(Object[]) a) {
}
void main() {
    Foo[] b = [new Foo];
    foo(b);
}


This Java code compiles with no errors:


class Foo {
    Foo() {}
    void spam() {}
}
class Bar {
    Bar() {}
}
class Test {
    static void foo(Object[] a) {
        a[0] = new Bar(); // line 10, runtime error here
    }
    public static void main(String[] args) {
        Foo[] b = {new Foo()};
        Test.foo(b);
        b[0].spam(); // line 15
    }
}


Instead of crashing at run-time at line 15, it raises a java.lang.ArrayStoreException at runtime at line 10, where at runtime it tests that in a[0] you put a Foo() instead of something else like a Bar() or Object(). So  (in theory) the JavaVM has to perform a runtime test every time you perform an assignment of a class reference to an array cell.

Bye,
bearophile
December 14, 2011
Am 14.12.2011 08:05, schrieb Walter Bright:
> Highlights are use of XMM floating point registers in 64 bit targets, and now supporting OS X 64 as a target.
> 
> http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.057.zip
> 
> A lot of people put a ton of effort into making this D's best release ever. Thanks!

I have a strange crash of the new dmd 2.057 compiler.

I am running the compiler from inside VisualD. In debug mode the code compiles fine. In release mode the compiler crashes and Windows starts the Just-In-Time-Debugger saying that there is an unhandled exception inside dmd.exe.

as a side note: the same code did compile with 2.056 !

When I try to find the source of the error it gets really funky strange:

int main(string[] argv)
{
	writeln("Hello D-World!");
	auto i = uniform(0, 15);          // line A
	auto c = 0;
	if (c++ < c)					  // line B
		writeln("Why did they call it c++"); // line C
	//writeln(bench!(doStringTest));  // line D
	//writeln(bench!(doBench1));	  // line E
	//writeln(bench!(doBench2));      // line F
	//writeln(bench!(doBench3));      // line G
//	main1(argv);			  // line I
//	return 0;                         // line J
//}                                       // line K

//int main1(string[] argv)                // line L
//{                                       // line M

  ... much more code
}

- the code above crashes
- when I comment out line A it compiles
- when I leave A comment out  B and C - dmd gets into an endless loop (
I waited several minutes for the process to terminate)

- when I leave A and uncomment I to M it compiles
- when I uncomment A to G it compiles
- when I uncomment A to F it crashes

now I tried the following:

int main(string[] argv)
{
	writeln("Hello D-World!");
	auto i = uniform(0, 15);          // line A
	auto c = 0;
	if (c++ < c)					  // line B
		writeln("Why did they call it c++"); // line C
	//writeln(bench!(doStringTest));  // line D
	//writeln(bench!(doBench1));	  // line E
	//writeln(bench!(doBench2));      // line F
	//writeln(bench!(doBench3));      // line G
	main1(argv);			  // line I
	return 0;                         // line J
}                                       // line K

int main1(string[] argv)                // line L
{                                       // line M

  ... much more code
}


- as soon as I uncomment line G it compiles with any combination of line
D to F uncommented
- when line G is commented out any combination of line D to F
uncommented crashes.
- when I comment out line "I" any other combination compiles

I really would like to find a minimal stripped down version of the code, but as soon as I try to find it, the behavior changes.





December 14, 2011
Ideally, every nontrivial change should have a bugzilla entry, even if that means its created by whoever made the change. It's too easy to miss things otherwise.

Sent from my iPhone

On Dec 14, 2011, at 3:11 AM, Jacob Carlborg <doob@me.com> wrote:

> On 2011-12-14 11:10, Walter Bright wrote:
>> On 12/14/2011 1:59 AM, Jacob Carlborg wrote:
>>> What happened to arrays in this release:
>>> 
>>> void foo (Object[] a) {}
>>> class Foo {}
>>> 
>>> void main ()
>>> {
>>> Foo[] b;
>>> foo(b);
>>> }
>>> 
>>> The above code fails with the following message:
>>> 
>>> main.d(54): Error: function main.foo (Object[] a) is not callable
>>> using argument
>>> types (Foo[])
>>> main.d(54): Error: cannot implicitly convert expression (b) of type
>>> Foo[] to
>>> Object[]
>>> 
>>> Have I missed something, I can't find this in the changelog?
>> 
>> I don't remember if there was a bugzilla entry for it, but it's the object slicing problem. The thing is, main() expects b to be an array of Foo's. If foo() replaces one of the array elements with an Object, then b is no longer an array of Foo's, and can crash.
> 
> I think it would be good if it's in the changelog, even if there is no bugzilla entry for it.
> 
>> Note that if you write foo as:
>> 
>> void foo(const(Object)[] a)
>> 
>> it will work.
> 
> Ok, thanks.
> 
> -- 
> /Jacob Carlborg
December 14, 2011
On Wednesday, December 14, 2011 12:11:03 Jacob Carlborg wrote:
> On 2011-12-14 11:10, Walter Bright wrote:
> > On 12/14/2011 1:59 AM, Jacob Carlborg wrote:
> >> What happened to arrays in this release:
> >> 
> >> void foo (Object[] a) {}
> >> class Foo {}
> >> 
> >> void main ()
> >> {
> >> Foo[] b;
> >> foo(b);
> >> }
> >> 
> >> The above code fails with the following message:
> >> 
> >> main.d(54): Error: function main.foo (Object[] a) is not callable
> >> using argument
> >> types (Foo[])
> >> main.d(54): Error: cannot implicitly convert expression (b) of type
> >> Foo[] to
> >> Object[]
> >> 
> >> Have I missed something, I can't find this in the changelog?
> > 
> > I don't remember if there was a bugzilla entry for it, but it's the object slicing problem. The thing is, main() expects b to be an array of Foo's. If foo() replaces one of the array elements with an Object, then b is no longer an array of Foo's, and can crash.
> 
> I think it would be good if it's in the changelog, even if there is no bugzilla entry for it.

It's the first dmd bug on the list: http://d.puremagic.com/issues/show_bug.cgi?id=2095

- Jonathan M Davis
December 14, 2011
On 12/14/2011 6:59 AM, Adrian wrote:
> I have a strange crash of the new dmd 2.057 compiler.

I can't do anything without a reproducible test case.
December 15, 2011
On 14/12/11 7:05 AM, Walter Bright wrote:
> Highlights are use of XMM floating point registers in 64 bit targets,
> and now supporting OS X 64 as a target.
>
> http://www.digitalmars.com/d/2.0/changelog.html
> http://ftp.digitalmars.com/dmd.2.057.zip
>
> A lot of people put a ton of effort into making this D's best release
> ever. Thanks!

Great release.

64-bit OSX is working for my project without any problems. Had to change some uint's to size_t's and fix some inline asm but everything was fine after that :-)