Skip to content

Commit f860c0c

Browse files
committed
Guard the changes behind an experimental feature flag.
1 parent 04f9efe commit f860c0c

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ EXPERIMENTAL_FEATURE(PreambleMacros, false)
232232
EXPERIMENTAL_FEATURE(TupleConformances, false)
233233
EXPERIMENTAL_FEATURE(FullTypedThrows, false)
234234
EXPERIMENTAL_FEATURE(SameElementRequirements, false)
235+
EXPERIMENTAL_FEATURE(GlobalActorInferenceCutoff, false)
235236

236237
// Whether to enable @_used and @_section attributes
237238
EXPERIMENTAL_FEATURE(SymbolLinkageMarkers, true)

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ UNINTERESTING_FEATURE(ExtractConstantsFromMembers)
204204
UNINTERESTING_FEATURE(FixedArrays)
205205
UNINTERESTING_FEATURE(GroupActorErrors)
206206
UNINTERESTING_FEATURE(SameElementRequirements)
207+
UNINTERESTING_FEATURE(GlobalActorInferenceCutoff)
207208

208209
static bool usesFeatureSendingArgsAndResults(Decl *decl) {
209210
auto isFunctionTypeWithSending = [](Type type) {

lib/Sema/TypeCheckAttr.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7127,6 +7127,15 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
71277127
// 'nonisolated' can be applied to global and static/class variables
71287128
// that do not have storage.
71297129
auto dc = D->getDeclContext();
7130+
auto &ctx = D->getASTContext();
7131+
7132+
if (!ctx.LangOpts.hasFeature(Feature::GlobalActorInferenceCutoff)) {
7133+
if (isa<ProtocolDecl>(D) || isa<ExtensionDecl>(D) || isa<ClassDecl>(D) ||
7134+
isa<StructDecl>(D) || isa<EnumDecl>(D)) {
7135+
diagnoseAndRemoveAttr(attr, diag::invalid_decl_modifier, attr);
7136+
return;
7137+
}
7138+
}
71307139

71317140
// nonisolated(unsafe) is unsafe, but only under strict concurrency.
71327141
if (attr->isUnsafe() &&
@@ -7149,12 +7158,14 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
71497158
}
71507159
}
71517160

7152-
// Additionally, a stored property of a non-'Sendable' type can be
7153-
// explicitly marked 'nonisolated'.
7154-
if (auto parentDecl = dc->getDeclaredTypeInContext())
7155-
if (!parentDecl->isSendableType()) {
7156-
canBeNonisolated = true;
7157-
}
7161+
if (ctx.LangOpts.hasFeature(Feature::GlobalActorInferenceCutoff)) {
7162+
// Additionally, a stored property of a non-'Sendable' type can be
7163+
// explicitly marked 'nonisolated'.
7164+
if (auto parentDecl = dc->getDeclaredTypeInContext())
7165+
if (!parentDecl->isSendableType()) {
7166+
canBeNonisolated = true;
7167+
}
7168+
}
71587169

71597170
// Otherwise, this stored property has to be qualified as 'unsafe'.
71607171
if (var->supportsMutation() && !attr->isUnsafe() && !canBeNonisolated) {
@@ -7164,14 +7175,16 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
71647175
return;
71657176
}
71667177

7167-
// 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
7168-
// variables, unless they are a member of a non-'Sendable' type.
7169-
if (!attr->isUnsafe() && !type->hasError() && !canBeNonisolated) {
7170-
bool diagnosed = diagnoseIfAnyNonSendableTypes(
7171-
type, SendableCheckContext(dc), Type(), SourceLoc(),
7172-
attr->getLocation(), diag::nonisolated_non_sendable);
7173-
if (diagnosed)
7174-
return;
7178+
if (ctx.LangOpts.hasFeature(Feature::GlobalActorInferenceCutoff)) {
7179+
// 'nonisolated' without '(unsafe)' is not allowed on non-Sendable
7180+
// variables, unless they are a member of a non-'Sendable' type.
7181+
if (!attr->isUnsafe() && !type->hasError() && !canBeNonisolated) {
7182+
bool diagnosed = diagnoseIfAnyNonSendableTypes(
7183+
type, SendableCheckContext(dc), Type(), SourceLoc(),
7184+
attr->getLocation(), diag::nonisolated_non_sendable);
7185+
if (diagnosed)
7186+
return;
7187+
}
71757188
}
71767189
}
71777190

test/Concurrency/nonisolated_rules.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -swift-version 6 -parse-as-library %s -emit-sil -o /dev/null -verify
2-
// RUN: %target-swift-frontend -disable-availability-checking -swift-version 6 -parse-as-library %s -emit-sil -o /dev/null -verify -strict-concurrency=complete
1+
// RUN: %target-swift-frontend -disable-availability-checking -swift-version 6 -enable-experimental-feature GlobalActorInferenceCutoff -parse-as-library %s -emit-sil -o /dev/null -verify -strict-concurrency=complete
32

43
// REQUIRES: concurrency
54
// REQUIRES: asserts

0 commit comments

Comments
 (0)