Skip to content

Commit c246a7a

Browse files
committed
[AST/Sema] Hide using declaration behind DefaultIsolationPerFile experimental feature
1 parent ad71e07 commit c246a7a

File tree

9 files changed

+31
-5
lines changed

9 files changed

+31
-5
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,8 @@ ERROR(nonisolated_nonsending_repeated,none,
21932193
ERROR(using_decl_invalid_specifier,PointsToFirstBadToken,
21942194
"'using' declaration does not support %0 %select{modifier|attribute}1",
21952195
(Identifier, bool))
2196+
ERROR(experimental_using_decl_disabled,PointsToFirstBadToken,
2197+
"'using' is an experimental feature that is currently disabled", ())
21962198

21972199
#define UNDEFINE_DIAGNOSTIC_MACROS
21982200
#include "DefineDiagnosticMacros.h"

include/swift/Basic/Features.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ExtensibleAttribute, false)
521521
/// Allow use of `Module::name` syntax
522522
EXPERIMENTAL_FEATURE(ModuleSelector, false)
523523

524+
/// Allow use of `using` declaration that control default isolation
525+
/// in a file scope.
526+
EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)
527+
524528
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
525529
#undef EXPERIMENTAL_FEATURE
526530
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,10 @@ static bool usesFeatureAlwaysInheritActorContext(Decl *decl) {
643643
return false;
644644
}
645645

646+
static bool usesFeatureDefaultIsolationPerFile(Decl *D) {
647+
return isa<UsingDecl>(D);
648+
}
649+
646650
UNINTERESTING_FEATURE(BuiltinSelect)
647651

648652
// ----------------------------------------------------------------------------

lib/ASTGen/Sources/ASTGen/SourceFile.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extension Parser.ExperimentalFeatures {
7878
mapFeature(.OldOwnershipOperatorSpellings, to: .oldOwnershipOperatorSpellings)
7979
mapFeature(.KeyPathWithMethodMembers, to: .keypathWithMethodMembers)
8080
mapFeature(.InlineArrayTypeSugar, to: .inlineArrayTypeSugar)
81+
mapFeature(.DefaultIsolationPerFile, to: .defaultIsolationPerFile)
8182
}
8283
}
8384

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6672,6 +6672,10 @@ ParserResult<UsingDecl> Parser::parseDeclUsing(ParseDeclOptions Flags,
66726672
assert(Tok.isContextualKeyword("using"));
66736673
DebuggerContextChange DCC(*this);
66746674

6675+
if (!Context.LangOpts.hasFeature(Feature::DefaultIsolationPerFile)) {
6676+
diagnose(Tok, diag::experimental_using_decl_disabled);
6677+
}
6678+
66756679
SourceLoc UsingLoc = consumeToken();
66766680

66776681
if (Tok.is(tok::code_complete)) {

test/ASTGen/decls.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
// RUN: %empty-directory(%t)
33
// RUN: %target-swift-frontend-dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-concurrency -enable-experimental-feature ParserASTGen \
44
// RUN: -enable-experimental-feature CoroutineAccessors \
5+
// RUN: -enable-experimental-feature DefaultIsolationPerFile \
56
// RUN: | %sanitize-address > %t/astgen.ast
67
// RUN: %target-swift-frontend-dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-concurrency \
78
// RUN: -enable-experimental-feature CoroutineAccessors \
9+
// RUN: -enable-experimental-feature DefaultIsolationPerFile \
810
// RUN: | %sanitize-address > %t/cpp-parser.ast
911

1012
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
1113

12-
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -Xfrontend -enable-experimental-concurrency -enable-experimental-feature CoroutineAccessors -enable-experimental-feature ParserASTGen)
14+
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -Xfrontend -enable-experimental-concurrency -enable-experimental-feature CoroutineAccessors -enable-experimental-feature DefaultIsolationPerFile -enable-experimental-feature ParserASTGen)
1315

1416
// REQUIRES: executable_test
1517
// REQUIRES: swift_swift_parser
1618
// REQUIRES: swift_feature_ParserASTGen
1719
// REQUIRES: swift_feature_CoroutineAccessors
20+
// REQUIRES: swift_feature_DefaultIsolationPerFile
1821

1922
// rdar://116686158
2023
// UNSUPPORTED: asan

test/ASTGen/diagnostics.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-bare-slash-regex -enable-experimental-feature ParserASTGen
3+
// RUN: %target-typecheck-verify-swift -disable-availability-checking \
4+
// RUN: -enable-bare-slash-regex \
5+
// RUN: -enable-experimental-feature ParserASTGen \
6+
// RUN: -enable-experimental-feature DefaultIsolationPerFile
47

58
// REQUIRES: swift_swift_parser
69
// REQUIRES: swift_feature_ParserASTGen
10+
// REQUIRES: swift_feature_DefaultIsolationPerFile
711

812
// rdar://116686158
913
// UNSUPPORTED: asan
@@ -75,4 +79,4 @@ using @Test
7579
// expected-error@-1 {{default isolation can only be set to '@MainActor' or 'nonisolated'}}
7680

7781
using test
78-
// expected-error@-1 {{default isolation can only be set to '@MainActor' or 'nonisolated'}}
82+
// expected-error@-1 {{default isolation can only be set to '@MainActor' or 'nonisolated'}}

test/ModuleInterface/using.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s
1+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -enable-experimental-feature DefaultIsolationPerFile
22

33
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface)
44

55
// RUN: %FileCheck %s --input-file %t.swiftinterface
66

7+
// REQUIRES: swift_feature_DefaultIsolationPerFile
8+
79
using @MainActor
810

911
// CHECK-NOT: using @MainActor

test/Parse/using.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature DefaultIsolationPerFile
2+
3+
// REQUIRES: swift_feature_DefaultIsolationPerFile
24

35
// REQUIRES: concurrency
46

0 commit comments

Comments
 (0)