Skip to content

Commit 3b60ae1

Browse files
committed
AST: Rename AnyFunctionType::Param::getType() to getOldType()
1 parent 4975f3a commit 3b60ae1

29 files changed

+100
-94
lines changed

include/swift/AST/TypeMatcher.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ class TypeMatcher {
217217
if (firstElt.getLabel() != secondElt.getLabel() ||
218218
firstElt.isVariadic() != secondElt.isVariadic() ||
219219
firstElt.isInOut() != secondElt.isInOut())
220-
return mismatch(firstElt.getType().getPointer(),
221-
secondElt.getType(),
222-
sugaredFirstFunc->getParams()[i].getType());
220+
return mismatch(firstElt.getOldType().getPointer(),
221+
secondElt.getOldType(),
222+
sugaredFirstFunc->getParams()[i].getOldType());
223223

224224
// Recurse on parameter components.
225-
if (!this->visit(firstElt.getType()->getCanonicalType(),
226-
secondElt.getType(),
227-
sugaredFirstFunc->getParams()[i].getType()))
225+
if (!this->visit(firstElt.getOldType()->getCanonicalType(),
226+
secondElt.getOldType(),
227+
sugaredFirstFunc->getParams()[i].getOldType()))
228228
return false;
229229
}
230230

include/swift/AST/Types.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,13 +2647,21 @@ class AnyFunctionType : public TypeBase {
26472647
ParameterTypeFlags Flags = {};
26482648

26492649
public:
2650-
/// FIXME(Remove InOutType): This is mostly for copying between param
2651-
/// types and should go away.
2652-
Type getType() const;
2650+
/// FIXME: Remove this. Return the formal type of the parameter in the
2651+
/// function type, including the InOutType if there is one.
2652+
///
2653+
/// For example, 'inout Int' => 'inout Int', 'Int...' => 'Int'.
2654+
Type getOldType() const;
26532655

2656+
/// Return the formal type of the parameter.
2657+
///
2658+
/// For example, 'inout Int' => 'Int', 'Int...' => 'Int'.
26542659
Type getPlainType() const { return Ty; }
26552660

2656-
/// The type of the parameter. Adjusts for varargs, but not inout.
2661+
/// The type of the parameter when referenced inside the function body
2662+
/// as an rvalue.
2663+
///
2664+
/// For example, 'inout Int' => 'Int', 'Int...' => '[Int]'.
26572665
Type getParameterType(bool forCanonical = false,
26582666
ASTContext *ctx = nullptr) const;
26592667

@@ -2699,7 +2707,7 @@ class AnyFunctionType : public TypeBase {
26992707
public:
27002708
static CanParam getFromParam(const Param &param) { return CanParam(param); }
27012709

2702-
CanType getType() const { return CanType(Param::getType()); }
2710+
CanType getOldType() const { return CanType(Param::getOldType()); }
27032711
CanType getPlainType() const { return CanType(Param::getPlainType()); }
27042712
CanType getParameterType() const {
27052713
return CanType(Param::getParameterType(/*forCanonical*/ true));

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,8 @@ FuncDecl *ASTContext::getEqualIntDecl() const {
10291029
intType, [=](FunctionType *type) {
10301030
// Check for the signature: (Int, Int) -> Bool
10311031
if (type->getParams().size() != 2) return false;
1032-
if (!type->getParams()[0].getType()->isEqual(intType) ||
1033-
!type->getParams()[1].getType()->isEqual(intType)) return false;
1032+
if (!type->getParams()[0].getOldType()->isEqual(intType) ||
1033+
!type->getParams()[1].getOldType()->isEqual(intType)) return false;
10341034
return type->getResult()->isEqual(boolType);
10351035
});
10361036
getImpl().EqualIntDecl = decl;
@@ -1046,7 +1046,7 @@ FuncDecl *ASTContext::getGetBoolDecl(LazyResolver *resolver) const {
10461046
resolver, [=](FunctionType *type) {
10471047
// Look for the signature (Builtin.Int1) -> Bool
10481048
if (type->getParams().size() != 1) return false;
1049-
if (!isBuiltinInt1Type(type->getParams()[0].getType())) return false;
1049+
if (!isBuiltinInt1Type(type->getParams()[0].getOldType())) return false;
10501050
return type->getResult()->isEqual(boolType);
10511051
});
10521052
getImpl().GetBoolDecl = decl;
@@ -1238,7 +1238,7 @@ FuncDecl *ASTContext::getIsOSVersionAtLeastDecl(LazyResolver *resolver) const {
12381238
return nullptr;
12391239

12401240
if (llvm::any_of(intrinsicsParams, [](const AnyFunctionType::Param &p) {
1241-
return !isBuiltinWordType(p.getType());
1241+
return !isBuiltinWordType(p.getOldType());
12421242
})) {
12431243
return nullptr;
12441244
}
@@ -3155,11 +3155,8 @@ Type TupleTypeElt::getType() const {
31553155
return ElementType;
31563156
}
31573157

3158-
Type AnyFunctionType::Param::getType() const {
3158+
Type AnyFunctionType::Param::getOldType() const {
31593159
if (Flags.isInOut()) return InOutType::get(Ty);
3160-
// FIXME: Callers are inconsistenly setting this flag and retrieving this
3161-
// type with and without the Array Slice type.
3162-
// if (Flags.isVariadic()) return ArraySliceType::get(Ty);
31633160
return Ty;
31643161
}
31653162

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3404,7 +3404,7 @@ namespace {
34043404
if (param.hasLabel())
34053405
printField("name", param.getLabel().str());
34063406
dumpParameterFlags(param.getParameterFlags());
3407-
printRec(param.getType());
3407+
printRec(param.getOldType());
34083408
OS << ")";
34093409
}
34103410
Indent -= 2;

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,7 +3772,7 @@ findProtocolSelfReferences(const ProtocolDecl *proto, Type type,
37723772
if (auto funcTy = type->getAs<AnyFunctionType>()) {
37733773
auto inputKind = SelfReferenceKind::None();
37743774
for (auto &elt : funcTy->getParams()) {
3775-
inputKind |= findProtocolSelfReferences(proto, elt.getType(),
3775+
inputKind |= findProtocolSelfReferences(proto, elt.getOldType(),
37763776
skipAssocTypes);
37773777
}
37783778
auto resultKind = findProtocolSelfReferences(proto, funcTy->getResult(),
@@ -3882,7 +3882,7 @@ ProtocolDecl::findProtocolSelfReferences(const ValueDecl *value,
38823882
if (!allowCovariantParameters) {
38833883
auto inputKind = SelfReferenceKind::None();
38843884
for (auto &elt : type->castTo<AnyFunctionType>()->getParams()) {
3885-
inputKind |= ::findProtocolSelfReferences(this, elt.getType(),
3885+
inputKind |= ::findProtocolSelfReferences(this, elt.getOldType(),
38863886
skipAssocTypes);
38873887
}
38883888

lib/AST/Type.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,8 @@ bool TypeBase::isBindableTo(Type b) {
15381538
return false;
15391539

15401540
for (unsigned i : indices(func->getParams())) {
1541-
if (!visit(func->getParams()[i].getType(),
1542-
substFunc.getParams()[i].getType()))
1541+
if (!visit(func->getParams()[i].getOldType(),
1542+
substFunc.getParams()[i].getOldType()))
15431543
return false;
15441544
}
15451545

@@ -1916,7 +1916,7 @@ getForeignRepresentable(Type type, ForeignLanguage language,
19161916
for (const auto &param : functionType->getParams()) {
19171917
if (param.isVariadic())
19181918
return failure();
1919-
if (recurse(param.getType()))
1919+
if (recurse(param.getOldType()))
19201920
return failure();
19211921
}
19221922

@@ -2277,7 +2277,7 @@ static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
22772277

22782278
// Inputs are contravariant.
22792279
for (auto i : indices(fn2.getParams())) {
2280-
if (!matches(fn2Params[i].getType(), fn1Params[i].getType(),
2280+
if (!matches(fn2Params[i].getOldType(), fn1Params[i].getOldType(),
22812281
matchMode, ParameterPosition::ParameterTupleElement,
22822282
OptionalUnwrapping::None)) {
22832283
return false;

lib/AST/TypeWalker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Traversal : public TypeVisitor<Traversal, bool>
8585

8686
bool visitAnyFunctionType(AnyFunctionType *ty) {
8787
for (const auto &param : ty->getParams()) {
88-
if (doIt(param.getType()))
88+
if (doIt(param.getOldType()))
8989
return true;
9090
}
9191

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ static std::pair<Type, ParamDecl *> decomposeSubscriptSetter(FuncDecl *setter) {
16481648
->castTo<AnyFunctionType>()
16491649
->getResult()
16501650
->castTo<AnyFunctionType>()
1651-
->getParams().front().getType();
1651+
->getParams().front().getOldType();
16521652
ParamDecl *keyDecl = PL->get(1);
16531653

16541654
return {elementType, keyDecl};

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ static bool hasTrivialTrailingClosure(const FuncDecl *FD,
15671567
if (defaultMap.size() - defaultMap.count() == 1) {
15681568
auto param = funcType->getParams().back();
15691569
if (!param.isAutoClosure()) {
1570-
if (auto Fn = param.getType()->getAs<AnyFunctionType>()) {
1570+
if (auto Fn = param.getOldType()->getAs<AnyFunctionType>()) {
15711571
return Fn->getParams().empty() && Fn->getResult()->isVoid();
15721572
}
15731573
}
@@ -3885,8 +3885,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
38853885
if (seenNames.insert(Param.getLabel()).second)
38863886
ExpectedNames.push_back(Param.getLabel().str());
38873887
} else {
3888-
if (seenTypes.insert(Param.getType().getPointer()).second)
3889-
ExpectedTypes.push_back(Param.getType());
3888+
if (seenTypes.insert(Param.getOldType().getPointer()).second)
3889+
ExpectedTypes.push_back(Param.getOldType());
38903890
}
38913891
}
38923892
}

lib/IDE/TypeReconstruction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ static void VisitNodeConstructor(
935935
// inits are typed as (Foo.Type) -> (args...) -> Foo, but don't
936936
// assert that in case we're dealing with broken code.
937937
if (identifier_func->getParams().size() == 1 &&
938-
identifier_func->getParams()[0].getType()->is<AnyMetatypeType>() &&
938+
identifier_func->getParams()[0].getOldType()->is<AnyMetatypeType>() &&
939939
identifier_func->getResult()->is<AnyFunctionType>()) {
940940
identifier_func =
941941
identifier_func->getResult()->getAs<AnyFunctionType>();
@@ -1227,7 +1227,8 @@ static bool CompareFunctionTypes(const AnyFunctionType *f,
12271227
auto label1 = getLabel(fLabels, param1, i);
12281228
auto label2 = getLabel(gLabels, param2, i);
12291229

1230-
if (label1.equals(label2) && param1.getType()->isEqual(param2.getType()))
1230+
if (label1.equals(label2) &&
1231+
param1.getOldType()->isEqual(param2.getOldType()))
12311232
continue;
12321233

12331234
in_matches = false;

lib/IRGen/GenProto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3046,7 +3046,7 @@ void NecessaryBindings::addTypeMetadata(CanType type) {
30463046
}
30473047
if (auto fn = dyn_cast<FunctionType>(type)) {
30483048
for (const auto &elt : fn.getParams())
3049-
addTypeMetadata(elt.getType());
3049+
addTypeMetadata(elt.getOldType());
30503050
addTypeMetadata(fn.getResult());
30513051
return;
30523052
}

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
19091909
if (!FT->getParams().empty()) {
19101910
interleave(FT->getParams(),
19111911
[this](const AnyFunctionType::Param &param) {
1912-
print(param.getType(), OTK_None, param.getLabel(),
1912+
print(param.getOldType(), OTK_None, param.getLabel(),
19131913
IsFunctionParam);
19141914
},
19151915
[this] { os << ", "; });
@@ -2061,7 +2061,7 @@ class ReferencedTypeFinder : public TypeVisitor<ReferencedTypeFinder> {
20612061

20622062
void visitAnyFunctionType(AnyFunctionType *fnTy) {
20632063
for (auto &param : fnTy->getParams())
2064-
visit(param.getType());
2064+
visit(param.getOldType());
20652065
visit(fnTy->getResult());
20662066
}
20672067

lib/SILGen/SILGenBridging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static SmallVector<CanType, 8>
348348
expandTupleTypes(AnyFunctionType::CanParamArrayRef params) {
349349
SmallVector<CanType, 8> results;
350350
for (auto param : params)
351-
expandTupleTypes(param.getType(), results);
351+
expandTupleTypes(param.getOldType(), results);
352352
return results;
353353
}
354354

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static SILValue emitConstructorMetatypeArg(SILGenFunction &SGF,
3535
auto ctorFnType = ctor->getInterfaceType()->castTo<AnyFunctionType>();
3636
assert(ctorFnType->getParams().size() == 1 &&
3737
"more than one self parameter?");
38-
Type metatype = ctorFnType->getParams()[0].getType();
38+
Type metatype = ctorFnType->getParams()[0].getOldType();
3939
auto *DC = ctor->getInnermostDeclContext();
4040
auto &AC = SGF.getASTContext();
4141
auto VD =

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static std::pair<unsigned, unsigned> getTypeDepthAndWidth(Type t) {
156156
for (auto &Param : Params) {
157157
unsigned TypeWidth;
158158
unsigned TypeDepth;
159-
std::tie(TypeDepth, TypeWidth) = getTypeDepthAndWidth(Param.getType());
159+
std::tie(TypeDepth, TypeWidth) = getTypeDepthAndWidth(Param.getOldType());
160160
if (TypeDepth > MaxTypeDepth)
161161
MaxTypeDepth = TypeDepth;
162162
Width += TypeWidth;

lib/Sema/CSApply.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ namespace {
547547
if (wantsRValueInstanceType)
548548
return base.getPlainType()->getMetatypeInstanceType();
549549

550-
return base.getType();
550+
return base.getOldType();
551551
}
552552

553553
public:
@@ -1441,7 +1441,7 @@ namespace {
14411441
// Dig the key path expression out of the arguments.
14421442
auto indexKP = cast<TupleExpr>(index)->getElement(0);
14431443
auto keyPathExprTy = cs.getType(indexKP);
1444-
auto keyPathTy = applicationTy->getParams().front().getType();
1444+
auto keyPathTy = applicationTy->getParams().front().getOldType();
14451445

14461446
Type valueTy;
14471447
Type baseTy;
@@ -5584,7 +5584,7 @@ Expr *ExprRewriter::coerceCallArguments(
55845584
return nullptr;
55855585

55865586
// Record this parameter.
5587-
auto paramBaseType = param.getType();
5587+
auto paramBaseType = param.getOldType();
55885588
assert(sliceType.isNull() && "Multiple variadic parameters?");
55895589
sliceType = tc.getArraySliceType(arg->getLoc(), paramBaseType);
55905590
toSugarFields.push_back(
@@ -5632,8 +5632,8 @@ Expr *ExprRewriter::coerceCallArguments(
56325632
toSugarFields.push_back(TupleTypeElt(
56335633
param.isVariadic()
56345634
? tc.getArraySliceType(arg->getLoc(),
5635-
param.getType())
5636-
: param.getType(),
5635+
param.getOldType())
5636+
: param.getOldType(),
56375637
param.getLabel(),
56385638
param.getParameterFlags()));
56395639

@@ -5657,7 +5657,7 @@ Expr *ExprRewriter::coerceCallArguments(
56575657
sources.push_back(argIdx);
56585658

56595659
// If the types exactly match, this is easy.
5660-
auto paramType = param.getType();
5660+
auto paramType = param.getOldType();
56615661
if (argType->isEqual(paramType)) {
56625662
toSugarFields.push_back(
56635663
TupleTypeElt(param.getPlainType(), getArgLabel(argIdx),
@@ -6298,7 +6298,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
62986298

62996299
// This handles situations like argument: (()), parameter: ().
63006300
if (params1.size() == 1 && params2.empty()) {
6301-
auto tupleTy = params1.front().getType()->getAs<TupleType>();
6301+
auto tupleTy = params1.front().getOldType()->getAs<TupleType>();
63026302
if (tupleTy && tupleTy->getNumElements() == 0)
63036303
break;
63046304
}
@@ -7127,7 +7127,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
71277127

71287128
auto escapable = new (tc.Context)
71297129
OpaqueValueExpr(apply->getFn()->getLoc(), Type());
7130-
cs.setType(escapable, escapableParams[0].getType());
7130+
cs.setType(escapable, escapableParams[0].getOldType());
71317131

71327132
auto getType = [&](const Expr *E) -> Type {
71337133
return cs.getType(E);

0 commit comments

Comments
 (0)