summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-07-05 14:37:48 -0700
committerGitHub <noreply@github.com>2023-07-05 14:37:48 -0700
commit6c7120d684cc46caafbe348d658158c0060a7638 (patch)
treee8ba738564b5cdceda22013900a0ed762c184bd3 /source/slang
parent6063304cb8d73d430e7ef81c62cd9822302fcc19 (diff)
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 <yhe@nvidia.com>
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-ast-builder.cpp21
-rw-r--r--source/slang/slang-ast-builder.h29
-rw-r--r--source/slang/slang-ast-print.cpp12
-rw-r--r--source/slang/slang-ast-support-types.h57
-rw-r--r--source/slang/slang-ast-synthesis.cpp4
-rw-r--r--source/slang/slang-ast-type.cpp2
-rw-r--r--source/slang/slang-ast-type.h4
-rw-r--r--source/slang/slang-ast-val.cpp2
-rw-r--r--source/slang/slang-ast-val.h9
-rw-r--r--source/slang/slang-check-conformance.cpp13
-rw-r--r--source/slang/slang-check-constraint.cpp6
-rw-r--r--source/slang/slang-check-conversion.cpp6
-rw-r--r--source/slang/slang-check-decl.cpp96
-rw-r--r--source/slang/slang-check-expr.cpp11
-rw-r--r--source/slang/slang-check-overload.cpp33
-rw-r--r--source/slang/slang-check-shader.cpp10
-rw-r--r--source/slang/slang-check.h2
-rw-r--r--source/slang/slang-doc-markdown-writer.cpp8
-rw-r--r--source/slang/slang-language-server.cpp16
-rw-r--r--source/slang/slang-lookup.cpp18
-rw-r--r--source/slang/slang-lower-to-ir.cpp34
-rw-r--r--source/slang/slang-mangle.cpp14
-rw-r--r--source/slang/slang-parameter-binding.cpp2
-rw-r--r--source/slang/slang-parser.cpp6
-rw-r--r--source/slang/slang-reflection-api.cpp9
-rw-r--r--source/slang/slang-syntax.cpp8
-rw-r--r--source/slang/slang-syntax.h27
-rw-r--r--source/slang/slang-type-layout.cpp4
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>(decl, nullptr));
+ auto type = DeclRefType::create(m_astBuilder, DeclRef<Decl>(decl));
m_builtinTypes[Index(modifier->tag)] = type;
}
@@ -299,7 +299,7 @@ ArrayExpressionType* ASTBuilder::getArrayType(Type* elementType, IntVal* element
auto arrayGenericDecl = as<GenericDecl>(m_sharedASTBuilder->findMagicDecl("ArrayType"));
auto arrayTypeDecl = arrayGenericDecl->inner;
auto substitutions = getOrCreate<GenericSubstitution>(arrayGenericDecl, elementType, elementCount);
- result->declRef = DeclRef<Decl>(arrayTypeDecl, substitutions);
+ result->declRef = getSpecializedDeclRef<Decl>(arrayTypeDecl, substitutions);
}
return result;
}
@@ -314,7 +314,7 @@ VectorExpressionType* ASTBuilder::getVectorType(
auto vectorGenericDecl = as<GenericDecl>(m_sharedASTBuilder->findMagicDecl("Vector"));
auto vectorTypeDecl = vectorGenericDecl->inner;
auto substitutions = getOrCreate<GenericSubstitution>(vectorGenericDecl, elementType, elementCount);
- result->declRef = DeclRef<Decl>(vectorTypeDecl, substitutions);
+ result->declRef = getSpecializedDeclRef<Decl>(vectorTypeDecl, substitutions);
}
return result;
}
@@ -332,7 +332,7 @@ DifferentialPairType* ASTBuilder::getDifferentialPairType(
valueType,
primalIsDifferentialWitness);
- auto declRef = DeclRef<Decl>(typeDecl, substitutions);
+ auto declRef = getSpecializedDeclRef<Decl>(typeDecl, substitutions);
auto rsType = DeclRefType::create(this, declRef);
return as<DifferentialPairType>(rsType);
@@ -373,7 +373,7 @@ MeshOutputType* ASTBuilder::getMeshOutputTypeFromModifier(
elementType,
maxElementCount);
- auto declRef = DeclRef<Decl>(typeDecl, substitutions);
+ auto declRef = getSpecializedDeclRef<Decl>(typeDecl, substitutions);
auto rsType = DeclRefType::create(this, declRef);
return as<MeshOutputType>(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<Decl> _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<typename EnumType>
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<typename T>
+ DeclRef<T> getSpecializedDeclRef(T* decl, Substitutions* subst)
+ {
+ return DeclRef<T>(this, decl, subst);
+ }
+
+ template<typename T>
+ DeclRef<T> getSpecializedDeclRef(T* decl, SubstitutionSet subst)
+ {
+ return DeclRef<T>(this, decl, subst);
+ }
+
ConstantIntVal* getIntVal(Type* type, IntegerLiteralValue value)
{
return getOrCreate<ConstantIntVal>(type, value);
@@ -263,7 +280,7 @@ public:
{
desc.operands.add(outer);
}
- auto result = (DeclRefType*)_getOrCreateImpl(desc, [&]() {return create<DeclRefType>(decl, outer); });
+ auto result = (DeclRefType*)_getOrCreateImpl(desc, [&]() {return create<DeclRefType>(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<Decl>& 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<GenericDecl>();
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<GenericDecl>& genericDeclRef)
sb << "<";
bool first = true;
- for (auto paramDeclRef : getMembers(genericDeclRef))
+ for (auto paramDeclRef : getMembers(m_astBuilder, genericDeclRef))
{
if (auto genericTypeParam = paramDeclRef.as<GenericTypeParamDecl>())
{
@@ -270,7 +270,7 @@ void ASTPrinter::addDeclParams(const DeclRef<Decl>& declRef, List<Range<Index>>*
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<Decl>& declRef, List<Range<Index>>*
{
addGenericParams(genericDeclRef);
- addDeclParams(DeclRef<Decl>(getInner(genericDeclRef), genericDeclRef.substitutions), outParamRange);
+ addDeclParams(m_astBuilder->getSpecializedDeclRef<Decl>(getInner(genericDeclRef), genericDeclRef.substitutions), outParamRange);
}
else
{
@@ -443,7 +443,7 @@ void ASTPrinter::addDeclResultType(const DeclRef<Decl>& inDeclRef)
DeclRef<Decl> declRef = inDeclRef;
if (auto genericDeclRef = declRef.as<GenericDecl>())
{
- declRef = DeclRef<Decl>(getInner(genericDeclRef), genericDeclRef.substitutions);
+ declRef = m_astBuilder->getSpecializedDeclRef<Decl>(getInner(genericDeclRef), genericDeclRef.substitutions);
}
if (as<ConstructorDecl>(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<typename T>
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<typename T>
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 <typename U>
DeclRef(DeclRef<U> const& other,
typename EnableIf<IsConvertible<T*, U*>::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<T> unsafeInit(DeclRefBase const& declRef)
{
- return DeclRef<T>((T*) declRef.decl, declRef.substitutions);
+ DeclRef<T> 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<T>::unsafeInit(DeclRefBase::substituteImpl(astBuilder, subst, ioDiff));
}
- DeclRef<ContainerDecl> getParent() const
+ DeclRef<ContainerDecl> getParent(ASTBuilder* astBuilder) const
{
- return DeclRef<ContainerDecl>::unsafeInit(DeclRefBase::getParent());
+ return DeclRef<ContainerDecl>::unsafeInit(DeclRefBase::getParent(astBuilder));
}
};
@@ -902,7 +918,7 @@ namespace Slang
template<typename T>
inline DeclRef<T> makeDeclRef(T* decl)
{
- return DeclRef<T>(decl, nullptr);
+ return DeclRef<T>(decl);
}
enum class MemberFilterStyle
@@ -1033,14 +1049,17 @@ namespace Slang
List<Decl*> const& m_decls;
SubstitutionSet m_substitutions;
MemberFilterStyle m_filterStyle;
+ ASTBuilder* m_astBuilder;
FilteredMemberRefList(
+ ASTBuilder* astBuilder,
List<Decl*> 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<T>(m_filterStyle, m_decls.begin(), m_decls.end()); }
@@ -1056,7 +1075,7 @@ namespace Slang
{
Decl*const* decl = getFilterCursorByIndex<T>(m_filterStyle, m_decls.begin(), m_decls.end(), index);
SLANG_ASSERT(decl);
- return DeclRef<T>((T*) *decl, m_substitutions);
+ return _getSpecializedDeclRef(m_astBuilder, (T*)*decl, m_substitutions).template as<T>();
}
List<DeclRef<T>> toArray() const
@@ -1091,7 +1110,7 @@ namespace Slang
void operator++() { m_ptr = adjustFilterCursor<T>(m_filterStyle, m_ptr + 1, m_end); }
- DeclRef<T> operator*() { return DeclRef<T>((T*)*m_ptr, m_list->m_substitutions); }
+ DeclRef<T> operator*() { return _getSpecializedDeclRef(m_list->m_astBuilder, (T*)*m_ptr, m_list->m_substitutions).template as<T>(); }
};
Iterator begin() const { return Iterator(this, adjustFilterCursor<T>(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<VarExpr>();
- expr->declRef = DeclRef<Decl>(var, nullptr);
+ expr->declRef = DeclRef<Decl>(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<VarExpr>();
- expr->declRef = DeclRef<Decl>(as<Decl>(varStmt->decl), nullptr);
+ expr->declRef = DeclRef<Decl>(as<Decl>(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<InterfaceDecl> ExtractExistentialType::getSpecializedInterfaceDeclRef()
openedThisType->interfaceDecl = interfaceDecl;
openedThisType->witness = openedWitness;
- DeclRef<InterfaceDecl> specialiedInterfaceDeclRef = DeclRef<InterfaceDecl>(interfaceDecl, openedThisType);
+ DeclRef<InterfaceDecl> specialiedInterfaceDeclRef = m_astBuilder->getSpecializedDeclRef<InterfaceDecl>(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<Decl> 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<DeclaredSubtypeWitness>(
- 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<VarDeclBase> 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<Decl> 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<DeclaredSubtypeWitness>(
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<DeclaredSubtypeWitness>(
- 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<TransitiveSubtypeWitness>();
transitiveWitness->sub = subType;
@@ -200,7 +199,7 @@ namespace Slang
bool SemanticsVisitor::isInterfaceSafeForTaggedUnion(
DeclRef<InterfaceDecl> 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<GenericTypeConstraintDecl>(aggTypeDeclRef))
+ for (auto genConstraintDeclRef : getMembersOfType<GenericTypeConstraintDecl>(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<GenericDecl>();
+ auto genericDeclRef = genericTypeParamDeclRef.getParent(m_astBuilder).as<GenericDecl>();
SLANG_ASSERT(genericDeclRef);
- for( auto constraintDeclRef : getMembersOfType<GenericTypeConstraintDecl>(genericDeclRef) )
+ for( auto constraintDeclRef : getMembersOfType<GenericTypeConstraintDecl>(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<T> : IContainer` to `X<Int>` if we find
// that `X<T>.IndexType == T`.
- for( auto constraintDeclRef : getMembersOfType<GenericTypeConstraintDecl>(genericDeclRef) )
+ for( auto constraintDeclRef : getMembersOfType<GenericTypeConstraintDecl>(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<GenericTypeParamDecl>())
{
@@ -461,7 +461,7 @@ namespace Slang
for( auto constraintDecl : genericDeclRef.getDecl()->getMembersOfType<GenericTypeConstraintDecl>() )
{
- DeclRef<GenericTypeConstraintDecl> constraintDeclRef(
+ DeclRef<GenericTypeConstraintDecl> 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<StructDecl> const& structTypeDeclRef)
{
- auto inheritanceDecl = getMembersOfType<InheritanceDecl>(structTypeDeclRef).getFirstOrNull();
+ auto inheritanceDecl = getMembersOfType<InheritanceDecl>(astBuilder, structTypeDeclRef).getFirstOrNull();
if(!inheritanceDecl)
return nullptr;
@@ -184,7 +184,7 @@ namespace Slang
DeclRef<StructDecl> findBaseStructDeclRef(ASTBuilder* astBuilder, DeclRef<StructDecl> const& structTypeDeclRef)
{
- auto inheritanceDecl = getMembersOfType<InheritanceDecl>(structTypeDeclRef).getFirstOrNull();
+ auto inheritanceDecl = getMembersOfType<InheritanceDecl>(astBuilder, structTypeDeclRef).getFirstOrNull();
if (!inheritanceDecl)
return DeclRef<StructDecl>();
@@ -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<VarDecl>(toStructDeclRef, MemberFilterStyle::Instance))
+ for(auto fieldDeclRef : getMembersOfType<VarDecl>(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<GenericTypeParamDecl>(mm) )
{
- args.add(DeclRefType::create(astBuilder, DeclRef<Decl>(genericTypeParamDecl, outerSubst)));
+ args.add(DeclRefType::create(astBuilder, astBuilder->getSpecializedDeclRef<Decl>(genericTypeParamDecl, outerSubst)));
}
else if( auto genericValueParamDecl = as<GenericValueParamDecl>(mm) )
{
@@ -651,7 +651,7 @@ namespace Slang
args.add(astBuilder->getOrCreate<GenericParamIntVal>(
genericValueParamDecl->getType(),
- genericValueParamDecl, outerSubst));
+ astBuilder->getSpecializedDeclRef(genericValueParamDecl, outerSubst)));
}
}
@@ -666,13 +666,12 @@ namespace Slang
{
ensureDecl(semantics, genericTypeConstraintDecl, DeclCheckState::ReadyForReference);
}
- auto constraintDeclRef = DeclRef<GenericTypeConstraintDecl>(genericTypeConstraintDecl, outerSubst);
+ auto constraintDeclRef = astBuilder->getSpecializedDeclRef<GenericTypeConstraintDecl>(genericTypeConstraintDecl, outerSubst);
DeclaredSubtypeWitness* witness =
astBuilder->getOrCreate<DeclaredSubtypeWitness>(
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<VarDeclBase>(varDecl, nullptr), nullptr);
+ tryConstantFoldDeclRef(DeclRef<VarDeclBase>(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<AccessorDecl>, DeclRef<AccessorDecl>> mapRequiredToSatisfyingAccessorDeclRef;
- for( auto requiredAccessorDeclRef : getMembersOfType<AccessorDecl>(requiredMemberDeclRef) )
+ for( auto requiredAccessorDeclRef : getMembersOfType<AccessorDecl>(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<AccessorDecl>(satisfyingMemberDeclRef) )
+ for( auto satisfyingAccessorDeclRef : getMembersOfType<AccessorDecl>(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<GenericParamIntVal>(
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<GenericDecl>(requiredGenericDeclRef.getDecl(), requiredSubst);
- auto specializedRequiredMemberDeclRefs = getMembers(specializedRequiredGenericDeclRef);
+ auto specializedRequiredGenericDeclRef = m_astBuilder->getSpecializedDeclRef<GenericDecl>(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<Decl>(satisfyingGenericDeclRef.getDecl()->inner, satisfyingGenericDeclRef.substitutions),
- DeclRef<Decl>(requiredGenericDeclRef.getDecl()->inner, requiredSubst),
+ m_astBuilder->getSpecializedDeclRef<Decl>(satisfyingGenericDeclRef.getDecl()->inner, satisfyingGenericDeclRef.substitutions),
+ m_astBuilder->getSpecializedDeclRef<Decl>(requiredGenericDeclRef.getDecl()->inner, requiredSubst),
witnessTable);
}
@@ -2429,7 +2429,7 @@ namespace Slang
//
bool conformance = true;
Val* witness = nullptr;
- for (auto requiredConstraintDeclRef : getMembersOfType<TypeConstraintDecl>(requiredAssociatedTypeDeclRef))
+ for (auto requiredConstraintDeclRef : getMembersOfType<TypeConstraintDecl>(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<DeclRef<AccessorDecl>, AccessorDecl*> mapRequiredAccessorToSynAccessor;
- for( auto requiredAccessorDeclRef : getMembersOfType<AccessorDecl>(requiredMemberDeclRef) )
+ for( auto requiredAccessorDeclRef : getMembersOfType<AccessorDecl>(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<Expr*> 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<Decl>(synFunc, substSet)));
+ witnessTable->add(requirementDeclRef, RequirementWitness(m_astBuilder->getSpecializedDeclRef<Decl>(synFunc, substSet)));
return true;
}
@@ -3569,8 +3569,9 @@ namespace Slang
m_astBuilder->getOrCreate<DeclaredSubtypeWitness>(
superInterfaceType,
reqType,
- requiredInheritanceDeclRef.getDecl(),
- requiredInheritanceDeclRef.substitutions.substitutions);
+ m_astBuilder->getSpecializedDeclRef(
+ requiredInheritanceDeclRef.getDecl(),
+ requiredInheritanceDeclRef.substitutions.substitutions));
// ...
TransitiveSubtypeWitness* subIsReqWitness = m_astBuilder->getOrCreateWithDefaultCtor<TransitiveSubtypeWitness>(subType, reqType, interfaceIsReqWitness);
@@ -3774,7 +3775,7 @@ namespace Slang
thisTypeSubst->witness = subTypeConformsToSuperInterfaceWitness;
thisTypeSubst->outer = superInterfaceDeclRef.substitutions.substitutions;
- auto specializedSuperInterfaceDeclRef = DeclRef<InterfaceDecl>(superInterfaceDeclRef.getDecl(), thisTypeSubst);
+ auto specializedSuperInterfaceDeclRef = m_astBuilder->getSpecializedDeclRef<InterfaceDecl>(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<InheritanceDecl>(extDeclRef))
+ for(auto requiredInheritanceDeclRef : getMembersOfType<InheritanceDecl>(m_astBuilder, extDeclRef))
{
auto requirementSatisfied = findWitnessForInterfaceRequirement(
context,
@@ -4984,7 +4985,7 @@ namespace Slang
// arguments into account.
//
GenericTypeConstraintDecl* leftConstraint = leftConstraints[cc];
- DeclRef<GenericTypeConstraintDecl> rightConstraint(rightConstraints[cc], substRightToLeft);
+ DeclRef<GenericTypeConstraintDecl> 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<GenericParamIntVal>(
valueParam->getType(),
- valueParam,
- nullptr);
+ DeclRef<VarDeclBase>(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<FuncDecl> newDeclRef(newDecl, nullptr);
- DeclRef<FuncDecl> oldDeclRef(oldDecl, nullptr);
+ DeclRef<FuncDecl> newDeclRef(newDecl);
+ DeclRef<FuncDecl> 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<ForwardDerivativeRequirementDecl>();
reqDecl->originalRequirementDecl = decl;
cloneModifiers(reqDecl, decl);
- auto declRef = DeclRef<CallableDecl>(decl, createDefaultSubstitutions(m_astBuilder, this, decl));
+ auto declRef = m_astBuilder->getSpecializedDeclRef<CallableDecl>(decl, createDefaultSubstitutions(m_astBuilder, this, decl));
auto diffFuncType = getForwardDiffFuncType(getFuncType(m_astBuilder, declRef));
setFuncTypeIntoRequirementDecl(reqDecl, as<FuncType>(diffFuncType));
interfaceDecl->members.add(reqDecl);
@@ -5664,7 +5664,7 @@ namespace Slang
if (decl->hasModifier<BackwardDifferentiableAttribute>())
{
// Requirement for backward derivative.
- auto declRef = DeclRef<CallableDecl>(decl, createDefaultSubstitutions(m_astBuilder, this, decl));
+ auto declRef = m_astBuilder->getSpecializedDeclRef<CallableDecl>(decl, createDefaultSubstitutions(m_astBuilder, this, decl));
auto originalFuncType = getFuncType(m_astBuilder, declRef);
auto diffFuncType = as<FuncType>(getBackwardDiffFuncType(originalFuncType));
{
@@ -6218,7 +6218,7 @@ namespace Slang
if (!TryUnifyTypes(constraints, extDecl->targetType.Ptr(), type))
return DeclRef<ExtensionDecl>();
- auto constraintSubst = trySolveConstraintSystem(&constraints, DeclRef<Decl>(extGenericDecl, nullptr).as<GenericDecl>());
+ auto constraintSubst = trySolveConstraintSystem(&constraints, m_astBuilder->getSpecializedDeclRef<Decl>(extGenericDecl, nullptr).as<GenericDecl>());
if (!constraintSubst)
{
return DeclRef<ExtensionDecl>();
@@ -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<Decl>(extDecl, constraintSubst).as<ExtensionDecl>();
+ extDeclRef = m_astBuilder->getSpecializedDeclRef<Decl>(extDecl, constraintSubst).as<ExtensionDecl>();
}
// 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<InterfaceDecl>(targetInterfaceDeclRef.getDecl(), newTargetSubst));
+ m_astBuilder->getSpecializedDeclRef<InterfaceDecl>(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<ExtensionDecl>(
+ extDeclRef = m_astBuilder->getSpecializedDeclRef<ExtensionDecl>(
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<GenericTypeParamDecl*, List<Type*>> getCanonicalGenericConstraints(
+ ASTBuilder* astBuilder,
DeclRef<ContainerDecl> genericDecl)
{
OrderedDictionary<GenericTypeParamDecl*, List<Type*>> genericConstraints;
- for (auto mm : getMembersOfType<GenericTypeParamDecl>(genericDecl))
+ for (auto mm : getMembersOfType<GenericTypeParamDecl>(astBuilder, genericDecl))
{
genericConstraints[mm.getDecl()] = List<Type*>();
}
- for (auto genericTypeConstraintDecl : getMembersOfType<GenericTypeConstraintDecl>(genericDecl))
+ for (auto genericTypeConstraintDecl : getMembersOfType<GenericTypeConstraintDecl>(astBuilder, genericDecl))
{
assert(
genericTypeConstraintDecl.getDecl()->sub.type->astNodeType ==
@@ -7246,8 +7247,7 @@ namespace Slang
auto derivativeAttr = visitor->getASTBuilder()->create<TDerivativeAttr>();
derivativeAttr->loc = derivativeOfAttr->loc;
auto outterGeneric = visitor->GetOuterGeneric(funcDecl);
- auto declRef =
- DeclRef<Decl>((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<TypeAliasDecl>();
typeDef->nameAndLoc.name = getName("Differential");
- auto declRef = createDefaultSubstitutionsIfNeeded(m_astBuilder, this, DeclRef<Decl>(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<GenericParamIntVal>(
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<IntVal>(valResult);
}
@@ -2472,7 +2473,7 @@ namespace Slang
if (auto baseFuncGenericDeclRef = declRefExpr->declRef.as<GenericDecl>())
{
// Get inner function
- DeclRef<Decl> unspecializedInnerRef = DeclRef<Decl>(
+ DeclRef<Decl> unspecializedInnerRef = astBuilder->getSpecializedDeclRef<Decl>(
getInner(baseFuncGenericDeclRef),
baseFuncGenericDeclRef.substitutions);
auto callableDeclRef = unspecializedInnerRef.as<CallableDecl>();
@@ -3576,7 +3577,7 @@ namespace Slang
for (auto lookupResult : overloadedExpr->lookupResult2)
{
bool shouldRemove = false;
- if (lookupResult.declRef.getParent().as<InterfaceDecl>())
+ if (lookupResult.declRef.getParent(m_astBuilder).as<InterfaceDecl>())
{
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<CallableDecl>()));
+ paramCounts = CountParameters(getParameters(m_astBuilder, candidate.item.declRef.as<CallableDecl>()));
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<GenericTypeParamDecl>())
{
@@ -367,7 +367,7 @@ namespace Slang
switch (candidate.flavor)
{
case OverloadCandidate::Flavor::Func:
- for (auto param : getParameters(candidate.item.declRef.as<CallableDecl>()))
+ for (auto param : getParameters(m_astBuilder, candidate.item.declRef.as<CallableDecl>()))
{
auto paramType = getType(m_astBuilder, param);
paramTypes.add(paramType);
@@ -524,7 +524,7 @@ namespace Slang
{
auto subset = genericDeclRef.substitutions;
subset.substitutions = subst;
- DeclRef<GenericTypeConstraintDecl> constraintDeclRef(
+ DeclRef<GenericTypeConstraintDecl> 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<Decl> innerDeclRef(getInner(baseGenericRef), subst);
+ DeclRef<Decl> innerDeclRef = m_astBuilder->getSpecializedDeclRef<Decl>(getInner(baseGenericRef), subst);
Expr* base = nullptr;
if (auto mbrExpr = as<MemberExpr>(baseExpr))
@@ -688,7 +688,8 @@ namespace Slang
if(auto subscriptDeclRef = candidate.item.declRef.as<SubscriptDecl>())
{
const auto& decl = subscriptDeclRef.getDecl();
- if (decl->getMembersOfType<SetterDecl>().isNonEmpty() || decl->getMembersOfType<RefAccessorDecl>().isNonEmpty())
+ if (decl->getMembersOfType<SetterDecl>().isNonEmpty() ||
+ decl->getMembersOfType<RefAccessorDecl>().isNonEmpty())
{
callExpr->type.isLeftValue = true;
}
@@ -762,14 +763,14 @@ namespace Slang
}
/// Does the given `declRef` represent an interface requirement?
- bool isInterfaceRequirement(DeclRef<Decl> const& declRef)
+ bool isInterfaceRequirement(ASTBuilder* builder, DeclRef<Decl> const& declRef)
{
if(!declRef)
return false;
- auto parent = declRef.getParent();
+ auto parent = declRef.getParent(builder);
if(parent.as<GenericDecl>())
- parent = parent.getParent();
+ parent = parent.getParent(builder);
if(parent.as<InterfaceDecl>())
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<GenericDecl>();
+ auto parentGeneric = declRef.getParent(m_astBuilder).as<GenericDecl>();
if(!parentGeneric)
return 0;
//
@@ -1243,7 +1244,7 @@ namespace Slang
}
auto innerDecl = getInner(genericDeclRef);
- DeclRef<Decl> partiallySpecializedInnerRef = DeclRef<Decl>(
+ DeclRef<Decl> partiallySpecializedInnerRef = m_astBuilder->getSpecializedDeclRef<Decl>(
innerDecl,
substForInnerDecl);
@@ -1254,7 +1255,7 @@ namespace Slang
List<Type*> 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<Decl>(nullptr, nullptr);
+ return DeclRef<Decl>(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<Decl>(nullptr, nullptr);
+ return DeclRef<Decl>(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<Decl>(nullptr, nullptr);
+ return DeclRef<Decl>(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<Decl>(innerDecl, constraintSubst);
+ return m_astBuilder->getSpecializedDeclRef<Decl>(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<GenericTypeConstraintDecl>())
{
// Get the type that the constraint is enforcing conformance to
- auto interfaceType = getSup(getLinkage()->getASTBuilder(), DeclRef<GenericTypeConstraintDecl>(constraintDecl, nullptr));
+ auto interfaceType = getSup(getLinkage()->getASTBuilder(), DeclRef<GenericTypeConstraintDecl>(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<GenericDecl>();
+ auto genericDeclRef = m_funcDeclRef.getParent(getLinkage()->getASTBuilder()).as<GenericDecl>();
SLANG_ASSERT(genericDeclRef); // otherwise we wouldn't have generic parameters
List<Val*> genericArgs;
@@ -1214,7 +1214,7 @@ namespace Slang
auto constraintSubst = genericDeclRef.substitutions;
constraintSubst.substitutions = genericSubst;
- DeclRef<GenericTypeConstraintDecl> constraintDeclRef(
+ DeclRef<GenericTypeConstraintDecl> 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<GenericTypeParamDecl*, List<Type*>> getCanonicalGenericConstraints(
- DeclRef<ContainerDecl> genericDecl);
+ ASTBuilder* builder, DeclRef<ContainerDecl> 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<ASTPrinter::Part> parts;
ASTPrinter printer(m_astBuilder, ASTPrinter::OptionFlag::ParamNames, &parts);
- printer.addDeclSignature(DeclRef<Decl>(callableDecl, nullptr));
+ printer.addDeclSignature(m_astBuilder->getSpecializedDeclRef<Decl>(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<Decl>(callableDecl, nullptr));
+ printer.addOverridableDeclPath(DeclRef<Decl>(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<Decl>(aggTypeDecl, nullptr));
+ printer.addDeclPath(DeclRef<Decl>(aggTypeDecl));
if (as<StructDecl>(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<Decl>(aggTypeDecl, nullptr));
+ printer.addDeclPath(DeclRef<Decl>(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<Decl> declRef)
}
else if (auto varDecl = declRef.as<VarDeclBase>())
{
- auto parent = declRef.getParent();
+ auto parent = declRef.getDecl()->parentDecl;
if (as<GenericDecl>(parent))
- parent = parent.getParent();
- if (parent.as<InterfaceDecl>())
+ parent = parent->parentDecl;
+ if (as<InterfaceDecl>(parent))
{
return "(associated constant) ";
}
- else if (parent.as<AggTypeDeclBase>())
+ else if (as<AggTypeDeclBase>(parent))
{
return "(field) ";
}
const char* scopeKind = "";
- if (parent.as<NamespaceDeclBase>())
+ if (as<NamespaceDeclBase>(parent))
scopeKind = "global ";
else if (getParentDecl(declRef.getDecl()))
scopeKind = "local ";
@@ -707,11 +707,11 @@ SlangResult LanguageServer::hover(
}
else if (auto decl = as<Decl>(leafNode))
{
- fillDeclRefHoverInfo(DeclRef<Decl>(decl, nullptr));
+ fillDeclRefHoverInfo(version->linkage->getASTBuilder()->getSpecializedDeclRef(decl, nullptr));
}
else if (auto attr = as<Attribute>(leafNode))
{
- fillDeclRefHoverInfo(DeclRef<Decl>(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<ConstructorDecl>())
{
- addDeclRef(DeclRef<Decl>(member, declRefExpr->declRef.substitutions));
+ addDeclRef(version->linkage->getASTBuilder()->getSpecializedDeclRef<Decl>(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<Decl>(member, containerDeclRef.substitutions), inBreadcrumbs));
+ astBuilder->getSpecializedDeclRef<Decl>(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<Decl>(m, containerDeclRef.substitutions), inBreadcrumbs));
+ AddToLookupResult(result, CreateLookupResultItem(astBuilder->getSpecializedDeclRef<Decl>(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<Decl> transparentMemberDeclRef(transparentInfo.decl, containerDeclRef.substitutions);
+ DeclRef<Decl> 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<Decl>(superInterfaceDeclRef.getDecl(), thisTypeSubst);
+ auto specializedInterfaceDeclRef = astBuilder->getSpecializedDeclRef<Decl>(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<GenericDecl>();
+ auto genericDeclRef = genericTypeParamDeclRef.getParent(astBuilder).as<GenericDecl>();
assert(genericDeclRef);
- for(auto constraintDeclRef : getMembersOfType<GenericTypeConstraintDecl>(genericDeclRef))
+ for(auto constraintDeclRef : getMembersOfType<GenericTypeConstraintDecl>(astBuilder, genericDeclRef))
{
if( semantics )
{
@@ -467,7 +467,7 @@ static void _lookUpMembersInSuperTypeDeclImpl(
}
else if (declRef.as<AssocTypeDecl>() || declRef.as<GlobalGenericParamDecl>())
{
- for (auto constraintDeclRef : getMembersOfType<TypeConstraintDecl>(declRef.as<ContainerDecl>()))
+ for (auto constraintDeclRef : getMembersOfType<TypeConstraintDecl>(astBuilder, declRef.as<ContainerDecl>()))
{
_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<InheritanceDecl>(aggTypeDeclBaseRef))
+ for (auto inheritanceDeclRef : getMembersOfType<InheritanceDecl>(astBuilder, aggTypeDeclBaseRef))
{
ensureDecl(semantics, inheritanceDeclRef.getDecl(), DeclCheckState::CanUseBaseOfInheritanceDecl);
@@ -801,7 +801,7 @@ static void _lookUpInScopes(
// just a decl.
//
DeclRef<ContainerDecl> containerDeclRef =
- DeclRef<Decl>(containerDecl, createDefaultSubstitutions(astBuilder, request.semantics, containerDecl)).as<ContainerDecl>();
+ astBuilder->getSpecializedDeclRef<Decl>(containerDecl, createDefaultSubstitutions(astBuilder, request.semantics, containerDecl)).as<ContainerDecl>();
// 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<GetterDecl> getterDeclRef;
bool justAGetter = true;
- for (auto accessorDeclRef : getMembersOfType<AccessorDecl>(storageDeclRef, MemberFilterStyle::Instance))
+ for (auto accessorDeclRef : getMembersOfType<AccessorDecl>(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<GetterDecl>(boundStorageInfo->declRef, MemberFilterStyle::Instance);
+ auto getters = getMembersOfType<GetterDecl>(context->astBuilder, boundStorageInfo->declRef, MemberFilterStyle::Instance);
if (getters.getCount())
{
auto getter = *getters.begin();
@@ -1031,7 +1031,7 @@ top:
goto top;
}
- auto refAccessors = getMembersOfType<RefAccessorDecl>(boundStorageInfo->declRef, MemberFilterStyle::Instance);
+ auto refAccessors = getMembersOfType<RefAccessorDecl>(context->astBuilder, boundStorageInfo->declRef, MemberFilterStyle::Instance);
if(refAccessors.getCount())
{
auto refAccessor = *refAccessors.begin();
@@ -1643,7 +1643,7 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower
// Now we will iterate over the requirements (members) of the
// interface and try to synthesize an appropriate value for each.
//
- for( auto reqDeclRef : getMembers(supInterfaceDeclRef) )
+ for( auto reqDeclRef : getMembers(context->astBuilder, 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<ValLoweringVisitor, LoweredValInfo, Lower
// mapped to the correct witness value).
//
List<IRParam*> irParams;
- for( auto paramDeclRef : getMembersOfType<ParamDecl>(callableDeclRef) )
+ for( auto paramDeclRef : getMembersOfType<ParamDecl>(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<Decl> callableDeclRef)
{
- auto parentDeclRef = callableDeclRef.getParent();
+ auto parentDeclRef = callableDeclRef.getParent(context->astBuilder);
if(auto subscriptDeclRef = parentDeclRef.as<SubscriptDecl>())
- parentDeclRef = subscriptDeclRef.getParent();
+ parentDeclRef = subscriptDeclRef.getParent(context->astBuilder);
if(auto genericDeclRef = parentDeclRef.as<GenericDecl>())
- 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<Derived, LoweredValInfo>
}
}
- for (auto ff : getMembersOfType<VarDecl>(aggTypeDeclRef, MemberFilterStyle::Instance))
+ for (auto ff : getMembersOfType<VarDecl>(getASTBuilder(), aggTypeDeclRef, MemberFilterStyle::Instance))
{
auto irFieldVal = getSimpleVal(context, getDefaultVal(ff));
args.add(irFieldVal);
@@ -3792,7 +3792,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
}
}
- for (auto ff : getMembersOfType<VarDecl>(aggTypeDeclRef, MemberFilterStyle::Instance))
+ for (auto ff : getMembersOfType<VarDecl>(getASTBuilder(), aggTypeDeclRef, MemberFilterStyle::Instance))
{
UInt argIndex = argCounter++;
if (argIndex < argCount)
@@ -4016,7 +4016,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
List<OutArgumentFixup>* ioFixups)
{
Count argCounter = 0;
- for (auto paramDeclRef : getMembersOfType<ParamDecl>(funcDeclRef))
+ for (auto paramDeclRef : getMembersOfType<ParamDecl>(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<SetterDecl>(subscriptInfo->declRef, MemberFilterStyle::Instance).isNonEmpty())
+ && getMembersOfType<SetterDecl>(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<RefAccessorDecl>(subscriptInfo->declRef, MemberFilterStyle::Instance);
+ auto refAccessors = getMembersOfType<RefAccessorDecl>(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<SetterDecl>(subscriptInfo->declRef, MemberFilterStyle::Instance);
+ auto setters = getMembersOfType<SetterDecl>(context->astBuilder, subscriptInfo->declRef, MemberFilterStyle::Instance);
if (setters.isNonEmpty())
{
auto setter = *setters.begin();
@@ -6404,7 +6404,7 @@ top:
return;
}
- auto refAccessors = getMembersOfType<RefAccessorDecl>(subscriptInfo->declRef, MemberFilterStyle::Instance);
+ auto refAccessors = getMembersOfType<RefAccessorDecl>(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<Decl> declRef)
{
- auto parentDeclRef = declRef.getParent();
+ auto parentDeclRef = declRef.getParent(context->astBuilder);
auto parentGenericDeclRef = parentDeclRef.as<GenericDecl>();
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<GenericTypeParamDecl>())
{
@@ -463,7 +463,7 @@ namespace Slang
emit(context, genericParameterCount);
OrderedDictionary<GenericTypeParamDecl*, List<Type*>> genericConstraints;
- for (auto mm : getMembers(parentGenericDeclRef))
+ for (auto mm : getMembers(context->astBuilder, parentGenericDeclRef))
{
if (auto genericTypeParamDecl = mm.as<GenericTypeParamDecl>())
{
@@ -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<Decl>(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<CallableDecl>())
{
- 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<Decl>(declRef.decl, declRef.substitutions));
+ astBuilder->getSpecializedDeclRef<Decl>(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<TypeLayout> processEntryPointVaryingParameter(
//
Decl* firstExplicit = nullptr;
Decl* firstImplicit = nullptr;
- for( auto field : getFields(structDeclRef, MemberFilterStyle::Instance) )
+ for( auto field : getFields(context->getASTBuilder(), structDeclRef, MemberFilterStyle::Instance) )
{
RefPtr<VarLayout> 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<Decl>(paramDecl, nullptr));
+ DeclRef<Decl>(paramDecl));
auto paramTypeExpr = parser->astBuilder->create<SharedTypeExpr>();
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>(decl, nullptr));
+ DeclRefType* paramType = DeclRefType::create(parser->astBuilder, DeclRef<Decl>(decl));
SharedTypeExpr* paramTypeExpr = parser->astBuilder->create<SharedTypeExpr>();
paramTypeExpr->loc = decl->loc;
@@ -4320,7 +4320,7 @@ namespace Slang
{
// TODO(JS):
// Is it valid to always have empty substitution set here?
- DeclRef<ContainerDecl> declRef(aggTypeDecl, SubstitutionSet());
+ DeclRef<ContainerDecl> 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<StructDecl>())
{
- 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<StructDecl>())
{
- 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<Decl>(declRefBase.decl, declRefBase.substitutions);
+ return astBuilder->getSpecializedDeclRef<Decl>(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<AggTypeDecl> const& declRef,
SemanticsVisitor* semantics);
- inline FilteredMemberRefList<Decl> getMembers(DeclRef<ContainerDecl> const& declRef, MemberFilterStyle filterStyle = MemberFilterStyle::All)
+ inline FilteredMemberRefList<Decl> getMembers(ASTBuilder* astBuilder, DeclRef<ContainerDecl> const& declRef, MemberFilterStyle filterStyle = MemberFilterStyle::All)
{
- return FilteredMemberRefList<Decl>(declRef.getDecl()->members, declRef.substitutions, filterStyle);
+ return FilteredMemberRefList<Decl>(astBuilder, declRef.getDecl()->members, declRef.substitutions, filterStyle);
}
template<typename T>
- inline FilteredMemberRefList<T> getMembersOfType( DeclRef<ContainerDecl> const& declRef, MemberFilterStyle filterStyle = MemberFilterStyle::All)
+ inline FilteredMemberRefList<T> getMembersOfType(ASTBuilder* astBuilder, DeclRef<ContainerDecl> const& declRef, MemberFilterStyle filterStyle = MemberFilterStyle::All)
{
- return FilteredMemberRefList<T>(declRef.getDecl()->members, declRef.substitutions, filterStyle);
+ return FilteredMemberRefList<T>(astBuilder, declRef.getDecl()->members, declRef.substitutions, filterStyle);
}
void _foreachDirectOrExtensionMemberOfType(
@@ -70,6 +70,8 @@ namespace Slang
void (*callback)(DeclRefBase, void*),
void const* userData);
+ DeclRef<Decl> _getSpecializedDeclRef(ASTBuilder* builder, Decl* decl, Substitutions* subst);
+
template<typename T, typename F>
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>((T*) declRef.decl, declRef.substitutions));
+ (*((*(Helper*)userData).userFunc))(_getSpecializedDeclRef((*(Helper*)userData).semanticsVisitor->getASTBuilder(), declRef.decl, declRef.substitutions).template as<T>());
}
};
- _foreachDirectOrExtensionMemberOfType(semantics, declRef, getClass<T>(), &Helper::callback, &func);
+ Helper helper;
+ helper.userFunc = &func;
+ helper.semanticsVisitor = semantics;
+ _foreachDirectOrExtensionMemberOfType(semantics, declRef, getClass<T>(), &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<VarDecl> getFields(DeclRef<StructDecl> const& declRef, MemberFilterStyle filterStyle)
+ inline FilteredMemberRefList<VarDecl> getFields(ASTBuilder* astBuilder, DeclRef<StructDecl> const& declRef, MemberFilterStyle filterStyle)
{
- return getMembersOfType<VarDecl>(declRef, filterStyle);
+ return getMembersOfType<VarDecl>(astBuilder, declRef, filterStyle);
}
/// If the given `structTypeDeclRef` inherits from another struct type, return that base type
@@ -178,9 +185,9 @@ namespace Slang
}
}
- inline FilteredMemberRefList<ParamDecl> getParameters(DeclRef<CallableDecl> const& declRef)
+ inline FilteredMemberRefList<ParamDecl> getParameters(ASTBuilder* astBuilder, DeclRef<CallableDecl> const& declRef)
{
- return getMembersOfType<ParamDecl>(declRef);
+ return getMembersOfType<ParamDecl>(astBuilder, declRef);
}
inline Decl* getInner(DeclRef<GenericDecl> 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<HLSLPackOffsetSemantic>())
continue;