Skip to content

[6.2] [SE-0466] Enable SendableProhibitsMainActorInference by default #82923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: release/6.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,6 @@ EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)
/// Enable @_lifetime attribute
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(Lifetimes, true)

/// Disable @MainActor inference when the primary definition of a type conforms
/// to SendableMetatype (or Sendable).
EXPERIMENTAL_FEATURE(SendableProhibitsMainActorInference, true)

#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
#undef EXPERIMENTAL_FEATURE
#undef UPCOMING_FEATURE
Expand Down
1 change: 0 additions & 1 deletion lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ UNINTERESTING_FEATURE(MacrosOnImports)
UNINTERESTING_FEATURE(ExtensibleEnums)
UNINTERESTING_FEATURE(NonisolatedNonsendingByDefault)
UNINTERESTING_FEATURE(KeyPathWithMethodMembers)
UNINTERESTING_FEATURE(SendableProhibitsMainActorInference)

static bool usesFeatureNonescapableTypes(Decl *decl) {
auto containsNonEscapable =
Expand Down
12 changes: 0 additions & 12 deletions lib/Sema/DerivedConformance/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,6 @@ addImplicitCodingKeys(NominalTypeDecl *target,
enumDecl->setSynthesized();
enumDecl->setAccess(AccessLevel::Private);

if (!C.LangOpts.hasFeature(Feature::SendableProhibitsMainActorInference)) {
switch (C.LangOpts.DefaultIsolationBehavior) {
case DefaultIsolation::MainActor:
enumDecl->getAttrs().add(NonisolatedAttr::createImplicit(C));
break;

case DefaultIsolation::Nonisolated:
// Nothing to do.
break;
}
}

// For classes which inherit from something Encodable or Decodable, we
// provide case `super` as the first key (to be used in encoding super).
auto *classDecl = dyn_cast<ClassDecl>(target);
Expand Down
3 changes: 0 additions & 3 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6010,9 +6010,6 @@ static void addAttributesForActorIsolation(ValueDecl *value,
/// be nonisolated (preventing @MainActor inference).
static bool sendableConformanceRequiresNonisolated(NominalTypeDecl *nominal) {
ASTContext &ctx = nominal->getASTContext();
if (!ctx.LangOpts.hasFeature(Feature::SendableProhibitsMainActorInference))
return false;

if (isa<ProtocolDecl>(nominal))
return false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// RUN: %target-swift-frontend -swift-version 5 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift5- -enable-experimental-feature SendableProhibitsMainActorInference
// RUN: %target-swift-frontend -swift-version 6 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift6- -enable-experimental-feature SendableProhibitsMainActorInference

// REQUIRES: swift_feature_SendableProhibitsMainActorInference
// RUN: %target-swift-frontend -swift-version 5 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift5-
// RUN: %target-swift-frontend -swift-version 6 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift6-

// Ensure that a Sendable-conforming protocol suppresses @MainActor inference
// for a type.
Expand Down
4 changes: 1 addition & 3 deletions test/Macros/default_main_actor_nonisolated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath

// Check for errors
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) %s -I %t -disable-availability-checking -swift-version 6 -default-isolation MainActor -enable-experimental-feature SendableProhibitsMainActorInference

// REQUIRES: swift_feature_SendableProhibitsMainActorInference
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) %s -I %t -disable-availability-checking -swift-version 6 -default-isolation MainActor

@attached(extension, conformances: Sendable)
macro AddSendable() = #externalMacro(module: "MacroDefinition", type: "SendableMacro")
Expand Down