From dbf05f8dca79d7bb166038652d968554d486c9fd Mon Sep 17 00:00:00 2001 From: Ronan Date: Fri, 9 May 2025 21:34:08 +0200 Subject: Fixed name mangling of generic extensions (#6671) * Fixed name mangling of generic extensions * Added tests for generic extensions linking. - Disabled bugs/gh-6331.slang since it now triggers an assertion error revealed by the new version of the mangler. * Re-enabled test gh-6331 (fixed by a5efbb1b775afb2f6b29b37d39947c41744bb005) --------- Co-authored-by: Yong He --- source/slang/slang-lower-to-ir.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'source/slang/slang-lower-to-ir.cpp') diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 45efca2d9..2271e750e 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -8242,6 +8242,16 @@ struct DeclLoweringVisitor : DeclVisitor { subType = DeclRefType::create(context->astBuilder, makeDeclRef(parentDecl)); } + bool isGenericExtension = false; + // Test if we are in a generic extension context + if (parentDecl->parentDecl) + { + auto genDecl = as(parentDecl->parentDecl); + if (genDecl) + { + isGenericExtension = true; + } + } // What is the super-type that we have declared we inherit from? Type* superType = inheritanceDecl->base.type; @@ -8304,14 +8314,17 @@ struct DeclLoweringVisitor : DeclVisitor { // Construct the mangled name for the witness table, which depends // on the type that is conforming, and the type that it conforms to. - // - // TODO: This approach doesn't really make sense for generic `extension` - // conformances. - auto mangledName = getMangledNameForConformanceWitness( - context->astBuilder, - subType, - superType, - irSubType->getOp()); + String mangledName; + if (isGenericExtension) + { + mangledName = + getMangledNameForConformanceWitness(context->astBuilder, parentDecl, superType); + } + else + { + mangledName = + getMangledNameForConformanceWitness(context->astBuilder, subType, superType); + } // TODO(JS): // Should the mangled name take part in obfuscation if enabled? -- cgit v1.2.3