Skip to content

core/internal/array/utils.d: TraceHook support types with quotes in name - #21510

Merged
thewilsonator merged 1 commit into
dlang:stablefrom
the-horo:tracehook-fix
Jul 6, 2025
Merged

core/internal/array/utils.d: TraceHook support types with quotes in name#21510
thewilsonator merged 1 commit into
dlang:stablefrom
the-horo:tracehook-fix

Conversation

@the-horo

@the-horo the-horo commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

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.


I've hit this in the CI of dcd where dub build --profile=gc fails with:

2025-07-02T18:28:13.0112323Z     Building dcd:dsymbol 0.16.0-beta.3: building configuration [library]
2025-07-02T18:28:13.8846640Z /opt/hostedtoolcache/dmd/2.111.0/x64/dmd2/linux/bin64/../../src/druntime/import/core/internal/array/utils.d-mixin-94(98,830): Error: semicolon needed to end declaration of `name` instead of `trivia`
2025-07-02T18:28:13.8849145Z /opt/hostedtoolcache/dmd/2.111.0/x64/dmd2/linux/bin64/../../src/druntime/import/core/lifetime.d-mixin-3002(3006,847): Error: semicolon needed to end declaration of `name` instead of `trivia`
2025-07-02T18:28:13.8861060Z /opt/hostedtoolcache/dmd/2.111.0/x64/dmd2/linux/bin64/../../src/phobos/std/array.d(3588,16): Error: template instance `core.lifetime._d_newitemTTrace!(InPlaceAppender!(TokenStructure!(ubyte, "\n    import dparse.lexer : Token;\n\n    this(Token token) pure nothrow @safe @nogc {\n        this(token.type, token.text, token.line, token.column, token.index);\n    }\n\n    int opCmp(size_t i) const pure nothrow @safe @nogc {\n        if (index < i) return -1;\n        if (index > i) return 1;\n        return 0;\n    }\n\n    int opCmp(ref const typeof(this) other) const pure nothrow @safe @nogc {\n        return opCmp(other.index);\n    }\n\n    string toString() const @safe pure\n    {\n        import std.array : appender;\n\n        auto sink = appender!string;\n        toString(sink);\n        return sink.data;\n    }\n\n    void toString(R)(auto ref R sink) const\n    {\n        import std.conv : to;\n        import dparse.lexer : str;\n\n        sink.put(`trivia!\"`);\n        sink.put(str(type));\n        sink.put(`\"(`);\n        sink.put(\"text: \");\n        sink.put([text].to!string[1 .. $ - 1]); // escape hack\n        sink.put(\", index: \");\n        sink.put(index.to!string);\n        sink.put(\", line: \");\n        sink.put(line.to!string);\n        sink.put(\", column: \");\n        sink.put(column.to!string);\n        sink.put(\")\");\n    }\n")[]))` error instantiating
2025-07-02T18:28:13.8867415Z         impl = new InPlaceAppender!A(arr);
2025-07-02T18:28:13.8867851Z                ^
2025-07-02T18:28:13.8873549Z /opt/hostedtoolcache/dmd/2.111.0/x64/dmd2/linux/bin64/../../src/phobos/std/array.d(4494,1):        instantiated from here: `Appender!(TokenStructure!(ubyte, "\n    import dparse.lexer : Token;\n\n    this(Token token) pure nothrow @safe @nogc {\n        this(token.type, token.text, token.line, token.column, token.index);\n    }\n\n    int opCmp(size_t i) const pure nothrow @safe @nogc {\n        if (index < i) return -1;\n        if (index > i) return 1;\n        return 0;\n    }\n\n    int opCmp(ref const typeof(this) other) const pure nothrow @safe @nogc {\n        return opCmp(other.index);\n    }\n\n    string toString() const @safe pure\n    {\n        import std.array : appender;\n\n        auto sink = appender!string;\n        toString(sink);\n        return sink.data;\n    }\n\n    void toString(R)(auto ref R sink) const\n    {\n        import std.conv : to;\n        import dparse.lexer : str;\n\n        sink.put(`trivia!\"`);\n        sink.put(str(type));\n        sink.put(`\"(`);\n        sink.put(\"text: \");\n        sink.put([text].to!string[1 .. $ - 1]); // escape hack\n        sink.put(\", index: \");\n        sink.put(index.to!string);\n        sink.put(\", line: \");\n        sink.put(line.to!string);\n        sink.put(\", column: \");\n        sink.put(column.to!string);\n        sink.put(\")\");\n    }\n")[])`
2025-07-02T18:28:13.8879528Z Appender!A appender(A)()
2025-07-02T18:28:13.8879870Z ^
2025-07-02T18:28:13.8884998Z ../../../.dub/packages/libdparse/0.25.0/libdparse/src/dparse/lexer.d(568,58):        instantiated from here: `appender!(TokenStructure!(ubyte, "\n    import dparse.lexer : Token;\n\n    this(Token token) pure nothrow @safe @nogc {\n        this(token.type, token.text, token.line, token.column, token.index);\n    }\n\n    int opCmp(size_t i) const pure nothrow @safe @nogc {\n        if (index < i) return -1;\n        if (index > i) return 1;\n        return 0;\n    }\n\n    int opCmp(ref const typeof(this) other) const pure nothrow @safe @nogc {\n        return opCmp(other.index);\n    }\n\n    string toString() const @safe pure\n    {\n        import std.array : appender;\n\n        auto sink = appender!string;\n        toString(sink);\n        return sink.data;\n    }\n\n    void toString(R)(auto ref R sink) const\n    {\n        import std.conv : to;\n        import dparse.lexer : str;\n\n        sink.put(`trivia!\"`);\n        sink.put(str(type));\n        sink.put(`\"(`);\n        sink.put(\"text: \");\n        sink.put([text].to!string[1 .. $ - 1]); // escape hack\n        sink.put(\", index: \");\n        sink.put(index.to!string);\n        sink.put(\", line: \");\n        sink.put(line.to!string);\n        sink.put(\", column: \");\n        sink.put(column.to!string);\n        sink.put(\")\");\n    }\n")[])`
2025-07-02T18:28:13.8890838Z     auto leadingTriviaAppender = appender!(TriviaToken[])();
2025-07-02T18:28:13.8891374Z                                                          ^
2025-07-02T18:28:13.8892128Z dsymbol/src/dsymbol/modulecache.d(181,31):        instantiated from here: `getTokensForParser!(ubyte[])`
2025-07-02T18:28:13.8892923Z             tokens = getTokensForParser(
2025-07-02T18:28:13.8893344Z                                        ^
2025-07-02T18:28:14.0152750Z Error dmd failed with exit code 1.

@dlang-bot

dlang-bot commented Jul 6, 2025

Copy link
Copy Markdown

Thanks for your pull request and interest in making D better, @the-horo! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + dmd#21510"

@thewilsonator

Copy link
Copy Markdown
Contributor

If you need this for CI, do you want to target stable?

@the-horo

the-horo commented Jul 6, 2025

Copy link
Copy Markdown
Contributor Author

Nah, the dcd CI has been silently failing for a while (probably), I'm in no rush. Maybe the dcd maintainers would me interested though...

@the-horo

the-horo commented Jul 6, 2025

Copy link
Copy Markdown
Contributor Author

It should be failing since dlang-community/libdparse@92df030 from 2024-04 so >1 year ago

@thewilsonator

Copy link
Copy Markdown
Contributor

Well, we're about to have a release so it would be good to have, and unlikely to cause problems.

@the-horo
the-horo changed the base branch from master to stable July 6, 2025 12:00
@the-horo
the-horo requested a review from ibuclaw as a code owner July 6, 2025 12:00
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 <a.horodniceanu@proton.me>
@thewilsonator
thewilsonator merged commit cb0f80c into dlang:stable Jul 6, 2025
@dkorpel dkorpel mentioned this pull request Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants