Skip to content

Commit 34fd5fa

Browse files
committed
AST: Replace remaining uses of FunctionType::getInput() with getParams()
1 parent 3554da1 commit 34fd5fa

File tree

7 files changed

+42
-33
lines changed

7 files changed

+42
-33
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5954,9 +5954,6 @@ class ConstructorDecl : public AbstractFunctionDecl {
59545954
SourceLoc getStartLoc() const { return getConstructorLoc(); }
59555955
SourceRange getSourceRange() const;
59565956

5957-
/// getArgumentInterfaceType - get the interface type of the argument tuple
5958-
Type getArgumentInterfaceType() const;
5959-
59605957
/// \brief Get the interface type of the constructed object.
59615958
Type getResultInterfaceType() const;
59625959

lib/AST/Decl.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5765,7 +5765,9 @@ Type EnumElementDecl::getArgumentInterfaceType() const {
57655765

57665766
auto funcTy = interfaceType->castTo<AnyFunctionType>();
57675767
funcTy = funcTy->getResult()->castTo<FunctionType>();
5768-
return funcTy->getInput();
5768+
return AnyFunctionType::composeInput(funcTy->getASTContext(),
5769+
funcTy->getParams(),
5770+
/*canonicalVararg=*/false);
57695771
}
57705772

57715773
EnumCaseDecl *EnumElementDecl::getParentCase() const {
@@ -5801,13 +5803,6 @@ SourceRange ConstructorDecl::getSourceRange() const {
58015803
return { getConstructorLoc(), End };
58025804
}
58035805

5804-
Type ConstructorDecl::getArgumentInterfaceType() const {
5805-
Type ArgTy = getInterfaceType();
5806-
ArgTy = ArgTy->castTo<AnyFunctionType>()->getResult();
5807-
ArgTy = ArgTy->castTo<AnyFunctionType>()->getInput();
5808-
return ArgTy;
5809-
}
5810-
58115806
Type ConstructorDecl::getResultInterfaceType() const {
58125807
Type ArgTy = getInterfaceType();
58135808
ArgTy = ArgTy->castTo<AnyFunctionType>()->getResult();

lib/Sema/CSDiag.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5489,7 +5489,9 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
54895489
if (locator->getAnchor() == callExpr) {
54905490
auto calleeType = CS.simplifyType(constraint->getSecondType());
54915491
if (auto *fnType = calleeType->getAs<FunctionType>())
5492-
argType = fnType->getInput();
5492+
argType = AnyFunctionType::composeInput(fnType->getASTContext(),
5493+
fnType->getParams(),
5494+
/*canonicalVararg=*/false);
54935495
}
54945496
}
54955497
}

lib/Sema/CSSimplify.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,7 +2515,9 @@ ConstraintSystem::simplifyConstructionConstraint(
25152515

25162516
case TypeKind::Tuple: {
25172517
// Tuple construction is simply tuple conversion.
2518-
Type argType = fnType->getInput();
2518+
Type argType = AnyFunctionType::composeInput(getASTContext(),
2519+
fnType->getParams(),
2520+
/*canonicalVararg=*/false);
25192521
Type resultType = fnType->getResult();
25202522

25212523
if (matchTypes(resultType, desugarValueType,
@@ -2923,35 +2925,37 @@ ConstraintSystem::simplifyFunctionComponentConstraint(
29232925
Type first, Type second,
29242926
TypeMatchOptions flags,
29252927
ConstraintLocatorBuilder locator) {
2926-
auto funcTy = simplifyType(first);
2928+
auto simplified = simplifyType(first);
29272929

29282930
unsigned unwrapCount = 0;
29292931
if (shouldAttemptFixes()) {
2930-
while (auto objectTy = funcTy->getOptionalObjectType()) {
2931-
funcTy = objectTy;
2932+
while (auto objectTy = simplified->getOptionalObjectType()) {
2933+
simplified = objectTy;
29322934

29332935
// Track how many times we do this so that we can record a fix for each.
29342936
++unwrapCount;
29352937
}
29362938
}
29372939

2938-
if (funcTy->isTypeVariableOrMember()) {
2940+
if (simplified->isTypeVariableOrMember()) {
29392941
if (!flags.contains(TMF_GenerateConstraints))
29402942
return SolutionKind::Unsolved;
29412943

29422944
addUnsolvedConstraint(
2943-
Constraint::create(*this, kind, funcTy, second,
2945+
Constraint::create(*this, kind, simplified, second,
29442946
getConstraintLocator(locator)));
2945-
} else if (funcTy->is<FunctionType>()) {
2947+
} else if (auto *funcTy = simplified->getAs<FunctionType>()) {
29462948
// Equate it to the other type in the constraint.
29472949
Type type;
29482950
ConstraintLocator::PathElementKind locKind;
29492951

29502952
if (kind == ConstraintKind::FunctionInput) {
2951-
type = funcTy->castTo<FunctionType>()->getInput();
2953+
type = AnyFunctionType::composeInput(getASTContext(),
2954+
funcTy->getParams(),
2955+
/*canonicalVararg=*/false);
29522956
locKind = ConstraintLocator::FunctionArgument;
29532957
} else if (kind == ConstraintKind::FunctionResult) {
2954-
type = funcTy->castTo<FunctionType>()->getResult();
2958+
type = funcTy->getResult();
29552959
locKind = ConstraintLocator::FunctionResult;
29562960
} else {
29572961
llvm_unreachable("Bad function component constraint kind");
@@ -3330,7 +3334,10 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
33303334

33313335
// Only try and favor monomorphic initializers.
33323336
if (!ctor->isGenericContext()) {
3333-
auto argType = ctor->getArgumentInterfaceType();
3337+
auto args = ctor->getMethodInterfaceType()
3338+
->castTo<FunctionType>()->getParams();
3339+
auto argType = AnyFunctionType::composeInput(getASTContext(), args,
3340+
/*canonicalVarargs=*/false);
33343341
if (argType->isEqual(favoredType))
33353342
if (!decl->getAttrs().isUnavailable(getASTContext()))
33363343
result.FavoredChoice = result.ViableCandidates.size();

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,11 @@ static Type getTypeForDisplay(ModuleDecl *module, ValueDecl *decl) {
17581758

17591759
// For a constructor, we only care about the parameter types.
17601760
if (auto ctor = dyn_cast<ConstructorDecl>(decl)) {
1761-
return ctor->getArgumentInterfaceType();
1761+
return AnyFunctionType::composeInput(module->getASTContext(),
1762+
ctor->getMethodInterfaceType()
1763+
->castTo<FunctionType>()
1764+
->getParams(),
1765+
/*canonicalVararg=*/false);
17621766
}
17631767

17641768
// We have something function-like, so we want to strip off the 'self'.

lib/Sema/TypeChecker.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,17 @@ DeclName TypeChecker::getObjectLiteralConstructorName(ObjectLiteralExpr *expr) {
192192
/// unambiguous name.
193193
Type TypeChecker::getObjectLiteralParameterType(ObjectLiteralExpr *expr,
194194
ConstructorDecl *ctor) {
195-
Type argType = ctor->getArgumentInterfaceType();
196-
auto argTuple = argType->getAs<TupleType>();
197-
if (!argTuple) return argType;
195+
auto params = ctor->getMethodInterfaceType()
196+
->castTo<FunctionType>()->getParams();
197+
SmallVector<AnyFunctionType::Param, 8> newParams;
198+
newParams.append(params.begin(), params.end());
198199

199200
auto replace = [&](StringRef replacement) -> Type {
200-
SmallVector<TupleTypeElt, 4> elements;
201-
elements.append(argTuple->getElements().begin(),
202-
argTuple->getElements().end());
203-
elements[0] = TupleTypeElt(elements[0].getType(),
204-
Context.getIdentifier(replacement));
205-
return TupleType::get(elements, Context);
201+
newParams[0] = AnyFunctionType::Param(newParams[0].getPlainType(),
202+
Context.getIdentifier(replacement),
203+
newParams[0].getParameterFlags());
204+
return AnyFunctionType::composeInput(Context, newParams,
205+
/*canonicalVararg=*/false);
206206
};
207207

208208
switch (expr->getLiteralKind()) {

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,11 @@ SwiftDeclCollector::constructTypeNode(Type T,
10801080

10811081
// Still, return type first
10821082
Root->addChild(constructTypeNode(Fun->getResult()));
1083-
Root->addChild(constructTypeNode(Fun->getInput()));
1083+
1084+
auto Input = AnyFunctionType::composeInput(Fun->getASTContext(),
1085+
Fun->getParams(),
1086+
/*canonicalVararg=*/false);
1087+
Root->addChild(constructTypeNode(Input));
10841088
return Root;
10851089
}
10861090

0 commit comments

Comments
 (0)