Skip to content

Commit fbd66e2

Browse files
committed
[Distributed] Only parse distributed when experimentla mode enabled
1 parent 86c7245 commit fbd66e2

16 files changed

+131
-22
lines changed

include/swift/AST/ASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,9 @@ class ASTContext final {
753753
/// Get the runtime availability of support for concurrency.
754754
AvailabilityContext getConcurrencyAvailability();
755755

756+
/// Get the runtime availability of support for distributed actors.
757+
AvailabilityContext getDistributedAvailability();
758+
756759
/// Get the runtime availability of support for differentiation.
757760
AvailabilityContext getDifferentiationAvailability();
758761

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: 4 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.
@@ -536,6 +533,10 @@ class CompilerInstance {
536533
/// i.e. if it can be found.
537534
bool canImportSwiftConcurrency() const;
538535

536+
/// Whether the Distributed actors support library can be imported
537+
/// i.e. if it can be found.
538+
bool canImportSwiftDistributed() const;
539+
539540
/// Gets the SourceFile which is the primary input for this CompilerInstance.
540541
/// \returns the primary SourceFile, or nullptr if there is no primary input;
541542
/// if there are _multiple_ primary inputs, fails with an assertion.

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+
DistributedAvailability,
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+
DistributedAvailability,
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/AST/Availability.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ AvailabilityContext ASTContext::getConcurrencyAvailability() {
330330
return getSwift55Availability();
331331
}
332332

333+
AvailabilityContext ASTContext::getDistributedAvailability() {
334+
return getSwift55Availability(); // FIXME(distributed): getSwiftFutureAvailability perhaps? The module is not shipping in any release so far so it does not matter for real though.
335+
}
336+
333337
AvailabilityContext ASTContext::getDifferentiationAvailability() {
334338
return getSwiftFutureAvailability();
335339
}

lib/Frontend/Frontend.cpp

Lines changed: 5 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
@@ -825,6 +819,11 @@ bool CompilerInstance::canImportSwiftConcurrency() const {
825819
{getASTContext().getIdentifier(SWIFT_CONCURRENCY_NAME), SourceLoc()});
826820
}
827821

822+
bool CompilerInstance::canImportSwiftDistributed() const {
823+
return getASTContext().canImportModule(
824+
{getASTContext().getIdentifier(SWIFT_DISTRIBUTED_NAME), SourceLoc()});
825+
}
826+
828827
ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
829828
auto &frontendOpts = Invocation.getFrontendOptions();
830829

lib/IRGen/IRGenModule.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,14 @@ namespace RuntimeConstants {
786786
return RuntimeAvailability::AlwaysAvailable;
787787
}
788788

789+
RuntimeAvailability DistributedAvailability(ASTContext &context) {
790+
auto featureAvailability = context.getDistributedAvailability();
791+
if (!isDeploymentAvailabilityContainedIn(context, featureAvailability)) {
792+
return RuntimeAvailability::ConditionallyAvailable;
793+
}
794+
return RuntimeAvailability::AlwaysAvailable;
795+
}
796+
789797
RuntimeAvailability DifferentiationAvailability(ASTContext &context) {
790798
auto featureAvailability = context.getDifferentiationAvailability();
791799
if (!isDeploymentAvailabilityContainedIn(context, featureAvailability)) {

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,

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,24 @@ void TypeChecker::checkConcurrencyAvailability(SourceRange ReferenceRange,
17021702
}
17031703
}
17041704

1705+
void TypeChecker::checkDistributedAvailability(SourceRange ReferenceRange,
1706+
const DeclContext *ReferenceDC) {
1707+
// Check the availability of concurrency runtime support.
1708+
ASTContext &ctx = ReferenceDC->getASTContext();
1709+
if (ctx.LangOpts.DisableAvailabilityChecking)
1710+
return;
1711+
1712+
auto runningOS =
1713+
TypeChecker::overApproximateAvailabilityAtLocation(
1714+
ReferenceRange.Start, ReferenceDC);
1715+
auto availability = ctx.getDistributedAvailability();
1716+
if (!runningOS.isContainedIn(availability)) {
1717+
diagnosePotentialConcurrencyUnavailability(
1718+
ReferenceRange, ReferenceDC,
1719+
UnavailabilityReason::requiresVersionRange(availability.getOSVersion()));
1720+
}
1721+
}
1722+
17051723
void TypeChecker::diagnosePotentialUnavailability(
17061724
const ValueDecl *D, SourceRange ReferenceRange,
17071725
const DeclContext *ReferenceDC,

0 commit comments

Comments
 (0)