diff options
| author | Yong He <yonghe@outlook.com> | 2017-11-24 11:55:54 -0500 |
|---|---|---|
| committer | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-11-24 08:55:54 -0800 |
| commit | 109ee8aae399042fba6ea71e43e5ee2d441288dd (patch) | |
| tree | 3ece48c6b575f14500666d9f808022eda846a517 /source/slang/ir.cpp | |
| parent | 83d49ce376185f7dc3f40eb531f01ee350220959 (diff) | |
Fix substitution mechanism to remove special cases for global params (#297)
Add a new function:
`substituteSubstitutions(Substitutions * substHead, Substitutions subst, int * ioDiff)`
This function substitutes the type arguments referenced in a linked list of substitutions headed at `substHead` using the substitutions specified by `subst`. If the linked list `substHead` does not contain `GlobalGenericParamSubstitution` entries, they will be added to the bottom (outter most) of the linked list.
Note that this function should be called when `substHead` is known to be the head of substitution linked list because the existance of `GlobalGenericPaaramSubstitution` is detected assuming the linked lists starts at `substHead`. If a substitution that is not the head of a substitution linked list is passed in, duplicate `GlobalGenericParamSubstitution`s could be appended to the linked list.
This means that this function should *not* be called in places like `GenericSubstitution::SubstitutionImpl()` for its outer substitutions, because `outer` is obviously not the head of the linked list. Instead, use this function to substitution the substitution lists of `DeclRef` etc. instead of calling `declRef.substitutions->SubstituteImpl()` where the head to the linked list is known as a member of that class.
With this function, IRSpecContext::maybeCloneType() is simplified down to `originalType->Substitute(subst)`
Updates `DeclRefBase::SubstituteImpl` and `DeclRefType::SubstituteImpl` to call `substituteSubstitutions` instead of making direct `substitutions->SubstituteImpl` call.
Providing actual implementation of `GlobalGenericParamSubstitution::SubstituteImpl` instead of just returning `this` to deal with potential situations where a true substitution is needed.
Diffstat (limited to 'source/slang/ir.cpp')
| -rw-r--r-- | source/slang/ir.cpp | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 598445fcd..eb78d144e 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3109,24 +3109,7 @@ namespace Slang RefPtr<Type> IRSpecContext::maybeCloneType(Type* originalType) { - 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; + return originalType->Substitute(subst).As<Type>(); } IRValue* IRSpecContext::maybeCloneValue(IRValue* originalValue) |
