From 3321df74904dfe3a11a41179b66a4c3ce5b57022 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 4 Oct 2020 01:40:58 -0700 Subject: Handle partial existential parameter type specialization. (#1568) * Specialize exsitentials parameters in struct fields. * Cleanup. * Handle partial existential parameter type specialization. Co-authored-by: Yong He --- source/slang/slang-ir-insts.h | 2 +- source/slang/slang-ir.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index ef382373f..658e50f28 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -1807,7 +1807,7 @@ struct IRBuilder IRInOutType* getInOutType(IRType* valueType); IRRefType* getRefType(IRType* valueType); IRPtrTypeBase* getPtrType(IROp op, IRType* valueType); - IRExistentialBoxType* getExistentialBoxType(IRType* concreteType, IRType* interfaceType); + IRType* getExistentialBoxType(IRType* concreteType, IRType* interfaceType); IRArrayTypeBase* getArrayTypeBase( IROp op, diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index e9d90adfe..3820119d2 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -2336,10 +2336,14 @@ namespace Slang operands); } - IRExistentialBoxType* IRBuilder::getExistentialBoxType(IRType* concreteType, IRType* interfaceType) + IRType* IRBuilder::getExistentialBoxType(IRType* concreteType, IRType* interfaceType) { + // Don't wrap an existential box if concreteType is __Dynamic. + if (as(concreteType)) + return interfaceType; + IRInst* operands[] = {concreteType, interfaceType}; - return (IRExistentialBoxType*)getType(kIROp_ExistentialBoxType, 2, operands); + return getType(kIROp_ExistentialBoxType, 2, operands); } IRArrayTypeBase* IRBuilder::getArrayTypeBase( @@ -2845,6 +2849,8 @@ namespace Slang // We want to emit `makeExistential(load(value), witnessTable)`. // auto deref = emitLoad(value); + if (slotArgs[0]->op == kIROp_DynamicType) + return deref; return emitMakeExistential(type, deref, slotArgs[1]); } } -- cgit v1.2.3