diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-20 20:51:57 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-20 20:51:57 -0700 |
| commit | f9f6a28df40f418ddd0c8ff3b9cacccdb085e202 (patch) | |
| tree | a6bafa63cee4f9bbcfe496de54af6e5727bb021e /source/slang/slang-ir-clone.cpp | |
| parent | 03e1e17745920c8e3a7b6f4e3b1e64062589604a (diff) | |
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.
Diffstat (limited to 'source/slang/slang-ir-clone.cpp')
| -rw-r--r-- | source/slang/slang-ir-clone.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
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<IRCloningOldNewPair> pairs; + ShortList<IRCloningOldNewPair> 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 |
