From 9304c2d04c9bfbae33cc328d404b24aba375aa4f Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 21 Oct 2021 15:51:18 -0700 Subject: Diagnostic for no type conformance + bug fix. (#1985) * Diagnostic for no type conformance + bug fix. * Fixes. * Fix. * Include heterogeneous example only with --enable-experimental-projects premake flag Co-authored-by: Yong He Co-authored-by: jsmall-nvidia --- source/slang/slang-ir-lower-generics.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source/slang/slang-ir-lower-generics.cpp') diff --git a/source/slang/slang-ir-lower-generics.cpp b/source/slang/slang-ir-lower-generics.cpp index 241827561..95046787a 100644 --- a/source/slang/slang-ir-lower-generics.cpp +++ b/source/slang/slang-ir-lower-generics.cpp @@ -117,6 +117,36 @@ namespace Slang cleanUpInterfaceTypes(sharedContext); } + void checkTypeConformanceExists(SharedGenericsLoweringContext* context) + { + HashSet implementedInterfaces; + + // Add all interface type that are implemented by at least one type to a set. + for (auto inst : context->module->getGlobalInsts()) + { + if (inst->getOp() == kIROp_WitnessTable) + { + auto interfaceType = cast(inst->getDataType())->getConformanceType(); + implementedInterfaces.Add(interfaceType); + } + } + // Check if an interface type has any implementations. + workOnModule(context, [&](IRInst* inst) + { + if (auto lookupWitnessMethod = as(inst)) + { + auto witnessTableType = lookupWitnessMethod->getWitnessTable()->getDataType(); + auto interfaceType = cast(witnessTableType)->getConformanceType(); + if (!implementedInterfaces.Contains(interfaceType)) + { + context->sink->diagnose(interfaceType->sourceLoc, Diagnostics::noTypeConformancesFoundForInterface, interfaceType); + // Add to set to prevent duplicate diagnostic messages. + implementedInterfaces.Add(interfaceType); + } + } + }); + } + void lowerGenerics( TargetRequest* targetReq, IRModule* module, @@ -127,6 +157,8 @@ namespace Slang sharedContext.module = module; sharedContext.sink = sink; + checkTypeConformanceExists(&sharedContext); + // Replace all `makeExistential` insts with `makeExistentialWithRTTI` // before making any other changes. This is necessary because a parameter of // generic type will be lowered into `AnyValueType`, and after that we can no longer -- cgit v1.2.3