From 0ca75fe002f346f6ab9b77f40c0576d2905560f1 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 24 Jun 2020 13:16:11 -0700 Subject: Dynamic dispatch for generic interface requirements. -Lower interfaces into actual `IRInterfaceType` insts. -Lower `DeclRef` into `IRAssociatedType` -Generate proper IRType for generic functions. -Add a test case exercising dynamic dispatching a generic static function through an associated type. -Bug fixes for the test case. --- source/slang/slang-ir.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 77011b569..891f4b3e0 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -2508,14 +2508,16 @@ namespace Slang IRInst* IRBuilder::emitLookupInterfaceMethodInst( IRType* type, IRInst* witnessTableVal, - IRInst* interfaceMethodVal) + IRInst* interfaceMethodVal, + IRType* interfaceType) { + IRInst* args[3] = { witnessTableVal , interfaceMethodVal, interfaceType }; auto inst = createInst( this, kIROp_lookup_interface_method, type, - witnessTableVal, - interfaceMethodVal); + 3, + args); addInst(inst); return inst; @@ -2811,6 +2813,20 @@ namespace Slang return entry; } + IRInterfaceRequirementEntry* IRBuilder::createInterfaceRequirementEntry( + IRInst* requirementKey, + IRInst* requirementVal) + { + IRInterfaceRequirementEntry* entry = createInst( + this, + kIROp_InterfaceRequirementEntry, + nullptr, + requirementKey, + requirementVal); + addGlobalValue(this, entry); + return entry; + } + IRStructType* IRBuilder::createStructType() { IRStructType* structType = createInst( @@ -2821,6 +2837,16 @@ namespace Slang return structType; } + IRAssociatedType* IRBuilder::createAssociatedType() + { + IRAssociatedType* associatedType = createInst( + this, + kIROp_AssociatedType, + nullptr); + addGlobalValue(this, associatedType); + return associatedType; + } + IRInterfaceType* IRBuilder::createInterfaceType(UInt operandCount, IRInst* const* operands) { IRInterfaceType* interfaceType = createInst( -- cgit v1.2.3