From 6af3381f47e3c22e1657c0e0064fa466e8bde0f6 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 6 Oct 2025 17:21:37 -0700 Subject: Use symbol alias instead of wrapper synthesis to implement link-time types. (#8603) This change achieves link-time type resolution with a different mechanism. For `extern struct Foo : IFoo = FooImpl;`, instead of synthesizing a wrapper type `Foo` that has a `FooImpl inner` field and dispatches all interface method calls to `inner.method()`, this PR completely removes this synthesis step, and instead just lower such `extern`/`export` types as `IRSymbolAlias` instructions that is just a reference to the type being wrapped. Then we extend the linker logic to clone the referenced symbol instead of the SymbolAlias insts itself during linking. By doing so, we greatly simply the logic need to support link-time types, and achieves higher robustness by not having to deal with many AST synthesis scenarios. Closes #8554. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-ir-link.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-ir-link.cpp') diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index c46c57043..8ba1f354d 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -302,6 +302,7 @@ IRInst* IRSpecContext::maybeCloneValue(IRInst* originalValue) case kIROp_GlobalGenericParam: case kIROp_WitnessTable: case kIROp_InterfaceType: + case kIROp_SymbolAlias: return cloneGlobalValue(this, originalValue); case kIROp_BoolLit: @@ -346,7 +347,6 @@ IRInst* IRSpecContext::maybeCloneValue(IRInst* originalValue) return builder->getVoidValue(); } break; - default: { // In the default case, assume that we have some sort of "hoistable" @@ -1411,7 +1411,10 @@ IRInst* cloneInst( builder, cast(originalInst), originalValues); - + case kIROp_SymbolAlias: + // If we encounter a symbol alias, we want to clone + // the value it refers to instead of the alias itself. + return context->maybeCloneValue(cast(originalInst)->getOperand(0)); default: break; } -- cgit v1.2.3