summaryrefslogtreecommitdiff
path: root/source/slang/lower-to-ir.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-12-27 20:17:36 -0500
committerGitHub <noreply@github.com>2017-12-27 20:17:36 -0500
commite370fe2984e7e260dc2d78d67b087e542d0102b0 (patch)
treedd441836025e802f79e74646f8f280c7515cbaec /source/slang/lower-to-ir.cpp
parent69242398be1ba76898c0d6541eec3b7ca0ec1ab4 (diff)
parentd55b56bc804f25d8390f1dc6b09ff9116ffcaf29 (diff)
Merge pull request #335 from csyonghe/master
Support nested generic types (e.g. L<T<S>>)
Diffstat (limited to 'source/slang/lower-to-ir.cpp')
-rw-r--r--source/slang/lower-to-ir.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp
index 8fc1239cd..1d6da3a3b 100644
--- a/source/slang/lower-to-ir.cpp
+++ b/source/slang/lower-to-ir.cpp
@@ -2740,10 +2740,6 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
context->getSession(),
makeDeclRef(parentDecl));
-
- // TODO: if the parent type is generic, then I suppose these
- // need to be *generic* witness tables?
-
// What is the super-type that we have declared we inherit from?
RefPtr<Type> superType = inheritanceDecl->base.type;
@@ -2758,6 +2754,11 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
auto witnessTable = context->irBuilder->createWitnessTable();
witnessTable->mangledName = mangledName;
+ if (parentDecl->ParentDecl)
+ witnessTable->genericDecl = dynamic_cast<GenericDecl*>(parentDecl->ParentDecl);
+ witnessTable->subTypeDeclRef = makeDeclRef(parentDecl);
+ witnessTable->supTypeDeclRef = inheritanceDecl->base.type->AsDeclRefType()->declRef;
+
// Register the value now, rather than later, to avoid
// infinite recursion.
context->shared->declValues[inheritanceDecl] = LoweredValInfo::simple(witnessTable);
@@ -3713,7 +3714,7 @@ LoweredValInfo ensureDecl(
return result;
}
-IRWitnessTable* findWitnessTable(
+IRValue* findWitnessTable(
IRGenContext* context,
DeclRef<Decl> declRef)
{
@@ -3724,10 +3725,13 @@ IRWitnessTable* findWitnessTable(
return nullptr;
}
+ if (irVal->op == kIROp_specialize)
+ {
+ return irVal;
+ }
+
if (irVal->op != kIROp_witness_table)
{
- // TODO: We might eventually have cases of `specialize` called
- // on a witness table...
SLANG_UNEXPECTED("expected a witness table");
return nullptr;
}
@@ -3764,7 +3768,7 @@ RefPtr<Val> lowerSubstitutionArg(
// up in a reasonably clean fashion.
//
RefPtr<IRProxyVal> proxyVal = new IRProxyVal();
- proxyVal->inst = irWitnessTable;
+ proxyVal->inst.init(nullptr, irWitnessTable);
return proxyVal;
}
else
@@ -3860,7 +3864,7 @@ LoweredValInfo maybeEmitSpecializeInst(IRGenContext* context,
// Otherwise, we need to construct a specialization of the
// given declaration.
- return LoweredValInfo::simple(context->irBuilder->emitSpecializeInst(
+ return LoweredValInfo::simple((IRInst*)context->irBuilder->emitSpecializeInst(
type,
val,
declRef));