Skip to content

Commit 7b8f76e

Browse files
authored
Merge pull request swiftlang#73007 from xedin/promote-dynamic-actor-isolation-to-upcoming-feature
[SE-0423] Promote `DynamicActorIsolation` to an upcoming feature and add a way to disable checks
2 parents fb2f49c + 72eb8ab commit 7b8f76e

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
@@ -5697,8 +5697,6 @@ ERROR(preconcurrency_not_inheritance_clause,none,
56975697
"'preconcurrency' attribute only applies in inheritance clauses", ())
56985698
ERROR(preconcurrency_not_existential,none,
56995699
"'preconcurrency' attribute cannot apply to non-protocol type %0", (Type))
5700-
ERROR(preconcurrency_attr_disabled,none,
5701-
"attribute requires '-enable-experimental-feature DynamicActorIsolation'", ())
57025700

57035701
ERROR(redundant_any_in_existential,none,
57045702
"redundant 'any' in type %0",

include/swift/Basic/Features.def

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

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

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

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
@@ -645,29 +645,7 @@ static bool usesFeatureTransferringArgsAndResults(Decl *decl) {
645645
return false;
646646
}
647647

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

672650
UNINTERESTING_FEATURE(BorrowingSwitch)
673651

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
@@ -1535,6 +1535,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
15351535
}
15361536
}
15371537

1538+
Opts.DisableDynamicActorIsolation |=
1539+
Args.hasArg(OPT_disable_dynamic_actor_isolation);
1540+
15381541
#if SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
15391542
/// Enable round trip parsing via the new swift parser unless it is disabled
15401543
/// 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)