From f9f6a28df40f418ddd0c8ff3b9cacccdb085e202 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 20 Aug 2024 20:51:57 -0700 Subject: Support dependent generic constraints. (#4870) * Support dependent generic constraints. * Fix warning. * Update comment. * Fix. * Add a test case to verify fix of #3804. * Address review. --- source/slang/slang-ir-clone.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'source/slang/slang-ir-clone.cpp') diff --git a/source/slang/slang-ir-clone.cpp b/source/slang/slang-ir-clone.cpp index 43b60d6ed..e2297bcb2 100644 --- a/source/slang/slang-ir-clone.cpp +++ b/source/slang/slang-ir-clone.cpp @@ -152,6 +152,7 @@ static void _cloneInstDecorationsAndChildren( // require the second phase. // List pairs; + ShortList paramPairs; for( auto oldChild : oldInst->getDecorationsAndChildren() ) { @@ -172,7 +173,19 @@ static void _cloneInstDecorationsAndChildren( // on the child, and register it in our map from // old to new values. // - auto newChild = cloneInstAndOperands(env, builder, oldChild); + IRInst* newChild = nullptr; + if (oldChild->getOp() == kIROp_Param) + { + // For parameters, don't clone its type just yet, since + // the type might be a forward reference to things defined + // later in the block that we haven't cloned and registered yet. + newChild = builder->emitParam(nullptr); + paramPairs.add({ oldChild, newChild }); + } + else + { + newChild = cloneInstAndOperands(env, builder, oldChild); + } env->mapOldValToNew.add(oldChild, newChild); // If and only if the old child had decorations @@ -181,10 +194,7 @@ static void _cloneInstDecorationsAndChildren( // if( oldChild->getFirstDecorationOrChild() ) { - IRCloningOldNewPair pair; - pair.oldInst = oldChild; - pair.newInst = newChild; - pairs.add(pair); + pairs.add({ oldChild, newChild }); } } @@ -200,6 +210,17 @@ static void _cloneInstDecorationsAndChildren( _cloneInstDecorationsAndChildren(env, module, oldChild, newChild); } + + // For params, we can now clone their types since we have done cloning the entire block. + for (auto pair : paramPairs) + { + auto oldParam = pair.oldInst; + auto newParam = pair.newInst; + + auto oldType = oldParam->getFullType(); + auto newType = (IRType*)findCloneForOperand(env, oldType); + newParam->setFullType(newType); + } } // The public version of `cloneInstDecorationsAndChildren` is then -- cgit v1.2.3