diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index fc607f3c4b42a..4235741ae1af4 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -871,6 +871,12 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args, continue; } + if (isUpcomingFeatureFlag && + argValue.compare("ApproachableConcurrency") == 0) { + psuedoFeatures.push_back(argValue); + continue; + } + // For all other features, the argument format is `[:migrate]`. StringRef featureName; std::optional featureMode; @@ -987,6 +993,15 @@ static bool ParseEnabledFeatureArgs(LangOptions &Opts, ArgList &Args, continue; } + if (featureName->compare("ApproachableConcurrency") == 0) { + Opts.enableFeature(Feature::DisableOutwardActorInference); + Opts.enableFeature(Feature::GlobalActorIsolatedTypesUsability); + Opts.enableFeature(Feature::InferIsolatedConformances); + Opts.enableFeature(Feature::InferSendableFromCaptures); + Opts.enableFeature(Feature::NonisolatedNonsendingByDefault); + continue; + } + // Hack: In order to support using availability macros in SPM packages, we // need to be able to use: // .enableExperimentalFeature("AvailabilityMacro='...'") diff --git a/test/Concurrency/approachable_concurrency.swift b/test/Concurrency/approachable_concurrency.swift new file mode 100644 index 0000000000000..dee90214792b6 --- /dev/null +++ b/test/Concurrency/approachable_concurrency.swift @@ -0,0 +1,40 @@ +// RUN: %target-swift-emit-silgen %s -verify -enable-upcoming-feature ApproachableConcurrency -default-isolation MainActor | %FileCheck %s + +// REQUIRES: concurrency + +struct S { + func test() { + } +} + +func takesSendable(_: T) {} + +// CHECK-LABEL: sil hidden [ossa] @$s24approachable_concurrency21testSendableInference1syAA1SV_tF : $@convention(thin) (S) -> () +// CHECK: function_ref @$s24approachable_concurrency21testSendableInference1syAA1SV_tFyyYbcAEYbcfu_ : $@convention(thin) @Sendable (S) -> @owned @Sendable @callee_guaranteed () -> () +// CHECK: } // end sil function '$s24approachable_concurrency21testSendableInference1syAA1SV_tF' +func testSendableInference(s: S) { + takesSendable(s.test) +} + +// CHECK-LABEL: sil hidden [ossa] @$s24approachable_concurrency25testNonisolatedNonSendingyyyyYaYCXEYaF : $@convention(thin) @async (@guaranteed @noescape @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Builtin.ImplicitActor) -> ()) -> () +func testNonisolatedNonSending(_: () async -> Void) async { +} + +// GlobalActorIsolatedTypesUsability +@MainActor +struct GAITU { + nonisolated var x: Int = 0 +} + +extension GAITU: Equatable { + static nonisolated func ==(lhs: GAITU, rhs: GAITU) -> Bool { + return lhs.x == rhs.x // okay + } +} + +// CHECK: // static IsolatedConformances.__derived_struct_equals(_:_:) +// CHECK-NEXT: // Isolation: global_actor. type: MainActor +// CHECK-LABEL: sil hidden [ossa] @$s24approachable_concurrency20IsolatedConformancesV23__derived_struct_equalsySbAC_ACtFZ : $@convention(method) (IsolatedConformances, IsolatedConformances, @thin IsolatedConformances.Type) -> Bool +struct IsolatedConformances: Equatable { + let x: Int = 0 +} diff --git a/test/Misc/verify-swift-feature-testing.test-sh b/test/Misc/verify-swift-feature-testing.test-sh index df65d56b4e590..045263498170d 100755 --- a/test/Misc/verify-swift-feature-testing.test-sh +++ b/test/Misc/verify-swift-feature-testing.test-sh @@ -27,6 +27,8 @@ EXCEPTIONAL_FILES = [ pathlib.Path("test/attr/feature_requirement.swift"), # Tests completion with features both enabled and disabled pathlib.Path("test/IDE/complete_decl_attribute_feature_requirement.swift"), + # Uses the pseudo-feature ApproachableConcurrency + pathlib.Path("test/Concurrency/approachable_concurrency.swift"), ] ENABLE_FEATURE_RE = re.compile(