Skip to content

Commit cb0f80c

Browse files
authored
core/internal/array/utils.d: TraceHook support types with quotes in name (#21510)
Avoid directly mixin'ing the result of T.stringof for arbitrary types since that proves problematic with string parameters to templates with their quote and other special characters. Signed-off-by: Andrei Horodniceanu <[email protected]>
1 parent 8ab5cad commit cb0f80c

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// REQUIRED_ARGS: -profile=gc
2+
struct T(string s) {}
3+
alias TypeWithQuotes = T!q"EOS
4+
`"'}])>
5+
EOS";
6+
7+
void foo() {
8+
TypeWithQuotes[] arr;
9+
arr ~= TypeWithQuotes();
10+
}

druntime/src/core/internal/array/appending.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ version (D_ProfileGC)
5757
version (D_TypeInfo)
5858
{
5959
import core.internal.array.utils: TraceHook, gcStatsPure, accumulatePure;
60-
mixin(TraceHook!(Tarr.stringof, "_d_arrayappendcTX"));
60+
mixin(TraceHook!("Tarr", "_d_arrayappendcTX"));
6161

6262
return _d_arrayappendcTX(px, n);
6363
}
@@ -120,7 +120,7 @@ version (D_ProfileGC)
120120
version (D_TypeInfo)
121121
{
122122
import core.internal.array.utils: TraceHook, gcStatsPure, accumulatePure;
123-
mixin(TraceHook!(Tarr.stringof, "_d_arrayappendT"));
123+
mixin(TraceHook!("Tarr", "_d_arrayappendT"));
124124

125125
return _d_arrayappendT(x, y);
126126
}

druntime/src/core/internal/array/concatenation.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ version (D_ProfileGC)
174174
version (D_TypeInfo)
175175
{
176176
import core.internal.array.utils: TraceHook, gcStatsPure, accumulatePure;
177-
mixin(TraceHook!(Tarr.stringof, "_d_arraycatnTX"));
177+
mixin(TraceHook!("Tarr", "_d_arraycatnTX"));
178178

179179
import core.lifetime: forward;
180180
return _d_arraycatnTX!Tret(forward!froms);

druntime/src/core/internal/array/construction.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ version (D_ProfileGC)
475475
version (D_TypeInfo)
476476
{
477477
import core.internal.array.utils : TraceHook, gcStatsPure, accumulatePure;
478-
mixin(TraceHook!(T.stringof, "_d_newarrayT"));
478+
mixin(TraceHook!("T", "_d_newarrayT"));
479479

480480
return _d_newarrayT!T(length, isShared);
481481
}
@@ -607,7 +607,7 @@ version (D_ProfileGC)
607607
version (D_TypeInfo)
608608
{
609609
import core.internal.array.utils : TraceHook, gcStatsPure, accumulatePure;
610-
mixin(TraceHook!(T.stringof, "_d_newarraymTX"));
610+
mixin(TraceHook!("T", "_d_newarraymTX"));
611611

612612
return _d_newarraymTX!(Tarr, T)(dims, isShared);
613613
}

druntime/src/core/internal/array/utils.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ version (D_ProfileGC)
4141
/**
4242
* TraceGC wrapper generator around the runtime hook `Hook`.
4343
* Params:
44-
* Type = The type of hook to report to accumulate
44+
* TypeIdent = The symbol of the type of hook to report to accumulate
4545
* Hook = The name hook to wrap
4646
*/
47-
template TraceHook(string Type, string Hook)
47+
template TraceHook(string TypeIdent, string Hook)
4848
{
4949
const char[] TraceHook = q{
5050
import core.internal.array.utils : gcStatsPure, accumulatePure;
5151

5252
pragma(inline, false);
53-
string name = } ~ "`" ~ Type ~ "`;" ~ q{
53+
string name = } ~ TypeIdent ~ q{.stringof;
5454

5555
// FIXME: use rt.tracegc.accumulator when it is accessable in the future.
5656
ulong currentlyAllocated = gcStatsPure().allocatedInCurrentThread;
@@ -91,7 +91,7 @@ version (D_ProfileGC)
9191
{
9292
version (D_TypeInfo)
9393
{
94-
mixin(TraceHook!(T.stringof, __traits(identifier, Hook)));
94+
mixin(TraceHook!("T", __traits(identifier, Hook)));
9595
return Hook(parameters);
9696
}
9797
else

druntime/src/core/lifetime.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,7 +2793,7 @@ T _d_newclassTTrace(T)(string file = __FILE__, int line = __LINE__, string funcn
27932793
version (D_TypeInfo)
27942794
{
27952795
import core.internal.array.utils : TraceHook, gcStatsPure, accumulatePure;
2796-
mixin(TraceHook!(T.stringof, "_d_newclassT"));
2796+
mixin(TraceHook!("T", "_d_newclassT"));
27972797

27982798
return _d_newclassT!T();
27992799
}
@@ -2999,7 +2999,7 @@ version (D_ProfileGC)
29992999
}
30003000

30013001
import core.internal.array.utils : TraceHook, gcStatsPure, accumulatePure;
3002-
mixin(TraceHook!(T.stringof, "_d_newitemT"));
3002+
mixin(TraceHook!("T", "_d_newitemT"));
30033003

30043004
return _d_newitemT!T();
30053005
}

0 commit comments

Comments
 (0)