-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Remove support for -swift-version 3 from the expression type checker. #17691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
28f759c
aa30cc5
efb1738
a5a1a63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3299,7 +3299,6 @@ namespace { | |
} | ||
expr->setCastKind(castKind); | ||
break; | ||
case CheckedCastKind::Swift3BridgingDowncast: | ||
case CheckedCastKind::ArrayDowncast: | ||
case CheckedCastKind::DictionaryDowncast: | ||
case CheckedCastKind::SetDowncast: | ||
|
@@ -3658,19 +3657,6 @@ namespace { | |
Expr *sub = handleOptionalBindings(expr->getSubExpr(), toType, | ||
OptionalBindingsCastKind::Bridged, | ||
[&](Expr *sub, Type toInstanceType) { | ||
// Warn about NSNumber and NSValue bridging coercions we accepted in | ||
// Swift 3 but which can fail at runtime. | ||
if (tc.Context.LangOpts.isSwiftVersion3() | ||
&& tc.typeCheckCheckedCast(cs.getType(sub), toInstanceType, | ||
CheckedCastContextKind::None, | ||
dc, SourceLoc(), sub, SourceRange()) | ||
== CheckedCastKind::Swift3BridgingDowncast) { | ||
tc.diagnose(expr->getLoc(), | ||
diag::missing_forced_downcast_swift3_compat_warning, | ||
cs.getType(sub), toInstanceType) | ||
.fixItReplace(expr->getAsLoc(), "as!"); | ||
} | ||
|
||
return buildObjCBridgeExpr(sub, toInstanceType, locator); | ||
}); | ||
|
||
|
@@ -3736,7 +3722,6 @@ namespace { | |
} | ||
|
||
// Valid casts. | ||
case CheckedCastKind::Swift3BridgingDowncast: | ||
case CheckedCastKind::ArrayDowncast: | ||
case CheckedCastKind::DictionaryDowncast: | ||
case CheckedCastKind::SetDowncast: | ||
|
@@ -3823,7 +3808,6 @@ namespace { | |
} | ||
|
||
// Valid casts. | ||
case CheckedCastKind::Swift3BridgingDowncast: | ||
case CheckedCastKind::ArrayDowncast: | ||
case CheckedCastKind::DictionaryDowncast: | ||
case CheckedCastKind::SetDowncast: | ||
|
@@ -5703,34 +5687,6 @@ Expr *ExprRewriter::coerceCallArguments( | |
return param.getType()->hasUnresolvedType(); | ||
}); | ||
|
||
// If you value your sanity, ignore the body of this 'if' statement. | ||
if (cs.getASTContext().isSwiftVersion3() && params.size() == 1) { | ||
const auto ¶m = params.front(); | ||
auto paramType = param.getType(); | ||
|
||
// Total hack: In Swift 3 mode, we can end up with an arity mismatch due to | ||
// loss of ParenType sugar. | ||
if (isa<TupleExpr>(arg)) { | ||
auto *tupleType = paramType->getAs<TupleType>(); | ||
if (!param.hasLabel() && !param.isVariadic() && tupleType) { | ||
// Rebuild the function type. | ||
funcType = FunctionType::get(tupleType, funcType->getResult(), | ||
funcType->getExtInfo()); | ||
params = funcType->getParams(); | ||
} | ||
} | ||
|
||
// Total hack: In Swift 3 mode, argument labels are ignored when calling | ||
// function type with a single Any parameter. | ||
if (params.size() == 1 && params.front().getType()->isAny()) { | ||
auto argType = cs.getType(arg); | ||
if (auto *tupleArgType = dyn_cast<TupleType>(argType.getPointer())) { | ||
if (tupleArgType->getNumElements() == 1) | ||
matchCanFail = true; | ||
} | ||
} | ||
} | ||
|
||
auto paramType = AnyFunctionType::composeInput(tc.Context, params, false); | ||
bool allParamsMatch = cs.getType(arg)->isEqual(paramType); | ||
|
||
|
@@ -5781,6 +5737,7 @@ Expr *ExprRewriter::coerceCallArguments( | |
|
||
assert((matchCanFail || !failed) && "Call arguments did not match up?"); | ||
(void)failed; | ||
(void)matchCanFail; | ||
|
||
// We should either have parentheses or a tuple. | ||
auto *argTuple = dyn_cast<TupleExpr>(arg); | ||
|
@@ -6526,8 +6483,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType, | |
if (toType->hasUnresolvedType()) | ||
break; | ||
|
||
// HACK: Fix problem related to Swift 3 mode (with assertions), | ||
// since Swift 3 mode allows passing arguments with extra parens | ||
// HACK: Fix problem related to Swift 4 mode (with assertions), | ||
// since Swift 4 mode allows passing arguments with extra parens | ||
// to parameters which don't expect them, it should be supported | ||
// by "deep equality" type - Optional<T> e.g. | ||
// ```swift | ||
|
@@ -6537,7 +6494,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType, | |
// ``` | ||
// | ||
// See also: https://bugs.swift.org/browse/SR-6796 | ||
if (cs.getASTContext().isSwiftVersionAtLeast(3) && | ||
if (cs.getASTContext().isSwiftVersionAtLeast(4) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn’t the first part always true? It should suffice to just check if you’re < 5 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was intentional. If there are tests passing -swift-version 3 explicitly they should break if they are relying on this behavior. You might have removed all of those with your PR, though. |
||
!cs.getASTContext().isSwiftVersionAtLeast(5)) { | ||
auto obj1 = fromType->getOptionalObjectType(); | ||
auto obj2 = toType->getOptionalObjectType(); | ||
|
@@ -8067,24 +8024,6 @@ bool ConstraintSystem::applySolutionFix(Expr *expr, | |
llvm_unreachable("Coercions handled in other disjunction branch"); | ||
|
||
// Valid casts. | ||
case CheckedCastKind::Swift3BridgingDowncast: { | ||
// Swift 3 accepted coercions from NSNumber and NSValue to Swift | ||
// value types, even though there are multiple Swift types that | ||
// bridge to those classes, and the bridging operation back into Swift | ||
// is type-checked. For compatibility, downgrade to a warning. | ||
assert(TC.Context.LangOpts.isSwiftVersion3() | ||
&& "should only appear in Swift 3 compat mode"); | ||
|
||
TC.diagnose(coerceExpr->getLoc(), | ||
diag::missing_forced_downcast_swift3_compat_warning, | ||
fromType, toType) | ||
.highlight(coerceExpr->getSourceRange()) | ||
.fixItReplace(coerceExpr->getLoc(), "as!"); | ||
|
||
// This is just a warning, so allow the expression to type-check. | ||
return false; | ||
} | ||
|
||
case CheckedCastKind::ArrayDowncast: | ||
case CheckedCastKind::DictionaryDowncast: | ||
case CheckedCastKind::SetDowncast: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "missing_forced_downcast_swift3_compat_warning"