Static array and array literal improvements #375

Merged
merged 5 commits into from May 8, 2012

Projects

None yet

5 participants

@9rnsr
D Programming Language member
  • Issue 3703 - static array assignment
    Check static-array length matching on assign expression.

  • Issue 5290 - Static array literals with too few elements
    Check static-array length matching on initialiging.

  • Issue 6470 - postblits not called on arrays of structs
    Call postblits of array literal elements correctly.

  • Issue 2356 - array literal as non static initializer generates horribly inefficient code
    If array literal is used as static-array initializer, the initializing is converted as initializings of elements.
    An initializing of static-array
    S[n] sa = [e0, e1, ..., en-1];
    is converted to
    sa[0] = e0, sa[1] = e1, ..., sa[n-1] = en-1;

  • Issue 6636 - Destructors of static array elements are not called on function parameter

  • Issue 6637 - Postblits of static array elements are not called on function argument

@donc

Your fix for bug 2356 is good when the array is small (length <= about 8), but a full fix would check if all elements are compile-time constants. If they are, create a const initializer, and blit it across.
There are some other optimization opportunities (eg, if most members of the array literals are zeros, or if there are only a couple of non-constants, perform a blit or zero-init first, and then fill in the gaps).

Also note that CTFE can create an array literal as well, so the transformation needs to happen in the glue layer, not in expression.c.

@9rnsr
D Programming Language member

Also note that CTFE can create an array literal as well, so the transformation needs to happen in the glue layer, not in expression.c.

I was able to move static array construction codes into AssignExp::toElem(), but I wasn't able to work the interpret() correctly.
Currently, it is difficult to me changing codes of interpret.c.

@donc

Interpret.c should not be changed. Array literals MUST survive until the glue layer.

@9rnsr
D Programming Language member

glue layer == e2ir.c ? (I think expression.c is front-end, and src/backend is backend layer.)
If so, I was able to survive array literals until the glue layer, see commit 662b5a3. But I that also means that survives array literals until interpret layer. At least, I had to change interpret.c to compile small sample code.

@9rnsr
D Programming Language member

Remove fixing 5290. Because it is not bug fix, it is enhancement.

@Trass3r

What prevents this from being merged?
Have all of Don's suggestions been implemented?

@9rnsr
D Programming Language member

Have all of Don's suggestions been implemented?

No, and I have no schedule to implement it in near future.

@yebblies
D Programming Language member

Could you please split this into several pull requests so the smaller issues can be fixed?

9rnsr added some commits Aug 26, 2011
@9rnsr 9rnsr Scanning past comma on AssignExp::e2 is not need, because it is alrea…
…dy processed at the starting of semantic.
aa7e809
@9rnsr 9rnsr Issue 3703 - static array assignment 6dfdd2d
@9rnsr 9rnsr Issue 6636 - Destructors of static array elements are not called on f…
…unction parameter

Call dtor of static array parameter at function scope end.
57d7f41
@9rnsr 9rnsr Issue 6637 - Postblits of static array elements are not called on fun…
…ction argument

call element postblits of static array on function argument
2f09427
@9rnsr 9rnsr Issue 6470 - postblits not called on arrays of structs
- Call postblits on array slice assign
- Call postblits on array literal elements
26aacf0
@9rnsr
D Programming Language member

Remove commit for bug 2356, and reconstructed commits.
Now, there are fixes for only postblit/destructor and array literal/static array problems.

@WalterBright WalterBright merged commit 385fd46 into dlang:master May 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment