Skip to content

Commit 575514e

Browse files
committed
[Feataures] Add an upcoming feature flag for complete concurrency checking.
1 parent 7cb9880 commit 575514e

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(RetroactiveAttribute, 364, "@retroactive", true)
115115

116116
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
117117
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)
118+
UPCOMING_FEATURE(CompleteConcurrency, 0337, 6)
118119
UPCOMING_FEATURE(BareSlashRegexLiterals, 354, 6)
119120
UPCOMING_FEATURE(DeprecateApplicationMain, 383, 6)
120121
UPCOMING_FEATURE(ImportObjcForwardDeclarations, 384, 6)

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,6 +3311,10 @@ static bool usesFeatureForwardTrailingClosures(Decl *decl) {
33113311
return false;
33123312
}
33133313

3314+
static bool usesFeatureCompleteConcurrency(Decl *decl) {
3315+
return false;
3316+
}
3317+
33143318
static bool usesFeatureBareSlashRegexLiterals(Decl *decl) {
33153319
return false;
33163320
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
888888
Opts.Features.insert(*feature);
889889
}
890890

891+
// CompleteConcurrency enables all data-race safety upcoming features.
892+
if (Opts.hasFeature(Feature::CompleteConcurrency)) {
893+
Opts.StrictConcurrencyLevel = StrictConcurrency::Complete;
894+
Opts.Features.insert(Feature::DisableOutwardActorInference);
895+
}
896+
891897
// Map historical flags over to experimental features. We do this for all
892898
// compilers because that's how existing experimental feature flags work.
893899
if (Args.hasArg(OPT_enable_experimental_static_assert))
@@ -1002,7 +1008,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10021008

10031009
} else if (Args.hasArg(OPT_warn_concurrency)) {
10041010
Opts.StrictConcurrencyLevel = StrictConcurrency::Complete;
1005-
} else if (Opts.hasFeature(Feature::StrictConcurrency)) {
1011+
} else if (Opts.hasFeature(Feature::CompleteConcurrency) ||
1012+
Opts.hasFeature(Feature::StrictConcurrency)) {
10061013
// Already set above.
10071014
} else {
10081015
// Default to minimal checking in Swift 5.x.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-upcoming-feature CompleteConcurrency -emit-sil -o /dev/null -verify %s
2+
3+
// REQUIRES: concurrency
4+
5+
// expected-note@+1 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
6+
class NonSendable {}
7+
8+
@MainActor func onMain(ns: NonSendable) async {
9+
// expected-warning@+1 {{passing argument of non-sendable type 'NonSendable' outside of main actor-isolated context may introduce data races}}
10+
await onGeneric(ns: ns)
11+
}
12+
13+
@propertyWrapper
14+
struct Wrapper {
15+
// expected-note@+1 {{mutation of this property is only permitted within the actor}}
16+
@preconcurrency @MainActor var wrappedValue: NonSendable
17+
18+
init(wrappedValue: NonSendable) {
19+
// expected-warning@+1 {{main actor-isolated property 'wrappedValue' can not be mutated from a non-isolated context; this is an error in Swift 6}}
20+
self.wrappedValue = wrappedValue
21+
}
22+
}
23+
24+
struct S {
25+
@Wrapper var value: NonSendable = NonSendable()
26+
}
27+
28+
nonisolated func onGeneric(ns: NonSendable) async {
29+
let _ = S()
30+
}

0 commit comments

Comments
 (0)