Skip to content

Commit 1e5dc45

Browse files
authored
Merge pull request #38889 from ktoso/wip-distributed-only-exp
2 parents 45f23f0 + 5617856 commit 1e5dc45

File tree

10 files changed

+82
-20
lines changed

10 files changed

+82
-20
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,11 @@ ERROR(attr_requires_concurrency, none,
18391839
"concurrency is enabled",
18401840
(StringRef, bool))
18411841

1842+
ERROR(attr_requires_distributed, none,
1843+
"'%0' %select{attribute|modifier}1 is only valid when experimental "
1844+
"distributed support is enabled",
1845+
(StringRef, bool))
1846+
18421847
//------------------------------------------------------------------------------
18431848
// MARK: syntax parsing diagnostics
18441849
//------------------------------------------------------------------------------

include/swift/Frontend/Frontend.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,6 @@ class CompilerInvocation {
354354
/// imported.
355355
bool shouldImportSwiftConcurrency() const;
356356

357-
/// Whether the Distributed support library should be implicitly imported.
358-
bool shouldImportSwiftDistributed() const;
359-
360357
/// Performs input setup common to these tools:
361358
/// sil-opt, sil-func-extractor, sil-llvm-gen, and sil-nm.
362359
/// Return value includes the buffer so caller can keep it alive.

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,15 +1692,15 @@ FUNCTION(DefaultActorDeallocateResilient,
16921692
// );
16931693
FUNCTION(DistributedActorInitializeRemote,
16941694
swift_distributedActor_remote_initialize, SwiftCC,
1695-
ConcurrencyAvailability,
1695+
ConcurrencyAvailability, // TODO(distributed): Introduce DistributedAvailability once shipping somewhere
16961696
RETURNS(OpaquePtrTy),
16971697
ARGS(TypeMetadataPtrTy),
16981698
ATTRS(NoUnwind))
16991699

1700-
// void swift_distributedActor_destroy(DefaultActor *actor); // TODO: ProxyActor *proxy?
1700+
// void swift_distributedActor_destroy(DefaultActor *actor);
17011701
FUNCTION(DistributedActorDestroy,
17021702
swift_distributedActor_destroy, SwiftCC,
1703-
ConcurrencyAvailability,
1703+
ConcurrencyAvailability, // TODO(distributed): Introduce DistributedAvailability once shipping somewhere
17041704
RETURNS(VoidTy),
17051705
ARGS(RefCountedPtrTy),
17061706
ATTRS(NoUnwind))

include/swift/Strings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ constexpr static const StringLiteral STDLIB_NAME = "Swift";
2424
constexpr static const StringLiteral SWIFT_ONONE_SUPPORT = "SwiftOnoneSupport";
2525
/// The name of the Concurrency module, which supports that extension.
2626
constexpr static const StringLiteral SWIFT_CONCURRENCY_NAME = "_Concurrency";
27+
/// The name of the Distributed module, which supports that extension.
28+
constexpr static const StringLiteral SWIFT_DISTRIBUTED_NAME = "_Distributed";
2729
/// The name of the SwiftShims module, which contains private stdlib decls.
2830
constexpr static const StringLiteral SWIFT_SHIMS_NAME = "SwiftShims";
2931
/// The name of the Builtin module, which contains Builtin functions.

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,6 @@ bool CompilerInvocation::shouldImportSwiftConcurrency() const {
779779
FrontendOptions::ParseInputMode::SwiftModuleInterface;
780780
}
781781

782-
bool CompilerInvocation::shouldImportSwiftDistributed() const {
783-
return getLangOptions().EnableExperimentalDistributed &&
784-
getFrontendOptions().InputMode !=
785-
FrontendOptions::ParseInputMode::SwiftModuleInterface;
786-
}
787-
788782
/// Implicitly import the SwiftOnoneSupport module in non-optimized
789783
/// builds. This allows for use of popular specialized functions
790784
/// from the standard library, which makes the non-optimized builds

lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,14 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
16111611
DiscardAttribute = true;
16121612
}
16131613

1614+
// If this attribute is only permitted when distributed is enabled, reject it.
1615+
if (DeclAttribute::isDistributedOnly(DK) &&
1616+
!shouldParseExperimentalDistributed()) {
1617+
diagnose(Loc, diag::attr_requires_distributed, AttrName,
1618+
DeclAttribute::isDeclModifier(DK));
1619+
DiscardAttribute = true;
1620+
}
1621+
16141622
if (Context.LangOpts.Target.isOSBinFormatCOFF()) {
16151623
if (DK == DAK_WeakLinked) {
16161624
diagnose(Loc, diag::attr_unsupported_on_target, AttrName,

test/Distributed/distributed_actor_is_experimental.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,37 @@ actor SomeActor {}
77

88
@available(SwiftStdlib 5.5, *)
99
distributed actor DA {}
10-
// expected-error@-1{{'_Distributed' module not imported, required for 'distributed actor'}}
10+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}
1111

1212
@available(SwiftStdlib 5.5, *)
13-
distributed actor class DAC {} // expected-error{{distributed' can only be applied to 'actor' definitions, and distributed actor-isolated async functions}}
14-
// expected-error@-1{{keyword 'class' cannot be used as an identifier here}}
13+
distributed actor class DAC {}
14+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}
15+
// expected-error@-2{{keyword 'class' cannot be used as an identifier here}}
1516

1617
actor A {
1718
func normal() async {}
18-
distributed func dist() {} // expected-error{{'distributed' function can only be declared within 'distributed actor'}}
19-
distributed func distAsync() async {} // expected-error{{'distributed' function can only be declared within 'distributed actor'}}
19+
distributed func dist() {}
20+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}
21+
distributed func distAsync() async {}
22+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}
2023

21-
distributed var neverOk: String { // expected-error{{'distributed' modifier cannot be applied to this declaration}}
24+
distributed var neverOk: String {
25+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}
2226
"vars are not allowed to be distributed *ever* anyway"
2327
}
2428
}
2529

2630
@available(SwiftStdlib 5.5, *)
2731
distributed actor DA2 {
28-
// expected-error@-1{{'_Distributed' module not imported, required for 'distributed actor'}}
32+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}
2933
func normal() async {}
3034
distributed func dist() {}
35+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}
3136
distributed func distAsync() async {}
37+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}
3238

33-
distributed var neverOk: String { // expected-error{{'distributed' modifier cannot be applied to this declaration}}
39+
distributed var neverOk: String {
40+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}
3441
"vars are not allowed to be distributed *ever* anyway"
3542
}
3643
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-distributed
2+
// REQUIRES: concurrency
3+
// REQUIRES: distributed
4+
5+
actor SomeActor {}
6+
7+
@available(SwiftStdlib 5.5, *)
8+
distributed actor DA {}
9+
// expected-error@-1{{'_Distributed' module not imported, required for 'distributed actor'}}
10+
11+
@available(SwiftStdlib 5.5, *)
12+
distributed actor class DAC {}
13+
// expected-error@-1{{distributed' can only be applied to 'actor' definitions, and distributed actor-isolated async functions}}
14+
// expected-error@-2{{keyword 'class' cannot be used as an identifier here}}
15+
16+
actor A {
17+
func normal() async {}
18+
distributed func dist() {} // expected-error{{'distributed' function can only be declared within 'distributed actor'}}
19+
distributed func distAsync() async {} // expected-error{{'distributed' function can only be declared within 'distributed actor'}}
20+
21+
distributed var neverOk: String { // expected-error{{'distributed' modifier cannot be applied to this declaration}}
22+
"vars are not allowed to be distributed *ever* anyway"
23+
}
24+
}
25+
26+
@available(SwiftStdlib 5.5, *)
27+
distributed actor DA2 {
28+
// expected-error@-1{{'_Distributed' module not imported, required for 'distributed actor'}}
29+
func normal() async {}
30+
distributed func dist() {}
31+
distributed func distAsync() async {}
32+
33+
distributed var neverOk: String { // expected-error{{'distributed' modifier cannot be applied to this declaration}}
34+
"vars are not allowed to be distributed *ever* anyway"
35+
}
36+
}
37+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking
2+
// ^^^^ notice the, on purpose, missing '-enable-experimental-distributed'
3+
// REQUIRES: concurrency
4+
// REQUIRES: distributed
5+
6+
import _Distributed
7+
8+
@available(macOS 12.0, *)
9+
distributed actor A {}
10+
// expected-error@-1{{'distributed' modifier is only valid when experimental distributed support is enabled}}

tools/sil-opt/SILOpt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ int main(int argc, char **argv) {
415415
}
416416
Invocation.getLangOptions().EnableExperimentalConcurrency =
417417
EnableExperimentalConcurrency;
418+
Invocation.getLangOptions().EnableExperimentalDistributed =
419+
EnableExperimentalDistributed;
418420

419421
Invocation.getLangOptions().EnableObjCInterop =
420422
EnableObjCInterop ? true :

0 commit comments

Comments
 (0)