Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static array and array literal improvements #375

Merged
merged 5 commits into from May 8, 2012

Conversation

9rnsr
Copy link
Contributor

@9rnsr 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
Copy link
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
Copy link
Contributor Author

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
Copy link
Collaborator

donc commented Sep 10, 2011

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

@9rnsr
Copy link
Contributor Author

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
Copy link
Contributor Author

9rnsr commented Sep 14, 2011

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

@Trass3r
Copy link
Contributor

Trass3r commented Nov 7, 2011

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

@9rnsr
Copy link
Contributor Author

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
Copy link
Member

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

9rnsr added 5 commits May 5, 2012 16:17
…unction parameter

Call dtor of static array parameter at function scope end.
…ction argument

call element postblits of static array on function argument
- Call postblits on array slice assign
- Call postblits on array literal elements
@9rnsr
Copy link
Contributor Author

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
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
Labels
None yet
Projects
None yet
5 participants