Skip to content

Commit 30a7ac7

Browse files
authored
Merge pull request #38925 from DougGregor/se-0286-swift-6
[SE-0286] Disable backward scanning for trailing closures in Swift 6 mode
2 parents 1007cc9 + 965e5bf commit 30a7ac7

File tree

10 files changed

+20
-39
lines changed

10 files changed

+20
-39
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,6 @@ namespace swift {
333333
/// behavior. This is a staging flag, and will be removed in the future.
334334
bool EnableNewOperatorLookup = false;
335335

336-
/// Whether to enable the "fuzzy" forward-scanning behavior for trailing
337-
/// closure matching, which skips over defaulted closure parameters
338-
/// to match later (non-defaulted) closure parameters
339-
///
340-
/// This is a backward-compatibility hack for unlabeled trailing closures,
341-
/// to be disabled in Swift 6+.
342-
bool EnableFuzzyForwardScanTrailingClosureMatching = true;
343-
344336
/// Use Clang function types for computing canonical types.
345337
/// If this option is false, the clang function types will still be computed
346338
/// but will not be used for checking type equality.

include/swift/Option/Options.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,16 +580,6 @@ def enable_experimental_concise_pound_file : Flag<["-"],
580580
Flags<[FrontendOption, ModuleInterfaceOption]>,
581581
HelpText<"Enable experimental concise '#file' identifier">;
582582

583-
def disable_fuzzy_forward_scan_trailing_closure_matching : Flag<["-"],
584-
"disable-fuzzy-forward-scan-trailing-closure-matching">,
585-
Flags<[FrontendOption]>,
586-
HelpText<"Disable fuzzy forward-scan trailing closure matching">;
587-
588-
def enable_fuzzy_forward_scan_trailing_closure_matching : Flag<["-"],
589-
"enable-fuzzy-forward-scan-trailing-closure-matching">,
590-
Flags<[FrontendOption]>,
591-
HelpText<"Enable fuzzy forward-scan trailing closure matching">;
592-
593583
def enable_experimental_cxx_interop :
594584
Flag<["-"], "enable-experimental-cxx-interop">,
595585
HelpText<"Allow importing C++ modules into Swift (experimental feature)">;

lib/Driver/ToolChains.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,6 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
282282
inputArgs.AddLastArg(arguments, options::OPT_diagnostic_style);
283283
inputArgs.AddLastArg(arguments,
284284
options::OPT_enable_experimental_concise_pound_file);
285-
inputArgs.AddLastArg(
286-
arguments,
287-
options::OPT_enable_fuzzy_forward_scan_trailing_closure_matching,
288-
options::OPT_disable_fuzzy_forward_scan_trailing_closure_matching);
289285
inputArgs.AddLastArg(arguments,
290286
options::OPT_verify_incremental_dependencies);
291287
inputArgs.AddLastArg(arguments, options::OPT_access_notes_path);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
659659
Opts.EnableConcisePoundFile =
660660
Args.hasArg(OPT_enable_experimental_concise_pound_file) ||
661661
Opts.EffectiveLanguageVersion.isVersionAtLeast(6);
662-
Opts.EnableFuzzyForwardScanTrailingClosureMatching =
663-
Args.hasFlag(OPT_enable_fuzzy_forward_scan_trailing_closure_matching,
664-
OPT_disable_fuzzy_forward_scan_trailing_closure_matching,
665-
true);
666662

667663
Opts.EnableCrossImportOverlays =
668664
Args.hasFlag(OPT_enable_cross_import_overlays,

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,11 @@ static bool matchCallArgumentsImpl(
446446
}
447447

448448
// If this parameter does not require an argument, consider applying a
449-
// "fuzzy" match rule that skips this parameter if doing so is the only
449+
// backward-match rule that skips this parameter if doing so is the only
450450
// way to successfully match arguments to parameters.
451451
if (!parameterRequiresArgument(params, paramInfo, paramIdx) &&
452-
param.getPlainType()->getASTContext().LangOpts
453-
.EnableFuzzyForwardScanTrailingClosureMatching &&
452+
!param.getPlainType()->getASTContext().LangOpts
453+
.isSwiftVersionAtLeast(6) &&
454454
anyParameterRequiresArgument(
455455
params, paramInfo, paramIdx + 1,
456456
nextArgIdx + 1 < numArgs
@@ -900,9 +900,9 @@ static bool requiresBothTrailingClosureDirections(
900900
if (params.empty())
901901
return false;
902902

903-
// If "fuzzy" matching is disabled, only scan forward.
903+
// If backward matching is disabled, only scan forward.
904904
ASTContext &ctx = params.front().getPlainType()->getASTContext();
905-
if (!ctx.LangOpts.EnableFuzzyForwardScanTrailingClosureMatching)
905+
if (ctx.LangOpts.isSwiftVersionAtLeast(6))
906906
return false;
907907

908908
// If there are at least two parameters that meet the backward scan's

test/Concurrency/actor_definite_init_swift6.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ struct CardboardBox<T> {
330330

331331

332332
@available(SwiftStdlib 5.5, *)
333-
var globalVar: EscapeArtist?
333+
var globalVar: EscapeArtist? // expected-note 2 {{var declared here}}
334334

335335
@available(SwiftStdlib 5.5, *)
336336
actor EscapeArtist {
@@ -340,7 +340,9 @@ actor EscapeArtist {
340340
self.x = 0
341341

342342
globalVar = self // expected-error {{this use of actor 'self' can only appear in an async initializer}}
343+
// expected-warning@-1{{reference to var 'globalVar' is not concurrency-safe because it involves shared mutable state}}
343344
Task { await globalVar!.isolatedMethod() }
345+
// expected-warning@-1{{reference to var 'globalVar' is not concurrency-safe because it involves shared mutable state}}
344346

345347
if self.x == 0 {
346348
fatalError("race detected.")

test/Concurrency/actor_keypath_isolation_swift6.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-concurrency -swift-version 6
22
// REQUIRES: concurrency && asserts
33

4-
class Box {
4+
class Box { // expected-note 3{{class 'Box' does not conform to the `Sendable` protocol}}
55
let size : Int = 0
66
}
77

test/decl/protocol/special/Sendable_swift6.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
func acceptSendable<T: Sendable>(_: T) { }
66

7-
class NotSendable { }
7+
class NotSendable { } // expected-note 2{{class 'NotSendable' does not conform to the `Sendable` protocol}}
88

99
func testSendableBuiltinConformances(
1010
i: Int, ns: NotSendable, sf: @escaping @Sendable () -> Void,
@@ -23,8 +23,11 @@ func testSendableBuiltinConformances(
2323

2424
// Complaints about missing Sendable conformances
2525
acceptSendable((i, ns)) // expected-error{{type 'NotSendable' does not conform to the 'Sendable' protocol}}
26-
acceptSendable(nsf) // expected-error{{function type '() -> Void' must be marked '@Sendable' to conform to 'Sendable'}}
27-
acceptSendable((nsf, i)) // expected-error{{function type '() -> Void' must be marked '@Sendable' to conform to 'Sendable'}}
28-
acceptSendable(funNotSendable) // expected-error{{function type '() -> Void' must be marked '@Sendable' to conform to 'Sendable'}}
26+
acceptSendable(nsf) // expected-error{{type '() -> Void' does not conform to the 'Sendable' protocol}}
27+
// expected-note@-1{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
28+
acceptSendable((nsf, i)) // expected-error{{type '() -> Void' does not conform to the 'Sendable' protocol}}
29+
// expected-note@-1{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
30+
acceptSendable(funNotSendable) // expected-error{{type '() -> Void' does not conform to the 'Sendable' protocol}}
31+
// expected-note@-1{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
2932
acceptSendable((i, ns)) // expected-error{{type 'NotSendable' does not conform to the 'Sendable' protocol}}
3033
}

test/expr/postfix/call/forward_trailing_closure.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-typecheck-verify-swift -disable-fuzzy-forward-scan-trailing-closure-matching
1+
// RUN: %target-typecheck-verify-swift -swift-version 6
2+
// REQUIRES: asserts
23

34
func forwardMatch1(
45
a: Int = 0, b: Int = 17, closure1: (Int) -> Int = { $0 }, c: Int = 42,

test/expr/postfix/call/forward_trailing_closure_errors.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-typecheck-verify-swift -disable-fuzzy-forward-scan-trailing-closure-matching
1+
// RUN: %target-typecheck-verify-swift -swift-version 6
2+
// REQUIRES: asserts
23

34
func forwardMatchWithGeneric<T>( // expected-note{{'forwardMatchWithGeneric(closure1:closure2:)' declared here}}
45
closure1: T,

0 commit comments

Comments
 (0)