Skip to content

Commit dffa29f

Browse files
committed
AST: Remove a few uses of FunctionType::Param::getOldType()
1 parent 12fa026 commit dffa29f

13 files changed

+65
-36
lines changed

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,13 +1034,17 @@ FuncDecl *ASTContext::getEqualIntDecl() const {
10341034
return nullptr;
10351035

10361036
auto intType = getIntDecl()->getDeclaredType();
1037+
auto isIntParam = [&](AnyFunctionType::Param param) {
1038+
return (!param.isVariadic() && !param.isInOut() &&
1039+
param.getPlainType()->isEqual(intType));
1040+
};
10371041
auto boolType = getBoolDecl()->getDeclaredType();
10381042
auto decl = lookupOperatorFunc(*this, "==",
10391043
intType, [=](FunctionType *type) {
10401044
// Check for the signature: (Int, Int) -> Bool
10411045
if (type->getParams().size() != 2) return false;
1042-
if (!type->getParams()[0].getOldType()->isEqual(intType) ||
1043-
!type->getParams()[1].getOldType()->isEqual(intType)) return false;
1046+
if (!isIntParam(type->getParams()[0]) ||
1047+
!isIntParam(type->getParams()[1])) return false;
10441048
return type->getResult()->isEqual(boolType);
10451049
});
10461050
getImpl().EqualIntDecl = decl;
@@ -1227,8 +1231,9 @@ FuncDecl *ASTContext::getIsOSVersionAtLeastDecl() const {
12271231
if (intrinsicsParams.size() != 3)
12281232
return nullptr;
12291233

1230-
if (llvm::any_of(intrinsicsParams, [](const AnyFunctionType::Param &p) {
1231-
return !isBuiltinWordType(p.getOldType());
1234+
if (llvm::any_of(intrinsicsParams, [](AnyFunctionType::Param param) {
1235+
return (param.isVariadic() || param.isInOut() ||
1236+
!isBuiltinWordType(param.getPlainType()));
12321237
})) {
12331238
return nullptr;
12341239
}

lib/AST/Decl.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,8 +4127,15 @@ findProtocolSelfReferences(const ProtocolDecl *proto, Type type,
41274127
// the parameter type.
41284128
if (auto funcTy = type->getAs<AnyFunctionType>()) {
41294129
auto inputKind = SelfReferenceKind::None();
4130-
for (auto &elt : funcTy->getParams()) {
4131-
inputKind |= findProtocolSelfReferences(proto, elt.getOldType(),
4130+
for (auto param : funcTy->getParams()) {
4131+
// inout parameters are invariant.
4132+
if (param.isInOut()) {
4133+
if (findProtocolSelfReferences(proto, param.getPlainType(),
4134+
skipAssocTypes)) {
4135+
return SelfReferenceKind::Other();
4136+
}
4137+
}
4138+
inputKind |= findProtocolSelfReferences(proto, param.getParameterType(),
41324139
skipAssocTypes);
41334140
}
41344141
auto resultKind = findProtocolSelfReferences(proto, funcTy->getResult(),
@@ -4159,14 +4166,6 @@ findProtocolSelfReferences(const ProtocolDecl *proto, Type type,
41594166
skipAssocTypes);
41604167
}
41614168

4162-
// InOut types are invariant.
4163-
if (auto inOutType = type->getAs<InOutType>()) {
4164-
if (findProtocolSelfReferences(proto, inOutType->getObjectType(),
4165-
skipAssocTypes)) {
4166-
return SelfReferenceKind::Other();
4167-
}
4168-
}
4169-
41704169
// Bound generic types are invariant.
41714170
if (auto boundGenericType = type->getAs<BoundGenericType>()) {
41724171
for (auto paramType : boundGenericType->getGenericArgs()) {
@@ -4237,8 +4236,15 @@ ProtocolDecl::findProtocolSelfReferences(const ValueDecl *value,
42374236
// as a function result type.
42384237
if (!allowCovariantParameters) {
42394238
auto inputKind = SelfReferenceKind::None();
4240-
for (auto &elt : type->castTo<AnyFunctionType>()->getParams()) {
4241-
inputKind |= ::findProtocolSelfReferences(this, elt.getOldType(),
4239+
for (auto param : type->castTo<AnyFunctionType>()->getParams()) {
4240+
// inout parameters are invariant.
4241+
if (param.isInOut()) {
4242+
if (::findProtocolSelfReferences(this, param.getPlainType(),
4243+
skipAssocTypes)) {
4244+
return SelfReferenceKind::Other();
4245+
}
4246+
}
4247+
inputKind |= ::findProtocolSelfReferences(this, param.getParameterType(),
42424248
skipAssocTypes);
42434249
}
42444250

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ static std::pair<Type, ParamDecl *> decomposeSubscriptSetter(FuncDecl *setter) {
16541654
->castTo<AnyFunctionType>()
16551655
->getResult()
16561656
->castTo<AnyFunctionType>()
1657-
->getParams().front().getOldType();
1657+
->getParams().front().getParameterType();
16581658
ParamDecl *keyDecl = PL->get(1);
16591659

16601660
return {elementType, keyDecl};

lib/IRGen/GenProto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,7 @@ void NecessaryBindings::addTypeMetadata(CanType type) {
28492849
}
28502850
if (auto fn = dyn_cast<FunctionType>(type)) {
28512851
for (const auto &elt : fn.getParams())
2852-
addTypeMetadata(elt.getOldType());
2852+
addTypeMetadata(elt.getPlainType());
28532853
addTypeMetadata(fn.getResult());
28542854
return;
28552855
}

lib/SILGen/SILGenBridging.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,10 @@ static void expandTupleTypes(CanType type, SmallVectorImpl<CanType> &results) {
350350
static SmallVector<CanType, 8>
351351
expandTupleTypes(AnyFunctionType::CanParamArrayRef params) {
352352
SmallVector<CanType, 8> results;
353-
for (auto param : params)
354-
expandTupleTypes(param.getOldType(), results);
353+
for (auto param : params) {
354+
assert(!param.isInOut() && !param.isVariadic());
355+
expandTupleTypes(param.getPlainType(), results);
356+
}
355357
return results;
356358
}
357359

lib/SILGen/SILGenConstructor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ 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].getOldType();
38+
auto param = ctorFnType->getParams()[0];
39+
assert(!param.isVariadic() && !param.isInOut());
40+
Type metatype = param.getPlainType();
3941
auto *DC = ctor->getInnermostDeclContext();
4042
auto &AC = SGF.getASTContext();
4143
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.getOldType());
159+
std::tie(TypeDepth, TypeWidth) = getTypeDepthAndWidth(Param.getParameterType());
160160
if (TypeDepth > MaxTypeDepth)
161161
MaxTypeDepth = TypeDepth;
162162
Width += TypeWidth;

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,10 +2108,10 @@ bool isSubscriptReturningString(const ValueDecl *D, ASTContext &Context) {
21082108
return false;
21092109

21102110
const auto &param = params.front();
2111-
if (param.hasLabel() || param.isVariadic())
2111+
if (param.hasLabel() || param.isVariadic() || param.isInOut())
21122112
return false;
21132113

2114-
auto inputTy = param.getOldType()->getAs<BoundGenericStructType>();
2114+
auto inputTy = param.getPlainType()->getAs<BoundGenericStructType>();
21152115
if (!inputTy)
21162116
return false;
21172117

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class FindCapturedVars : public ASTWalker {
166166
});
167167

168168
for (const auto &param : gft->getParams())
169-
param.getOldType().walk(walker);
169+
param.getPlainType().walk(walker);
170170

171171
gft->getResult().walk(walker);
172172
}

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -825,18 +825,22 @@ bool swift::isRepresentableInObjC(const SubscriptDecl *SD, ObjCReason Reason) {
825825
if (SubscriptType->getParams().size() != 1)
826826
return false;
827827

828-
Type IndicesType = SubscriptType->getParams()[0].getOldType();
829-
if (IndicesType->hasError())
828+
auto IndexParam = SubscriptType->getParams()[0];
829+
if (IndexParam.isInOut())
830830
return false;
831831

832-
bool IndicesResult =
833-
IndicesType->isRepresentableIn(ForeignLanguage::ObjectiveC,
834-
SD->getDeclContext());
832+
Type IndexType = SubscriptType->getParams()[0].getParameterType();
833+
if (IndexType->hasError())
834+
return false;
835+
836+
bool IndexResult =
837+
IndexType->isRepresentableIn(ForeignLanguage::ObjectiveC,
838+
SD->getDeclContext());
835839

836840
Type ElementType = SD->getElementInterfaceType();
837841
bool ElementResult = ElementType->isRepresentableIn(
838842
ForeignLanguage::ObjectiveC, SD->getDeclContext());
839-
bool Result = IndicesResult && ElementResult;
843+
bool Result = IndexResult && ElementResult;
840844

841845
if (Result && checkObjCInExtensionContext(SD, Diagnose))
842846
return false;
@@ -845,7 +849,7 @@ bool swift::isRepresentableInObjC(const SubscriptDecl *SD, ObjCReason Reason) {
845849
return Result;
846850

847851
SourceRange TypeRange;
848-
if (!IndicesResult)
852+
if (!IndexResult)
849853
TypeRange = SD->getIndices()->getSourceRange();
850854
else
851855
TypeRange = SD->getElementTypeLoc().getSourceRange();
@@ -854,8 +858,8 @@ bool swift::isRepresentableInObjC(const SubscriptDecl *SD, ObjCReason Reason) {
854858
.highlight(TypeRange);
855859

856860
diagnoseTypeNotRepresentableInObjC(SD->getDeclContext(),
857-
!IndicesResult ? IndicesType
858-
: ElementType,
861+
!IndexResult ? IndexType
862+
: ElementType,
859863
TypeRange);
860864
describeObjCReason(SD, Reason);
861865

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void TypeChecker::checkReferencedGenericParams(GenericContext *dc) {
322322
ReferencedGenericTypeWalker paramsAndResultWalker;
323323
auto *funcTy = decl->getInterfaceType()->castTo<GenericFunctionType>();
324324
for (const auto &param : funcTy->getParams())
325-
param.getOldType().walk(paramsAndResultWalker);
325+
param.getPlainType().walk(paramsAndResultWalker);
326326
funcTy->getResult().walk(paramsAndResultWalker);
327327

328328
// Set of generic params referenced in parameter types,

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ bool TypeChecker::coerceParameterListToType(ParameterList *P, ClosureExpr *CE,
15871587
bool hadError = false;
15881588
for (const auto &param : FN->getParams()) {
15891589
params.push_back(param);
1590-
hadError |= param.getOldType()->hasError();
1590+
hadError |= param.getPlainType()->hasError();
15911591
}
15921592

15931593
// Local function to check if the given type is valid e.g. doesn't have

test/IRGen/partial_apply_generic.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,13 @@ let g = dietaryFad(Chicken())
9191
do {
9292
try g()
9393
} catch {}
94+
95+
//
96+
// Incorrect assertion regarding inout parameters in NecessaryBindings
97+
//
98+
99+
func coyote<T, U>(_ t: T, _ u: U) {}
100+
101+
func hawk<A, B, C>(_: A, _ b: B, _ c: C) {
102+
let fn: (Optional<(A) -> B>, @escaping (inout B, C) -> ()) -> () = coyote
103+
}

0 commit comments

Comments
 (0)