Bug 24330 – Redundant template instantiations for equal string/array literals

Status
NEW
Severity
enhancement
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-01-11T14:49:42Z
Last change time
2024-12-13T19:32:30Z
Assigned to
No Owner
Creator
Dennis
See also
https://issues.dlang.org/show_bug.cgi?id=8660
Moved to GitHub: dmd#20379 →

Comments

Comment #0 by dkorpel — 2024-01-11T14:49:42Z
``` void g(string T)() { pragma(msg, "g ", T, " ", T.stringof); } void h(ubyte[] T)() { pragma(msg, "h ", T, " ", T.stringof); } void main() { g!"a"(); g!(['a'])(); h!(cast(ubyte[])"a")(); h!(['a'])(); } ``` Prints: ``` g a "a" g a ['a'] h a "a" h [cast(ubyte)97u] [cast(ubyte)97u] ``` Showing multiple instantiations are made. This is because internally, StringExp and ArrayLiteralExp are hashed/mangled differently. An improvement would be to consistently convert one to the other if possible.
Comment #1 by dkorpel — 2024-01-12T17:21:49Z
Related issue: ```D void f(int[] b)() { } void main() { enum dstring s = (""d ~ cast(dchar) 0xFFFF_FFFF); f!(cast(int[]) s ~ []); // works f!(cast(int[]) s); // invalid UCS-32 char \Uffffffff } ``` Fails because it tries to mangle the int[] as a string because it's a StringExp.
Comment #2 by robert.schadek — 2024-12-13T19:32:30Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20379 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB