Skip to content

Commit

Permalink
FlowChecker: Remove some TypeParameterInstantiation arguments
Browse files Browse the repository at this point in the history
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
  • Loading branch information
avp authored and facebook-github-bot committed Dec 4, 2024
1 parent 4c277f1 commit 240eff6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
6 changes: 2 additions & 4 deletions lib/Sema/FlowChecker-scopetypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,7 @@ class FlowChecker::DeclareScopeTypes {
bool populated = outer.validateAndBindTypeParameters(
llvh::cast<ESTree::TypeParameterDeclarationNode>(
aliasNode->_typeParameters),
llvh::cast<ESTree::TypeParameterInstantiationNode>(
generic.annotation->_typeParameters),
generic.annotation->_typeParameters->getSourceRange(),
generic.typeArgTypes,
scope);
if (!populated) {
Expand Down Expand Up @@ -903,8 +902,7 @@ class FlowChecker::DeclareScopeTypes {
assert(typeDecl->genericClassDecl && "Expected a generic class");
sema::Decl *newDecl = outer.specializeGenericWithParsedTypes(
typeDecl->genericClassDecl,
llvh::cast<ESTree::TypeParameterInstantiationNode>(
generic.annotation->_typeParameters),
generic.annotation->_typeParameters->getSourceRange(),
generic.typeArgTypes,
typeDecl->genericClassDecl->scope);

Expand Down
19 changes: 8 additions & 11 deletions lib/Sema/FlowChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ ESTree::Node *FlowChecker::implicitCheckedCast(

bool FlowChecker::validateAndBindTypeParameters(
ESTree::TypeParameterDeclarationNode *params,
ESTree::TypeParameterInstantiationNode *typeArgsNode,
SMRange errorRange,
llvh::ArrayRef<Type *> typeArgTypes,
sema::LexicalScope *scope) {
size_t i = 0;
Expand Down Expand Up @@ -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()));
Expand All @@ -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<Type *> typeArgTypes,
sema::LexicalScope *scope) {
// Extract info from types.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -2028,12 +2027,12 @@ sema::Decl *FlowChecker::specializeGenericWithParsedTypes(
if (auto *func =
llvh::dyn_cast<ESTree::FunctionDeclarationNode>(specialization)) {
typecheckGenericFunctionSpecialization(
func, typeArgsNode, typeArgTypes, oldDecl, newDecl);
func, typeArgTypes, oldDecl, newDecl);
} else if (
auto *classDecl =
llvh::dyn_cast<ESTree::ClassDeclarationNode>(specialization)) {
typecheckGenericClassSpecialization(
classDecl, typeArgsNode, typeArgTypes, oldDecl, newDecl);
classDecl, typeArgTypes, oldDecl, newDecl);
}
}

Expand Down Expand Up @@ -2062,7 +2061,6 @@ void FlowChecker::resolveCallToGenericFunctionSpecialization(

void FlowChecker::typecheckGenericFunctionSpecialization(
ESTree::FunctionDeclarationNode *specialization,
ESTree::TypeParameterInstantiationNode *typeArgsNode,
llvh::ArrayRef<Type *> typeArgTypes,
sema::Decl *oldDecl,
sema::Decl *newDecl) {
Expand All @@ -2088,7 +2086,6 @@ void FlowChecker::typecheckGenericFunctionSpecialization(

void FlowChecker::typecheckGenericClassSpecialization(
ESTree::ClassDeclarationNode *specialization,
ESTree::TypeParameterInstantiationNode *typeArgsNode,
llvh::ArrayRef<Type *> typeArgTypes,
sema::Decl *oldDecl,
sema::Decl *newDecl) {
Expand Down
9 changes: 4 additions & 5 deletions lib/Sema/FlowChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ class FlowChecker : public ESTree::RecursionDepthTracker<FlowChecker> {
/// 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
Expand All @@ -601,7 +601,7 @@ class FlowChecker : public ESTree::RecursionDepthTracker<FlowChecker> {
/// \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<Type *> typeArgTypes,
sema::LexicalScope *scope);

Expand All @@ -621,13 +621,14 @@ class FlowChecker : public ESTree::RecursionDepthTracker<FlowChecker> {
/// 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<Type *> typeArgTypes,
sema::LexicalScope *scope);

Expand All @@ -649,7 +650,6 @@ class FlowChecker : public ESTree::RecursionDepthTracker<FlowChecker> {
/// \param newDecl the new Decl for the specialization of the function.
void typecheckGenericFunctionSpecialization(
ESTree::FunctionDeclarationNode *specialization,
ESTree::TypeParameterInstantiationNode *typeArgsNode,
llvh::ArrayRef<Type *> typeArgTypes,
sema::Decl *oldDecl,
sema::Decl *newDecl);
Expand All @@ -664,7 +664,6 @@ class FlowChecker : public ESTree::RecursionDepthTracker<FlowChecker> {
/// \param newDecl the new Decl for the specialization of the function.
void typecheckGenericClassSpecialization(
ESTree::ClassDeclarationNode *specialization,
ESTree::TypeParameterInstantiationNode *typeArgsNode,
llvh::ArrayRef<Type *> typeArgTypes,
sema::Decl *oldDecl,
sema::Decl *newDecl);
Expand Down

0 comments on commit 240eff6

Please sign in to comment.