diff options
| author | Yong He <yonghe@outlook.com> | 2017-11-22 17:32:15 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-22 17:32:15 -0500 |
| commit | 83d49ce376185f7dc3f40eb531f01ee350220959 (patch) | |
| tree | 7e96f26c6b6e6bf6a8b15ba1820e844e78a31394 /source/slang/ir.cpp | |
| parent | 56e49feea3956d66e41b819c26628c65b3c28197 (diff) | |
| parent | 581b30dd5a4263c90539a8c5cc6063b2485885cd (diff) | |
Merge pull request #293 from csyonghe/generic-param-fix
Fixup global generic parameters
Diffstat (limited to 'source/slang/ir.cpp')
| -rw-r--r-- | source/slang/ir.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 0f34d5585..598445fcd 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3103,10 +3103,30 @@ namespace Slang IRGlobalVar* cloneGlobalVar(IRSpecContext* context, IRGlobalVar* originalVar); IRFunc* cloneFunc(IRSpecContext* context, IRFunc* originalFunc); IRWitnessTable* cloneWitnessTable(IRSpecContext* context, IRWitnessTable* originalVar); + RefPtr<Substitutions> cloneSubstitutions( + IRSpecContext* context, + Substitutions* subst); RefPtr<Type> IRSpecContext::maybeCloneType(Type* originalType) { - return originalType->Substitute(subst).As<Type>(); + auto rsType = originalType->GetCanonicalType()->Substitute(subst).As<Type>(); + if (auto declRefType = rsType.As<DeclRefType>()) + { + if (subst) + { + auto newSubst = cloneSubstitutions(this, subst); + insertSubstAtBottom(declRefType->declRef.substitutions, newSubst); + } + } + else if (auto funcType = rsType.As<FuncType>()) + { + RefPtr<FuncType> newFuncType = new FuncType(); + newFuncType->setSession(funcType->getSession()); + newFuncType->resultType = maybeCloneType(funcType->resultType); + for (auto paramType : funcType->paramTypes) + newFuncType->paramTypes.Add(maybeCloneType(paramType)); + } + return rsType; } IRValue* IRSpecContext::maybeCloneValue(IRValue* originalValue) @@ -3243,6 +3263,15 @@ namespace Slang newSubst->outer = cloneSubstitutions(context, subst->outer); return newSubst; } + else if (auto genTypeSubst = dynamic_cast<GlobalGenericParamSubstitution*>(subst)) + { + RefPtr<GlobalGenericParamSubstitution> newSubst = new GlobalGenericParamSubstitution(); + newSubst->actualType = genTypeSubst->actualType; + newSubst->paramDecl = genTypeSubst->paramDecl; + newSubst->witnessTables = genTypeSubst->witnessTables; + newSubst->outer = cloneSubstitutions(context, subst->outer); + return newSubst; + } else SLANG_UNREACHABLE("unimplemented cloneSubstitution"); UNREACHABLE_RETURN(nullptr); |
