From 2822bac9b773909786a444c7d196329df2eabf04 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Tue, 31 Dec 2024 12:41:33 +0800 Subject: [PATCH 1/2] [druntime/object.d] add public imports for `core.interpolation` --- compiler/test/fail_compilation/imphint.d | 6 +++--- druntime/src/object.d | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler/test/fail_compilation/imphint.d b/compiler/test/fail_compilation/imphint.d index 7ca81f47aa5d..6b1a290493ab 100644 --- a/compiler/test/fail_compilation/imphint.d +++ b/compiler/test/fail_compilation/imphint.d @@ -45,9 +45,6 @@ fail_compilation/imphint.d(102): Error: `startsWith` is not defined, perhaps `im fail_compilation/imphint.d(103): Error: `take` is not defined, perhaps `import std.range;` is needed? fail_compilation/imphint.d(104): Error: `text` is not defined, perhaps `import std.conv;` is needed? fail_compilation/imphint.d(105): Error: `to` is not defined, perhaps `import std.conv;` is needed? -fail_compilation/imphint.d(107): Error: `InterpolationHeader` is not defined, perhaps `import core.interpolation;` ? -fail_compilation/imphint.d(108): Error: template `heresy` is not callable using argument types `!()(InterpolationHeader, InterpolationFooter)` -fail_compilation/imphint.d(107): Candidate is: `heresy(Args...)(InterpolationHeader header, Args args, InterpolationFooter footer)` --- */ @@ -55,6 +52,9 @@ fail_compilation/imphint.d(107): Candidate is: `heresy(Args...)(Interpola + + + void foo() { printf("hello world\n"); diff --git a/druntime/src/object.d b/druntime/src/object.d index 565f6a1b15c6..3d852399e778 100644 --- a/druntime/src/object.d +++ b/druntime/src/object.d @@ -4721,6 +4721,11 @@ public import core.lifetime : _d_newclassT; public import core.lifetime : _d_newclassTTrace; public import core.lifetime : _d_newitemT; +public import core.interpolation : InterpolationHeader; +public import core.interpolation : InterpolationFooter; +public import core.interpolation : InterpolatedLiteral; +public import core.interpolation : InterpolatedExpression; + public @trusted @nogc nothrow pure extern (C) void _d_delThrowable(scope Throwable); // Compare class and interface objects for ordering. From dea60e812bad01c1e652aeabc54bf237bfc21873 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Tue, 31 Dec 2024 13:49:56 +0800 Subject: [PATCH 2/2] [expressionsem.d] generate direct references for `InterpolationHeader/Footer` --- compiler/src/dmd/expressionsem.d | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 413d31a6339f..0cac83e3ab0a 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -4294,9 +4294,9 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor // we need to turn that into: /+ tuple( - .object.imported!"core.interpolation".InterpolationHeader(), + InterpolationHeader(), ... - .object.imported!"core.interpolation".InterpolationFooter() + InterpolationFooter() ) There the ... loops through them all, making the even ones @@ -4312,12 +4312,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor error(e.loc, "String postfixes on interpolated expression sequences are not allowed."); Expression makeNonTemplateItem(Identifier which) { - Expression id = new IdentifierExp(e.loc, Id.empty); - id = new DotIdExp(e.loc, id, Id.object); - auto moduleNameArgs = new Objects(); - moduleNameArgs.push(new StringExp(e.loc, "core.interpolation")); - id = new DotTemplateInstanceExp(e.loc, id, Id.imported, moduleNameArgs); - id = new DotIdExp(e.loc, id, which); + Expression id = new IdentifierExp(e.loc, which); id = new CallExp(e.loc, id, new Expressions()); return id; }