diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ast-base.h | 28 | ||||
| -rw-r--r-- | source/slang/slang-ast-dump.cpp | 13 | ||||
| -rw-r--r-- | source/slang/slang-ast-substitutions.cpp | 71 | ||||
| -rw-r--r-- | source/slang/slang-ast-type.cpp | 16 | ||||
| -rw-r--r-- | source/slang/slang-ast-val.cpp | 15 | ||||
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 5 | ||||
| -rw-r--r-- | source/slang/slang-serialize-ast-type-info.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-syntax.cpp | 130 |
8 files changed, 1 insertions, 280 deletions
diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h index 2bfa7940b..b7810b49a 100644 --- a/source/slang/slang-ast-base.h +++ b/source/slang/slang-ast-base.h @@ -229,34 +229,6 @@ class ThisTypeSubstitution : public Substitutions HashCode _getHashCodeOverride() const; }; -struct GlobalGenericParamSubstitution_ConstraintArg -{ - SLANG_VALUE_CLASS(GlobalGenericParamSubstitution_ConstraintArg) - Decl* decl = nullptr; - Val* val = nullptr; -}; - -class GlobalGenericParamSubstitution : public Substitutions -{ - SLANG_AST_CLASS(GlobalGenericParamSubstitution) - - typedef GlobalGenericParamSubstitution_ConstraintArg ConstraintArg; - - // the type_param decl to be substituted - GlobalGenericParamDecl* paramDecl = nullptr; - - // the actual type to substitute in - Type* actualType = nullptr; - - // the values that satisfy any constraints on the type parameter - List<GlobalGenericParamSubstitution_ConstraintArg> constraintArgs; - - // Overrides should be public so base classes can access - Substitutions* _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff); - bool _equalsOverride(Substitutions* subst); - HashCode _getHashCodeOverride() const; -}; - class SyntaxNode : public SyntaxNodeBase { SLANG_ABSTRACT_AST_CLASS(SyntaxNode); diff --git a/source/slang/slang-ast-dump.cpp b/source/slang/slang-ast-dump.cpp index 38dfa9c2f..9da1a0163 100644 --- a/source/slang/slang-ast-dump.cpp +++ b/source/slang/slang-ast-dump.cpp @@ -500,19 +500,6 @@ struct ASTDumpContext m_writer->dedent(); m_writer->emit("}"); } - void dump(const GlobalGenericParamSubstitution::ConstraintArg& arg) - { - m_writer->emit(" { \n"); - m_writer->indent(); - - dump(arg.decl); - m_writer->emit(",\n"); - dump(arg.val); - m_writer->emit("\n"); - - m_writer->dedent(); - m_writer->emit("}"); - } void dump(const TypeExp& exp) { m_writer->emit(" { \n"); diff --git a/source/slang/slang-ast-substitutions.cpp b/source/slang/slang-ast-substitutions.cpp index acff8201e..6656f1fa6 100644 --- a/source/slang/slang-ast-substitutions.cpp +++ b/source/slang/slang-ast-substitutions.cpp @@ -163,75 +163,4 @@ HashCode ThisTypeSubstitution::_getHashCodeOverride() const return witness->getHashCode(); } -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GlobalGenericParamSubstitution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -Substitutions* GlobalGenericParamSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) -{ - // if we find a GlobalGenericParamSubstitution in subst that references the same type_param decl - // return a copy of that GlobalGenericParamSubstitution - int diff = 0; - - if (substOuter != outer) diff++; - - auto substActualType = as<Type>(actualType->substituteImpl(astBuilder, substSet, &diff)); - - List<ConstraintArg> substConstraintArgs; - for (auto constraintArg : constraintArgs) - { - ConstraintArg substConstraintArg; - substConstraintArg.decl = constraintArg.decl; - substConstraintArg.val = constraintArg.val->substituteImpl(astBuilder, substSet, &diff); - - substConstraintArgs.add(substConstraintArg); - } - - if (!diff) - return this; - - (*ioDiff)++; - - GlobalGenericParamSubstitution* substSubst = astBuilder->create<GlobalGenericParamSubstitution>(); - substSubst->paramDecl = paramDecl; - substSubst->actualType = substActualType; - substSubst->constraintArgs = substConstraintArgs; - substSubst->outer = substOuter; - return substSubst; -} - -bool GlobalGenericParamSubstitution::_equalsOverride(Substitutions* subst) -{ - if (!subst) - return false; - if (subst == this) - return true; - - if (auto genSubst = as<GlobalGenericParamSubstitution>(subst)) - { - if (paramDecl != genSubst->paramDecl) - return false; - if (!actualType->equalsVal(genSubst->actualType)) - return false; - if (constraintArgs.getCount() != genSubst->constraintArgs.getCount()) - return false; - for (Index i = 0; i < constraintArgs.getCount(); i++) - { - if (!constraintArgs[i].val->equalsVal(genSubst->constraintArgs[i].val)) - return false; - } - return true; - } - return false; -} - -HashCode GlobalGenericParamSubstitution::_getHashCodeOverride() const -{ - HashCode rs = actualType->getHashCode(); - for (auto && a : constraintArgs) - { - rs = combineHash(rs, a.val->getHashCode()); - } - return rs; -} - - } // namespace Slang diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp index 2c2557233..9c00c13ba 100644 --- a/source/slang/slang-ast-type.cpp +++ b/source/slang/slang-ast-type.cpp @@ -219,22 +219,6 @@ Val* DeclRefType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSe } } } - else if (auto globalGenParam = as<GlobalGenericParamDecl>(declRef.getDecl())) - { - // search for a substitution that might apply to us - for (auto s = subst.substitutions; s; s = s->outer) - { - auto genericSubst = as<GlobalGenericParamSubstitution>(s); - if (!genericSubst) - continue; - - if (genericSubst->paramDecl == globalGenParam) - { - (*ioDiff)++; - return genericSubst->actualType; - } - } - } int diff = 0; DeclRef<Decl> substDeclRef = declRef.substituteImpl(astBuilder, subst, &diff); diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp index 7dbda6e86..5396749e5 100644 --- a/source/slang/slang-ast-val.cpp +++ b/source/slang/slang-ast-val.cpp @@ -258,21 +258,6 @@ Val* DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, Sub return genericSubst->args[index + ordinaryParamCount]; } } - else if (auto globalGenericSubst = as<GlobalGenericParamSubstitution>(s)) - { - // check if the substitution is really about this global generic type parameter - if (globalGenericSubst->paramDecl != genConstraintDecl->parentDecl) - continue; - - for (auto constraintArg : globalGenericSubst->constraintArgs) - { - if (constraintArg.decl != genConstraintDecl) - continue; - - (*ioDiff)++; - return constraintArg.val; - } - } } } diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 1ea3c71fb..06e463d7d 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -7339,11 +7339,6 @@ LoweredValInfo emitDeclRef( // We need to proceed by considering the specializations that // have been put in place. - // Ignore any global generic type substitutions during lowering. - // Really, we don't even expect these to appear. - while(auto globalGenericSubst = as<GlobalGenericParamSubstitution>(subst)) - subst = globalGenericSubst->outer; - // If the declaration would not get wrapped in a `IRGeneric`, // even if it is nested inside of an AST `GenericDecl`, then // we should also ignore any generic substitutions. diff --git a/source/slang/slang-serialize-ast-type-info.h b/source/slang/slang-serialize-ast-type-info.h index 400474046..937ecc95f 100644 --- a/source/slang/slang-serialize-ast-type-info.h +++ b/source/slang/slang-serialize-ast-type-info.h @@ -144,9 +144,6 @@ struct SerialTypeInfo<LookupResult> } }; -// GlobalGenericParamSubstitution::ConstraintArg -SLANG_VALUE_TYPE_INFO(GlobalGenericParamSubstitution_ConstraintArg) - // SpecializationArg SLANG_VALUE_TYPE_INFO(SpecializationArg) // ExpandedSpecializationArg diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp index 82e94fb6a..d6e966aaa 100644 --- a/source/slang/slang-syntax.cpp +++ b/source/slang/slang-syntax.cpp @@ -667,25 +667,6 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return nullptr; } - GlobalGenericParamSubstitution* findGlobalGenericSubst( - Substitutions* substs, - GlobalGenericParamDecl* paramDecl) - { - for(auto s = substs; s; s = s->outer) - { - auto gSubst = as<GlobalGenericParamSubstitution>(s); - if(!gSubst) - continue; - - if(gSubst->paramDecl != paramDecl) - continue; - - return gSubst; - } - - return nullptr; - } - Substitutions* specializeSubstitutionsShallow( ASTBuilder* astBuilder, Substitutions* substToSpecialize, @@ -697,105 +678,6 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return substToSpecialize->applySubstitutionsShallow(astBuilder, substsToApply, restSubst, ioDiff); } - Substitutions* specializeGlobalGenericSubstitutions( - ASTBuilder* astBuilder, - Decl* declToSpecialize, - Substitutions* substsToSpecialize, - Substitutions* substsToApply, - int* ioDiff, - HashSet<GlobalGenericParamDecl*>& ioParametersFound) - { - // Any existing global-generic substitutions will trigger - // a recursive case that skips the rest of the function. - for(auto specSubst = substsToSpecialize; specSubst; specSubst = specSubst->outer) - { - auto specGlobalGenericSubst = as<GlobalGenericParamSubstitution>(specSubst); - if(!specGlobalGenericSubst) - continue; - - ioParametersFound.Add(specGlobalGenericSubst->paramDecl); - - int diff = 0; - auto restSubst = specializeGlobalGenericSubstitutions( - astBuilder, - declToSpecialize, - specSubst->outer, - substsToApply, - &diff, - ioParametersFound); - - auto firstSubst = specializeSubstitutionsShallow( - astBuilder, - specGlobalGenericSubst, - substsToApply, - restSubst, - &diff); - - *ioDiff += diff; - return firstSubst; - } - - // No more existing substitutions, so we know we can apply - // our global generic substitutions without any special work. - - // We expect global generic substitutions to come at - // the end of the list in all cases, so lets advance - // until we see them. - Substitutions* appGlobalGenericSubsts = substsToApply; - while(appGlobalGenericSubsts && !as<GlobalGenericParamSubstitution>(appGlobalGenericSubsts)) - appGlobalGenericSubsts = appGlobalGenericSubsts->outer; - - - // If there is nothing to apply, then we are done - if(!appGlobalGenericSubsts) - return nullptr; - - // Otherwise, it seems like something has to change. - (*ioDiff)++; - - // If there were no parameters bound by the existing substitution, - // then we can safely use the global generics from the to-apply set. - if(ioParametersFound.Count() == 0) - return appGlobalGenericSubsts; - - Substitutions* resultSubst = nullptr; - Substitutions** link = &resultSubst; - for(auto appSubst = appGlobalGenericSubsts; appSubst; appSubst = appSubst->outer) - { - auto appGlobalGenericSubst = as<GlobalGenericParamSubstitution>(appSubst); - if(!appSubst) - continue; - - // Don't include substitutions for parameters already handled. - if(ioParametersFound.Contains(appGlobalGenericSubst->paramDecl)) - continue; - - GlobalGenericParamSubstitution* newSubst = astBuilder->create<GlobalGenericParamSubstitution>(); - newSubst->paramDecl = appGlobalGenericSubst->paramDecl; - newSubst->actualType = appGlobalGenericSubst->actualType; - newSubst->constraintArgs = appGlobalGenericSubst->constraintArgs; - - *link = newSubst; - link = &newSubst->outer; - } - - return resultSubst; - } - - Substitutions* specializeGlobalGenericSubstitutions( - ASTBuilder* astBuilder, - Decl* declToSpecialize, - Substitutions* substsToSpecialize, - Substitutions* substsToApply, - int* ioDiff) - { - // Keep track of any parameters already present in the - // existing substitution. - HashSet<GlobalGenericParamDecl*> parametersFound; - return specializeGlobalGenericSubstitutions(astBuilder, declToSpecialize, substsToSpecialize, substsToApply, ioDiff, parametersFound); - } - - // Construct new substitutions to apply to a declaration, // based on a provided substitution set to be applied Substitutions* specializeSubstitutions( @@ -965,21 +847,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // would be specializations that don't actually apply to the given // declaration. // - // The remaining substitutions to apply, if any, should thus be - // global-generic substitutions. And similarly, those are the - // only remaining substitutions we really care about in - // `substsToApply`. - // // Note: this does *not* mean that `substsToApply` doesn't have // any generic or this-type substitutions; it just means that none // of them were applicable. // - return specializeGlobalGenericSubstitutions( - astBuilder, - declToSpecialize, - substsToSpecialize, - substsToApply, - ioDiff); + return nullptr; } DeclRefBase DeclRefBase::substituteImpl(ASTBuilder* astBuilder, SubstitutionSet substSet, int* ioDiff) |
