summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-overload.cpp
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/slang-check-overload.cpp
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/slang-check-overload.cpp')
-rw-r--r--source/slang/slang-check-overload.cpp33
1 files changed, 17 insertions, 16 deletions
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(