summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-06-24 13:16:11 -0700
committerYong He <yonghe@outlook.com>2020-06-24 18:10:15 -0700
commit0ca75fe002f346f6ab9b77f40c0576d2905560f1 (patch)
treeed8a3af372900923e59f0d6da629c2d0969ee7fd /source/slang/slang-ir.cpp
parent3fe4f5398d524333e955ecb91be5646e86f3b2da (diff)
Dynamic dispatch for generic interface requirements.
-Lower interfaces into actual `IRInterfaceType` insts. -Lower `DeclRef<AssocTypeDecl>` 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.
Diffstat (limited to 'source/slang/slang-ir.cpp')
-rw-r--r--source/slang/slang-ir.cpp32
1 files changed, 29 insertions, 3 deletions
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<IRLookupWitnessMethod>(
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<IRInterfaceRequirementEntry>(
+ this,
+ kIROp_InterfaceRequirementEntry,
+ nullptr,
+ requirementKey,
+ requirementVal);
+ addGlobalValue(this, entry);
+ return entry;
+ }
+
IRStructType* IRBuilder::createStructType()
{
IRStructType* structType = createInst<IRStructType>(
@@ -2821,6 +2837,16 @@ namespace Slang
return structType;
}
+ IRAssociatedType* IRBuilder::createAssociatedType()
+ {
+ IRAssociatedType* associatedType = createInst<IRAssociatedType>(
+ this,
+ kIROp_AssociatedType,
+ nullptr);
+ addGlobalValue(this, associatedType);
+ return associatedType;
+ }
+
IRInterfaceType* IRBuilder::createInterfaceType(UInt operandCount, IRInst* const* operands)
{
IRInterfaceType* interfaceType = createInst<IRInterfaceType>(