summaryrefslogtreecommitdiffstats
path: root/source/slang/ir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/ir.cpp')
-rw-r--r--source/slang/ir.cpp31
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);