Bug 12932 – Support @nogc for immediately iterated array literal

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-06-16T13:44:00Z
Last change time
2014-06-16T16:59:25Z
Keywords
pull
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2014-06-16T13:44:13Z
This code should work as expected. void main() @nogc { int sum; foreach (e; [1,2,3]) { sum += e; } assert(sum == 6); }
Comment #1 by k.hara.pg — 2014-06-16T13:52:34Z
Comment #2 by bearophile_hugs — 2014-06-16T14:14:54Z
This seems a nice improvement (if it's safe).
Comment #3 by github-bugzilla — 2014-06-16T15:06:13Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/dfb44a6d1f851eb9048ef459bf075f953a290fbf fix Issue 12932 - Support @nogc for immediately iterated array literal https://github.com/D-Programming-Language/dmd/commit/e719a3662657d58a2efeceff444b844eb0be1dcf Merge pull request #3673 from 9rnsr/fix12932 Issue 12932 - Support @nogc for immediately iterated array literal
Comment #4 by bearophile_hugs — 2014-06-16T15:41:23Z
Currently this gets rejected, is this right? void main() @nogc { foreach ( a; [[1]]) {} foreach (int[1] a; [[1]]) {} } test.d(2): Error: array literal in @nogc function main may cause GC allocation test.d(3): Error: array literal in @nogc function main may cause GC allocation
Comment #5 by bearophile_hugs — 2014-06-16T15:46:53Z
A better example: struct F { int x; } void main() @nogc { foreach ( a; [[1]]) {} // Error foreach (int[1] a; [[1]]) {} // Error foreach ( a; [F(1)]) {} // OK }
Comment #6 by k.hara.pg — 2014-06-16T16:10:34Z
(In reply to bearophile_hugs from comment #4) > Currently this gets rejected, is this right? > > void main() @nogc { > foreach ( a; [[1]]) {} > foreach (int[1] a; [[1]]) {} > } > > > test.d(2): Error: array literal in @nogc function main may cause GC > allocation > test.d(3): Error: array literal in @nogc function main may cause GC > allocation My PR does not support complex case. It would need more thought to improve the feature.
Comment #7 by bearophile_hugs — 2014-06-16T16:44:16Z
(In reply to Kenji Hara from comment #6) > My PR does not support complex case. It would need more thought to improve > the feature. OK. Do you want me to open another enhancement request, or do you want me to reopen this one, or do you think this improved feature is not worth implementing?
Comment #8 by k.hara.pg — 2014-06-16T16:48:57Z
(In reply to bearophile_hugs from comment #7) > OK. Do you want me to open another enhancement request, or do you want me to > reopen this one, or do you think this improved feature is not worth > implementing? If possible, I'd like to improve things. But it would need more time. Therefore openeng new encancement is the best.
Comment #9 by bearophile_hugs — 2014-06-16T16:59:25Z
(In reply to Kenji Hara from comment #8) > (In reply to bearophile_hugs from comment #7) > > OK. Do you want me to open another enhancement request, or do you want me to > > reopen this one, or do you think this improved feature is not worth > > implementing? > > If possible, I'd like to improve things. But it would need more time. > Therefore openeng new encancement is the best. OK, Issue 12936