From 240eff62241900e0430d299e067fa1340d11ea75 Mon Sep 17 00:00:00 2001 From: Aakash Patel Date: Tue, 3 Dec 2024 17:55:25 -0800 Subject: [PATCH] FlowChecker: Remove some TypeParameterInstantiation arguments Summary: This was either used just for error reporting or completely unused. Clean it up to allow for generics where the type arguments are inferred. Reviewed By: neildhar Differential Revision: D54090053 fbshipit-source-id: cd91fd1bad6ff95c462ca974112ae22c6c3f8511 --- lib/Sema/FlowChecker-scopetypes.cpp | 6 ++---- lib/Sema/FlowChecker.cpp | 19 ++++++++----------- lib/Sema/FlowChecker.h | 9 ++++----- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/Sema/FlowChecker-scopetypes.cpp b/lib/Sema/FlowChecker-scopetypes.cpp index 53c648e9dc5..141ea863ab7 100644 --- a/lib/Sema/FlowChecker-scopetypes.cpp +++ b/lib/Sema/FlowChecker-scopetypes.cpp @@ -866,8 +866,7 @@ class FlowChecker::DeclareScopeTypes { bool populated = outer.validateAndBindTypeParameters( llvh::cast( aliasNode->_typeParameters), - llvh::cast( - generic.annotation->_typeParameters), + generic.annotation->_typeParameters->getSourceRange(), generic.typeArgTypes, scope); if (!populated) { @@ -903,8 +902,7 @@ class FlowChecker::DeclareScopeTypes { assert(typeDecl->genericClassDecl && "Expected a generic class"); sema::Decl *newDecl = outer.specializeGenericWithParsedTypes( typeDecl->genericClassDecl, - llvh::cast( - generic.annotation->_typeParameters), + generic.annotation->_typeParameters->getSourceRange(), generic.typeArgTypes, typeDecl->genericClassDecl->scope); diff --git a/lib/Sema/FlowChecker.cpp b/lib/Sema/FlowChecker.cpp index 5c1481e5039..1bede0488e7 100644 --- a/lib/Sema/FlowChecker.cpp +++ b/lib/Sema/FlowChecker.cpp @@ -1854,7 +1854,7 @@ ESTree::Node *FlowChecker::implicitCheckedCast( bool FlowChecker::validateAndBindTypeParameters( ESTree::TypeParameterDeclarationNode *params, - ESTree::TypeParameterInstantiationNode *typeArgsNode, + SMRange errorRange, llvh::ArrayRef typeArgTypes, sema::LexicalScope *scope) { size_t i = 0; @@ -1890,7 +1890,7 @@ bool FlowChecker::validateAndBindTypeParameters( // Check that there aren't too many (or too few) type arguments provided. if (tooFewTypeArgs || i != typeArgTypes.size()) { sm_.error( - typeArgsNode->getSourceRange(), + errorRange, llvh::Twine("type argument mismatch, expected ") + llvh::Twine(params->_params.size()) + ", found " + llvh::Twine(typeArgTypes.size())); @@ -1912,12 +1912,12 @@ sema::Decl *FlowChecker::specializeGeneric( } return specializeGenericWithParsedTypes( - oldDecl, typeArgsNode, typeArgTypes, scope); + oldDecl, typeArgsNode->getSourceRange(), typeArgTypes, scope); } sema::Decl *FlowChecker::specializeGenericWithParsedTypes( sema::Decl *oldDecl, - ESTree::TypeParameterInstantiationNode *typeArgsNode, + SMRange errorRange, llvh::ArrayRef typeArgTypes, sema::LexicalScope *scope) { // Extract info from types. @@ -1965,8 +1965,7 @@ sema::Decl *FlowChecker::specializeGenericWithParsedTypes( }); if (!specialization) { sm_.error( - typeArgsNode->getSourceRange(), - "failed to create specialization for generic function"); + errorRange, "failed to create specialization for generic function"); return nullptr; } auto &nodeList = getNodeList(generic.parent); @@ -2019,7 +2018,7 @@ sema::Decl *FlowChecker::specializeGenericWithParsedTypes( ScopeRAII paramScope{*this}; bool populated = validateAndBindTypeParameters( - typeParamsNode, typeArgsNode, typeArgTypes, oldDecl->scope); + typeParamsNode, errorRange, typeArgTypes, oldDecl->scope); if (!populated) { LLVM_DEBUG(llvh::dbgs() << "Failed to bind type parameters\n"); return nullptr; @@ -2028,12 +2027,12 @@ sema::Decl *FlowChecker::specializeGenericWithParsedTypes( if (auto *func = llvh::dyn_cast(specialization)) { typecheckGenericFunctionSpecialization( - func, typeArgsNode, typeArgTypes, oldDecl, newDecl); + func, typeArgTypes, oldDecl, newDecl); } else if ( auto *classDecl = llvh::dyn_cast(specialization)) { typecheckGenericClassSpecialization( - classDecl, typeArgsNode, typeArgTypes, oldDecl, newDecl); + classDecl, typeArgTypes, oldDecl, newDecl); } } @@ -2062,7 +2061,6 @@ void FlowChecker::resolveCallToGenericFunctionSpecialization( void FlowChecker::typecheckGenericFunctionSpecialization( ESTree::FunctionDeclarationNode *specialization, - ESTree::TypeParameterInstantiationNode *typeArgsNode, llvh::ArrayRef typeArgTypes, sema::Decl *oldDecl, sema::Decl *newDecl) { @@ -2088,7 +2086,6 @@ void FlowChecker::typecheckGenericFunctionSpecialization( void FlowChecker::typecheckGenericClassSpecialization( ESTree::ClassDeclarationNode *specialization, - ESTree::TypeParameterInstantiationNode *typeArgsNode, llvh::ArrayRef typeArgTypes, sema::Decl *oldDecl, sema::Decl *newDecl) { diff --git a/lib/Sema/FlowChecker.h b/lib/Sema/FlowChecker.h index 188a6db9e04..2ae57bd412e 100644 --- a/lib/Sema/FlowChecker.h +++ b/lib/Sema/FlowChecker.h @@ -592,7 +592,7 @@ class FlowChecker : public ESTree::RecursionDepthTracker { /// Ensure that there are the correct number of type arguments and that they /// are valid to pass. /// \param params the type parameter declaration. - /// \param typeArgsNode the type arguments to pass. + /// \param errorRange used for reporting errors when binding fails. /// \param typeArgTypes the actual Types to instantiate the arguments with. /// \param scope the lexical scope to associate with each TypeDecl. /// \pre the binding table's scope is set to the new scope in which to place @@ -601,7 +601,7 @@ class FlowChecker : public ESTree::RecursionDepthTracker { /// \return true on success, false on failure and report an error. LLVM_NODISCARD bool validateAndBindTypeParameters( ESTree::TypeParameterDeclarationNode *params, - ESTree::TypeParameterInstantiationNode *typeArgsNode, + SMRange errorRange, llvh::ArrayRef typeArgTypes, sema::LexicalScope *scope); @@ -621,13 +621,14 @@ class FlowChecker : public ESTree::RecursionDepthTracker { /// If necessary, specialize and typecheck the specialization of a generic /// function. /// \param node the call expression passing the type arguments + /// \param errorRange used for reporting errors when binding fails. /// \param callee the name of the generic being called /// \param oldDecl the original Decl for the non-specialized generic function /// \return the new Decl for the specialization of the function, /// nullptr on error. sema::Decl *specializeGenericWithParsedTypes( sema::Decl *oldDecl, - ESTree::TypeParameterInstantiationNode *typeArgsNode, + SMRange errorRange, llvh::ArrayRef typeArgTypes, sema::LexicalScope *scope); @@ -649,7 +650,6 @@ class FlowChecker : public ESTree::RecursionDepthTracker { /// \param newDecl the new Decl for the specialization of the function. void typecheckGenericFunctionSpecialization( ESTree::FunctionDeclarationNode *specialization, - ESTree::TypeParameterInstantiationNode *typeArgsNode, llvh::ArrayRef typeArgTypes, sema::Decl *oldDecl, sema::Decl *newDecl); @@ -664,7 +664,6 @@ class FlowChecker : public ESTree::RecursionDepthTracker { /// \param newDecl the new Decl for the specialization of the function. void typecheckGenericClassSpecialization( ESTree::ClassDeclarationNode *specialization, - ESTree::TypeParameterInstantiationNode *typeArgsNode, llvh::ArrayRef typeArgTypes, sema::Decl *oldDecl, sema::Decl *newDecl);