Skip to content

Commit e5f1d73

Browse files
committed
AST: Remove FuncDecl::getNaturalArgumentCount(), NFC
1 parent 57c5817 commit e5f1d73

File tree

8 files changed

+15
-44
lines changed

8 files changed

+15
-44
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4838,35 +4838,13 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
48384838
/// depending on the function context.
48394839
bool argumentNameIsAPIByDefault() const;
48404840

4841+
/// \brief Returns the "natural" number of argument clauses taken by this
4842+
/// function. This value is one for free-standing functions, and two for
4843+
/// methods.
48414844
unsigned getNumParameterLists() const {
48424845
return AbstractFunctionDeclBits.NumParameterLists;
48434846
}
48444847

4845-
/// \brief Returns the "natural" number of argument clauses taken by this
4846-
/// function. This value is always at least one, and it may be more if the
4847-
/// function is implicitly or explicitly curried.
4848-
///
4849-
/// For example, this function:
4850-
/// \code
4851-
/// func negate(x : Int) -> Int { return -x }
4852-
/// \endcode
4853-
/// has a natural argument count of 1 if it is freestanding. If it is
4854-
/// a method, it has a natural argument count of 2, as does this
4855-
/// curried function:
4856-
/// \code
4857-
/// func add(x : Int)(y : Int) -> Int { return x + y }
4858-
/// \endcode
4859-
///
4860-
/// This value never exceeds the number of chained function types
4861-
/// in the function's type, but it can be less for functions which
4862-
/// return a value of function type:
4863-
/// \code
4864-
/// func const(x : Int) -> () -> Int { return { x } } // NAC==1
4865-
/// \endcode
4866-
unsigned getNaturalArgumentCount() const {
4867-
return getNumParameterLists();
4868-
}
4869-
48704848
/// \brief Returns the parameter pattern(s) for the function definition that
48714849
/// determine the parameter names bound in the function body.
48724850
///

include/swift/AST/Expr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,8 +2844,6 @@ class AbstractClosureExpr : public Expr, public DeclContext {
28442844
return parameterList ? parameterList : ArrayRef<const ParameterList *>();
28452845
}
28462846

2847-
unsigned getNaturalArgumentCount() const { return 1; }
2848-
28492847
/// \brief Retrieve the result type of this closure.
28502848
Type getResultType() const;
28512849

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ struct ASTNodeBase {};
23042304
// If a decl has the Throws bit set, the function type should throw,
23052305
// and vice versa.
23062306
auto fnTy = AFD->getType()->castTo<AnyFunctionType>();
2307-
for (unsigned i = 1, e = AFD->getNaturalArgumentCount(); i != e; ++i)
2307+
for (unsigned i = 1, e = AFD->getNumParameterLists(); i != e; ++i)
23082308
fnTy = fnTy->getResult()->castTo<AnyFunctionType>();
23092309

23102310
if (AFD->hasThrows() != fnTy->getExtInfo().throws()) {

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4415,7 +4415,7 @@ Type FuncDecl::getResultType() const {
44154415
if (resultTy->is<ErrorType>())
44164416
return resultTy;
44174417

4418-
for (unsigned i = 0, e = getNaturalArgumentCount(); i != e; ++i)
4418+
for (unsigned i = 0, e = getNumParameterLists(); i != e; ++i)
44194419
resultTy = resultTy->castTo<AnyFunctionType>()->getResult();
44204420

44214421
if (!resultTy)

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ namespace {
577577
if (auto func = dyn_cast<AbstractFunctionDecl>(member)) {
578578
// For functions, close the existential once the function
579579
// has been fully applied.
580-
return func->getNaturalArgumentCount();
580+
return func->getNumParameterLists();
581581
} else {
582582
// For storage, close the existential either when it's
583583
// accessed (if it's an rvalue only) or when it is loaded or

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
182182
if (expr->getArg()->getType()->hasInOut()) {
183183
// We need to apply all argument clauses.
184184
InvalidPartialApplications.insert({
185-
fnExpr, {fn->getNaturalArgumentCount(), kind}
185+
fnExpr, {fn->getNumParameterLists(), kind}
186186
});
187187
}
188188
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4564,7 +4564,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
45644564
if (auto func = dyn_cast<FuncDecl>(decl)) {
45654565
if (func->hasDynamicSelf()) {
45664566
type = type->replaceCovariantResultType(subclass,
4567-
func->getNaturalArgumentCount());
4567+
func->getNumParameterLists());
45684568
}
45694569
} else if (isa<ConstructorDecl>(decl)) {
45704570
type = type->replaceCovariantResultType(subclass, /*uncurryLevel=*/2);

lib/Sema/TypeCheckError.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ class AbstractFunction {
5656
: TheKind(Kind::Function),
5757
IsRethrows(fn->getAttrs().hasAttribute<RethrowsAttr>()),
5858
IsProtocolMethod(isProtocolMethod),
59-
ParamCount(fn->getNaturalArgumentCount()) {
59+
ParamCount(fn->getNumParameterLists()) {
6060
TheFunction = fn;
6161
}
6262

6363
explicit AbstractFunction(AbstractClosureExpr *closure)
6464
: TheKind(Kind::Closure),
6565
IsRethrows(false),
6666
IsProtocolMethod(false),
67-
ParamCount(closure->getNaturalArgumentCount()) {
67+
ParamCount(1) {
6868
TheClosure = closure;
6969
}
7070

@@ -380,11 +380,6 @@ classifyFunctionByType(Type type, unsigned numArgs) {
380380
}
381381
}
382382

383-
template <class T>
384-
static ThrowingKind classifyFunctionBodyWithoutContext(T *fn) {
385-
return classifyFunctionByType(fn->getType(), fn->getNaturalArgumentCount());
386-
}
387-
388383
/// A class for collecting information about rethrowing functions.
389384
class ApplyClassifier {
390385
llvm::DenseMap<void*, ThrowingKind> Cache;
@@ -850,9 +845,8 @@ class Context {
850845
};
851846

852847
private:
853-
template <class T>
854-
static Kind getKindForFunctionBody(T *fn) {
855-
switch (classifyFunctionBodyWithoutContext(fn)) {
848+
static Kind getKindForFunctionBody(Type type, unsigned numArgs) {
849+
switch (classifyFunctionByType(type, numArgs)) {
856850
case ThrowingKind::None:
857851
return Kind::NonThrowingFunction;
858852
case ThrowingKind::Invalid:
@@ -885,7 +879,8 @@ class Context {
885879
result.RethrowsDC = D;
886880
return result;
887881
}
888-
return Context(getKindForFunctionBody(D));
882+
return Context(getKindForFunctionBody(
883+
D->getType(), D->getNumParameterLists()));
889884
}
890885

891886
static Context forInitializer(Initializer *init) {
@@ -908,7 +903,7 @@ class Context {
908903
}
909904

910905
static Context forClosure(AbstractClosureExpr *E) {
911-
auto kind = getKindForFunctionBody(E);
906+
auto kind = getKindForFunctionBody(E->getType(), 1);
912907
if (kind != Kind::Handled && isa<AutoClosureExpr>(E))
913908
kind = Kind::NonThrowingAutoClosure;
914909
return Context(kind);

0 commit comments

Comments
 (0)