Bug 16297 – Immutable data with statically-known initializer should be implicitly "static"

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-07-19T13:13:54Z
Last change time
2024-12-13T18:48:56Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Moved to GitHub: dmd#19158 →

Comments

Comment #0 by andrei — 2016-07-19T13:13:54Z
This came up during the review of https://github.com/dlang/dmd/pull/5938. Consider: int fun(ubyte[] b) { immutable ubyte[4] d = [0x7F, 'E', 'L', 'F']; return b[] == d[]; } int gun(ubyte[] b) { static immutable ubyte[4] d = [0x7F, 'E', 'L', 'F']; return b[] == d[]; } By http://goo.gl/mxaVKe, different code is generated for these functions; namely, the immutable data in fun() is initialized with every call. An optimization would allocate that data statically.
Comment #1 by robert.schadek — 2024-12-13T18:48:56Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19158 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB