Bug 20734 – Array literals as arguments to scope slice parameters should be stack-allocated

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-04-13T14:36:31Z
Last change time
2022-06-07T17:25:03Z
Keywords
pull
Assigned to
No Owner
Creator
kinke
See also
https://issues.dlang.org/show_bug.cgi?id=21291, https://issues.dlang.org/show_bug.cgi?id=22306, https://issues.dlang.org/show_bug.cgi?id=23170

Comments

Comment #0 by kinke — 2020-04-13T14:36:31Z
This currently fails to compile: void foo() nothrow @safe @nogc { int[5] a = [ 1, 2, 3, 4, 5 ]; _d_assert_fail!("==")(a, [ 1, 2, 3, 4, 5 ]); // fails: non-nogc } // void _d_assert_fail!("==")(ref const(int[5]) a, scope const(int[]) b) void _d_assert_fail(string comp, A, B)(auto ref const scope A a, auto ref const scope B b) {} The problem is that the array literal is needlessly allocated by the GC, although _d_assert_fail is not going to escape any reference to its data, and a stack allocation would do just fine, making this work for -betterC as well as eliminating one hurdle towards compiling the Phobos unittests with -checkaction=context.
Comment #1 by dlang-bot — 2020-04-14T12:23:40Z
@kinke created dlang/dmd pull request #11039 "Fix issue 20734 - Allocate array literals as arguments to scope slice parameters on the stack" fixing this issue: - Fix issue 20734 - Allocate array literals as arguments to scope slice parameters on the stack https://github.com/dlang/dmd/pull/11039
Comment #2 by dlang-bot — 2020-04-15T18:31:22Z
dlang/dmd pull request #11039 "Fix issue 20734 - Allocate array literals as arguments to scope slice parameters on the stack" was merged into master: - f551f1b810d798a9ea9222e7e228ede32a90b6c2 by Martin Kinkelin: Fix issue 20734 - Allocate array literals as arguments to scope slice parameters on the stack https://github.com/dlang/dmd/pull/11039
Comment #3 by pro.mathias.lang — 2020-05-10T06:40:59Z
*** Issue 11657 has been marked as a duplicate of this issue. ***