From 6c7120d684cc46caafbe348d658158c0060a7638 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 5 Jul 2023 14:37:48 -0700 Subject: Bottleneck DeclRef creation through ASTBuilder. (#2689) * Bottleneck DeclRef creation through ASTBuilder. * Fix clang error. * Fix. * Fix. * More fix. * Rebase on top of tree. --------- Co-authored-by: Yong He --- source/slang/slang-ast-builder.cpp | 21 ++++--- source/slang/slang-ast-builder.h | 29 +++++++-- source/slang/slang-ast-print.cpp | 12 ++-- source/slang/slang-ast-support-types.h | 57 ++++++++++++------ source/slang/slang-ast-synthesis.cpp | 4 +- source/slang/slang-ast-type.cpp | 2 +- source/slang/slang-ast-type.h | 4 -- source/slang/slang-ast-val.cpp | 2 +- source/slang/slang-ast-val.h | 9 +-- source/slang/slang-check-conformance.cpp | 13 ++-- source/slang/slang-check-constraint.cpp | 6 +- source/slang/slang-check-conversion.cpp | 6 +- source/slang/slang-check-decl.cpp | 96 +++++++++++++++--------------- source/slang/slang-check-expr.cpp | 11 ++-- source/slang/slang-check-overload.cpp | 33 +++++----- source/slang/slang-check-shader.cpp | 10 ++-- source/slang/slang-check.h | 2 +- source/slang/slang-doc-markdown-writer.cpp | 8 +-- source/slang/slang-language-server.cpp | 16 ++--- source/slang/slang-lookup.cpp | 18 +++--- source/slang/slang-lower-to-ir.cpp | 34 +++++------ source/slang/slang-mangle.cpp | 14 ++--- source/slang/slang-parameter-binding.cpp | 2 +- source/slang/slang-parser.cpp | 6 +- source/slang/slang-reflection-api.cpp | 9 ++- source/slang/slang-syntax.cpp | 8 +-- source/slang/slang-syntax.h | 27 +++++---- source/slang/slang-type-layout.cpp | 4 +- 28 files changed, 255 insertions(+), 208 deletions(-) diff --git a/source/slang/slang-ast-builder.cpp b/source/slang/slang-ast-builder.cpp index 56861949f..d914b4568 100644 --- a/source/slang/slang-ast-builder.cpp +++ b/source/slang/slang-ast-builder.cpp @@ -167,7 +167,7 @@ SharedASTBuilder::~SharedASTBuilder() void SharedASTBuilder::registerBuiltinDecl(Decl* decl, BuiltinTypeModifier* modifier) { - auto type = DeclRefType::create(m_astBuilder, DeclRef(decl, nullptr)); + auto type = DeclRefType::create(m_astBuilder, DeclRef(decl)); m_builtinTypes[Index(modifier->tag)] = type; } @@ -299,7 +299,7 @@ ArrayExpressionType* ASTBuilder::getArrayType(Type* elementType, IntVal* element auto arrayGenericDecl = as(m_sharedASTBuilder->findMagicDecl("ArrayType")); auto arrayTypeDecl = arrayGenericDecl->inner; auto substitutions = getOrCreate(arrayGenericDecl, elementType, elementCount); - result->declRef = DeclRef(arrayTypeDecl, substitutions); + result->declRef = getSpecializedDeclRef(arrayTypeDecl, substitutions); } return result; } @@ -314,7 +314,7 @@ VectorExpressionType* ASTBuilder::getVectorType( auto vectorGenericDecl = as(m_sharedASTBuilder->findMagicDecl("Vector")); auto vectorTypeDecl = vectorGenericDecl->inner; auto substitutions = getOrCreate(vectorGenericDecl, elementType, elementCount); - result->declRef = DeclRef(vectorTypeDecl, substitutions); + result->declRef = getSpecializedDeclRef(vectorTypeDecl, substitutions); } return result; } @@ -332,7 +332,7 @@ DifferentialPairType* ASTBuilder::getDifferentialPairType( valueType, primalIsDifferentialWitness); - auto declRef = DeclRef(typeDecl, substitutions); + auto declRef = getSpecializedDeclRef(typeDecl, substitutions); auto rsType = DeclRefType::create(this, declRef); return as(rsType); @@ -373,7 +373,7 @@ MeshOutputType* ASTBuilder::getMeshOutputTypeFromModifier( elementType, maxElementCount); - auto declRef = DeclRef(typeDecl, substitutions); + auto declRef = getSpecializedDeclRef(typeDecl, substitutions); auto rsType = DeclRefType::create(this, declRef); return as(rsType); @@ -458,7 +458,8 @@ bool ASTBuilder::NodeDesc::operator==(NodeDesc const& that) const // via a `NodeDesc` *should* all be going through the // deduplication path anyway, as should their operands. // - if(operands[i].values.nodeOperand != that.operands[i].values.nodeOperand) return false; + if (operands[i].values.nodeOperand[0] != that.operands[i].values.nodeOperand[0]) return false; + if (operands[i].values.nodeOperand[1] != that.operands[i].values.nodeOperand[1]) return false; } return true; } @@ -473,9 +474,15 @@ HashCode ASTBuilder::NodeDesc::getHashCode() const // to match the semantics implemented for `==` on // `NodeDesc`. // - hasher.hashValue(operands[i].values.nodeOperand); + hasher.hashValue(operands[i].values.nodeOperand[0]); + hasher.hashValue(operands[i].values.nodeOperand[1]); } return hasher.getResult(); } +DeclRef _getSpecializedDeclRef(ASTBuilder* builder, Decl* decl, Substitutions* subst) +{ + return builder->getSpecializedDeclRef(decl, subst); +} + } // namespace Slang diff --git a/source/slang/slang-ast-builder.h b/source/slang/slang-ast-builder.h index 1ef56894b..3207ef73c 100644 --- a/source/slang/slang-ast-builder.h +++ b/source/slang/slang-ast-builder.h @@ -114,16 +114,21 @@ public: { union { - NodeBase* nodeOperand; - int64_t intOperand; + NodeBase* nodeOperand[2]; + int64_t intOperand[2]; } values; - NodeOperand() { values.nodeOperand = nullptr; } - NodeOperand(NodeBase* node) { values.nodeOperand = node; } + NodeOperand() + { + values.nodeOperand[0] = nullptr; + values.nodeOperand[1] = nullptr; + } + NodeOperand(NodeBase* node) { values.nodeOperand[0] = node; values.nodeOperand[1] = nullptr; } template NodeOperand(EnumType intVal) { static_assert(sizeof(EnumType) <= sizeof(values), "size of operand must be less than pointer size."); - values.intOperand = 0; + values.intOperand[0] = 0; + values.intOperand[1] = 0; memcpy(&values, &intVal, sizeof(intVal)); } }; @@ -249,6 +254,18 @@ public: }); } + template + DeclRef getSpecializedDeclRef(T* decl, Substitutions* subst) + { + return DeclRef(this, decl, subst); + } + + template + DeclRef getSpecializedDeclRef(T* decl, SubstitutionSet subst) + { + return DeclRef(this, decl, subst); + } + ConstantIntVal* getIntVal(Type* type, IntegerLiteralValue value) { return getOrCreate(type, value); @@ -263,7 +280,7 @@ public: { desc.operands.add(outer); } - auto result = (DeclRefType*)_getOrCreateImpl(desc, [&]() {return create(decl, outer); }); + auto result = (DeclRefType*)_getOrCreateImpl(desc, [&]() {return create(getSpecializedDeclRef(decl, outer)); }); return result; } diff --git a/source/slang/slang-ast-print.cpp b/source/slang/slang-ast-print.cpp index da35a2818..bc0410fee 100644 --- a/source/slang/slang-ast-print.cpp +++ b/source/slang/slang-ast-print.cpp @@ -107,14 +107,14 @@ void ASTPrinter::_addDeclPathRec(const DeclRef& declRef, Index depth) auto& sb = m_builder; // Find the parent declaration - auto parentDeclRef = declRef.getParent(); + auto parentDeclRef = declRef.getParent(m_astBuilder); // If the immediate parent is a generic, then we probably // want the declaration above that... auto parentGenericDeclRef = parentDeclRef.as(); if (parentGenericDeclRef) { - parentDeclRef = parentGenericDeclRef.getParent(); + parentDeclRef = parentGenericDeclRef.getParent(m_astBuilder); } // Depending on what the parent is, we may want to format things specially @@ -224,7 +224,7 @@ void ASTPrinter::addGenericParams(const DeclRef& genericDeclRef) sb << "<"; bool first = true; - for (auto paramDeclRef : getMembers(genericDeclRef)) + for (auto paramDeclRef : getMembers(m_astBuilder, genericDeclRef)) { if (auto genericTypeParam = paramDeclRef.as()) { @@ -270,7 +270,7 @@ void ASTPrinter::addDeclParams(const DeclRef& declRef, List>* sb << "("; bool first = true; - for (auto paramDeclRef : getParameters(funcDeclRef)) + for (auto paramDeclRef : getParameters(m_astBuilder, funcDeclRef)) { if (!first) sb << ", "; @@ -331,7 +331,7 @@ void ASTPrinter::addDeclParams(const DeclRef& declRef, List>* { addGenericParams(genericDeclRef); - addDeclParams(DeclRef(getInner(genericDeclRef), genericDeclRef.substitutions), outParamRange); + addDeclParams(m_astBuilder->getSpecializedDeclRef(getInner(genericDeclRef), genericDeclRef.substitutions), outParamRange); } else { @@ -443,7 +443,7 @@ void ASTPrinter::addDeclResultType(const DeclRef& inDeclRef) DeclRef declRef = inDeclRef; if (auto genericDeclRef = declRef.as()) { - declRef = DeclRef(getInner(genericDeclRef), genericDeclRef.substitutions); + declRef = m_astBuilder->getSpecializedDeclRef(getInner(genericDeclRef), genericDeclRef.substitutions); } if (as(declRef)) diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h index c366a4c4e..b6e98bbd4 100644 --- a/source/slang/slang-ast-support-types.h +++ b/source/slang/slang-ast-support-types.h @@ -740,6 +740,7 @@ namespace Slang template struct DeclRef; + Module* getModule(Decl* decl); // A reference to a declaration, which may include // substitutions for generic parameters. @@ -759,17 +760,22 @@ namespace Slang DeclRefBase(Decl* decl) :decl(decl) - {} + { + } - DeclRefBase(Decl* decl, SubstitutionSet subst) + DeclRefBase(ASTBuilder* astBuilder, Decl* decl, SubstitutionSet subst) :decl(decl), substitutions(subst) - {} + { + SLANG_RELEASE_ASSERT(astBuilder); + } - DeclRefBase(Decl* decl, Substitutions* subst) + DeclRefBase(ASTBuilder* astBuilder, Decl* decl, Substitutions* subst) : decl(decl) , substitutions(subst) - {} + { + SLANG_RELEASE_ASSERT(astBuilder); + } // Apply substitutions to a type or declaration Type* substitute(ASTBuilder* astBuilder, Type* type) const; @@ -801,7 +807,7 @@ namespace Slang Name* getName() const; SourceLoc getNameLoc() const; SourceLoc getLoc() const; - DeclRefBase getParent() const; + DeclRefBase getParent(ASTBuilder* astBuilder) const; HashCode getHashCode() const; @@ -819,24 +825,31 @@ namespace Slang template struct DeclRef : DeclRefBase { + friend class ASTBuilder; + private: + DeclRef(ASTBuilder* builder, T* decl, SubstitutionSet subst) + : DeclRefBase(builder, decl, subst) + {} + + DeclRef(ASTBuilder* builder, T* decl, Substitutions* subst) + : DeclRefBase(builder, decl, SubstitutionSet(subst)) + {} + public: typedef T DeclType; DeclRef() {} - - DeclRef(T* decl, SubstitutionSet subst) - : DeclRefBase(decl, subst) - {} - DeclRef(T* decl, Substitutions* subst) - : DeclRefBase(decl, SubstitutionSet(subst)) + DeclRef(T* decl) + : DeclRefBase(decl) {} template DeclRef(DeclRef const& other, typename EnableIf::Value, void>::type* = 0) - : DeclRefBase(other.decl, other.substitutions) { + this->decl = other.decl; + this->substitutions = other.substitutions; } T* getDecl() const @@ -852,7 +865,10 @@ namespace Slang // static DeclRef unsafeInit(DeclRefBase const& declRef) { - return DeclRef((T*) declRef.decl, declRef.substitutions); + DeclRef rs; + rs.decl = declRef.decl; + rs.substitutions = declRef.substitutions; + return rs; } Type* substitute(ASTBuilder* astBuilder, Type* type) const @@ -878,9 +894,9 @@ namespace Slang return DeclRef::unsafeInit(DeclRefBase::substituteImpl(astBuilder, subst, ioDiff)); } - DeclRef getParent() const + DeclRef getParent(ASTBuilder* astBuilder) const { - return DeclRef::unsafeInit(DeclRefBase::getParent()); + return DeclRef::unsafeInit(DeclRefBase::getParent(astBuilder)); } }; @@ -902,7 +918,7 @@ namespace Slang template inline DeclRef makeDeclRef(T* decl) { - return DeclRef(decl, nullptr); + return DeclRef(decl); } enum class MemberFilterStyle @@ -1033,14 +1049,17 @@ namespace Slang List const& m_decls; SubstitutionSet m_substitutions; MemberFilterStyle m_filterStyle; + ASTBuilder* m_astBuilder; FilteredMemberRefList( + ASTBuilder* astBuilder, List const& decls, SubstitutionSet substitutions, MemberFilterStyle filterStyle = MemberFilterStyle::All) : m_decls(decls) , m_substitutions(substitutions) , m_filterStyle(filterStyle) + , m_astBuilder(astBuilder) {} Index getCount() const { return getFilterCount(m_filterStyle, m_decls.begin(), m_decls.end()); } @@ -1056,7 +1075,7 @@ namespace Slang { Decl*const* decl = getFilterCursorByIndex(m_filterStyle, m_decls.begin(), m_decls.end(), index); SLANG_ASSERT(decl); - return DeclRef((T*) *decl, m_substitutions); + return _getSpecializedDeclRef(m_astBuilder, (T*)*decl, m_substitutions).template as(); } List> toArray() const @@ -1091,7 +1110,7 @@ namespace Slang void operator++() { m_ptr = adjustFilterCursor(m_filterStyle, m_ptr + 1, m_end); } - DeclRef operator*() { return DeclRef((T*)*m_ptr, m_list->m_substitutions); } + DeclRef operator*() { return _getSpecializedDeclRef(m_list->m_astBuilder, (T*)*m_ptr, m_list->m_substitutions).template as(); } }; Iterator begin() const { return Iterator(this, adjustFilterCursor(m_filterStyle, m_decls.begin(), m_decls.end()), m_decls.end(), m_filterStyle); } diff --git a/source/slang/slang-ast-synthesis.cpp b/source/slang/slang-ast-synthesis.cpp index bab651ed9..5ad14321d 100644 --- a/source/slang/slang-ast-synthesis.cpp +++ b/source/slang/slang-ast-synthesis.cpp @@ -67,7 +67,7 @@ Expr* ASTSynthesizer::emitVarExpr(VarDecl* varDecl) Expr* ASTSynthesizer::emitVarExpr(VarDecl* var, Type* type) { auto expr = m_builder->create(); - expr->declRef = DeclRef(var, nullptr); + expr->declRef = DeclRef(var); expr->type.type = type; expr->type.isLeftValue = true; return expr; @@ -76,7 +76,7 @@ Expr* ASTSynthesizer::emitVarExpr(VarDecl* var, Type* type) Expr* ASTSynthesizer::emitVarExpr(DeclStmt* varStmt, Type* type) { auto expr = m_builder->create(); - expr->declRef = DeclRef(as(varStmt->decl), nullptr); + expr->declRef = DeclRef(as(varStmt->decl)); expr->type.type = type; expr->type.isLeftValue = true; return expr; diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp index 90ed1b8e4..c4d301852 100644 --- a/source/slang/slang-ast-type.cpp +++ b/source/slang/slang-ast-type.cpp @@ -777,7 +777,7 @@ DeclRef ExtractExistentialType::getSpecializedInterfaceDeclRef() openedThisType->interfaceDecl = interfaceDecl; openedThisType->witness = openedWitness; - DeclRef specialiedInterfaceDeclRef = DeclRef(interfaceDecl, openedThisType); + DeclRef specialiedInterfaceDeclRef = m_astBuilder->getSpecializedDeclRef(interfaceDecl, openedThisType); this->cachedSpecializedInterfaceDeclRef = specialiedInterfaceDeclRef; return specialiedInterfaceDeclRef; diff --git a/source/slang/slang-ast-type.h b/source/slang/slang-ast-type.h index 7da7ecc88..5113e65f8 100644 --- a/source/slang/slang-ast-type.h +++ b/source/slang/slang-ast-type.h @@ -80,10 +80,6 @@ protected: DeclRefType(DeclRef declRef) : declRef(declRef) {} - - DeclRefType(Decl* decl, Substitutions* substitutions) - : declRef(decl, substitutions) - {} }; // Base class for types that can be used in arithmetic expressions diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp index 21f876048..f9b668f55 100644 --- a/source/slang/slang-ast-val.cpp +++ b/source/slang/slang-ast-val.cpp @@ -349,7 +349,7 @@ Val* DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, Sub } DeclaredSubtypeWitness* rs = astBuilder->getOrCreate( - substSub, substSup, substDeclRef.getDecl(), substDeclRef.substitutions.substitutions); + substSub, substSup, astBuilder->getSpecializedDeclRef(substDeclRef.getDecl(), substDeclRef.substitutions.substitutions)); rs->sub = substSub; rs->sup = substSup; rs->declRef = substDeclRef; diff --git a/source/slang/slang-ast-val.h b/source/slang/slang-ast-val.h index 222ba48d1..218f03200 100644 --- a/source/slang/slang-ast-val.h +++ b/source/slang/slang-ast-val.h @@ -53,11 +53,6 @@ class GenericParamIntVal : public IntVal HashCode _getHashCodeOverride(); Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); - GenericParamIntVal(Type* inType, VarDeclBase* inDecl, Substitutions* inSubst) - : IntVal(inType), declRef(inDecl, inSubst) - {} - -protected: GenericParamIntVal(Type* inType, DeclRef inDeclRef) : IntVal(inType), declRef(inDeclRef) {} @@ -335,8 +330,8 @@ class DeclaredSubtypeWitness : public SubtypeWitness HashCode _getHashCodeOverride(); Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); - DeclaredSubtypeWitness(Type* inSub, Type* inSup, Decl* decl, Substitutions* subst) - : declRef(decl, subst) + DeclaredSubtypeWitness(Type* inSub, Type* inSup, DeclRef inDeclRef) + : declRef(inDeclRef) { sub = inSub; sup = inSup; diff --git a/source/slang/slang-check-conformance.cpp b/source/slang/slang-check-conformance.cpp index 34d6c34cd..8df4631ac 100644 --- a/source/slang/slang-check-conformance.cpp +++ b/source/slang/slang-check-conformance.cpp @@ -13,8 +13,7 @@ namespace Slang DeclaredSubtypeWitness* witness = m_astBuilder->getOrCreate( breadcrumb->sub, breadcrumb->sup, - breadcrumb->declRef.decl, - breadcrumb->declRef.substitutions.substitutions); + m_astBuilder->getSpecializedDeclRef(breadcrumb->declRef.decl, breadcrumb->declRef.substitutions.substitutions)); return witness; } @@ -144,7 +143,7 @@ namespace Slang { DeclaredSubtypeWitness* declaredWitness = m_astBuilder->getOrCreate( - bb->sub, bb->sup, bb->declRef.decl, bb->declRef.substitutions.substitutions); + bb->sub, bb->sup, m_astBuilder->getSpecializedDeclRef(bb->declRef.decl, bb->declRef.substitutions.substitutions)); TransitiveSubtypeWitness* transitiveWitness = m_astBuilder->getOrCreateWithDefaultCtor(); transitiveWitness->sub = subType; @@ -200,7 +199,7 @@ namespace Slang bool SemanticsVisitor::isInterfaceSafeForTaggedUnion( DeclRef interfaceDeclRef) { - for( auto memberDeclRef : getMembers(interfaceDeclRef) ) + for( auto memberDeclRef : getMembers(m_astBuilder, interfaceDeclRef) ) { if(!isInterfaceRequirementSafeForTaggedUnion(interfaceDeclRef, memberDeclRef)) return false; @@ -328,7 +327,7 @@ namespace Slang return true; // if an inheritance decl is not found, try to find a GenericTypeConstraintDecl - for (auto genConstraintDeclRef : getMembersOfType(aggTypeDeclRef)) + for (auto genConstraintDeclRef : getMembersOfType(m_astBuilder, aggTypeDeclRef)) { ensureDecl(genConstraintDeclRef, DeclCheckState::CanUseBaseOfInheritanceDecl); auto inheritedType = getSup(m_astBuilder, genConstraintDeclRef); @@ -348,10 +347,10 @@ namespace Slang // We need to enumerate the constraints placed on this type by its outer // generic declaration, and see if any of them guarantees that we // satisfy the given interface.. - auto genericDeclRef = genericTypeParamDeclRef.getParent().as(); + auto genericDeclRef = genericTypeParamDeclRef.getParent(m_astBuilder).as(); SLANG_ASSERT(genericDeclRef); - for( auto constraintDeclRef : getMembersOfType(genericDeclRef) ) + for( auto constraintDeclRef : getMembersOfType(m_astBuilder, genericDeclRef) ) { ensureDecl(constraintDeclRef, DeclCheckState::CanUseBaseOfInheritanceDecl); auto sub = getSub(m_astBuilder, constraintDeclRef); diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp index f0df78c43..65d716db0 100644 --- a/source/slang/slang-check-constraint.cpp +++ b/source/slang/slang-check-constraint.cpp @@ -285,7 +285,7 @@ namespace Slang // These seem more reasonable to have influence constraint solving, since it could // conceivably let us specialize a `X : IContainer` to `X` if we find // that `X.IndexType == T`. - for( auto constraintDeclRef : getMembersOfType(genericDeclRef) ) + for( auto constraintDeclRef : getMembersOfType(m_astBuilder, genericDeclRef) ) { if(!TryUnifyTypes(*system, getSub(m_astBuilder, constraintDeclRef), getSup(m_astBuilder, constraintDeclRef))) return SubstitutionSet(); @@ -323,7 +323,7 @@ namespace Slang // and try to solve for each. // Count paramCounter = 0; - for (auto m : getMembers(genericDeclRef)) + for (auto m : getMembers(m_astBuilder, genericDeclRef)) { if (auto typeParam = m.as()) { @@ -461,7 +461,7 @@ namespace Slang for( auto constraintDecl : genericDeclRef.getDecl()->getMembersOfType() ) { - DeclRef constraintDeclRef( + DeclRef constraintDeclRef = m_astBuilder->getSpecializedDeclRef( constraintDecl, solvedSubst); diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp index 9ee5bca1f..1afbaf6e8 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -165,7 +165,7 @@ namespace Slang DeclRefType* findBaseStructType(ASTBuilder* astBuilder, DeclRef const& structTypeDeclRef) { - auto inheritanceDecl = getMembersOfType(structTypeDeclRef).getFirstOrNull(); + auto inheritanceDecl = getMembersOfType(astBuilder, structTypeDeclRef).getFirstOrNull(); if(!inheritanceDecl) return nullptr; @@ -184,7 +184,7 @@ namespace Slang DeclRef findBaseStructDeclRef(ASTBuilder* astBuilder, DeclRef const& structTypeDeclRef) { - auto inheritanceDecl = getMembersOfType(structTypeDeclRef).getFirstOrNull(); + auto inheritanceDecl = getMembersOfType(astBuilder, structTypeDeclRef).getFirstOrNull(); if (!inheritanceDecl) return DeclRef(); @@ -454,7 +454,7 @@ namespace Slang // We will go through the fields in order and try to match them // up with initializer arguments. // - for(auto fieldDeclRef : getMembersOfType(toStructDeclRef, MemberFilterStyle::Instance)) + for(auto fieldDeclRef : getMembersOfType(m_astBuilder, toStructDeclRef, MemberFilterStyle::Instance)) { Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index eeb54fc4e..e2d6b797a 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -642,7 +642,7 @@ namespace Slang { if( auto genericTypeParamDecl = as(mm) ) { - args.add(DeclRefType::create(astBuilder, DeclRef(genericTypeParamDecl, outerSubst))); + args.add(DeclRefType::create(astBuilder, astBuilder->getSpecializedDeclRef(genericTypeParamDecl, outerSubst))); } else if( auto genericValueParamDecl = as(mm) ) { @@ -651,7 +651,7 @@ namespace Slang args.add(astBuilder->getOrCreate( genericValueParamDecl->getType(), - genericValueParamDecl, outerSubst)); + astBuilder->getSpecializedDeclRef(genericValueParamDecl, outerSubst))); } } @@ -666,13 +666,12 @@ namespace Slang { ensureDecl(semantics, genericTypeConstraintDecl, DeclCheckState::ReadyForReference); } - auto constraintDeclRef = DeclRef(genericTypeConstraintDecl, outerSubst); + auto constraintDeclRef = astBuilder->getSpecializedDeclRef(genericTypeConstraintDecl, outerSubst); DeclaredSubtypeWitness* witness = astBuilder->getOrCreate( getSub(astBuilder, constraintDeclRef), getSup(astBuilder, constraintDeclRef), - genericTypeConstraintDecl, - outerSubst); + astBuilder->getSpecializedDeclRef(genericTypeConstraintDecl, outerSubst)); // TODO: this is an ugly hack to prevent crashing. // In early stages of compilation witness->sub and witness->sup may not be checked yet. // When semanticVisitor is present we have used that to ensure the type is checked. @@ -1053,7 +1052,7 @@ namespace Slang // if(!isScalarIntegerType(varDecl->type)) return; - tryConstantFoldDeclRef(DeclRef(varDecl, nullptr), nullptr); + tryConstantFoldDeclRef(DeclRef(varDecl), nullptr); } void SemanticsDeclHeaderVisitor::checkDerivativeMemberAttribute( @@ -1996,8 +1995,8 @@ namespace Slang // and those parameters have the right types, and also the result/return type // is the required one. // - auto requiredParams = getParameters(requiredMemberDeclRef).toArray(); - auto satisfyingParams = getParameters(satisfyingMemberDeclRef).toArray(); + auto requiredParams = getParameters(m_astBuilder, requiredMemberDeclRef).toArray(); + auto satisfyingParams = getParameters(m_astBuilder, satisfyingMemberDeclRef).toArray(); auto paramCount = requiredParams.getCount(); if(satisfyingParams.getCount() != paramCount) return false; @@ -2089,7 +2088,7 @@ namespace Slang // than the original declaration. // Dictionary, DeclRef> mapRequiredToSatisfyingAccessorDeclRef; - for( auto requiredAccessorDeclRef : getMembersOfType(requiredMemberDeclRef) ) + for( auto requiredAccessorDeclRef : getMembersOfType(m_astBuilder, requiredMemberDeclRef) ) { // We need to search for an accessor that can satisfy the requirement. // @@ -2097,7 +2096,7 @@ namespace Slang // which is mostly fine because the number of accessors is bounded. // bool found = false; - for( auto satisfyingAccessorDeclRef : getMembersOfType(satisfyingMemberDeclRef) ) + for( auto satisfyingAccessorDeclRef : getMembersOfType(m_astBuilder, satisfyingMemberDeclRef) ) { if( doesAccessorMatchRequirement(satisfyingAccessorDeclRef, requiredAccessorDeclRef) ) { @@ -2200,8 +2199,8 @@ namespace Slang // We then want to check that pairwise members match, in order. // - auto requiredMemberDeclRefs = getMembers(requiredGenericDeclRef); - auto satisfyingMemberDeclRefs = getMembers(satisfyingGenericDeclRef); + auto requiredMemberDeclRefs = getMembers(m_astBuilder, requiredGenericDeclRef); + auto satisfyingMemberDeclRefs = getMembers(m_astBuilder, satisfyingGenericDeclRef); // // We start by performing a superficial "structural" match of the parameters // to ensure that the two generics have an equivalent mix of type, value, @@ -2302,8 +2301,9 @@ namespace Slang auto satisfyingVal = m_astBuilder->getOrCreate( requiredValueParamDeclRef.getDecl()->getType(), - satisfyingValueParamDeclRef.getDecl(), - satisfyingValueParamDeclRef.substitutions.substitutions); + m_astBuilder->getSpecializedDeclRef( + satisfyingValueParamDeclRef.getDecl(), + satisfyingValueParamDeclRef.substitutions.substitutions)); satisfyingVal->declRef = satisfyingValueParamDeclRef; requiredSubstArgs.add(satisfyingVal); @@ -2338,8 +2338,8 @@ namespace Slang // generic, we can construct a reference to that declaration and re-run some // of the earlier checking logic with more type information usable. // - auto specializedRequiredGenericDeclRef = DeclRef(requiredGenericDeclRef.getDecl(), requiredSubst); - auto specializedRequiredMemberDeclRefs = getMembers(specializedRequiredGenericDeclRef); + auto specializedRequiredGenericDeclRef = m_astBuilder->getSpecializedDeclRef(requiredGenericDeclRef.getDecl(), requiredSubst); + auto specializedRequiredMemberDeclRefs = getMembers(m_astBuilder, specializedRequiredGenericDeclRef); for (Index i = 0; i < memberCount; i++) { auto requiredMemberDeclRef = specializedRequiredMemberDeclRefs[i]; @@ -2417,8 +2417,8 @@ namespace Slang // declaration (whatever it is) for an exact match. // return doesMemberSatisfyRequirement( - DeclRef(satisfyingGenericDeclRef.getDecl()->inner, satisfyingGenericDeclRef.substitutions), - DeclRef(requiredGenericDeclRef.getDecl()->inner, requiredSubst), + m_astBuilder->getSpecializedDeclRef(satisfyingGenericDeclRef.getDecl()->inner, satisfyingGenericDeclRef.substitutions), + m_astBuilder->getSpecializedDeclRef(requiredGenericDeclRef.getDecl()->inner, requiredSubst), witnessTable); } @@ -2429,7 +2429,7 @@ namespace Slang // bool conformance = true; Val* witness = nullptr; - for (auto requiredConstraintDeclRef : getMembersOfType(requiredAssociatedTypeDeclRef)) + for (auto requiredConstraintDeclRef : getMembersOfType(m_astBuilder, requiredAssociatedTypeDeclRef)) { // Grab the type we expect to conform to from the constraint. auto requiredSuperType = getSup(m_astBuilder, requiredConstraintDeclRef); @@ -2652,7 +2652,7 @@ namespace Slang // that reference those parametesr as arguments for the call expresison // that makes up the body. // - for (auto paramDeclRef : getParameters(requiredMemberDeclRef)) + for (auto paramDeclRef : getParameters(m_astBuilder, requiredMemberDeclRef)) { auto paramType = getType(m_astBuilder, paramDeclRef); @@ -3031,7 +3031,7 @@ namespace Slang // a subroutine so that it can be shared between properties and subscripts. // Dictionary, AccessorDecl*> mapRequiredAccessorToSynAccessor; - for( auto requiredAccessorDeclRef : getMembersOfType(requiredMemberDeclRef) ) + for( auto requiredAccessorDeclRef : getMembersOfType(m_astBuilder, requiredMemberDeclRef) ) { // The synthesized accessor will be an AST node of the same class as // the required accessor. @@ -3048,7 +3048,7 @@ namespace Slang // and they will only have a single parameter. // List synArgs; - for( auto requiredParamDeclRef : getParameters(requiredAccessorDeclRef) ) + for( auto requiredParamDeclRef : getParameters(m_astBuilder, requiredAccessorDeclRef) ) { auto paramType = getType(m_astBuilder, requiredParamDeclRef); @@ -3515,7 +3515,7 @@ namespace Slang } } - witnessTable->add(requirementDeclRef, RequirementWitness(DeclRef(synFunc, substSet))); + witnessTable->add(requirementDeclRef, RequirementWitness(m_astBuilder->getSpecializedDeclRef(synFunc, substSet))); return true; } @@ -3569,8 +3569,9 @@ namespace Slang m_astBuilder->getOrCreate( superInterfaceType, reqType, - requiredInheritanceDeclRef.getDecl(), - requiredInheritanceDeclRef.substitutions.substitutions); + m_astBuilder->getSpecializedDeclRef( + requiredInheritanceDeclRef.getDecl(), + requiredInheritanceDeclRef.substitutions.substitutions)); // ... TransitiveSubtypeWitness* subIsReqWitness = m_astBuilder->getOrCreateWithDefaultCtor(subType, reqType, interfaceIsReqWitness); @@ -3774,7 +3775,7 @@ namespace Slang thisTypeSubst->witness = subTypeConformsToSuperInterfaceWitness; thisTypeSubst->outer = superInterfaceDeclRef.substitutions.substitutions; - auto specializedSuperInterfaceDeclRef = DeclRef(superInterfaceDeclRef.getDecl(), thisTypeSubst); + auto specializedSuperInterfaceDeclRef = m_astBuilder->getSpecializedDeclRef(superInterfaceDeclRef.getDecl(), thisTypeSubst); bool result = true; @@ -3806,7 +3807,7 @@ namespace Slang // constraints and solve for those type variables as part of the // conformance-checking process. // - for(auto requiredMemberDeclRef : getMembers(specializedSuperInterfaceDeclRef)) + for(auto requiredMemberDeclRef : getMembers(m_astBuilder, specializedSuperInterfaceDeclRef)) { if(!isAssociatedTypeDecl(requiredMemberDeclRef)) continue; @@ -3823,7 +3824,7 @@ namespace Slang result = result && requirementSatisfied; } - for(auto requiredMemberDeclRef : getMembers(specializedSuperInterfaceDeclRef)) + for(auto requiredMemberDeclRef : getMembers(m_astBuilder, specializedSuperInterfaceDeclRef)) { if(isAssociatedTypeDecl(requiredMemberDeclRef)) continue; @@ -3877,7 +3878,7 @@ namespace Slang continue; // Only inheritance clauses from the extension matter right now. - for(auto requiredInheritanceDeclRef : getMembersOfType(extDeclRef)) + for(auto requiredInheritanceDeclRef : getMembersOfType(m_astBuilder, extDeclRef)) { auto requirementSatisfied = findWitnessForInterfaceRequirement( context, @@ -4984,7 +4985,7 @@ namespace Slang // arguments into account. // GenericTypeConstraintDecl* leftConstraint = leftConstraints[cc]; - DeclRef rightConstraint(rightConstraints[cc], substRightToLeft); + DeclRef rightConstraint = m_astBuilder->getSpecializedDeclRef(rightConstraints[cc], substRightToLeft); // For now, every constraint has the form `sub : sup` // to indicate that `sub` must be a subtype of `sup`. @@ -5016,8 +5017,8 @@ namespace Slang { // TODO(tfoley): This copies the parameter array, which is bad for performance. - auto fstParams = getParameters(fst).toArray(); - auto sndParams = getParameters(snd).toArray(); + auto fstParams = getParameters(m_astBuilder, fst).toArray(); + auto sndParams = getParameters(m_astBuilder, snd).toArray(); // If the functions have different numbers of parameters, then // their signatures trivially don't match. @@ -5072,8 +5073,7 @@ namespace Slang { auto val = m_astBuilder->getOrCreate( valueParam->getType(), - valueParam, - nullptr); + DeclRef(valueParam)); args.add(val); } } @@ -5192,8 +5192,8 @@ namespace Slang // We'll go ahead and create some (unspecialized) declaration // references here, just to be prepared. // - DeclRef newDeclRef(newDecl, nullptr); - DeclRef oldDeclRef(oldDecl, nullptr); + DeclRef newDeclRef(newDecl); + DeclRef oldDeclRef(oldDecl); // If we are working with generic functions, then we need to // consider if their generic signatures match. @@ -5649,7 +5649,7 @@ namespace Slang auto reqDecl = m_astBuilder->create(); reqDecl->originalRequirementDecl = decl; cloneModifiers(reqDecl, decl); - auto declRef = DeclRef(decl, createDefaultSubstitutions(m_astBuilder, this, decl)); + auto declRef = m_astBuilder->getSpecializedDeclRef(decl, createDefaultSubstitutions(m_astBuilder, this, decl)); auto diffFuncType = getForwardDiffFuncType(getFuncType(m_astBuilder, declRef)); setFuncTypeIntoRequirementDecl(reqDecl, as(diffFuncType)); interfaceDecl->members.add(reqDecl); @@ -5664,7 +5664,7 @@ namespace Slang if (decl->hasModifier()) { // Requirement for backward derivative. - auto declRef = DeclRef(decl, createDefaultSubstitutions(m_astBuilder, this, decl)); + auto declRef = m_astBuilder->getSpecializedDeclRef(decl, createDefaultSubstitutions(m_astBuilder, this, decl)); auto originalFuncType = getFuncType(m_astBuilder, declRef); auto diffFuncType = as(getBackwardDiffFuncType(originalFuncType)); { @@ -6218,7 +6218,7 @@ namespace Slang if (!TryUnifyTypes(constraints, extDecl->targetType.Ptr(), type)) return DeclRef(); - auto constraintSubst = trySolveConstraintSystem(&constraints, DeclRef(extGenericDecl, nullptr).as()); + auto constraintSubst = trySolveConstraintSystem(&constraints, m_astBuilder->getSpecializedDeclRef(extGenericDecl, nullptr).as()); if (!constraintSubst) { return DeclRef(); @@ -6226,7 +6226,7 @@ namespace Slang // Construct a reference to the extension with our constraint variables // set as they were found by solving the constraint system. - extDeclRef = DeclRef(extDecl, constraintSubst).as(); + extDeclRef = m_astBuilder->getSpecializedDeclRef(extDecl, constraintSubst).as(); } // Now extract the target type from our (possibly specialized) extension decl-ref. @@ -6267,7 +6267,7 @@ namespace Slang newTargetSubst->outer = targetInterfaceDeclRef.substitutions.substitutions; targetType = DeclRefType::create(m_astBuilder, - DeclRef(targetInterfaceDeclRef.getDecl(), newTargetSubst)); + m_astBuilder->getSpecializedDeclRef(targetInterfaceDeclRef.getDecl(), newTargetSubst)); // Note: we are constructing a this-type substitution that // we will apply to the extension declaration as well. @@ -6281,7 +6281,7 @@ namespace Slang newExtSubst->witness = appThisTypeSubst->witness; newExtSubst->outer = extDeclRef.substitutions.substitutions; - extDeclRef = DeclRef( + extDeclRef = m_astBuilder->getSpecializedDeclRef( extDeclRef.getDecl(), newExtSubst); @@ -6754,7 +6754,7 @@ namespace Slang // // We start with the direct members. // - for( auto memberDeclRef : getMembers(containerDeclRef) ) + for( auto memberDeclRef : getMembers(semantics->getASTBuilder(), containerDeclRef)) { if( memberDeclRef.decl->getClass().isSubClassOfImpl(syntaxClass) ) { @@ -6786,7 +6786,7 @@ namespace Slang if(!extDeclRef) continue; - for( auto memberDeclRef : getMembers(extDeclRef) ) + for( auto memberDeclRef : getMembers(semantics->getASTBuilder(), extDeclRef) ) { if( memberDeclRef.decl->getClass().isSubClassOfImpl(syntaxClass) ) { @@ -6850,14 +6850,15 @@ namespace Slang } } OrderedDictionary> getCanonicalGenericConstraints( + ASTBuilder* astBuilder, DeclRef genericDecl) { OrderedDictionary> genericConstraints; - for (auto mm : getMembersOfType(genericDecl)) + for (auto mm : getMembersOfType(astBuilder, genericDecl)) { genericConstraints[mm.getDecl()] = List(); } - for (auto genericTypeConstraintDecl : getMembersOfType(genericDecl)) + for (auto genericTypeConstraintDecl : getMembersOfType(astBuilder, genericDecl)) { assert( genericTypeConstraintDecl.getDecl()->sub.type->astNodeType == @@ -7246,8 +7247,7 @@ namespace Slang auto derivativeAttr = visitor->getASTBuilder()->create(); derivativeAttr->loc = derivativeOfAttr->loc; auto outterGeneric = visitor->GetOuterGeneric(funcDecl); - auto declRef = - DeclRef((outterGeneric ? (Decl*)outterGeneric : funcDecl), nullptr); + auto declRef = visitor->getASTBuilder()->getSpecializedDeclRef((outterGeneric ? (Decl*)outterGeneric : funcDecl), nullptr); auto declRefExpr = visitor->ConstructDeclRefExpr(declRef, nullptr, derivativeOfAttr->loc, nullptr); declRefExpr->type.type = nullptr; derivativeAttr->args.add(declRefExpr); diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 587dcc2b5..aa3ca889d 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -538,7 +538,7 @@ namespace Slang synthesizedDecl = structDecl; auto typeDef = m_astBuilder->create(); typeDef->nameAndLoc.name = getName("Differential"); - auto declRef = createDefaultSubstitutionsIfNeeded(m_astBuilder, this, DeclRef(structDecl, nullptr)); + auto declRef = createDefaultSubstitutionsIfNeeded(m_astBuilder, this,m_astBuilder->getSpecializedDeclRef(structDecl, nullptr)); typeDef->type.type = m_astBuilder->getOrCreateDeclRefType(declRef.decl, declRef.substitutions); typeDef->parentDecl = structDecl; structDecl->members.add(typeDef); @@ -1577,8 +1577,9 @@ namespace Slang { Val* valResult = m_astBuilder->getOrCreate( declRef.substitute(m_astBuilder, genericValParamRef.getDecl()->getType()), - genericValParamRef.getDecl(), - genericValParamRef.substitutions.substitutions); + m_astBuilder->getSpecializedDeclRef( + genericValParamRef.getDecl(), + genericValParamRef.substitutions.substitutions)); valResult = valResult->substitute(m_astBuilder, expr.getSubsts()); return as(valResult); } @@ -2472,7 +2473,7 @@ namespace Slang if (auto baseFuncGenericDeclRef = declRefExpr->declRef.as()) { // Get inner function - DeclRef unspecializedInnerRef = DeclRef( + DeclRef unspecializedInnerRef = astBuilder->getSpecializedDeclRef( getInner(baseFuncGenericDeclRef), baseFuncGenericDeclRef.substitutions); auto callableDeclRef = unspecializedInnerRef.as(); @@ -3576,7 +3577,7 @@ namespace Slang for (auto lookupResult : overloadedExpr->lookupResult2) { bool shouldRemove = false; - if (lookupResult.declRef.getParent().as()) + if (lookupResult.declRef.getParent(m_astBuilder).as()) { shouldRemove = true; } diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 0d10b05be..a72ca621f 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -103,7 +103,7 @@ namespace Slang switch (candidate.flavor) { case OverloadCandidate::Flavor::Func: - paramCounts = CountParameters(getParameters(candidate.item.declRef.as())); + paramCounts = CountParameters(getParameters(m_astBuilder, candidate.item.declRef.as())); break; case OverloadCandidate::Flavor::Generic: @@ -232,7 +232,7 @@ namespace Slang bool success = true; Index aa = 0; - for (auto memberRef : getMembers(genericDeclRef)) + for (auto memberRef : getMembers(m_astBuilder, genericDeclRef)) { if (auto typeParamRef = memberRef.as()) { @@ -367,7 +367,7 @@ namespace Slang switch (candidate.flavor) { case OverloadCandidate::Flavor::Func: - for (auto param : getParameters(candidate.item.declRef.as())) + for (auto param : getParameters(m_astBuilder, candidate.item.declRef.as())) { auto paramType = getType(m_astBuilder, param); paramTypes.add(paramType); @@ -524,7 +524,7 @@ namespace Slang { auto subset = genericDeclRef.substitutions; subset.substitutions = subst; - DeclRef constraintDeclRef( + DeclRef constraintDeclRef = m_astBuilder->getSpecializedDeclRef( constraintDecl, subset); auto sub = getSub(m_astBuilder, constraintDeclRef); @@ -598,7 +598,7 @@ namespace Slang subst->genericDecl = baseGenericRef.getDecl(); subst->outer = baseGenericRef.substitutions.substitutions; - DeclRef innerDeclRef(getInner(baseGenericRef), subst); + DeclRef innerDeclRef = m_astBuilder->getSpecializedDeclRef(getInner(baseGenericRef), subst); Expr* base = nullptr; if (auto mbrExpr = as(baseExpr)) @@ -688,7 +688,8 @@ namespace Slang if(auto subscriptDeclRef = candidate.item.declRef.as()) { const auto& decl = subscriptDeclRef.getDecl(); - if (decl->getMembersOfType().isNonEmpty() || decl->getMembersOfType().isNonEmpty()) + if (decl->getMembersOfType().isNonEmpty() || + decl->getMembersOfType().isNonEmpty()) { callExpr->type.isLeftValue = true; } @@ -762,14 +763,14 @@ namespace Slang } /// Does the given `declRef` represent an interface requirement? - bool isInterfaceRequirement(DeclRef const& declRef) + bool isInterfaceRequirement(ASTBuilder* builder, DeclRef const& declRef) { if(!declRef) return false; - auto parent = declRef.getParent(); + auto parent = declRef.getParent(builder); if(parent.as()) - parent = parent.getParent(); + parent = parent.getParent(builder); if(parent.as()) return true; @@ -789,7 +790,7 @@ namespace Slang // "inner" declaration of a generic. That means that // the parent of the decl ref must be a generic. // - auto parentGeneric = declRef.getParent().as(); + auto parentGeneric = declRef.getParent(m_astBuilder).as(); if(!parentGeneric) return 0; // @@ -1243,7 +1244,7 @@ namespace Slang } auto innerDecl = getInner(genericDeclRef); - DeclRef partiallySpecializedInnerRef = DeclRef( + DeclRef partiallySpecializedInnerRef = m_astBuilder->getSpecializedDeclRef( innerDecl, substForInnerDecl); @@ -1254,7 +1255,7 @@ namespace Slang List paramTypes; if (!innerParameterTypes) { - auto params = getParameters(funcDeclRef).toArray(); + auto params = getParameters(m_astBuilder, funcDeclRef).toArray(); for (auto param : params) { paramTypes.add(getType(m_astBuilder, param)); @@ -1273,7 +1274,7 @@ namespace Slang // if (valueArgCount > valueParamCount) { - return DeclRef(nullptr, nullptr); + return DeclRef(nullptr); } // If any of the arguments were specified explicitly (and are thus known), @@ -1309,7 +1310,7 @@ namespace Slang else { // TODO(tfoley): any other cases needed here? - return DeclRef(nullptr, nullptr); + return DeclRef(nullptr); } // Once we have added all the appropriate constraints to the system, we @@ -1337,14 +1338,14 @@ namespace Slang // diagnostics), or this code could have a "just trying" vs. "actually // do things" distinction like some other steps. // - return DeclRef(nullptr, nullptr); + return DeclRef(nullptr); } // If we found a solution (that is, a set of argument values that satisfy // all the constraints), we can construct a reference to the inner // declaration that applies the generic to those arguments. // - return DeclRef(innerDecl, constraintSubst); + return m_astBuilder->getSpecializedDeclRef(innerDecl, constraintSubst); } void SemanticsVisitor::AddTypeOverloadCandidates( diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp index ed426831c..acefa7660 100644 --- a/source/slang/slang-check-shader.cpp +++ b/source/slang/slang-check-shader.cpp @@ -101,7 +101,7 @@ namespace Slang // A structure type should recursively introduce // existential slots for its fields. // - for( auto fieldDeclRef : getFields(structDeclRef, MemberFilterStyle::Instance) ) + for( auto fieldDeclRef : getFields(astBuilder, structDeclRef, MemberFilterStyle::Instance) ) { _collectExistentialSpecializationParamsRec( astBuilder, @@ -206,7 +206,7 @@ namespace Slang // if( auto funcDeclRef = getFuncDeclRef() ) { - for( auto paramDeclRef : getParameters(funcDeclRef) ) + for( auto paramDeclRef : getParameters(getLinkage()->getASTBuilder(), funcDeclRef) ) { ShaderParamInfo shaderParamInfo; shaderParamInfo.paramDeclRef = paramDeclRef; @@ -1059,7 +1059,7 @@ namespace Slang for(auto constraintDecl : genericTypeParamDecl->getMembersOfType()) { // Get the type that the constraint is enforcing conformance to - auto interfaceType = getSup(getLinkage()->getASTBuilder(), DeclRef(constraintDecl, nullptr)); + auto interfaceType = getSup(getLinkage()->getASTBuilder(), DeclRef(constraintDecl)); // Use our semantic-checking logic to search for a witness to the required conformance auto witness = visitor.tryGetSubtypeWitness(argType, interfaceType); @@ -1193,7 +1193,7 @@ namespace Slang // the semantic checking machinery to expand out // the rest of the arguments via inference... - auto genericDeclRef = m_funcDeclRef.getParent().as(); + auto genericDeclRef = m_funcDeclRef.getParent(getLinkage()->getASTBuilder()).as(); SLANG_ASSERT(genericDeclRef); // otherwise we wouldn't have generic parameters List genericArgs; @@ -1214,7 +1214,7 @@ namespace Slang auto constraintSubst = genericDeclRef.substitutions; constraintSubst.substitutions = genericSubst; - DeclRef constraintDeclRef( + DeclRef constraintDeclRef = getLinkage()->getASTBuilder()->getSpecializedDeclRef( constraintDecl, constraintSubst); ASTBuilder* astBuilder = getLinkage()->getASTBuilder(); diff --git a/source/slang/slang-check.h b/source/slang/slang-check.h index a7d51f951..e59f299fa 100644 --- a/source/slang/slang-check.h +++ b/source/slang/slang-check.h @@ -24,5 +24,5 @@ namespace Slang void registerBuiltinDecls(Session* session, Decl* decl); OrderedDictionary> getCanonicalGenericConstraints( - DeclRef genericDecl); + ASTBuilder* builder, DeclRef genericDecl); } diff --git a/source/slang/slang-doc-markdown-writer.cpp b/source/slang/slang-doc-markdown-writer.cpp index f2e6158d5..a439b4454 100644 --- a/source/slang/slang-doc-markdown-writer.cpp +++ b/source/slang/slang-doc-markdown-writer.cpp @@ -271,7 +271,7 @@ void DocMarkdownWriter::writeSignature(CallableDecl* callableDecl) List parts; ASTPrinter printer(m_astBuilder, ASTPrinter::OptionFlag::ParamNames, &parts); - printer.addDeclSignature(DeclRef(callableDecl, nullptr)); + printer.addDeclSignature(m_astBuilder->getSpecializedDeclRef(callableDecl, nullptr)); Signature signature; getSignature(parts, signature); @@ -689,7 +689,7 @@ void DocMarkdownWriter::writeCallableOverridable(const ASTMarkup::Entry& entry, { // Output the overridable path (ie without terminal generic parameters) ASTPrinter printer(m_astBuilder); - printer.addOverridableDeclPath(DeclRef(callableDecl, nullptr)); + printer.addOverridableDeclPath(DeclRef(callableDecl)); // Extract the name out << toSlice("# `") << printer.getStringBuilder() << toSlice("`\n\n"); } @@ -938,7 +938,7 @@ void DocMarkdownWriter::_appendAggTypeName(AggTypeDeclBase* aggTypeDecl) // This could be lots of different things - struct/class/extension/interface/.. ASTPrinter printer(m_astBuilder); - printer.addDeclPath(DeclRef(aggTypeDecl, nullptr)); + printer.addDeclPath(DeclRef(aggTypeDecl)); if (as(aggTypeDecl)) { @@ -972,7 +972,7 @@ void DocMarkdownWriter::writeAggType(const ASTMarkup::Entry& entry, AggTypeDeclB // We can write out he name using the printer ASTPrinter printer(m_astBuilder); - printer.addDeclPath(DeclRef(aggTypeDecl, nullptr)); + printer.addDeclPath(DeclRef(aggTypeDecl)); out << toSlice("# `"); _appendAggTypeName(aggTypeDecl); diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp index dbe031fd3..db50f9bdb 100644 --- a/source/slang/slang-language-server.cpp +++ b/source/slang/slang-language-server.cpp @@ -232,19 +232,19 @@ String getDeclKindString(DeclRef declRef) } else if (auto varDecl = declRef.as()) { - auto parent = declRef.getParent(); + auto parent = declRef.getDecl()->parentDecl; if (as(parent)) - parent = parent.getParent(); - if (parent.as()) + parent = parent->parentDecl; + if (as(parent)) { return "(associated constant) "; } - else if (parent.as()) + else if (as(parent)) { return "(field) "; } const char* scopeKind = ""; - if (parent.as()) + if (as(parent)) scopeKind = "global "; else if (getParentDecl(declRef.getDecl())) scopeKind = "local "; @@ -707,11 +707,11 @@ SlangResult LanguageServer::hover( } else if (auto decl = as(leafNode)) { - fillDeclRefHoverInfo(DeclRef(decl, nullptr)); + fillDeclRefHoverInfo(version->linkage->getASTBuilder()->getSpecializedDeclRef(decl, nullptr)); } else if (auto attr = as(leafNode)) { - fillDeclRefHoverInfo(DeclRef(attr->attributeDecl, nullptr)); + fillDeclRefHoverInfo(version->linkage->getASTBuilder()->getSpecializedDeclRef(attr->attributeDecl, nullptr)); } if (sb.getLength() == 0) { @@ -1320,7 +1320,7 @@ SlangResult LanguageServer::signatureHelp( // Look for initializers for (auto member : aggDecl->getMembersOfType()) { - addDeclRef(DeclRef(member, declRefExpr->declRef.substitutions)); + addDeclRef(version->linkage->getASTBuilder()->getSpecializedDeclRef(member, declRefExpr->declRef.substitutions)); } } else diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index 484797344..0c4279761 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -167,7 +167,7 @@ static void _lookUpDirectAndTransparentMembers( AddToLookupResult( result, CreateLookupResultItem( - DeclRef(member, containerDeclRef.substitutions), inBreadcrumbs)); + astBuilder->getSpecializedDeclRef(member, containerDeclRef.substitutions), inBreadcrumbs)); } } else @@ -186,7 +186,7 @@ static void _lookUpDirectAndTransparentMembers( continue; // The declaration passed the test, so add it! - AddToLookupResult(result, CreateLookupResultItem(DeclRef(m, containerDeclRef.substitutions), inBreadcrumbs)); + AddToLookupResult(result, CreateLookupResultItem(astBuilder->getSpecializedDeclRef(m, containerDeclRef.substitutions), inBreadcrumbs)); } } @@ -196,7 +196,7 @@ static void _lookUpDirectAndTransparentMembers( { // The reference to the transparent member should use whatever // substitutions we used in referring to its outer container - DeclRef transparentMemberDeclRef(transparentInfo.decl, containerDeclRef.substitutions); + DeclRef transparentMemberDeclRef = astBuilder->getSpecializedDeclRef(transparentInfo.decl, containerDeclRef.substitutions); // We need to leave a breadcrumb so that we know that the result // of lookup involves a member lookup step here @@ -307,7 +307,7 @@ static Type* _maybeSpecializeSuperType( thisTypeSubst->witness = subIsSuperWitness; thisTypeSubst->outer = superInterfaceDeclRef.substitutions.substitutions; - auto specializedInterfaceDeclRef = DeclRef(superInterfaceDeclRef.getDecl(), thisTypeSubst); + auto specializedInterfaceDeclRef = astBuilder->getSpecializedDeclRef(superInterfaceDeclRef.getDecl(), thisTypeSubst); auto specializedInterfaceType = DeclRefType::create(astBuilder, specializedInterfaceDeclRef); return specializedInterfaceType; @@ -432,10 +432,10 @@ static void _lookUpMembersInSuperTypeDeclImpl( // then the members it provides can only be discovered by looking // at the constraints that are placed on that type. - auto genericDeclRef = genericTypeParamDeclRef.getParent().as(); + auto genericDeclRef = genericTypeParamDeclRef.getParent(astBuilder).as(); assert(genericDeclRef); - for(auto constraintDeclRef : getMembersOfType(genericDeclRef)) + for(auto constraintDeclRef : getMembersOfType(astBuilder, genericDeclRef)) { if( semantics ) { @@ -467,7 +467,7 @@ static void _lookUpMembersInSuperTypeDeclImpl( } else if (declRef.as() || declRef.as()) { - for (auto constraintDeclRef : getMembersOfType(declRef.as())) + for (auto constraintDeclRef : getMembersOfType(astBuilder, declRef.as())) { _lookUpMembersInSuperType( astBuilder, @@ -534,7 +534,7 @@ static void _lookUpMembersInSuperTypeDeclImpl( // through the declared inheritance relationships on each declaration. // ensureDecl(semantics, aggTypeDeclBaseRef.getDecl(), DeclCheckState::CanEnumerateBases); - for (auto inheritanceDeclRef : getMembersOfType(aggTypeDeclBaseRef)) + for (auto inheritanceDeclRef : getMembersOfType(astBuilder, aggTypeDeclBaseRef)) { ensureDecl(semantics, inheritanceDeclRef.getDecl(), DeclCheckState::CanUseBaseOfInheritanceDecl); @@ -801,7 +801,7 @@ static void _lookUpInScopes( // just a decl. // DeclRef containerDeclRef = - DeclRef(containerDecl, createDefaultSubstitutions(astBuilder, request.semantics, containerDecl)).as(); + astBuilder->getSpecializedDeclRef(containerDecl, createDefaultSubstitutions(astBuilder, request.semantics, containerDecl)).as(); // If the container we are looking into represents a type // or an `extension` of a type, then we need to treat diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index c70cdb948..babadb0f5 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -883,7 +883,7 @@ static LoweredValInfo lowerStorageReference( { DeclRef getterDeclRef; bool justAGetter = true; - for (auto accessorDeclRef : getMembersOfType(storageDeclRef, MemberFilterStyle::Instance)) + for (auto accessorDeclRef : getMembersOfType(context->astBuilder, storageDeclRef, MemberFilterStyle::Instance)) { // We want to track whether this storage has any accessors other than // `get` (assuming that everything except `get` can be used for setting...). @@ -1018,7 +1018,7 @@ top: // in case the `get` operation has a natural translation for // a target, while the general `ref` case does not...) - auto getters = getMembersOfType(boundStorageInfo->declRef, MemberFilterStyle::Instance); + auto getters = getMembersOfType(context->astBuilder, boundStorageInfo->declRef, MemberFilterStyle::Instance); if (getters.getCount()) { auto getter = *getters.begin(); @@ -1031,7 +1031,7 @@ top: goto top; } - auto refAccessors = getMembersOfType(boundStorageInfo->declRef, MemberFilterStyle::Instance); + auto refAccessors = getMembersOfType(context->astBuilder, boundStorageInfo->declRef, MemberFilterStyle::Instance); if(refAccessors.getCount()) { auto refAccessor = *refAccessors.begin(); @@ -1643,7 +1643,7 @@ struct ValLoweringVisitor : ValVisitorastBuilder, supInterfaceDeclRef) ) { // TODO: if there are any members we shouldn't process as a requirement, // then we should detect and skip them here. @@ -1707,7 +1707,7 @@ struct ValLoweringVisitor : ValVisitor irParams; - for( auto paramDeclRef : getMembersOfType(callableDeclRef) ) + for( auto paramDeclRef : getMembersOfType(context->astBuilder, callableDeclRef) ) { // TODO: need to handle `out` and `in out` here. Over all // there is a lot of duplication here with the existing logic @@ -2889,13 +2889,13 @@ Type* getThisParamTypeForCallable( IRGenContext* context, DeclRef callableDeclRef) { - auto parentDeclRef = callableDeclRef.getParent(); + auto parentDeclRef = callableDeclRef.getParent(context->astBuilder); if(auto subscriptDeclRef = parentDeclRef.as()) - parentDeclRef = subscriptDeclRef.getParent(); + parentDeclRef = subscriptDeclRef.getParent(context->astBuilder); if(auto genericDeclRef = parentDeclRef.as()) - parentDeclRef = genericDeclRef.getParent(); + parentDeclRef = genericDeclRef.getParent(context->astBuilder); return getThisParamTypeForContainer(context, parentDeclRef); } @@ -3033,7 +3033,7 @@ void collectParameterLists( // The parameters introduced by any "parent" declarations // will need to come first, so we'll deal with that // logic here. - if( auto parentDeclRef = declRef.getParent() ) + if( auto parentDeclRef = declRef.getParent(context->astBuilder) ) { // Compute the mode to use when collecting parameters from // the outer declaration. The most important question here @@ -3077,7 +3077,7 @@ void collectParameterLists( // we are in a `static` context. if( mode == kParameterListCollectMode_Default ) { - for( auto paramDeclRef : getParameters(callableDeclRef) ) + for( auto paramDeclRef : getParameters(context->astBuilder, callableDeclRef) ) { ioParameterLists->params.add(getParameterInfo(context, paramDeclRef)); } @@ -3645,7 +3645,7 @@ struct ExprLoweringVisitorBase : ExprVisitor } } - for (auto ff : getMembersOfType(aggTypeDeclRef, MemberFilterStyle::Instance)) + for (auto ff : getMembersOfType(getASTBuilder(), aggTypeDeclRef, MemberFilterStyle::Instance)) { auto irFieldVal = getSimpleVal(context, getDefaultVal(ff)); args.add(irFieldVal); @@ -3792,7 +3792,7 @@ struct ExprLoweringVisitorBase : ExprVisitor } } - for (auto ff : getMembersOfType(aggTypeDeclRef, MemberFilterStyle::Instance)) + for (auto ff : getMembersOfType(getASTBuilder(), aggTypeDeclRef, MemberFilterStyle::Instance)) { UInt argIndex = argCounter++; if (argIndex < argCount) @@ -4016,7 +4016,7 @@ struct ExprLoweringVisitorBase : ExprVisitor List* ioFixups) { Count argCounter = 0; - for (auto paramDeclRef : getMembersOfType(funcDeclRef)) + for (auto paramDeclRef : getMembersOfType(getASTBuilder(), funcDeclRef)) { auto paramDecl = paramDeclRef.getDecl(); IRType* paramType = lowerType(context, getType(getASTBuilder(), paramDeclRef)); @@ -6004,14 +6004,14 @@ LoweredValInfo tryGetAddress( // where we really want/need a pointer to be able to make progress. // if(mode != TryGetAddressMode::Aggressive - && getMembersOfType(subscriptInfo->declRef, MemberFilterStyle::Instance).isNonEmpty()) + && getMembersOfType(context->astBuilder, subscriptInfo->declRef, MemberFilterStyle::Instance).isNonEmpty()) { // There is a setter that we should consider using, // so don't go and aggressively collapse things just yet. return val; } - auto refAccessors = getMembersOfType(subscriptInfo->declRef, MemberFilterStyle::Instance); + auto refAccessors = getMembersOfType(context->astBuilder, subscriptInfo->declRef, MemberFilterStyle::Instance); if(refAccessors.isNonEmpty()) { auto refAccessor = *refAccessors.begin(); @@ -6378,7 +6378,7 @@ top: auto subscriptInfo = left.getBoundStorageInfo(); // Search for an appropriate "setter" declaration - auto setters = getMembersOfType(subscriptInfo->declRef, MemberFilterStyle::Instance); + auto setters = getMembersOfType(context->astBuilder, subscriptInfo->declRef, MemberFilterStyle::Instance); if (setters.isNonEmpty()) { auto setter = *setters.begin(); @@ -6404,7 +6404,7 @@ top: return; } - auto refAccessors = getMembersOfType(subscriptInfo->declRef, MemberFilterStyle::Instance); + auto refAccessors = getMembersOfType(context->astBuilder, subscriptInfo->declRef, MemberFilterStyle::Instance); if(refAccessors.isNonEmpty()) { auto refAccessor = *refAccessors.begin(); diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp index 3b0d12da8..ee34358ab 100644 --- a/source/slang/slang-mangle.cpp +++ b/source/slang/slang-mangle.cpp @@ -355,7 +355,7 @@ namespace Slang ManglingContext* context, DeclRef declRef) { - auto parentDeclRef = declRef.getParent(); + auto parentDeclRef = declRef.getParent(context->astBuilder); auto parentGenericDeclRef = parentDeclRef.as(); if( parentDeclRef ) { @@ -441,7 +441,7 @@ namespace Slang // information about the parameters of the generic here. emitRaw(context, "g"); UInt genericParameterCount = 0; - for( auto mm : getMembers(parentGenericDeclRef) ) + for( auto mm : getMembers(context->astBuilder, parentGenericDeclRef) ) { if(mm.is()) { @@ -463,7 +463,7 @@ namespace Slang emit(context, genericParameterCount); OrderedDictionary> genericConstraints; - for (auto mm : getMembers(parentGenericDeclRef)) + for (auto mm : getMembers(context->astBuilder, parentGenericDeclRef)) { if (auto genericTypeParamDecl = mm.as()) { @@ -478,13 +478,13 @@ namespace Slang {} } - auto canonicalizedConstraints = getCanonicalGenericConstraints(parentGenericDeclRef); + auto canonicalizedConstraints = getCanonicalGenericConstraints(context->astBuilder, parentGenericDeclRef); for (auto& constraint : canonicalizedConstraints) { for (auto type : constraint.value) { emitRaw(context, "C"); - emitQualifiedName(context, DeclRef(constraint.key, nullptr)); + emitQualifiedName(context, context->astBuilder->getSpecializedDeclRef(constraint.key, nullptr)); emitType(context, type); } } @@ -501,7 +501,7 @@ namespace Slang // if( auto callableDeclRef = declRef.as()) { - auto parameters = getParameters(callableDeclRef); + auto parameters = getParameters(context->astBuilder, callableDeclRef); UInt parameterCount = parameters.getCount(); emitRaw(context, "p"); @@ -598,7 +598,7 @@ namespace Slang String getMangledName(ASTBuilder* astBuilder, DeclRefBase const & declRef) { return getMangledName(astBuilder, - DeclRef(declRef.decl, declRef.substitutions)); + astBuilder->getSpecializedDeclRef(declRef.decl, declRef.substitutions)); } String getMangledName(ASTBuilder* astBuilder, Decl* decl) diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index cd238f623..4679e58c3 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -2037,7 +2037,7 @@ static RefPtr processEntryPointVaryingParameter( // Decl* firstExplicit = nullptr; Decl* firstImplicit = nullptr; - for( auto field : getFields(structDeclRef, MemberFilterStyle::Instance) ) + for( auto field : getFields(context->getASTBuilder(), structDeclRef, MemberFilterStyle::Instance) ) { RefPtr fieldVarLayout = new VarLayout(); fieldVarLayout->varDecl = field; diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index f790cd4d2..5f9d5fbc4 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -1371,7 +1371,7 @@ namespace Slang auto paramType = DeclRefType::create( parser->astBuilder, - DeclRef(paramDecl, nullptr)); + DeclRef(paramDecl)); auto paramTypeExpr = parser->astBuilder->create(); paramTypeExpr->loc = paramDecl->loc; @@ -3107,7 +3107,7 @@ namespace Slang parser->FillPosition(paramConstraint); // substitution needs to be filled during check - DeclRefType* paramType = DeclRefType::create(parser->astBuilder, DeclRef(decl, nullptr)); + DeclRefType* paramType = DeclRefType::create(parser->astBuilder, DeclRef(decl)); SharedTypeExpr* paramTypeExpr = parser->astBuilder->create(); paramTypeExpr->loc = decl->loc; @@ -4320,7 +4320,7 @@ namespace Slang { // TODO(JS): // Is it valid to always have empty substitution set here? - DeclRef declRef(aggTypeDecl, SubstitutionSet()); + DeclRef declRef(aggTypeDecl); auto lookupResult = lookUpDirectAndTransparentMembers( parser->astBuilder, diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index 8ec0979e4..07857c293 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -432,7 +432,11 @@ SLANG_API unsigned int spReflectionType_GetFieldCount(SlangReflectionType* inTyp auto declRef = declRefType->declRef; if( auto structDeclRef = declRef.as()) { - return (unsigned int)getFields(structDeclRef, MemberFilterStyle::Instance).getCount(); + return (unsigned int)getFields( + getModule(declRef.decl)->getLinkage()->getASTBuilder(), + structDeclRef, + MemberFilterStyle::Instance) + .getCount(); } } @@ -451,7 +455,8 @@ SLANG_API SlangReflectionVariable* spReflectionType_GetFieldByIndex(SlangReflect auto declRef = declRefType->declRef; if( auto structDeclRef = declRef.as()) { - auto fields = getFields(structDeclRef, MemberFilterStyle::Instance); + auto fields = getFields( + getModule(declRef)->getLinkage()->getASTBuilder(), structDeclRef, MemberFilterStyle::Instance); auto fieldDeclRef = fields[index]; return (SlangReflectionVariable*) fieldDeclRef.getDecl(); } diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp index 53e77e646..09329689e 100644 --- a/source/slang/slang-syntax.cpp +++ b/source/slang/slang-syntax.cpp @@ -723,7 +723,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt int diff = 0; auto declRefBase = declRef.substituteImpl(astBuilder, substs, &diff); - return DeclRef(declRefBase.decl, declRefBase.substitutions); + return astBuilder->getSpecializedDeclRef(declRefBase.decl, declRefBase.substitutions); } Type* substituteType(SubstitutionSet const& substs, ASTBuilder* astBuilder, Type* type) @@ -1006,7 +1006,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return decl->loc; } - DeclRefBase DeclRefBase::getParent() const + DeclRefBase DeclRefBase::getParent(ASTBuilder* astBuilder) const { // Want access to the free function (the 'as' method by default gets priority) // Can access as method with this->as because it removes any ambiguity. @@ -1054,7 +1054,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt } } - return DeclRefBase(parentDecl, substToApply); + return astBuilder->getSpecializedDeclRef(parentDecl, substToApply); } HashCode DeclRefBase::getHashCode() const @@ -1138,7 +1138,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt funcType->resultType = getResultType(astBuilder, declRef); funcType->errorType = getErrorCodeType(astBuilder, declRef); - for (auto paramDeclRef : getParameters(declRef)) + for (auto paramDeclRef : getParameters(astBuilder, declRef)) { auto paramDecl = paramDeclRef.getDecl(); auto paramType = getParamType(astBuilder, paramDeclRef); diff --git a/source/slang/slang-syntax.h b/source/slang/slang-syntax.h index 65ad121a0..ec740d218 100644 --- a/source/slang/slang-syntax.h +++ b/source/slang/slang-syntax.h @@ -52,15 +52,15 @@ namespace Slang DeclRef const& declRef, SemanticsVisitor* semantics); - inline FilteredMemberRefList getMembers(DeclRef const& declRef, MemberFilterStyle filterStyle = MemberFilterStyle::All) + inline FilteredMemberRefList getMembers(ASTBuilder* astBuilder, DeclRef const& declRef, MemberFilterStyle filterStyle = MemberFilterStyle::All) { - return FilteredMemberRefList(declRef.getDecl()->members, declRef.substitutions, filterStyle); + return FilteredMemberRefList(astBuilder, declRef.getDecl()->members, declRef.substitutions, filterStyle); } template - inline FilteredMemberRefList getMembersOfType( DeclRef const& declRef, MemberFilterStyle filterStyle = MemberFilterStyle::All) + inline FilteredMemberRefList getMembersOfType(ASTBuilder* astBuilder, DeclRef const& declRef, MemberFilterStyle filterStyle = MemberFilterStyle::All) { - return FilteredMemberRefList(declRef.getDecl()->members, declRef.substitutions, filterStyle); + return FilteredMemberRefList(astBuilder, declRef.getDecl()->members, declRef.substitutions, filterStyle); } void _foreachDirectOrExtensionMemberOfType( @@ -70,6 +70,8 @@ namespace Slang void (*callback)(DeclRefBase, void*), void const* userData); + DeclRef _getSpecializedDeclRef(ASTBuilder* builder, Decl* decl, Substitutions* subst); + template inline void foreachDirectOrExtensionMemberOfType( SemanticsVisitor* semantics, @@ -78,12 +80,17 @@ namespace Slang { struct Helper { + const F* userFunc; + SemanticsVisitor* semanticsVisitor; static void callback(DeclRefBase declRef, void* userData) { - (*(F*)userData)(DeclRef((T*) declRef.decl, declRef.substitutions)); + (*((*(Helper*)userData).userFunc))(_getSpecializedDeclRef((*(Helper*)userData).semanticsVisitor->getASTBuilder(), declRef.decl, declRef.substitutions).template as()); } }; - _foreachDirectOrExtensionMemberOfType(semantics, declRef, getClass(), &Helper::callback, &func); + Helper helper; + helper.userFunc = &func; + helper.semanticsVisitor = semantics; + _foreachDirectOrExtensionMemberOfType(semantics, declRef, getClass(), &Helper::callback, &helper); } /// The the user-level name for a variable that might be a shader parameter. @@ -135,9 +142,9 @@ namespace Slang return declRef.substitute(astBuilder, declRef.getDecl()->targetType.Ptr()); } - inline FilteredMemberRefList getFields(DeclRef const& declRef, MemberFilterStyle filterStyle) + inline FilteredMemberRefList getFields(ASTBuilder* astBuilder, DeclRef const& declRef, MemberFilterStyle filterStyle) { - return getMembersOfType(declRef, filterStyle); + return getMembersOfType(astBuilder, declRef, filterStyle); } /// If the given `structTypeDeclRef` inherits from another struct type, return that base type @@ -178,9 +185,9 @@ namespace Slang } } - inline FilteredMemberRefList getParameters(DeclRef const& declRef) + inline FilteredMemberRefList getParameters(ASTBuilder* astBuilder, DeclRef const& declRef) { - return getMembersOfType(declRef); + return getMembersOfType(astBuilder, declRef); } inline Decl* getInner(DeclRef const& declRef) diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index 4d52b76eb..1388eba73 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -3903,7 +3903,7 @@ static TypeLayoutResult _createTypeLayout( _addLayout(context, type, typeLayout); // First, add all fields with explicit offsets. - for (auto field : getFields(structDeclRef, MemberFilterStyle::Instance)) + for (auto field : getFields(context.astBuilder, structDeclRef, MemberFilterStyle::Instance)) { // If the field has an explicit offset, then we will // use that to place it. @@ -3919,7 +3919,7 @@ static TypeLayoutResult _createTypeLayout( } } - for (auto field : getFields(structDeclRef, MemberFilterStyle::Instance)) + for (auto field : getFields(context.astBuilder, structDeclRef, MemberFilterStyle::Instance)) { if (const auto packOffsetModifier = field.getDecl()->findModifier()) continue; -- cgit v1.2.3