Skip to content

Commit 866a8d8

Browse files
committed
Introduce checking for ConcurrentValue conformance across actors.
When referring to an actor-isolated declaration from outside of the actor, ensure that the types involved conform to the `ConcurrentValue` protocol. Otherwise, produce a diagnostic stating that it is unsafe to pass such types across actors. Apply the same rule to local captures within concurrent code.
1 parent a632118 commit 866a8d8

File tree

14 files changed

+654
-68
lines changed

14 files changed

+654
-68
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4305,6 +4305,17 @@ ERROR(global_actor_isolated_requirement_witness_conflict,none,
43054305
"requirement from protocol %3 isolated to global actor %4",
43064306
(DescriptiveDeclKind, DeclName, Type, Identifier, Type))
43074307

4308+
WARNING(non_concurrent_param_type,none,
4309+
"cannot pass argument of non-concurrent-value type %0 across actors",
4310+
(Type))
4311+
WARNING(non_concurrent_result_type,none,
4312+
"cannot call function returning non-concurrent-value type %0 across "
4313+
"actors", (Type))
4314+
WARNING(non_concurrent_property_type,none,
4315+
"cannot use %0 %1 with a non-concurrent-value type %2 "
4316+
"%select{across actors|from concurrently-executed code}3",
4317+
(DescriptiveDeclKind, DeclName, Type, bool))
4318+
43084319
ERROR(actorindependent_let,none,
43094320
"'@actorIndependent' is meaningless on 'let' declarations because "
43104321
"they are immutable",

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ namespace swift {
244244
/// Enable experimental concurrency model.
245245
bool EnableExperimentalConcurrency = false;
246246

247+
/// Enable experimental ConcurrentValue checking.
248+
bool EnableExperimentalConcurrentValueChecking = false;
249+
247250
/// Disable the implicit import of the _Concurrency module.
248251
bool DisableImplicitConcurrencyModuleImport = false;
249252

include/swift/Option/FrontendOptions.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,12 @@ let Flags = [FrontendOption, NoDriverOption, HelpHidden, ModuleInterfaceOption]
221221
def enable_experimental_concurrency :
222222
Flag<["-"], "enable-experimental-concurrency">,
223223
HelpText<"Enable experimental concurrency model">;
224-
def enable_resilience : Flag<["-"], "enable-resilience">,
224+
225+
def enable_experimental_concurrent_value_checking :
226+
Flag<["-"], "enable-experimental-concurrent-value-checking">,
227+
HelpText<"Enable ConcurrentValue checking">;
228+
229+
def enable_resilience : Flag<["-"], "enable-resilience">,
225230
HelpText<"Deprecated, use -enable-library-evolution instead">;
226231
}
227232

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
385385

386386
Opts.EnableExperimentalConcurrency |=
387387
Args.hasArg(OPT_enable_experimental_concurrency);
388+
Opts.EnableExperimentalConcurrentValueChecking |=
389+
Args.hasArg(OPT_enable_experimental_concurrent_value_checking);
388390

389391
Opts.DisableImplicitConcurrencyModuleImport |=
390392
Args.hasArg(OPT_disable_implicit_concurrency_module_import);

0 commit comments

Comments
 (0)