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