From 8196dc4a684a75344e507697273e2123af97b979 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 21 Jan 2018 16:26:52 -0800 Subject: specialize witness tables when needed when specializing `lookup_witness_table` instruction. (#376) --- source/slang/ir.cpp | 14 ++++++++++++++ source/slang/syntax.cpp | 7 ++++++- source/slang/type-defs.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 7318bff4c..1d3c91979 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -4862,6 +4862,20 @@ namespace Slang auto interfaceDeclRef = ((IRDeclRef*)lookupInst->interfaceType.usedValue)->declRef; auto mangledName = getMangledNameForConformanceWitness(srcDeclRef, interfaceDeclRef); witnessTables.TryGetValue(mangledName, witnessTable); + + if (!witnessTable) + { + // try specialize the witness table + auto genDeclRef = srcDeclRef; + genDeclRef.substitutions = createDefaultSubstitutions(module->session, genDeclRef.decl); + auto genName = getMangledNameForConformanceWitness(genDeclRef, interfaceDeclRef); + IRWitnessTable* genTable = nullptr; + if (witnessTables.TryGetValue(genName, genTable)) + { + witnessTable = specializeWitnessTable(sharedContext, genTable, srcDeclRef, nullptr); + witnessTables.AddIfNotExists(witnessTable->mangledName, witnessTable); + } + } if (witnessTable) { lookupInst->replaceUsesWith(witnessTable); diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index ab4a5f94c..3bccf51ce 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -856,7 +856,12 @@ void Type::accept(IValVisitor* visitor, void* extra) Type* ErrorType::CreateCanonicalType() { - return this; + return this; + } + + RefPtr ErrorType::SubstituteImpl(SubstitutionSet /*subst*/, int* /*ioDiff*/) + { + return this; } int ErrorType::GetHashCode() diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h index c4ec09f1d..db9630c0e 100644 --- a/source/slang/type-defs.h +++ b/source/slang/type-defs.h @@ -36,6 +36,7 @@ public: protected: virtual bool EqualsImpl(Type * type) override; + virtual RefPtr SubstituteImpl(SubstitutionSet subst, int* ioDiff) override; virtual Type* CreateCanonicalType() override; virtual int GetHashCode() override; ) -- cgit v1.2.3