Static array and array literal improvements #375

Merged
merged 5 commits into from May 8, 2012

Conversation

Projects
None yet
5 participants
@9rnsr
Member

9rnsr commented Sep 9, 2011

  • 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

This comment has been minimized.

Show comment
Hide comment
@donc

donc Sep 10, 2011

Collaborator

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.

Collaborator

donc commented Sep 10, 2011

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

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Sep 10, 2011

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.

Member

9rnsr commented Sep 10, 2011

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

This comment has been minimized.

Show comment
Hide comment
@donc

donc Sep 10, 2011

Collaborator

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

Collaborator

donc commented Sep 10, 2011

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

@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Sep 10, 2011

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.

Member

9rnsr commented Sep 10, 2011

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

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Sep 14, 2011

Member

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

Member

9rnsr commented Sep 14, 2011

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

@Trass3r

This comment has been minimized.

Show comment
Hide comment
@Trass3r

Trass3r Nov 7, 2011

Contributor

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

Contributor

Trass3r commented Nov 7, 2011

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

@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Nov 7, 2011

Member

Have all of Don's suggestions been implemented?

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

Member

9rnsr commented Nov 7, 2011

Have all of Don's suggestions been implemented?

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

@yebblies

This comment has been minimized.

Show comment
Hide comment
@yebblies

yebblies Jan 30, 2012

Member

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

Member

yebblies commented Jan 30, 2012

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

9rnsr added some commits Aug 26, 2011

Issue 6636 - Destructors of static array elements are not called on f…
…unction parameter

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

call element postblits of static array on function argument
Issue 6470 - postblits not called on arrays of structs
- Call postblits on array slice assign
- Call postblits on array literal elements
@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr May 5, 2012

Member

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

Member

9rnsr commented May 5, 2012

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

WalterBright added a commit that referenced this pull request May 8, 2012

Merge pull request #375 from 9rnsr/fixarrays
Static array and array literal improvements

@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