Skip to content

Commit eb57e20

Browse files
authored
Merge pull request #17691 from rudkx/remove-swift-3-in-expr-typechecking
Remove support for -swift-version 3 from the expression type checker.
2 parents 51f8c93 + a5a1a63 commit eb57e20

File tree

12 files changed

+29
-270
lines changed

12 files changed

+29
-270
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,6 @@ ERROR(err_noescape_param_call,none,
294294
"parameter %0 to a call to a non-escaping function parameter can allow "
295295
"re-entrant modification of a variable",
296296
(DeclName, unsigned))
297-
WARNING(warn_noescape_param_call,none,
298-
"passing a %select{|closure which captures a }1non-escaping function "
299-
"parameter %0 to a call to a non-escaping function parameter can allow "
300-
"re-entrant modification of a variable and will be illegal in Swift 4",
301-
(DeclName, unsigned))
302-
303297
ERROR(cannot_call_function_value,none,
304298
"cannot invoke value of function type with argument list '%0'",
305299
(StringRef))
@@ -924,10 +918,6 @@ ERROR(missing_unwrap_optional_try,none,
924918
ERROR(missing_forced_downcast,none,
925919
"%0 is not convertible to %1; "
926920
"did you mean to use 'as!' to force downcast?", (Type, Type))
927-
WARNING(missing_forced_downcast_swift3_compat_warning,none,
928-
"bridging %0 to %1 may fail at runtime and will become a checked "
929-
"cast in Swift 4; did you mean to use 'as!' to force downcast?",
930-
(Type, Type))
931921
ERROR(missing_explicit_conversion,none,
932922
"%0 is not implicitly convertible to %1; "
933923
"did you mean to use 'as' to explicitly convert?", (Type, Type))
@@ -2866,18 +2856,11 @@ WARNING(store_in_willset,none,
28662856
"attempting to store to property %0 within its own willSet, which is "
28672857
"about to be overwritten by the new value", (Identifier))
28682858

2869-
ERROR(tuple_splat_use,none,
2870-
"passing %0 arguments to a callee as a single tuple value has been removed in Swift 3",
2871-
(unsigned))
2872-
2873-
28742859
ERROR(value_of_module_type,none,
28752860
"expected module member name after module name", ())
28762861

28772862
ERROR(value_of_metatype_type,none,
28782863
"expected member name or constructor call after type name", ())
2879-
WARNING(warn_value_of_metatype_missing_self,none,
2880-
"missing '.self' for reference to metatype of type %0", (Type))
28812864

28822865
NOTE(add_parens_to_type,none,
28832866
"add arguments after the type to construct a value of the type", ())

include/swift/AST/Expr.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -93,15 +93,8 @@ enum class CheckedCastKind : unsigned {
9393
SetDowncast,
9494
/// A bridging conversion that always succeeds.
9595
BridgingCoercion,
96-
/// A bridging conversion that may fail, because there are multiple Swift
97-
/// value types that bridge to the same Cocoa object type.
98-
///
99-
/// This kind is only used for Swift 3 compatibility diagnostics and is
100-
/// treated the same as 'BridgingCoercion' otherwise. In Swift 4 or later,
101-
/// any conversions with this kind show up as ValueCasts.
102-
Swift3BridgingDowncast,
10396

104-
Last_CheckedCastKind = Swift3BridgingDowncast,
97+
Last_CheckedCastKind = BridgingCoercion,
10598
};
10699

107100
/// What are the high-level semantics of this access?

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -4009,8 +4009,6 @@ StringRef swift::getCheckedCastKindName(CheckedCastKind kind) {
40094009
return "set_downcast";
40104010
case CheckedCastKind::BridgingCoercion:
40114011
return "bridging_coercion";
4012-
case CheckedCastKind::Swift3BridgingDowncast:
4013-
return "bridging_downcast";
40144012
}
40154013
llvm_unreachable("bad checked cast name");
40164014
}

lib/SILOptimizer/FunctionSignatureTransforms/FunctionSignatureOpts.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ FunctionSignatureTransformDescriptor::createOptimizedSILFunctionName() {
185185
Mangler.setReturnValueOwnedToUnowned();
186186
}
187187

188-
SILModule &M = F->getModule();
189188
auto MangledName = Mangler.mangle();
190-
assert(!M.hasFunction(MangledName));
189+
assert(!F->getModule().hasFunction(MangledName));
191190

192191
return MangledName;
193192
}

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,6 @@ namespace {
32993299
}
33003300
expr->setCastKind(castKind);
33013301
break;
3302-
case CheckedCastKind::Swift3BridgingDowncast:
33033302
case CheckedCastKind::ArrayDowncast:
33043303
case CheckedCastKind::DictionaryDowncast:
33053304
case CheckedCastKind::SetDowncast:
@@ -3658,19 +3657,6 @@ namespace {
36583657
Expr *sub = handleOptionalBindings(expr->getSubExpr(), toType,
36593658
OptionalBindingsCastKind::Bridged,
36603659
[&](Expr *sub, Type toInstanceType) {
3661-
// Warn about NSNumber and NSValue bridging coercions we accepted in
3662-
// Swift 3 but which can fail at runtime.
3663-
if (tc.Context.LangOpts.isSwiftVersion3()
3664-
&& tc.typeCheckCheckedCast(cs.getType(sub), toInstanceType,
3665-
CheckedCastContextKind::None,
3666-
dc, SourceLoc(), sub, SourceRange())
3667-
== CheckedCastKind::Swift3BridgingDowncast) {
3668-
tc.diagnose(expr->getLoc(),
3669-
diag::missing_forced_downcast_swift3_compat_warning,
3670-
cs.getType(sub), toInstanceType)
3671-
.fixItReplace(expr->getAsLoc(), "as!");
3672-
}
3673-
36743660
return buildObjCBridgeExpr(sub, toInstanceType, locator);
36753661
});
36763662

@@ -3736,7 +3722,6 @@ namespace {
37363722
}
37373723

37383724
// Valid casts.
3739-
case CheckedCastKind::Swift3BridgingDowncast:
37403725
case CheckedCastKind::ArrayDowncast:
37413726
case CheckedCastKind::DictionaryDowncast:
37423727
case CheckedCastKind::SetDowncast:
@@ -3823,7 +3808,6 @@ namespace {
38233808
}
38243809

38253810
// Valid casts.
3826-
case CheckedCastKind::Swift3BridgingDowncast:
38273811
case CheckedCastKind::ArrayDowncast:
38283812
case CheckedCastKind::DictionaryDowncast:
38293813
case CheckedCastKind::SetDowncast:
@@ -5703,34 +5687,6 @@ Expr *ExprRewriter::coerceCallArguments(
57035687
return param.getType()->hasUnresolvedType();
57045688
});
57055689

5706-
// If you value your sanity, ignore the body of this 'if' statement.
5707-
if (cs.getASTContext().isSwiftVersion3() && params.size() == 1) {
5708-
const auto &param = params.front();
5709-
auto paramType = param.getType();
5710-
5711-
// Total hack: In Swift 3 mode, we can end up with an arity mismatch due to
5712-
// loss of ParenType sugar.
5713-
if (isa<TupleExpr>(arg)) {
5714-
auto *tupleType = paramType->getAs<TupleType>();
5715-
if (!param.hasLabel() && !param.isVariadic() && tupleType) {
5716-
// Rebuild the function type.
5717-
funcType = FunctionType::get(tupleType, funcType->getResult(),
5718-
funcType->getExtInfo());
5719-
params = funcType->getParams();
5720-
}
5721-
}
5722-
5723-
// Total hack: In Swift 3 mode, argument labels are ignored when calling
5724-
// function type with a single Any parameter.
5725-
if (params.size() == 1 && params.front().getType()->isAny()) {
5726-
auto argType = cs.getType(arg);
5727-
if (auto *tupleArgType = dyn_cast<TupleType>(argType.getPointer())) {
5728-
if (tupleArgType->getNumElements() == 1)
5729-
matchCanFail = true;
5730-
}
5731-
}
5732-
}
5733-
57345690
auto paramType = AnyFunctionType::composeInput(tc.Context, params, false);
57355691
bool allParamsMatch = cs.getType(arg)->isEqual(paramType);
57365692

@@ -5781,6 +5737,7 @@ Expr *ExprRewriter::coerceCallArguments(
57815737

57825738
assert((matchCanFail || !failed) && "Call arguments did not match up?");
57835739
(void)failed;
5740+
(void)matchCanFail;
57845741

57855742
// We should either have parentheses or a tuple.
57865743
auto *argTuple = dyn_cast<TupleExpr>(arg);
@@ -6526,8 +6483,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
65266483
if (toType->hasUnresolvedType())
65276484
break;
65286485

6529-
// HACK: Fix problem related to Swift 3 mode (with assertions),
6530-
// since Swift 3 mode allows passing arguments with extra parens
6486+
// HACK: Fix problem related to Swift 4 mode (with assertions),
6487+
// since Swift 4 mode allows passing arguments with extra parens
65316488
// to parameters which don't expect them, it should be supported
65326489
// by "deep equality" type - Optional<T> e.g.
65336490
// ```swift
@@ -6537,7 +6494,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
65376494
// ```
65386495
//
65396496
// See also: https://bugs.swift.org/browse/SR-6796
6540-
if (cs.getASTContext().isSwiftVersionAtLeast(3) &&
6497+
if (cs.getASTContext().isSwiftVersionAtLeast(4) &&
65416498
!cs.getASTContext().isSwiftVersionAtLeast(5)) {
65426499
auto obj1 = fromType->getOptionalObjectType();
65436500
auto obj2 = toType->getOptionalObjectType();
@@ -8080,24 +8037,6 @@ bool ConstraintSystem::applySolutionFix(Expr *expr,
80808037
llvm_unreachable("Coercions handled in other disjunction branch");
80818038

80828039
// Valid casts.
8083-
case CheckedCastKind::Swift3BridgingDowncast: {
8084-
// Swift 3 accepted coercions from NSNumber and NSValue to Swift
8085-
// value types, even though there are multiple Swift types that
8086-
// bridge to those classes, and the bridging operation back into Swift
8087-
// is type-checked. For compatibility, downgrade to a warning.
8088-
assert(TC.Context.LangOpts.isSwiftVersion3()
8089-
&& "should only appear in Swift 3 compat mode");
8090-
8091-
TC.diagnose(coerceExpr->getLoc(),
8092-
diag::missing_forced_downcast_swift3_compat_warning,
8093-
fromType, toType)
8094-
.highlight(coerceExpr->getSourceRange())
8095-
.fixItReplace(coerceExpr->getLoc(), "as!");
8096-
8097-
// This is just a warning, so allow the expression to type-check.
8098-
return false;
8099-
}
8100-
81018040
case CheckedCastKind::ArrayDowncast:
81028041
case CheckedCastKind::DictionaryDowncast:
81038042
case CheckedCastKind::SetDowncast:

lib/Sema/CSRanking.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -613,12 +613,10 @@ static bool isDeclAsSpecializedAs(TypeChecker &tc, DeclContext *dc,
613613

614614
// If they both have trailing closures, compare those separately.
615615
bool compareTrailingClosureParamsSeparately = false;
616-
if (!tc.getLangOpts().isSwiftVersion3()) {
617-
if (numParams1 > 0 && numParams2 > 0 &&
618-
params1.back().getType()->is<AnyFunctionType>() &&
619-
params2.back().getType()->is<AnyFunctionType>()) {
620-
compareTrailingClosureParamsSeparately = true;
621-
}
616+
if (numParams1 > 0 && numParams2 > 0 &&
617+
params1.back().getType()->is<AnyFunctionType>() &&
618+
params2.back().getType()->is<AnyFunctionType>()) {
619+
compareTrailingClosureParamsSeparately = true;
622620
}
623621

624622
auto maybeAddSubtypeConstraint =

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,8 @@ matchCallArguments(ConstraintSystem &cs, ConstraintKind kind,
664664
// Check if exactly one argument was passed to this function, otherwise
665665
// we obviously have a mismatch.
666666
if (auto tupleArgType = dyn_cast<TupleType>(argType.getPointer())) {
667-
// Total hack: In Swift 3 mode, argument labels are ignored when calling
668-
// function type with a single Any parameter.
669667
if (tupleArgType->getNumElements() != 1 ||
670-
(!cs.getASTContext().isSwiftVersion3() &&
671-
tupleArgType->getElement(0).hasName())) {
668+
tupleArgType->getElement(0).hasName()) {
672669
return cs.getTypeMatchFailure(locator);
673670
}
674671
}
@@ -704,21 +701,6 @@ matchCallArguments(ConstraintSystem &cs, ConstraintKind kind,
704701
llvm::SmallBitVector defaultMap =
705702
computeDefaultMap(params, callee, calleeLevel);
706703

707-
if (callee && cs.getASTContext().isSwiftVersion3()
708-
&& argType->is<TupleType>()) {
709-
// Hack: In Swift 3 mode, accept `foo(x, y)` for `foo((x, y))` when the
710-
// callee is a function-typed property or an enum constructor whose
711-
// argument is a single unlabeled type parameter.
712-
if (auto *prop = dyn_cast<VarDecl>(callee)) {
713-
auto *fnType = prop->getInterfaceType()->getAs<AnyFunctionType>();
714-
if (fnType && fnType->getInput()->isTypeParameter())
715-
argType = ParenType::get(cs.getASTContext(), argType);
716-
} else if (auto *enumCtor = dyn_cast<EnumElementDecl>(callee)) {
717-
if (enumCtor->getArgumentInterfaceType()->isTypeParameter())
718-
argType = ParenType::get(cs.getASTContext(), argType);
719-
}
720-
}
721-
722704
// Extract the arguments.
723705
auto args = decomposeArgType(argType, argLabels);
724706

@@ -1154,7 +1136,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
11541136
// arity).
11551137
auto func1Input = func1->getInput();
11561138
auto func2Input = func2->getInput();
1157-
if (!getASTContext().isSwiftVersion3()) {
1139+
{
11581140
SmallVector<LocatorPathElt, 4> path;
11591141
locator.getLocatorParts(path);
11601142

@@ -1573,13 +1555,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
15731555
// types of two function types, we have to be careful to preserve
15741556
// ParenType sugar.
15751557
bool isArgumentTupleMatch = isArgumentTupleConversion;
1576-
bool isSwiftVersion3 = getASTContext().isSwiftVersion3();
15771558

1578-
// ... but not in Swift 3 mode, where this behavior was broken.
1579-
if (!isSwiftVersion3)
1580-
if (auto elt = locator.last())
1581-
if (elt->getKind() == ConstraintLocator::FunctionArgument)
1582-
isArgumentTupleMatch = true;
1559+
if (auto elt = locator.last())
1560+
if (elt->getKind() == ConstraintLocator::FunctionArgument)
1561+
isArgumentTupleMatch = true;
15831562

15841563
// If we have type variables that have been bound to fixed types, look through
15851564
// to the fixed type.
@@ -1591,8 +1570,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
15911570
auto desugar1 = type1->getDesugaredType();
15921571
auto desugar2 = type2->getDesugaredType();
15931572
TypeVariableType *typeVar1, *typeVar2;
1594-
if (isArgumentTupleMatch &&
1595-
!isSwiftVersion3) {
1573+
if (isArgumentTupleMatch) {
15961574
typeVar1 = dyn_cast<TypeVariableType>(type1.getPointer());
15971575
typeVar2 = dyn_cast<TypeVariableType>(type2.getPointer());
15981576

@@ -1777,8 +1755,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
17771755
return formUnsolvedResult();
17781756
}
17791757

1780-
if (isArgumentTupleMatch &&
1781-
!isSwiftVersion3) {
1758+
if (isArgumentTupleMatch) {
17821759
if (!typeVar1 && !typeVar2) {
17831760
if (type1->hasParenSugar() != type2->hasParenSugar()) {
17841761
return getTypeMatchFailure(locator);
@@ -2853,7 +2830,6 @@ ConstraintSystem::simplifyCheckedCastConstraint(
28532830

28542831
case CheckedCastKind::Coercion:
28552832
case CheckedCastKind::BridgingCoercion:
2856-
case CheckedCastKind::Swift3BridgingDowncast:
28572833
case CheckedCastKind::Unresolved:
28582834
llvm_unreachable("Not a valid result");
28592835
}
@@ -3750,10 +3726,7 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
37503726
// Bridging NSNumber to NSValue is one-way, since there are multiple Swift
37513727
// value types that bridge to those object types. It requires a checked
37523728
// cast to get back.
3753-
// We accepted these coercions in Swift 3 mode, so we have to live with
3754-
// them (but give a warning) in that language mode.
3755-
if (!TC.Context.LangOpts.isSwiftVersion3()
3756-
&& TC.Context.isObjCClassWithMultipleSwiftBridgedTypes(objcClass))
3729+
if (TC.Context.isObjCClassWithMultipleSwiftBridgedTypes(objcClass))
37573730
return SolutionKind::Error;
37583731

37593732
// If the bridged value type is generic, the generic arguments

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,10 +893,8 @@ static unsigned getNumRemovedArgumentLabels(TypeChecker &TC, ValueDecl *decl,
893893
// bar.map(E.foo)
894894
//
895895
// `E.foo` has to act as a regular function type passed as a value.
896-
if (!TC.getLangOpts().isSwiftVersion3()) {
897-
if (auto *EED = dyn_cast<EnumElementDecl>(decl)) {
898-
numParameterLists = EED->hasAssociatedValues() ? 2 : 1;
899-
}
896+
if (auto *EED = dyn_cast<EnumElementDecl>(decl)) {
897+
numParameterLists = EED->hasAssociatedValues() ? 2 : 1;
900898
}
901899

902900
// Only applicable to functions. Nothing else should have argument labels in

0 commit comments

Comments
 (0)