Skip to content

Commit dcf078a

Browse files
authored
Merge pull request #73104 from xedin/promote-dynamic-actor-isolation-to-upcoming-feature-6.0
[6.0][SE-0423] Promote `DynamicActorIsolation` to an upcoming feature and add a way to disable checks
2 parents c9aa734 + cf4f030 commit dcf078a

20 files changed

+417
-82
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5690,8 +5690,6 @@ ERROR(preconcurrency_not_inheritance_clause,none,
56905690
"'preconcurrency' attribute only applies in inheritance clauses", ())
56915691
ERROR(preconcurrency_not_existential,none,
56925692
"'preconcurrency' attribute cannot apply to non-protocol type %0", (Type))
5693-
ERROR(preconcurrency_attr_disabled,none,
5694-
"attribute requires '-enable-experimental-feature DynamicActorIsolation'", ())
56955693

56965694
ERROR(redundant_any_in_existential,none,
56975695
"redundant 'any' in type %0",

include/swift/Basic/Features.def

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ UPCOMING_FEATURE(GlobalConcurrency, 412, 6)
190190
UPCOMING_FEATURE(InferSendableFromCaptures, 418, 6)
191191
UPCOMING_FEATURE(ImplicitOpenExistentials, 352, 6)
192192
UPCOMING_FEATURE(RegionBasedIsolation, 414, 6)
193+
UPCOMING_FEATURE(DynamicActorIsolation, 423, 6)
193194
UPCOMING_FEATURE(MoveOnlyPartialConsumption, 429, 6)
194195

195196
// Swift 7
@@ -353,11 +354,6 @@ EXPERIMENTAL_FEATURE(GroupActorErrors, true)
353354
// Allow for the 'transferring' keyword to be applied to arguments and results.
354355
EXPERIMENTAL_FEATURE(TransferringArgsAndResults, true)
355356

356-
// Enable `@preconcurrency` attribute on protocol conformances and runtime checks
357-
// of actor isolation in @obj thunks and arguments of APIs that haven't yet adopted
358-
// strict concurrency checking.
359-
EXPERIMENTAL_FEATURE(DynamicActorIsolation, false)
360-
361357
// Allow for `switch` of noncopyable values to be borrowing or consuming.
362358
EXPERIMENTAL_FEATURE(BorrowingSwitch, true)
363359

include/swift/Basic/LangOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ namespace swift {
593593
/// type-checking, SIL verification, and IR emission,
594594
bool BypassResilienceChecks = false;
595595

596+
/// Disables `DynamicActorIsolation` feature.
597+
bool DisableDynamicActorIsolation = false;
598+
596599
/// Whether or not to allow experimental features that are only available
597600
/// in "production".
598601
#ifdef NDEBUG
@@ -605,6 +608,11 @@ namespace swift {
605608
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
606609
}
607610

611+
bool isDynamicActorIsolationCheckingEnabled() const {
612+
return !DisableDynamicActorIsolation &&
613+
hasFeature(Feature::DynamicActorIsolation);
614+
}
615+
608616
LangOptions();
609617

610618
/// Sets the target we are building for and updates platform conditions

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,11 @@ def disable_actor_data_race_checks :
817817
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
818818
HelpText<"Disable runtime checks for actor data races">;
819819

820+
def disable_dynamic_actor_isolation :
821+
Flag<["-"], "disable-dynamic-actor-isolation">,
822+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
823+
HelpText<"Disable dynamic actor isolation checks">;
824+
820825
def enable_bare_slash_regex : Flag<["-"], "enable-bare-slash-regex">,
821826
Flags<[FrontendOption, ModuleInterfaceOption]>,
822827
HelpText<"Enable the use of forward slash regular-expression literal syntax">;

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -643,29 +643,7 @@ static bool usesFeatureTransferringArgsAndResults(Decl *decl) {
643643
return false;
644644
}
645645

646-
static bool usesFeatureDynamicActorIsolation(Decl *decl) {
647-
auto usesPreconcurrencyConformance = [&](const InheritedTypes &inherited) {
648-
return llvm::any_of(
649-
inherited.getEntries(),
650-
[](const InheritedEntry &entry) { return entry.isPreconcurrency(); });
651-
};
652-
653-
if (auto *T = dyn_cast<TypeDecl>(decl))
654-
return usesPreconcurrencyConformance(T->getInherited());
655-
656-
if (auto *E = dyn_cast<ExtensionDecl>(decl)) {
657-
// If type has `@preconcurrency` conformance(s) all of its
658-
// extensions have to be guarded by the flag too.
659-
if (auto *T = dyn_cast<TypeDecl>(E->getExtendedNominal())) {
660-
if (usesPreconcurrencyConformance(T->getInherited()))
661-
return true;
662-
}
663-
664-
return usesPreconcurrencyConformance(E->getInherited());
665-
}
666-
667-
return false;
668-
}
646+
UNINTERESTING_FEATURE(DynamicActorIsolation)
669647

670648
UNINTERESTING_FEATURE(BorrowingSwitch)
671649

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
264264
inputArgs.AddLastArg(arguments,
265265
options::OPT_enable_actor_data_race_checks,
266266
options::OPT_disable_actor_data_race_checks);
267+
inputArgs.AddLastArg(arguments, options::OPT_disable_dynamic_actor_isolation);
267268
inputArgs.AddLastArg(arguments, options::OPT_warn_concurrency);
268269
inputArgs.AddLastArg(arguments, options::OPT_strict_concurrency);
269270
inputArgs.AddAllArgs(arguments, options::OPT_enable_experimental_feature);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
15171517
if (Opts.hasFeature(Feature::DebugDescriptionMacro))
15181518
Opts.enableFeature(Feature::SymbolLinkageMarkers);
15191519

1520+
Opts.DisableDynamicActorIsolation |=
1521+
Args.hasArg(OPT_disable_dynamic_actor_isolation);
1522+
15201523
#if SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
15211524
/// Enable round trip parsing via the new swift parser unless it is disabled
15221525
/// explicitly. The new Swift parser can have mismatches with C++ parser -

lib/SILGen/SILGenBridging.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,14 +1593,12 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
15931593
loc.markAutoGenerated();
15941594
Scope scope(Cleanups, CleanupLocation(loc));
15951595

1596-
bool emitExecutorPrecondition =
1597-
getASTContext().LangOpts.hasFeature(Feature::DynamicActorIsolation);
1598-
15991596
std::optional<ActorIsolation> isolation;
16001597
if (F.isAsync()) {
16011598
if (thunk.hasDecl())
16021599
isolation = getActorIsolation(thunk.getDecl());
1603-
} else if (emitExecutorPrecondition) {
1600+
} else if (getASTContext()
1601+
.LangOpts.isDynamicActorIsolationCheckingEnabled()) {
16041602
if (thunk.hasDecl()) {
16051603
isolation = getActorIsolation(thunk.getDecl());
16061604
} else if (auto globalActor = nativeInfo.FormalType->getGlobalActor()) {

lib/SILGen/SILGenPoly.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7021,7 +7021,10 @@ void SILGenFunction::emitProtocolWitness(
70217021

70227022
if (!F.isAsync()) {
70237023
assert(isPreconcurrency);
7024-
emitPreconditionCheckExpectedExecutor(loc, *enterIsolation, actorSelf);
7024+
7025+
if (getASTContext().LangOpts.isDynamicActorIsolationCheckingEnabled()) {
7026+
emitPreconditionCheckExpectedExecutor(loc, *enterIsolation, actorSelf);
7027+
}
70257028
} else {
70267029
emitHopToTargetActor(loc, enterIsolation, actorSelf);
70277030
}

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7462,7 +7462,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
74627462
}
74637463
}
74647464

7465-
if (ctx.LangOpts.hasFeature(Feature::DynamicActorIsolation)) {
7465+
if (ctx.LangOpts.isDynamicActorIsolationCheckingEnabled()) {
74667466
// Passing a synchronous global actor-isolated function value and
74677467
// parameter that expects a synchronous non-isolated function type could
74687468
// require a runtime check to ensure that function is always called in

0 commit comments

Comments
 (0)