Skip to content

Commit 2e17f40

Browse files
committed
Sema: Hide SE-0110 behind it's own command line flag instead of Swift 4 mode
1 parent cdab4de commit 2e17f40

File tree

8 files changed

+29
-33
lines changed

8 files changed

+29
-33
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ namespace swift {
181181
/// \brief Enable experimental property behavior feature.
182182
bool EnableExperimentalPropertyBehaviors = false;
183183

184+
/// \brief Enable SE-0110.
185+
bool EnableExperimentalSE0110 = false;
186+
184187
/// \brief Staging flag for treating inout parameters as Thread Sanitizer
185188
/// accesses.
186189
bool DisableTsanInoutInstrumentation = false;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ def enable_sil_opaque_values : Flag<["-"], "enable-sil-opaque-values">,
268268
def enable_large_loadable_types : Flag<["-"], "enable-large-loadable-types">,
269269
HelpText<"Enable Large Loadable types IRGen pass">;
270270

271+
def enable_experimental_se_0110 :
272+
Flag<["-"], "enable-experimental-se-0110">,
273+
HelpText<"Enable experimental SE-0110 implementation">;
274+
271275
def enable_experimental_property_behaviors :
272276
Flag<["-"], "enable-experimental-property-behaviors">,
273277
HelpText<"Enable experimental property behaviors">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
940940
Opts.EnableExperimentalKeyPathComponents |=
941941
Args.hasArg(OPT_enable_experimental_keypath_components);
942942

943+
Opts.EnableExperimentalSE0110 |=
944+
Args.hasArg(OPT_enable_experimental_se_0110);
945+
943946
Opts.EnableClassResilience |=
944947
Args.hasArg(OPT_enable_class_resilience);
945948

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5204,14 +5204,16 @@ Expr *ExprRewriter::coerceCallArguments(
52045204
matchCanFail = true;
52055205

52065206
// If you value your sanity, ignore the body of this 'if' statement.
5207-
if (cs.getASTContext().isSwiftVersion3()) {
5207+
if (!cs.getASTContext().LangOpts.EnableExperimentalSE0110) {
52085208
// Total hack: In Swift 3 mode, we can end up with an arity mismatch due to
52095209
// loss of ParenType sugar.
52105210
if (isa<TupleExpr>(arg))
52115211
if (auto *parenType = dyn_cast<ParenType>(paramType.getPointer()))
52125212
if (isa<TupleType>(parenType->getUnderlyingType().getPointer()))
52135213
paramType = parenType->getUnderlyingType();
5214+
}
52145215

5216+
if (cs.getASTContext().isSwiftVersion3()) {
52155217
// Total hack: In Swift 3 mode, argument labels are ignored when calling
52165218
// function type with a single Any parameter.
52175219
if (paramType->isAny()) {

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,9 @@ matchCallArguments(ConstraintSystem &cs, ConstraintKind kind,
656656
getCalleeDeclAndArgs(cs, locator, argLabelsScratch);
657657
auto params = decomposeParamType(paramType, callee, calleeLevel);
658658

659-
if (callee && cs.getASTContext().isSwiftVersion3()
660-
&& argType->is<TupleType>()) {
659+
if (callee &&
660+
!cs.getASTContext().LangOpts.EnableExperimentalSE0110 &&
661+
argType->is<TupleType>()) {
661662
// Hack: In Swift 3 mode, accept `foo(x, y)` for `foo((x, y))` when the
662663
// callee is a function-typed property or an enum constructor whose
663664
// argument is a single unlabeled type parameter.
@@ -1331,10 +1332,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
13311332
// types of two function types, we have to be careful to preserve
13321333
// ParenType sugar.
13331334
bool isArgumentTupleMatch = isArgumentTupleConversion;
1334-
bool isSwiftVersion3 = getASTContext().isSwiftVersion3();
1335+
bool isSE0110Enabled = getASTContext().LangOpts.EnableExperimentalSE0110;
13351336

1336-
// ... but not in Swift 3 mode, where this behavior was broken.
1337-
if (!isSwiftVersion3)
1337+
if (isSE0110Enabled)
13381338
if (auto elt = locator.last())
13391339
if (elt->getKind() == ConstraintLocator::FunctionArgument)
13401340
isArgumentTupleMatch = true;
@@ -1350,7 +1350,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
13501350
auto desugar2 = type2->getDesugaredType();
13511351
TypeVariableType *typeVar1, *typeVar2;
13521352
if (isArgumentTupleMatch &&
1353-
!isSwiftVersion3) {
1353+
isSE0110Enabled) {
13541354
typeVar1 = dyn_cast<TypeVariableType>(type1.getPointer());
13551355
typeVar2 = dyn_cast<TypeVariableType>(type2.getPointer());
13561356

@@ -1631,7 +1631,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
16311631
}
16321632

16331633
if (isArgumentTupleMatch &&
1634-
!isSwiftVersion3) {
1634+
isSE0110Enabled) {
16351635
if (!typeVar1 && !typeVar2) {
16361636
if (isa<ParenType>(type1.getPointer()) !=
16371637
isa<ParenType>(type2.getPointer())) {

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
253253
// Note that in Swift 4 mode, this is rejected much earlier in
254254
// the constraint solver; this check only exists to preserve the
255255
// behavior of the earlier, incomplete implementation of SE-0110.
256-
if (TC.Context.isSwiftVersion3())
256+
if (!TC.Context.LangOpts.EnableExperimentalSE0110)
257257
checkTupleSplat(Call);
258258

259259
// Check the callee, looking through implicit conversions.

test/Compatibility/tuple_arguments.swift

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// RUN: %target-typecheck-verify-swift -swift-version 3
2+
// RUN: %target-typecheck-verify-swift -swift-version 4
23

3-
// Tests for tuple argument behavior in Swift 3, which was broken.
4-
// The Swift 4 test is in test/Constraints/tuple_arguments.swift.
4+
// Tests for tuple argument behavior pre-SE0110, which was broken.
5+
// The SE-0110 test is in test/Constraints/tuple_arguments.swift.
6+
//
7+
// Note that SE-0110 is currently off by default, so the compatibility
8+
// test is run in both Swift 3 and 4 mode, and the new test is run with
9+
// the experimental flag enabled.
510

611
// Key:
712
// - "Crashes in actual Swift 3" -- snippets which crashed in Swift 3.0.1.
@@ -1386,27 +1391,6 @@ do {
13861391
let _: (Int, Int) -> () = { t, u in _ = (t, u) }
13871392
}
13881393

1389-
// rdar://problem/28952837 - argument labels ignored when calling function
1390-
// with single 'Any' parameter
1391-
func takesAny(_: Any) {}
1392-
1393-
enum HasAnyCase {
1394-
case any(_: Any)
1395-
}
1396-
1397-
do {
1398-
let fn: (Any) -> () = { _ in }
1399-
1400-
fn(123)
1401-
fn(data: 123)
1402-
1403-
takesAny(123)
1404-
takesAny(data: 123)
1405-
1406-
_ = HasAnyCase.any(123)
1407-
_ = HasAnyCase.any(data: 123)
1408-
}
1409-
14101394
// rdar://problem/29739905 - protocol extension methods on Array had
14111395
// ParenType sugar stripped off the element type
14121396
typealias BoolPair = (Bool, Bool)

test/Constraints/tuple_arguments.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 4
1+
// RUN: %target-typecheck-verify-swift -swift-version 4 -enable-experimental-se-0110
22

33
// See test/Compatibility/tuple_arguments.swift for the Swift 3 behavior.
44

0 commit comments

Comments
 (0)