From 9f3e83cf0d664c87a618edf08d834829178030e6 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 6 Sep 2022 16:08:48 -0700 Subject: Specialize and SSA in a loop + better diagnostics on dynamic dispatch failure (#2396) * Report diagnostic when dynamic dispatch failed instead of crashing. * Specialize and SSA in a loop. Explicit specialization only interface. Co-authored-by: Yong He --- source/slang/slang-ir-specialize-dispatch.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-ir-specialize-dispatch.cpp') diff --git a/source/slang/slang-ir-specialize-dispatch.cpp b/source/slang/slang-ir-specialize-dispatch.cpp index b6e9d2c45..88e2497be 100644 --- a/source/slang/slang-ir-specialize-dispatch.cpp +++ b/source/slang/slang-ir-specialize-dispatch.cpp @@ -91,7 +91,10 @@ IRFunc* specializeDispatchFunction(SharedGenericsLoweringContext* sharedContext, { auto witnessTable = witnessTables[i]; auto seqIdDecoration = witnessTable->findDecoration(); - SLANG_ASSERT(seqIdDecoration); + if (!seqIdDecoration) + { + sharedContext->sink->diagnose(witnessTable->getConcreteType(), Diagnostics::typeCannotBeUsedInDynamicDispatch, witnessTable->getConcreteType()); + } if (i != witnessTables.getCount() - 1) { @@ -220,6 +223,15 @@ void ensureWitnessTableSequentialIDs(SharedGenericsLoweringContext* sharedContex } else { + auto witnessTableType = as(inst->getDataType()); + if (witnessTableType && witnessTableType->getConformanceType()->findDecoration()) + { + // The interface is for specialization only, it would be an error if dynamic dispatch is used + // through the interface. + // Skip assigning ID for the witness table. + continue; + } + // If this witness table entry does not have a linkage, // we need to check if it is transitively visible via // associatedtypes from an existing witness table with linkage. -- cgit v1.2.3