www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [GDC] Evaluation order: Please update the dmd backend

reply Johannes Pfau <nospam example.com> writes:
I started fixing GDC bug #8 (*) which is basically that array op
evaluation order currently depends on the target architecture. Consider
this example:
a()[] = b()[] + c()[];
The order in which c,a,b are called is currently architecture specific.
As stated in that bug report by Andrei we want this to evaluate LTR, so
a() first, then b(), then c().

These operations are actually rewritten to calls to extern(C)
functions. Arguments to C function should be evaluated LTR as well, but
dmd currently evaluates them RTL (GDC: architecture dependent). In order
to fix the array op bug in gdc we have to define the evaluation order
for extern(C) function parameters.

So I've changed extern(C) functions to evaluate LTR in GDC and then had
to change the array op code, cause that assumed extern(C) function
evaluate RTL. Now I'd like to push these array op changes into dmd as we
want to keep as few gdc specific changes as possible and dmd (and ldc)
will need these changes anyway as soon as they implement extern(C)
functions as LTR. This is required by dmd issue #6620 (**) and the
language spec (***).

However, if we apply only these changes the array op order reverses for
DMD as it evaluates extern(C) function arguments RTL.

So I need someone with dmd backend knowledge to fix the evaluation
order of extern(C) function parameters to be LTR.
Evaluation order of assignments should also be fixed to be LTR in the
dmd backend. Although not strictly required for the array op changes
it'd be inconsistent to have array op assignments execute LTR but
normal assignments RTL:
a()[] = b()[] + c()[]; //Array op assignment
a() = b() + c();       //Normal assignment
 |      |    | 
 1      2    3

The frontend changes for dmd are here:
https://github.com/jpf91/dmd/tree/fixOrder
Frontend:
https://github.com/jpf91/dmd/commit/5d61b812977dbdc1f99100e2fbaf1f45e9d25b03
Test cases:
https://github.com/jpf91/dmd/commit/82bffe0862b272f02c27cc428b22a7dd113b4a07

Druntime changes (need to be applied at the same time as dmd changes)
https://github.com/jpf91/druntime/tree/fixOrder
https://github.com/jpf91/druntime/commit/f3f6f49c595d4fb25fb298e435ad1874abac516d


(*)   http://bugzilla.gdcproject.org/show_bug.cgi?id=8
(**)  https://d.puremagic.com/issues/show_bug.cgi?id=6620
(***) https://github.com/D-Programming-Language/dlang.org/pull/6
Apr 01 2014
next sibling parent "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Johannes Pfau"  wrote in message news:lhe96q$27ua$1 digitalmars.com...

 So I need someone with dmd backend knowledge to fix the evaluation
 order of extern(C) function parameters to be LTR.
 Evaluation order of assignments should also be fixed to be LTR in the
 dmd backend. Although not strictly required for the array op changes
 it'd be inconsistent to have array op assignments execute LTR but
 normal assignments RTL:
 a()[] = b()[] + c()[]; //Array op assignment
 a() = b() + c();       //Normal assignment
  |      |    |
  1      2    3

It shouldn't need backend changes, just a glue layer fix to evaluate all args to a temporary before the actual call expression. Something similar to the way https://d.puremagic.com/issues/show_bug.cgi?id=8396 was done should work.
Apr 01 2014
prev sibling next sibling parent reply Iain Buclaw <ibuclaw gdcproject.org> writes:
--089e01493982c2806004f5fab88a
Content-Type: text/plain; charset=ISO-8859-1

On 1 Apr 2014 14:45, "Daniel Murphy" <yebbliesnospam gmail.com> wrote:
 "Johannes Pfau"  wrote in message news:lhe96q$27ua$1 digitalmars.com...


 So I need someone with dmd backend knowledge to fix the evaluation
 order of extern(C) function parameters to be LTR.
 Evaluation order of assignments should also be fixed to be LTR in the
 dmd backend. Although not strictly required for the array op changes
 it'd be inconsistent to have array op assignments execute LTR but
 normal assignments RTL:
 a()[] = b()[] + c()[]; //Array op assignment
 a() = b() + c();       //Normal assignment
  |      |    |
  1      2    3

It shouldn't need backend changes, just a glue layer fix to evaluate all

 Something similar to the way

So you can write the patches then? :o) --089e01493982c2806004f5fab88a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <p dir=3D"ltr">On 1 Apr 2014 14:45, &quot;Daniel Murphy&quot; &lt;<a href= =3D"mailto:yebbliesnospam gmail.com">yebbliesnospam gmail.com</a>&gt; wrote= :<br> &gt;<br> &gt; &quot;Johannes Pfau&quot; =A0wrote in message news:lhe96q$27ua$1 digit= almars.com...<br> &gt;<br> &gt;<br> &gt;&gt; So I need someone with dmd backend knowledge to fix the evaluation= <br> &gt;&gt; order of extern(C) function parameters to be LTR.<br> &gt;&gt; Evaluation order of assignments should also be fixed to be LTR in = the<br> &gt;&gt; dmd backend. Although not strictly required for the array op chang= es<br> &gt;&gt; it&#39;d be inconsistent to have array op assignments execute LTR = but<br> &gt;&gt; normal assignments RTL:<br> &gt;&gt; a()[] =3D b()[] + c()[]; //Array op assignment<br> &gt;&gt; a() =3D b() + c(); =A0 =A0 =A0 //Normal assignment<br> &gt;&gt; =A0| =A0 =A0 =A0| =A0 =A0|<br> &gt;&gt; =A01 =A0 =A0 =A02 =A0 =A03<br> &gt;<br> &gt;<br> &gt; It shouldn&#39;t need backend changes, just a glue layer fix to evalua= te all args to a temporary before the actual call expression.<br> &gt;<br> &gt; Something similar to the way <a href=3D"https://d.puremagic.com/issues= /show_bug.cgi?id=3D8396">https://d.puremagic.com/issues/show_bug.cgi?id=3D8= 396</a> was done should work. </p> <p dir=3D"ltr">So you can write the patches then? :o)</p> --089e01493982c2806004f5fab88a--
Apr 01 2014
parent "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Iain Buclaw" <ibuclaw gdcproject.org> wrote in message 
news:mailman.13.1396357117.19942.digitalmars-d puremagic.com...

 So you can write the patches then? :o)

Sure, as long as you're not in a hurry.
Apr 01 2014
prev sibling next sibling parent reply "Sarath Kodali" <sarath dummy.com> writes:
On Tuesday, 1 April 2014 at 11:50:51 UTC, Johannes Pfau wrote:
 I started fixing GDC bug #8 (*) which is basically that array op
 evaluation order currently depends on the target architecture. 
 Consider
 this example:
 a()[] = b()[] + c()[];
 The order in which c,a,b are called is currently architecture 
 specific.
 As stated in that bug report by Andrei we want this to evaluate 
 LTR, so
 a() first, then b(), then c().

 These operations are actually rewritten to calls to extern(C)
 functions. Arguments to C function should be evaluated LTR as 
 well, but
 dmd currently evaluates them RTL (GDC: architecture dependent). 
 In order
 to fix the array op bug in gdc we have to define the evaluation 
 order
 for extern(C) function parameters.

 So I've changed extern(C) functions to evaluate LTR in GDC and 
 then had
 to change the array op code, cause that assumed extern(C) 
 function
 evaluate RTL. Now I'd like to push these array op changes into 
 dmd as we
 want to keep as few gdc specific changes as possible and dmd 
 (and ldc)
 will need these changes anyway as soon as they implement 
 extern(C)
 functions as LTR. This is required by dmd issue #6620 (**) and 
 the
 language spec (***).

 However, if we apply only these changes the array op order 
 reverses for
 DMD as it evaluates extern(C) function arguments RTL.

 So I need someone with dmd backend knowledge to fix the 
 evaluation
 order of extern(C) function parameters to be LTR.
 Evaluation order of assignments should also be fixed to be LTR 
 in the
 dmd backend. Although not strictly required for the array op 
 changes
 it'd be inconsistent to have array op assignments execute LTR 
 but
 normal assignments RTL:
 a()[] = b()[] + c()[]; //Array op assignment
 a() = b() + c();       //Normal assignment
  |      |    |
  1      2    3

 The frontend changes for dmd are here:
 https://github.com/jpf91/dmd/tree/fixOrder
 Frontend:
 https://github.com/jpf91/dmd/commit/5d61b812977dbdc1f99100e2fbaf1f45e9d25b03
 Test cases:
 https://github.com/jpf91/dmd/commit/82bffe0862b272f02c27cc428b22a7dd113b4a07

 Druntime changes (need to be applied at the same time as dmd 
 changes)
 https://github.com/jpf91/druntime/tree/fixOrder
 https://github.com/jpf91/druntime/commit/f3f6f49c595d4fb25fb298e435ad1874abac516d


 (*)   http://bugzilla.gdcproject.org/show_bug.cgi?id=8
 (**)  https://d.puremagic.com/issues/show_bug.cgi?id=6620
 (***) https://github.com/D-Programming-Language/dlang.org/pull/6

The evaluation order of assign operators should not be LTR as they have right associativity. In "a = b = c", c has to be evaluated first, then b and then a. Similarly, in "a = b + c", "b+c" has to be evaluated first before a is evaluated. Otherwise it will be very confusing, that in some cases it is LTR and in some it is RTL. Other binary operators like "+" have left associativity, and hence evaluation for these should be LTR as mentioned in D spec. The C spec requires that the function arguments are to be pushed in RTL order. The DMD codegen uses pushl x86 instructions for pushing args. If the frontend changes the func args evaluation order to LTR, then the backend has to be modified to use mov x86 instructions as is done by gcc codegen. - Sarath
Apr 01 2014
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 04/01/2014 08:40 PM, Sarath Kodali wrote:
 ...

 The evaluation order of assign operators should not be LTR as they have
 right associativity. In "a = b = c", c has to be evaluated first, then b
 and then a. Similarly, in "a = b + c", "b+c" has to be evaluated first
 before a is evaluated. Otherwise it will be very confusing, that in some
 cases it is LTR and in some it is RTL.

Note that this is after a paragraph that suggests to make evaluation in some cases LTR and in some RTL.
 Other binary operators like "+" have left associativity, and hence
 evaluation for these should be LTR as mentioned in D spec.
 ...

What's the presumed relation between associativity and evaluation order? In particular, the ternary operator ?: is right associative. How on earth are you going to evaluate it right to left?
 The C spec requires that the function arguments are to be pushed in RTL
 order.

[citation needed]
 The DMD codegen uses pushl x86 instructions for pushing args. If the
 frontend changes the func args evaluation order to LTR, then the backend
 has to be modified  to use mov x86 instructions as is done by gcc codegen.

 - Sarath

The backend does not necessarily have to be modified to achieve this.
Apr 01 2014
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 04/02/2014 09:47 AM, Sarath Kodali wrote:
 On Tuesday, 1 April 2014 at 22:04:43 UTC, Timon Gehr wrote:
 On 04/01/2014 08:40 PM, Sarath Kodali wrote:
 ...

 The evaluation order of assign operators should not be LTR as they have
 right associativity. In "a = b = c", c has to be evaluated first, then b
 and then a. Similarly, in "a = b + c", "b+c" has to be evaluated first
 before a is evaluated. Otherwise it will be very confusing, that in some
 cases it is LTR and in some it is RTL.

Note that this is after a paragraph that suggests to make evaluation in some cases LTR and in some RTL.

There are 2 evaluation orders that need to be considered while evaluating expressions - the evaluation order of operators and the the evaluation order of operands of an operator. The evaluation order of operators is well defined

(That's a somewhat strong/ill-formed statement, as operator applications will in general occur as operands.)
 and is done according to its precedence and
 associativity.

Evaluation order is according to data dependencies. (But C does not even guarantee this.) Expressions are _parsed_ according to precedence and associativity. Precedence and associativity are determined roughly according to common usage to reduce the number of parentheses needed to write down a typical expression.
 However the evaluation order of operands for some of the
 binary operators is not defined. D left it undefined for assign
 operator. So in "a=b", the compiler can choose to evaluate a first and
 then b. However in "a=b=c", "b=c" has to be evaluated first

Before the outer assignment, not necessarily before 'a'.
 due to right associativity of '=' operator.
 Similarly in "a=b+c", "b+c" has to be
 evaluated first

Again, evaluated before the assignment, not necessarily before 'a'.
 due to higher precedence of + operator over = operator.
 In both these cases, the right operand of = operator is evaluated first
 and then the left operand.

No, neither of the two cases made any point about the left operand.
 So it naturally follows

I disagree here. Doing it the same way consistently for all operations is more 'natural' a priori. Deviations should be justified by actual semantics, not parsing details. (E.g. a hypothetical argument might be that 'ref' returns are less dangerous with RTL evaluation of assignments.) Such arguments, if convincing ones exist, would not necessarily generalize to all right-associative expressions.
 that even in the unspecified case (a=b), the right operand should be evaluated
first so
 that it is consistent with other cases of = operator. All this means,
 the evaluation order of operands also should be according to the
 associativity of its operator.
 You can test this with other right or left associative binary operators.

int a = 1; int b = (a++)^^(a++)^^(a++); // 1 is a fine value
Apr 02 2014
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Wed, 02 Apr 2014 00:04:42 +0200
schrieb Timon Gehr <timon.gehr gmx.ch>:

 On 04/01/2014 08:40 PM, Sarath Kodali wrote:
 ...

 The evaluation order of assign operators should not be LTR as they
 have right associativity. In "a = b = c", c has to be evaluated
 first, then b and then a. Similarly, in "a = b + c", "b+c" has to
 be evaluated first before a is evaluated. Otherwise it will be very
 confusing, that in some cases it is LTR and in some it is RTL.

Note that this is after a paragraph that suggests to make evaluation in some cases LTR and in some RTL.
 Other binary operators like "+" have left associativity, and hence
 evaluation for these should be LTR as mentioned in D spec.
 ...

What's the presumed relation between associativity and evaluation order? In particular, the ternary operator ?: is right associative. How on earth are you going to evaluate it right to left?
 The C spec requires that the function arguments are to be pushed in
 RTL order.

[citation needed]

The C standard explicitly doesn't define the evaluation order: http://stackoverflow.com/questions/376278/parameter-evaluation-order-before-a-function-calling-in-c/376333#376333 It's probably the platform ABI for x86 which specifies this, however this is architecture specific. For example ARM evaluates LTR.
 
 The DMD codegen uses pushl x86 instructions for pushing args. If the
 frontend changes the func args evaluation order to LTR, then the
 backend has to be modified  to use mov x86 instructions as is done
 by gcc codegen.

 - Sarath

The backend does not necessarily have to be modified to achieve this.

If this point is about performance it doesn't matter anyway as parameters for extern(D) functions are already evaluated LTR and D functions are much more common than C functions. http://dpaste.dzfl.pl/f5a5caeea8ed
Apr 02 2014
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Wed, 2 Apr 2014 00:54:40 +1100
schrieb "Daniel Murphy" <yebbliesnospam gmail.com>:

 
 "Iain Buclaw" <ibuclaw gdcproject.org> wrote in message 
 news:mailman.13.1396357117.19942.digitalmars-d puremagic.com...
 
 So you can write the patches then? :o)

Sure, as long as you're not in a hurry.

Thanks. There's no need to hurry ;-)
Apr 02 2014
prev sibling next sibling parent "Sarath Kodali" <sarath dummy.com> writes:
On Tuesday, 1 April 2014 at 22:04:43 UTC, Timon Gehr wrote:
 On 04/01/2014 08:40 PM, Sarath Kodali wrote:
 ...

 The evaluation order of assign operators should not be LTR as 
 they have
 right associativity. In "a = b = c", c has to be evaluated 
 first, then b
 and then a. Similarly, in "a = b + c", "b+c" has to be 
 evaluated first
 before a is evaluated. Otherwise it will be very confusing, 
 that in some
 cases it is LTR and in some it is RTL.

Note that this is after a paragraph that suggests to make evaluation in some cases LTR and in some RTL.

There are 2 evaluation orders that need to be considered while evaluating expressions - the evaluation order of operators and the the evaluation order of operands of an operator. The evaluation order of operators is well defined and is done according to its precedence and associativity. However the evaluation order of operands for some of the binary operators is not defined. D left it undefined for assign operator. So in "a=b", the compiler can choose to evaluate a first and then b. However in "a=b=c", "b=c" has to be evaluated first due to right associativity of '=' operator. Similarly in "a=b+c", "b+c" has to be evaluated first due to higher precedence of + operator over = operator. In both these cases, the right operand of = operator is evaluated first and then the left operand. So it naturally follows that even in the unspecified case (a=b), the right operand should be evaluated first so that it is consistent with other cases of = operator. All this means, the evaluation order of operands also should be according to the associativity of its operator. You can test this with other right or left associative binary operators.
 Other binary operators like "+" have left associativity, and 
 hence
 evaluation for these should be LTR as mentioned in D spec.
 ...

What's the presumed relation between associativity and evaluation order? In particular, the ternary operator ?: is right associative. How on earth are you going to evaluate it right to left?
 The C spec requires that the function arguments are to be 
 pushed in RTL
 order.

[citation needed]

You can get that info from any C ABI doc from Intel or AMD or some other arch.
 The DMD codegen uses pushl x86 instructions for pushing args. 
 If the
 frontend changes the func args evaluation order to LTR, then 
 the backend
 has to be modified  to use mov x86 instructions as is done by 
 gcc codegen.

 - Sarath

The backend does not necessarily have to be modified to achieve this.

Can you please explain how you are going to do that without modifying the backend? - Sarath
Apr 02 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
--001a11340566a63d3704f60ab206
Content-Type: text/plain; charset=ISO-8859-1

On 2 Apr 2014 09:52, "Sarath Kodali" <sarath dummy.com> wrote:
 On Tuesday, 1 April 2014 at 22:04:43 UTC, Timon Gehr wrote:
 On 04/01/2014 08:40 PM, Sarath Kodali wrote:
 ...

 The evaluation order of assign operators should not be LTR as they have
 right associativity. In "a = b = c", c has to be evaluated first, then b
 and then a. Similarly, in "a = b + c", "b+c" has to be evaluated first
 before a is evaluated. Otherwise it will be very confusing, that in some
 cases it is LTR and in some it is RTL.

Note that this is after a paragraph that suggests to make evaluation in



There are 2 evaluation orders that need to be considered while evaluating

order of operands of an operator. The evaluation order of operators is well defined and is done according to its precedence and associativity. However the evaluation order of operands for some of the binary operators is not defined. D left it undefined for assign operator. So in "a=b", the compiler can choose to evaluate a first and then b. However in "a=b=c", "b=c" has to be evaluated first due to right associativity of '=' operator. Similarly in "a=b+c", "b+c" has to be evaluated first due to higher precedence of + operator over = operator. In both these cases, the right operand of = operator is evaluated first and then the left operand. So it naturally follows that even in the unspecified case (a=b), the right operand should be evaluated first so that it is consistent with other cases of = operator. All this means, the evaluation order of operands also should be according to the associativity of its operator. You can test this with other right or left associative binary operators.
 Other binary operators like "+" have left associativity, and hence
 evaluation for these should be LTR as mentioned in D spec.
 ...

What's the presumed relation between associativity and evaluation order? In particular, the ternary operator ?: is right associative. How on


 The C spec requires that the function arguments are to be pushed in RTL
 order.

[citation needed]

You can get that info from any C ABI doc from Intel or AMD or some other


That's order of pushing arguments, not order of evaluation. Also, heavy stress on the words *Intel* and *AMD*. That is in no way a C standard. :) --001a11340566a63d3704f60ab206 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <p dir=3D"ltr"><br> On 2 Apr 2014 09:52, &quot;Sarath Kodali&quot; &lt;<a href=3D"mailto:sarath= dummy.com">sarath dummy.com</a>&gt; wrote:<br> &gt;<br> &gt; On Tuesday, 1 April 2014 at 22:04:43 UTC, Timon Gehr wrote:<br> &gt;&gt;<br> &gt;&gt; On 04/01/2014 08:40 PM, Sarath Kodali wrote:<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; ...<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; The evaluation order of assign operators should not be LTR as = they have<br> &gt;&gt;&gt; right associativity. In &quot;a =3D b =3D c&quot;, c has to be= evaluated first, then b<br> &gt;&gt;&gt; and then a. Similarly, in &quot;a =3D b + c&quot;, &quot;b+c&q= uot; has to be evaluated first<br> &gt;&gt;&gt; before a is evaluated. Otherwise it will be very confusing, th= at in some<br> &gt;&gt;&gt; cases it is LTR and in some it is RTL.<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; Note that this is after a paragraph that suggests to make evaluati= on in some cases LTR and in some RTL.<br> &gt;&gt;<br> &gt;<br> &gt; There are 2 evaluation orders that need to be considered while evaluat= ing expressions - the evaluation order of operators and the the evaluation = order of operands of an operator. The evaluation order of operators is well= defined and is done according to its precedence and associativity. However= the evaluation order of operands for some of the binary operators is not d= efined. D left it undefined for assign operator. So in &quot;a=3Db&quot;, t= he compiler can choose to evaluate a first and then b. However in &quot;a= =3Db=3Dc&quot;, &quot;b=3Dc&quot; has to be evaluated first due to right as= sociativity of &#39;=3D&#39; operator. Similarly in &quot;a=3Db+c&quot;, &q= uot;b+c&quot; has to be evaluated first due to higher precedence of + opera= tor over =3D operator. =A0In both these cases, the right operand of =3D ope= rator is evaluated first and then the left operand. So it naturally follows= that even in the unspecified case (a=3Db), the right operand should be eva= luated first so that it is consistent with other cases of =3D operator. All= this means, the evaluation order of operands also should be according to t= he associativity of its operator. You can test this with other right or lef= t associative binary operators.<br> &gt;<br> &gt;<br> &gt;<br> &gt;&gt;&gt; Other binary operators like &quot;+&quot; have left associativ= ity, and hence<br> &gt;&gt;&gt; evaluation for these should be LTR as mentioned in D spec.<br> &gt;&gt;&gt; ...<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; What&#39;s the presumed relation between associativity and evaluat= ion order?<br> &gt;&gt;<br> &gt;&gt; In particular, the ternary operator ?: is right associative. How o= n earth are you going to evaluate it right to left?<br> &gt;&gt;<br> &gt;&gt;&gt; The C spec requires that the function arguments are to be push= ed in RTL<br> &gt;&gt;&gt; order.<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; [citation needed]<br> &gt;&gt;<br> &gt;<br> &gt; You can get that info from any C ABI doc from Intel or AMD or some oth= er arch.<br> &gt;</p> <p dir=3D"ltr">That&#39;s order of pushing arguments, not order of evaluati= on.=A0 Also, heavy stress on the words *Intel* and *AMD*.=A0 That is in no = way a C standard. :)<br> </p> --001a11340566a63d3704f60ab206--
Apr 02 2014
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Wed, 02 Apr 2014 07:47:23 +0000
schrieb "Sarath Kodali" <sarath dummy.com>:

 On Tuesday, 1 April 2014 at 22:04:43 UTC, Timon Gehr wrote:
 On 04/01/2014 08:40 PM, Sarath Kodali wrote:
 ...

 The evaluation order of assign operators should not be LTR as 
 they have
 right associativity. In "a = b = c", c has to be evaluated 
 first, then b
 and then a. Similarly, in "a = b + c", "b+c" has to be 
 evaluated first
 before a is evaluated. Otherwise it will be very confusing, 
 that in some
 cases it is LTR and in some it is RTL.

Note that this is after a paragraph that suggests to make evaluation in some cases LTR and in some RTL.

There are 2 evaluation orders that need to be considered while evaluating expressions - the evaluation order of operators and the the evaluation order of operands of an operator. The evaluation order of operators is well defined and is done according to its precedence and associativity. However the evaluation order of operands for some of the binary operators is not defined. D left it undefined for assign operator. So in "a=b", the compiler can choose to evaluate a first and then b. However in "a=b=c", "b=c" has to be evaluated first due to right associativity of '=' operator. Similarly in "a=b+c", "b+c" has to be evaluated first due to higher precedence of + operator over = operator. In both these cases, the right operand of = operator is evaluated first and then the left operand. So it naturally follows that even in the unspecified case (a=b), the right operand should be evaluated first so that it is consistent with other cases of = operator. All this means, the evaluation order of operands also should be according to the associativity of its operator. You can test this with other right or left associative binary operators.

In a=b=c you have to do assignment b=c first, then assign a=b. But we're talking about _side effects_ here, i.e. a() = b() = c(). And you can evaluate the side effects in LTR order: a() = b() = c(); ==> auto tmp1 = &a(); auto tmp2 = &b(); *tmp2 = c(); *tmp1 = *tmp2; http://dpaste.dzfl.pl/19c118b7d368
Apr 02 2014
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Wed, 2 Apr 2014 10:48:33 +0200
schrieb Johannes Pfau <nospam example.com>:

 http://dpaste.dzfl.pl/19c118b7d368

BTW: LDC and even very old versions of GDC already evaluate that LTR, you can switch the compiler to LDC to see that: http://dpaste.dzfl.pl/cec5cc3b7dd7
Apr 02 2014
prev sibling next sibling parent "Sarath Kodali" <sarath dummy.com> writes:
On Wednesday, 2 April 2014 at 08:02:36 UTC, Iain Buclaw wrote:
 On 2 Apr 2014 09:52, "Sarath Kodali" <sarath dummy.com> wrote:
 On Tuesday, 1 April 2014 at 22:04:43 UTC, Timon Gehr wrote:
 On 04/01/2014 08:40 PM, Sarath Kodali wrote:
 ...

 The evaluation order of assign operators should not be LTR 
 as they have
 right associativity. In "a = b = c", c has to be evaluated 
 first, then b
 and then a. Similarly, in "a = b + c", "b+c" has to be 
 evaluated first
 before a is evaluated. Otherwise it will be very confusing, 
 that in some
 cases it is LTR and in some it is RTL.

Note that this is after a paragraph that suggests to make evaluation in



There are 2 evaluation orders that need to be considered while evaluating

evaluation order of operands of an operator. The evaluation order of operators is well defined and is done according to its precedence and associativity. However the evaluation order of operands for some of the binary operators is not defined. D left it undefined for assign operator. So in "a=b", the compiler can choose to evaluate a first and then b. However in "a=b=c", "b=c" has to be evaluated first due to right associativity of '=' operator. Similarly in "a=b+c", "b+c" has to be evaluated first due to higher precedence of + operator over = operator. In both these cases, the right operand of = operator is evaluated first and then the left operand. So it naturally follows that even in the unspecified case (a=b), the right operand should be evaluated first so that it is consistent with other cases of = operator. All this means, the evaluation order of operands also should be according to the associativity of its operator. You can test this with other right or left associative binary operators.
 Other binary operators like "+" have left associativity, and 
 hence
 evaluation for these should be LTR as mentioned in D spec.
 ...

What's the presumed relation between associativity and evaluation order? In particular, the ternary operator ?: is right associative. How on


 The C spec requires that the function arguments are to be 
 pushed in RTL
 order.

[citation needed]

You can get that info from any C ABI doc from Intel or AMD or some other


That's order of pushing arguments, not order of evaluation. Also, heavy stress on the words *Intel* and *AMD*. That is in no way a C standard. :)

Please do not get confused between operands evaluation order in an expression and arguments passing order to a function. Those are two different things. I was talking about both of them because both of them are involved in the evaluation of a()[] = b()[] + c()[]. To a programmer this is an expression that should follow expression evaluation rules. To a compiler implementer, this is a builtin function call whose arguments should be evaluated such that the expression evaluation rules are not broken. If you read the last para in my first post, I was talking about argument pushing order *not* evaluation order for function args. The function argument passing order (called calling convention) is not defined by C spec, but by C ABI spec of any architecture. In all the C calling conventions, the first few arguments are passed in registers and the remaining on the stack. On Linux+x86, all the arguments are passed on the stack. For C, the arguments that are passed on the stack are in reverse order i.e RTL. Since the proposal was to change the argument evaluation order for extern(C) functions, I was merely pointing out that this will have an impact on the dmd backend because it uses pushl instructions. Notice that for extern (C) functions, the argument evaluation order and argument pushing order is same. So dmd evaluates an argument and pushes it immediately. If the evaluation order is opposite to that of the pushing order, then it cannot immediately push the argument that it has evaluated. However if it uses movl instructions as is done by gcc backend, then there is no issue. - Sarath * pushl and movl are x86 instructions.
Apr 02 2014
prev sibling next sibling parent "Sarath Kodali" <sarath dummy.com> writes:
On Wednesday, 2 April 2014 at 08:50:17 UTC, Johannes Pfau wrote:
 Am Wed, 02 Apr 2014 07:47:23 +0000
 schrieb "Sarath Kodali" <sarath dummy.com>:

 On Tuesday, 1 April 2014 at 22:04:43 UTC, Timon Gehr wrote:
 On 04/01/2014 08:40 PM, Sarath Kodali wrote:
 ...

 The evaluation order of assign operators should not be LTR 
 as they have
 right associativity. In "a = b = c", c has to be evaluated 
 first, then b
 and then a. Similarly, in "a = b + c", "b+c" has to be 
 evaluated first
 before a is evaluated. Otherwise it will be very confusing, 
 that in some
 cases it is LTR and in some it is RTL.

Note that this is after a paragraph that suggests to make evaluation in some cases LTR and in some RTL.

There are 2 evaluation orders that need to be considered while evaluating expressions - the evaluation order of operators and the the evaluation order of operands of an operator. The evaluation order of operators is well defined and is done according to its precedence and associativity. However the evaluation order of operands for some of the binary operators is not defined. D left it undefined for assign operator. So in "a=b", the compiler can choose to evaluate a first and then b. However in "a=b=c", "b=c" has to be evaluated first due to right associativity of '=' operator. Similarly in "a=b+c", "b+c" has to be evaluated first due to higher precedence of + operator over = operator. In both these cases, the right operand of = operator is evaluated first and then the left operand. So it naturally follows that even in the unspecified case (a=b), the right operand should be evaluated first so that it is consistent with other cases of = operator. All this means, the evaluation order of operands also should be according to the associativity of its operator. You can test this with other right or left associative binary operators.

In a=b=c you have to do assignment b=c first, then assign a=b. But we're talking about _side effects_ here, i.e. a() = b() = c(). And you can evaluate the side effects in LTR order: a() = b() = c(); ==> auto tmp1 = &a(); auto tmp2 = &b(); *tmp2 = c(); *tmp1 = *tmp2; http://dpaste.dzfl.pl/19c118b7d368

Once the evaluation order of an operator is defined, it should be consistent in all the cases. Otherwise it will be very confusing to the programmer. - Sarath
Apr 02 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On 2 April 2014 15:04, Sarath Kodali <sarath dummy.com> wrote:
 On Wednesday, 2 April 2014 at 08:02:36 UTC, Iain Buclaw wrote:
 On 2 Apr 2014 09:52, "Sarath Kodali" <sarath dummy.com> wrote:
 On Tuesday, 1 April 2014 at 22:04:43 UTC, Timon Gehr wrote:
 On 04/01/2014 08:40 PM, Sarath Kodali wrote:
 ...

 The evaluation order of assign operators should not be LTR as they have
 right associativity. In "a = b = c", c has to be evaluated first, then
 b
 and then a. Similarly, in "a = b + c", "b+c" has to be evaluated first
 before a is evaluated. Otherwise it will be very confusing, that in
 some
 cases it is LTR and in some it is RTL.

Note that this is after a paragraph that suggests to make evaluation in


some cases LTR and in some RTL.

There are 2 evaluation orders that need to be considered while evaluating

expressions - the evaluation order of operators and the the evaluation order of operands of an operator. The evaluation order of operators is well defined and is done according to its precedence and associativity. However the evaluation order of operands for some of the binary operators is not defined. D left it undefined for assign operator. So in "a=b", the compiler can choose to evaluate a first and then b. However in "a=b=c", "b=c" has to be evaluated first due to right associativity of '=' operator. Similarly in "a=b+c", "b+c" has to be evaluated first due to higher precedence of + operator over = operator. In both these cases, the right operand of = operator is evaluated first and then the left operand. So it naturally follows that even in the unspecified case (a=b), the right operand should be evaluated first so that it is consistent with other cases of = operator. All this means, the evaluation order of operands also should be according to the associativity of its operator. You can test this with other right or left associative binary operators.
 Other binary operators like "+" have left associativity, and hence
 evaluation for these should be LTR as mentioned in D spec.
 ...

What's the presumed relation between associativity and evaluation order? In particular, the ternary operator ?: is right associative. How on


earth are you going to evaluate it right to left?
 The C spec requires that the function arguments are to be pushed in RTL
 order.

[citation needed]

You can get that info from any C ABI doc from Intel or AMD or some other

arch.

That's order of pushing arguments, not order of evaluation. Also, heavy stress on the words *Intel* and *AMD*. That is in no way a C standard. :)

Please do not get confused between operands evaluation order in an expression and arguments passing order to a function. Those are two different things. I was talking about both of them because both of them are involved in the evaluation of a()[] = b()[] + c()[]. To a programmer this is an expression that should follow expression evaluation rules. To a compiler implementer, this is a builtin function call whose arguments should be evaluated such that the expression evaluation rules are not broken.

Right. But order of evaluation is Language-specific, order of pushing arguments is Target-specific. Both are completely indifferent from each other, and this is what I think you are not understanding.
 If you read the last para in my first post, I was talking about argument
 pushing order *not* evaluation order for function args. The function
 argument passing order (called calling convention) is not defined by C spec,
 but by C ABI spec of any architecture. In all the C calling conventions, the
 first few arguments are passed in registers and the remaining on the stack.
 On Linux+x86, all the arguments are passed on the stack. For C, the
 arguments that are passed on the stack are in reverse order i.e RTL. Since
 the proposal was to change the argument evaluation order for extern(C)
 functions,

And the pushing order is unaffected, so why bring it up in the first place?
 I was merely pointing out that this will have an impact on the
 dmd backend because it uses pushl instructions. Notice that for extern (C)
 functions, the argument evaluation order and argument pushing order is same.
 So dmd evaluates an argument and pushes it immediately. If the evaluation
 order is opposite to that of the pushing order, then it cannot immediately
 push the argument that it has evaluated. However if it uses movl
 instructions as is done by gcc backend, then there is no issue.

Actually, the gcc backend does the same if the parameter passed has not had all side effects removed from it.
Apr 02 2014
prev sibling next sibling parent "Sarath Kodali" <sarath dummy.com> writes:
On Wednesday, 2 April 2014 at 14:43:44 UTC, Iain Buclaw wrote:
 Please do not get confused between operands evaluation order 
 in an
 expression and arguments passing order to a function. Those 
 are two
 different things. I was talking about both of them because 
 both of them are
 involved in the evaluation of a()[] = b()[] + c()[]. To a 
 programmer this is
 an expression that should follow expression evaluation rules. 
 To a compiler
 implementer, this is a builtin function call whose arguments 
 should be
 evaluated such that the expression evaluation rules are not 
 broken.

Right. But order of evaluation is Language-specific, order of pushing arguments is Target-specific. Both are completely indifferent from each other, and this is what I think you are not understanding.

I know what is evaluation order and argument passing order. And more importantly, the discussion is about the *evaluation order* of "a()[] = b()[] + c()[]" and not about what I understand or don't! So if you have any valid points that says why this expression should be evaluated in LTR order (i.e. first a then b and then c) let us discuss that. You can write a small code that evaluates "a()[] = b()[] + c()[]" before and after the proposed modifications and check whether the evaluation order is same w.r.t dmd. DMD v2.64 evaluates first b, then c and then a. This behaviour conforms to the D spec.
 If you read the last para in my first post, I was talking 
 about argument
 pushing order *not* evaluation order for function args. The 
 function
 argument passing order (called calling convention) is not 
 defined by C spec,
 but by C ABI spec of any architecture. In all the C calling 
 conventions, the
 first few arguments are passed in registers and the remaining 
 on the stack.
 On Linux+x86, all the arguments are passed on the stack. For 
 C, the
 arguments that are passed on the stack are in reverse order 
 i.e RTL. Since
 the proposal was to change the argument evaluation order for 
 extern(C)
 functions,

And the pushing order is unaffected, so why bring it up in the first place?

Let me take an example to explain what I'm trying to say. extern (C) int foo(int a, int b); void main(void) { foo(a(), b()); } With RTL function argument evaluation order and with push instructions, the above code gets compiled by dmd as (only relevant asm code shown) (on x86) main: call b push %eax call a push %eax call foo Now if the evaluation order of function args is changed to LTR, the new asm code would be main: call a mov %eax, %esi call b push %eax push %esi call foo Notice the additional mov instruction to save the return value of a() in a temporary. This is the impact that I'm talking about. Now if dmd backend uses mov instructions to push args on to the stack instead of push, then there will not be a need for temporary. But the code size will increase as push is only 1 byte where as mov %eax offset(%esp) is 3 to 4 bytes long. Asm code with LTR func args evaluation order for extern(C) foo with mov instrs main: call a mov %eax, (%esp) call b mov %eax, 0x4(%esp) call foo Notice that the args are still pushed in RTL order.
 I was merely pointing out that this will have an impact on the
 dmd backend because it uses pushl instructions. Notice that 
 for extern (C)
 functions, the argument evaluation order and argument pushing 
 order is same.
 So dmd evaluates an argument and pushes it immediately. If the 
 evaluation
 order is opposite to that of the pushing order, then it cannot 
 immediately
 push the argument that it has evaluated. However if it uses 
 movl
 instructions as is done by gcc backend, then there is no issue.

Actually, the gcc backend does the same if the parameter passed has not had all side effects removed from it.

- Sarath
Apr 02 2014
prev sibling next sibling parent Iain Buclaw <ibuclaw gdcproject.org> writes:
--001a11c0f62ca30d8904f61456b7
Content-Type: text/plain; charset=ISO-8859-1

On 2 Apr 2014 21:00, "Sarath Kodali" <sarath dummy.com> wrote:
 On Wednesday, 2 April 2014 at 14:43:44 UTC, Iain Buclaw wrote:
 Please do not get confused between operands evaluation order in an
 expression and arguments passing order to a function. Those are two
 different things. I was talking about both of them because both of them



 involved in the evaluation of a()[] = b()[] + c()[]. To a programmer



 an expression that should follow expression evaluation rules. To a



 implementer, this is a builtin function call whose arguments should be
 evaluated such that the expression evaluation rules are not broken.

Right. But order of evaluation is Language-specific, order of pushing arguments is Target-specific. Both are completely indifferent from each other, and this is what I think you are not understanding.


the discussion is about the *evaluation order* of "a()[] = b()[] + c()[]" and not about what I understand or don't! So if you have any valid points that says why this expression should be evaluated in LTR order (i.e. first a then b and then c) let us discuss that.
 You can write a small code that evaluates "a()[] = b()[] + c()[]" before

is same w.r.t dmd. DMD v2.64 evaluates first b, then c and then a. This behaviour conforms to the D spec.

Array ops follow a different behaviour to what is what normally expected. In a() = b() + c(), the order is abc, not bca. The fact that the current behaviour is written in the spec is not a good reason to keep it.
 If you read the last para in my first post, I was talking about argument
 pushing order *not* evaluation order for function args. The function
 argument passing order (called calling convention) is not defined by C



 but by C ABI spec of any architecture. In all the C calling



 first few arguments are passed in registers and the remaining on the



 On Linux+x86, all the arguments are passed on the stack. For C, the
 arguments that are passed on the stack are in reverse order i.e RTL.



 the proposal was to change the argument evaluation order for extern(C)
 functions,

And the pushing order is unaffected, so why bring it up in the first



Let me take an example to explain what I'm trying to say. extern (C) int foo(int a, int b); void main(void) { foo(a(), b()); } With RTL function argument evaluation order and with push instructions,

x86)
 main:
    call b
    push %eax
    call a
    push %eax
    call foo

 Now if the evaluation order of function args is changed to LTR, the new

 main:
     call a
     mov %eax, %esi
     call b
     push %eax
     push %esi
     call foo

 Notice the additional mov instruction to save the return value of a() in

uses mov instructions to push args on to the stack instead of push, then there will not be a need for temporary. But the code size will increase as push is only 1 byte where as mov %eax offset(%esp) is 3 to 4 bytes long.
 Asm code with LTR func args evaluation order for extern(C) foo with mov

 main:
      call a
      mov %eax, (%esp)
      call b
      mov %eax, 0x4(%esp)
      call foo

 Notice that the args are still pushed in RTL order.

Your point? --001a11c0f62ca30d8904f61456b7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <p dir=3D"ltr"><br> On 2 Apr 2014 21:00, &quot;Sarath Kodali&quot; &lt;<a href=3D"mailto:sarath= dummy.com">sarath dummy.com</a>&gt; wrote:<br> &gt;<br> &gt; On Wednesday, 2 April 2014 at 14:43:44 UTC, Iain Buclaw wrote:<br> &gt;&gt;&gt;<br> &gt;&gt;&gt;<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; Please do not get confused between operands evaluation order i= n an<br> &gt;&gt;&gt; expression and arguments passing order to a function. Those ar= e two<br> &gt;&gt;&gt; different things. I was talking about both of them because bot= h of them are<br> &gt;&gt;&gt; involved in the evaluation of a()[] =3D b()[] + c()[]. To a pr= ogrammer this is<br> &gt;&gt;&gt; an expression that should follow expression evaluation rules. = To a compiler<br> &gt;&gt;&gt; implementer, this is a builtin function call whose arguments s= hould be<br> &gt;&gt;&gt; evaluated such that the expression evaluation rules are not br= oken.<br> &gt;&gt;&gt;<br> &gt;&gt;<br> &gt;&gt; Right. =A0But order of evaluation is Language-specific, order of p= ushing<br> &gt;&gt; arguments is Target-specific. =A0Both are completely indifferent f= rom<br> &gt;&gt; each other, and this is what I think you are not understanding.<br=

&gt;&gt;<br> &gt; I started my career, 19 years back, as a C compiler developer. So I kn= ow what is evaluation order and argument passing order. And more importantl= y, the discussion is about the *evaluation order* of &quot;a()[] =3D b()[] = + c()[]&quot; and not about what I understand or don&#39;t! So if you have = any valid points that says why this expression should be evaluated in LTR o= rder (i.e. first a then b and then c) let us discuss that.<br> &gt; You can write a small code that evaluates &quot;a()[] =3D b()[] + c()[= ]&quot; before and after the proposed modifications and check whether the e= valuation order is same w.r.t dmd. DMD v2.64 evaluates first b, then c and = then a. This behaviour conforms to the D spec.<br> &gt;</p> <p dir=3D"ltr">Array ops follow a different behaviour to what is what norma= lly expected.=A0 In a() =3D b() + c(), the order is abc, not bca.</p> <p dir=3D"ltr">The fact that the current behaviour is written in the spec i= s not a good reason to keep it.<br></p> <p dir=3D"ltr">&gt;&gt;&gt; If you read the last para in my first post, I w= as talking about argument<br> &gt;&gt;&gt; pushing order *not* evaluation order for function args. The fu= nction<br> &gt;&gt;&gt; argument passing order (called calling convention) is not defi= ned by C spec,<br> &gt;&gt;&gt; but by C ABI spec of any architecture. In all the C calling co= nventions, the<br> &gt;&gt;&gt; first few arguments are passed in registers and the remaining = on the stack.<br> &gt;&gt;&gt; On Linux+x86, all the arguments are passed on the stack. For C= , the<br> &gt;&gt;&gt; arguments that are passed on the stack are in reverse order i.= e RTL. Since<br> &gt;&gt;&gt; the proposal was to change the argument evaluation order for e= xtern(C)<br> &gt;&gt;&gt; functions,<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; And the pushing order is unaffected, so why bring it up in the fir= st place?<br> &gt;&gt;<br> &gt;<br> &gt; Let me take an example to explain what I&#39;m trying to say.<br> &gt;<br> &gt; extern (C) int foo(int a, int b);<br> &gt;<br> &gt; void main(void)<br> &gt; {<br> &gt; =A0 =A0 foo(a(), b());<br> &gt; }<br> &gt;<br> &gt; With RTL function argument evaluation order and with push instructions= , the above code gets compiled by dmd as (only relevant asm code shown) (on= x86)<br> &gt;<br> &gt; main:<br> &gt; =A0 =A0call b<br> &gt; =A0 =A0push %eax<br> &gt; =A0 =A0call a<br> &gt; =A0 =A0push %eax<br> &gt; =A0 =A0call foo<br> &gt;<br> &gt; Now if the evaluation order of function args is changed to LTR, the ne= w asm code would be<br> &gt;<br> &gt; main:<br> &gt; =A0 =A0 call a<br> &gt; =A0 =A0 mov %eax, %esi<br> &gt; =A0 =A0 call b<br> &gt; =A0 =A0 push %eax<br> &gt; =A0 =A0 push %esi<br> &gt; =A0 =A0 call foo<br> &gt;<br> &gt; Notice the additional mov instruction to save the return value of a() = in a temporary. =A0This is the impact that I&#39;m talking about. Now if dm= d backend uses mov instructions to push args on to the stack instead of pus= h, then there will not be a need for temporary. But the code size will incr= ease as push is only 1 byte where as mov %eax offset(%esp) is 3 to 4 bytes = long.<br> &gt;<br> &gt; Asm code with LTR func args evaluation order for extern(C) foo with mo= v instrs<br> &gt; main:<br> &gt; =A0 =A0 =A0call a<br> &gt; =A0 =A0 =A0mov %eax, (%esp)<br> &gt; =A0 =A0 =A0call b<br> &gt; =A0 =A0 =A0mov %eax, 0x4(%esp)<br> &gt; =A0 =A0 =A0call foo<br> &gt;<br> &gt; Notice that the args are still pushed in RTL order.<br> &gt;</p> <p dir=3D"ltr">Your point?<br> </p> --001a11c0f62ca30d8904f61456b7--
Apr 02 2014
prev sibling parent Kenji Hara via Digitalmars-d <digitalmars-d puremagic.com> writes:
--047d7b873762519c9505045d7836
Content-Type: text/plain; charset=UTF-8

Now I'm working to fix issue 6620

https://issues.dlang.org/show_bug.cgi?id=6620
https://github.com/D-Programming-Language/dmd/pull/4035

Kenji Hara

2014-04-01 20:49 GMT+09:00 Johannes Pfau <nospam example.com>:

 I started fixing GDC bug #8 (*) which is basically that array op
 evaluation order currently depends on the target architecture. Consider
 this example:
 a()[] = b()[] + c()[];
 The order in which c,a,b are called is currently architecture specific.
 As stated in that bug report by Andrei we want this to evaluate LTR, so
 a() first, then b(), then c().

 These operations are actually rewritten to calls to extern(C)
 functions. Arguments to C function should be evaluated LTR as well, but
 dmd currently evaluates them RTL (GDC: architecture dependent). In order
 to fix the array op bug in gdc we have to define the evaluation order
 for extern(C) function parameters.

 So I've changed extern(C) functions to evaluate LTR in GDC and then had
 to change the array op code, cause that assumed extern(C) function
 evaluate RTL. Now I'd like to push these array op changes into dmd as we
 want to keep as few gdc specific changes as possible and dmd (and ldc)
 will need these changes anyway as soon as they implement extern(C)
 functions as LTR. This is required by dmd issue #6620 (**) and the
 language spec (***).

 However, if we apply only these changes the array op order reverses for
 DMD as it evaluates extern(C) function arguments RTL.

 So I need someone with dmd backend knowledge to fix the evaluation
 order of extern(C) function parameters to be LTR.
 Evaluation order of assignments should also be fixed to be LTR in the
 dmd backend. Although not strictly required for the array op changes
 it'd be inconsistent to have array op assignments execute LTR but
 normal assignments RTL:
 a()[] = b()[] + c()[]; //Array op assignment
 a() = b() + c();       //Normal assignment
  |      |    |
  1      2    3

 The frontend changes for dmd are here:
 https://github.com/jpf91/dmd/tree/fixOrder
 Frontend:

 https://github.com/jpf91/dmd/commit/5d61b812977dbdc1f99100e2fbaf1f45e9d25b03
 Test cases:

 https://github.com/jpf91/dmd/commit/82bffe0862b272f02c27cc428b22a7dd113b4a07

 Druntime changes (need to be applied at the same time as dmd changes)
 https://github.com/jpf91/druntime/tree/fixOrder

 https://github.com/jpf91/druntime/commit/f3f6f49c595d4fb25fb298e435ad1874abac516d


 (*)   http://bugzilla.gdcproject.org/show_bug.cgi?id=8
 (**)  https://d.puremagic.com/issues/show_bug.cgi?id=6620
 (***) https://github.com/D-Programming-Language/dlang.org/pull/6

--047d7b873762519c9505045d7836 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra">Now I&#39;m working to fix issu= e 6620</div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra"=
<a href=3D"https://issues.dlang.org/show_bug.cgi?id=3D6620">https://issues=

ef=3D"https://github.com/D-Programming-Language/dmd/pull/4035">https://gith= ub.com/D-Programming-Language/dmd/pull/4035</a></div><div class=3D"gmail_ex= tra"><br></div><div class=3D"gmail_extra">Kenji Hara</div><div class=3D"gma= il_extra"><br><div class=3D"gmail_quote">2014-04-01 20:49 GMT+09:00 Johanne= s Pfau <span dir=3D"ltr">&lt;<a href=3D"mailto:nospam example.com" target= =3D"_blank">nospam example.com</a>&gt;</span>:<br><blockquote class=3D"gmai= l_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-lef= t-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I starte= d fixing GDC bug #8 (*) which is basically that array op<br> evaluation order currently depends on the target architecture. Consider<br> this example:<br> a()[] =3D b()[] + c()[];<br> The order in which c,a,b are called is currently architecture specific.<br> As stated in that bug report by Andrei we want this to evaluate LTR, so<br> a() first, then b(), then c().<br> <br> These operations are actually rewritten to calls to extern(C)<br> functions. Arguments to C function should be evaluated LTR as well, but<br> dmd currently evaluates them RTL (GDC: architecture dependent). In order<br=

for extern(C) function parameters.<br> <br> So I&#39;ve changed extern(C) functions to evaluate LTR in GDC and then had= <br> to change the array op code, cause that assumed extern(C) function<br> evaluate RTL. Now I&#39;d like to push these array op changes into dmd as w= e<br> want to keep as few gdc specific changes as possible and dmd (and ldc)<br> will need these changes anyway as soon as they implement extern(C)<br> functions as LTR. This is required by dmd issue #6620 (**) and the<br> language spec (***).<br> <br> However, if we apply only these changes the array op order reverses for<br> DMD as it evaluates extern(C) function arguments RTL.<br> <br> So I need someone with dmd backend knowledge to fix the evaluation<br> order of extern(C) function parameters to be LTR.<br> Evaluation order of assignments should also be fixed to be LTR in the<br> dmd backend. Although not strictly required for the array op changes<br> it&#39;d be inconsistent to have array op assignments execute LTR but<br> normal assignments RTL:<br> a()[] =3D b()[] + c()[]; //Array op assignment<br> a() =3D b() + c();=C2=A0 =C2=A0 =C2=A0 =C2=A0//Normal assignment<br> =C2=A0|=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 |<br> =C2=A01=C2=A0 =C2=A0 =C2=A0 2=C2=A0 =C2=A0 3<br> <br> The frontend changes for dmd are here:<br> <a href=3D"https://github.com/jpf91/dmd/tree/fixOrder" target=3D"_blank">ht= tps://github.com/jpf91/dmd/tree/fixOrder</a><br> Frontend:<br> <a href=3D"https://github.com/jpf91/dmd/commit/5d61b812977dbdc1f99100e2fbaf= 1f45e9d25b03" target=3D"_blank">https://github.com/jpf91/dmd/commit/5d61b81= 2977dbdc1f99100e2fbaf1f45e9d25b03</a><br> Test cases:<br> <a href=3D"https://github.com/jpf91/dmd/commit/82bffe0862b272f02c27cc428b22= a7dd113b4a07" target=3D"_blank">https://github.com/jpf91/dmd/commit/82bffe0= 862b272f02c27cc428b22a7dd113b4a07</a><br> <br> Druntime changes (need to be applied at the same time as dmd changes)<br> <a href=3D"https://github.com/jpf91/druntime/tree/fixOrder" target=3D"_blan= k">https://github.com/jpf91/druntime/tree/fixOrder</a><br> <a href=3D"https://github.com/jpf91/druntime/commit/f3f6f49c595d4fb25fb298e= 435ad1874abac516d" target=3D"_blank">https://github.com/jpf91/druntime/comm= it/f3f6f49c595d4fb25fb298e435ad1874abac516d</a><br> <br> <br> (*)=C2=A0 =C2=A0<a href=3D"http://bugzilla.gdcproject.org/show_bug.cgi?id= =3D8" target=3D"_blank">http://bugzilla.gdcproject.org/show_bug.cgi?id=3D8<= /a><br> (**)=C2=A0 <a href=3D"https://d.puremagic.com/issues/show_bug.cgi?id=3D6620= " target=3D"_blank">https://d.puremagic.com/issues/show_bug.cgi?id=3D6620</= a><br> (***) <a href=3D"https://github.com/D-Programming-Language/dlang.org/pull/6= " target=3D"_blank">https://github.com/D-Programming-Language/dlang.org/pul= l/6</a><br> </blockquote></div><br></div></div> --047d7b873762519c9505045d7836--
Oct 01 2014