Skip to content

Commit 06dc593

Browse files
authored
Merge pull request #35264 from DougGregor/concurrent-value-protocol
[Concurrency] Introduce "ConcurrentValue" protocol and checking.
2 parents 7223692 + 6fa673d commit 06dc593

File tree

82 files changed

+1130
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1130
-120
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4305,6 +4305,32 @@ 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+
WARNING(non_concurrent_function_type,none,
4319+
"`@concurrent` %select{function type|closure}0 has "
4320+
"non-concurrent-value %select{parameter|result}1 type %2",
4321+
(bool, bool, Type))
4322+
ERROR(non_concurrent_type_member,none,
4323+
"%select{stored property %1|associated value %1}0 of "
4324+
"'ConcurrentValue'-conforming %2 %3 has non-concurrent-value type %4",
4325+
(bool, DeclName, DescriptiveDeclKind, DeclName, Type))
4326+
ERROR(concurrent_value_class_mutable_property,none,
4327+
"stored property %0 of 'ConcurrentValue'-conforming %1 %2 is mutable",
4328+
(DeclName, DescriptiveDeclKind, DeclName))
4329+
ERROR(concurrent_value_outside_source_file,none,
4330+
"conformance 'ConcurrentValue' must occur in the same source file as "
4331+
"%0 %1; use 'UnsafeConcurrentValue' for retroactive conformance",
4332+
(DescriptiveDeclKind, DeclName))
4333+
43084334
ERROR(actorindependent_let,none,
43094335
"'@actorIndependent' is meaningless on 'let' declarations because "
43104336
"they are immutable",

include/swift/AST/KnownProtocols.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ PROTOCOL(CodingKey)
8080
PROTOCOL(Encodable)
8181
PROTOCOL(Decodable)
8282

83+
PROTOCOL(ConcurrentValue)
84+
PROTOCOL(UnsafeConcurrentValue)
85+
8386
PROTOCOL_(ObjectiveCBridgeable)
8487
PROTOCOL_(DestructorSafeContainer)
8588

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);

lib/IRGen/GenMeta.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5138,6 +5138,8 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
51385138
case KnownProtocolKind::Differentiable:
51395139
case KnownProtocolKind::FloatingPoint:
51405140
case KnownProtocolKind::Actor:
5141+
case KnownProtocolKind::ConcurrentValue:
5142+
case KnownProtocolKind::UnsafeConcurrentValue:
51415143
return SpecialProtocol::None;
51425144
}
51435145

lib/Sema/TypeCheckAttr.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
128128
IGNORED_ATTR(OriginallyDefinedIn)
129129
IGNORED_ATTR(NoDerivative)
130130
IGNORED_ATTR(SpecializeExtension)
131-
IGNORED_ATTR(Concurrent)
132131
#undef IGNORED_ATTR
133132

134133
void visitAlignmentAttr(AlignmentAttr *attr) {
@@ -420,6 +419,22 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
420419
}
421420
}
422421
}
422+
423+
void visitConcurrentAttr(ConcurrentAttr *attr) {
424+
auto VD = dyn_cast<ValueDecl>(D);
425+
if (!VD)
426+
return;
427+
428+
auto innermostDC = VD->getInnermostDeclContext();
429+
SubstitutionMap subs;
430+
if (auto genericEnv = innermostDC->getGenericEnvironmentOfContext()) {
431+
subs = genericEnv->getForwardingSubstitutionMap();
432+
}
433+
434+
(void)diagnoseNonConcurrentTypesInReference(
435+
ConcreteDeclRef(VD, subs), innermostDC, VD->getLoc(),
436+
ConcurrentReferenceKind::ConcurrentFunction);
437+
}
423438
};
424439
} // end anonymous namespace
425440

0 commit comments

Comments
 (0)