Slice expressions - exact evaluation order, dollar

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 26 05:33:01 PDT 2016


On 26.06.2016 10:08, Iain Buclaw via Digitalmars-d wrote:
>
>      > Evaluation order should be strictly left-to-right. DMD and GDC
>     get it wrong
>      > here.
>      >
>
>     It is evaluated left-to-right. getBase() -> getLowerBound() ->
>     getUpperBound().
>
>
> Ah, I see what you mean.  I think you may be using an old GDC version.
> Before I used to cache the result of getBase().
>
> Old codegen:
>
> _base = *(getBase());
> _lwr = getLowerBound(_base.length);
> _upr = getUpperBound(_base.length);
> r = {.length=(_upr - _lwr), .ptr=_base.ptr + _lwr * 4};
>
> ---

This seems to be what I'd expect. It's also what CTFE does.
CTFE and run time behaviour should be identical. (So either one of them 
needs to be fixed.)


> Now when creating temporaries of references, the reference is stabilized
> instead.
>
> New codegen:
>
> *(_ptr = getBase());
> _lwr = getLowerBound(_ptr.length);
> _upr = getUpperBound(_ptr.length);
> r = {.length=(_upr - _lwr), .ptr=_ptr.ptr + _lwr * 4};
> ---
>
> I suggest you fix LDC if it doesn't already do this. :-)


I'm not convinced this is a good idea. It makes 
(()=>base)()[lwr()..upr()] behave differently from base[lwr()..upr()].


More information about the Digitalmars-d mailing list