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-check-overload.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'source/slang/slang-check-overload.cpp') 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( -- cgit v1.2.3