From ff7c46a11787ca6ecebf0a224772a41efef33fc0 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 5 Nov 2017 05:49:42 -0500 Subject: small cleanups --- source/slang/check.cpp | 2 ++ source/slang/ir.cpp | 4 +++- source/slang/lower-to-ir.cpp | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 79a4f28cf..ed2ed4a1b 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -1662,6 +1662,8 @@ namespace Slang return false; auto structTypeDecl = declRefType->declRef.getDecl()->As(); + if (!structTypeDecl) + return false; //TODO: What do we do if type is a generic specialization? // i.e. if the struct defines typedef Generic T; // how to check if T satisfies the associatedtype constraints? diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 04569771a..ab961a159 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -562,11 +562,13 @@ namespace Slang IRValue * IRBuilder::getTypeVal(IRType * type) { - auto irValue = createValue( + auto irValue = createValue( this, kIROp_TypeType, nullptr); irValue->type = type; + if (auto typetype = dynamic_cast(type)) + irValue->type = typetype->type; return irValue; } diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index be91b9d3d..2672c5698 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -2311,8 +2311,11 @@ struct DeclLoweringVisitor : DeclVisitor ensureDecl(context, inheritanceDecl); } - // For now, we don't have an IR-level representation - // for the type itself. + // TODO: we currently store a Decl* in the witness table, which causes this function + // being invoked to translate the witness table entry into an IRValue. + // We should really allow a witness table entry to represent a type and not having to + // construct the type here. The current implementation will not work when the struct type + // is defined in a generic parent (we lose the environmental substitutions). return LoweredValInfo::simple(context->irBuilder->getTypeVal(DeclRefType::Create(context->getSession(), DeclRef(decl, nullptr)))); } -- cgit v1.2.3