diff options
| author | Yong He <yonghe@outlook.com> | 2024-05-02 16:48:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-02 16:48:27 -0700 |
| commit | 1863fe1deecc3f5b15b45020105f6cadcc2f9999 (patch) | |
| tree | c05cf87ac014e31368e70a3b75c2d20c657e789d /source/slang/slang-ir-link.cpp | |
| parent | 7ef980f79447f8deec2aaf4a501df29f97cf1a39 (diff) | |
Support generic constraints that are dependent on another generic param. (#4091)
Diffstat (limited to 'source/slang/slang-ir-link.cpp')
| -rw-r--r-- | source/slang/slang-ir-link.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index 4871062d4..e652745e7 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -746,6 +746,12 @@ void cloneGlobalValueWithCodeCommon( { IRBlock* ob = originalValue->getFirstBlock(); IRBlock* cb = clonedValue->getFirstBlock(); + struct ParamCloneInfo + { + IRParam* originalParam; + IRParam* clonedParam; + }; + ShortList<ParamCloneInfo> paramCloneInfos; while (ob) { SLANG_ASSERT(cb); @@ -753,9 +759,28 @@ void cloneGlobalValueWithCodeCommon( builder->setInsertInto(cb); for (auto oi = ob->getFirstInst(); oi; oi = oi->getNextInst()) { - cloneInst(context, builder, oi); + if (oi->getOp() == kIROp_Param) + { + // Params may have forward references in its type and + // decorations, so we just create a placeholder for it + // in this first pass. + IRParam* clonedParam = builder->emitParam(nullptr); + registerClonedValue(context, clonedParam, oi); + paramCloneInfos.add({ (IRParam*)oi, clonedParam }); + } + else + { + cloneInst(context, builder, oi); + } + } + // Clone the type and decorations of parameters after all instructs in the block + // have been cloned. + for (auto param : paramCloneInfos) + { + builder->setInsertInto(param.clonedParam); + param.clonedParam->setFullType((IRType*)cloneValue(context, param.originalParam->getFullType())); + cloneDecorations(context, param.clonedParam, param.originalParam); } - ob = ob->getNextBlock(); cb = cb->getNextBlock(); } |
