1515// ===----------------------------------------------------------------------===//
1616
1717#include " swift/AST/DistributedDecl.h"
18- #include " swift/AST/AccessRequests.h"
19- #include " swift/AST/AccessScope.h"
2018#include " swift/AST/ASTContext.h"
21- #include " swift/AST/ASTWalker.h"
2219#include " swift/AST/ASTMangler.h"
20+ #include " swift/AST/ASTWalker.h"
21+ #include " swift/AST/AccessRequests.h"
22+ #include " swift/AST/AccessScope.h"
2323#include " swift/AST/ConformanceLookup.h"
24+ #include " swift/AST/DiagnosticsSema.h"
2425#include " swift/AST/ExistentialLayout.h"
2526#include " swift/AST/Expr.h"
2627#include " swift/AST/ForeignAsyncConvention.h"
2930#include " swift/AST/GenericSignature.h"
3031#include " swift/AST/Initializer.h"
3132#include " swift/AST/LazyResolver.h"
32- #include " swift/AST/ASTMangler.h"
3333#include " swift/AST/Module.h"
3434#include " swift/AST/NameLookup.h"
3535#include " swift/AST/NameLookupRequests.h"
3939#include " swift/AST/ResilienceExpansion.h"
4040#include " swift/AST/SourceFile.h"
4141#include " swift/AST/Stmt.h"
42- #include " swift/AST/TypeCheckRequests.h"
4342#include " swift/AST/SwiftNameTranslation.h"
43+ #include " swift/AST/TypeCheckRequests.h"
4444#include " swift/Basic/Assertions.h"
45+ #include " swift/Basic/StringExtras.h"
4546#include " swift/ClangImporter/ClangModule.h"
4647#include " swift/Parse/Lexer.h" // FIXME: Bad dependency
4748#include " clang/Lex/MacroInfo.h"
5152#include " llvm/ADT/Statistic.h"
5253#include " llvm/Support/Compiler.h"
5354#include " llvm/Support/raw_ostream.h"
54- #include " swift/Basic/StringExtras.h"
5555
5656#include " clang/Basic/CharInfo.h"
5757#include " clang/Basic/Module.h"
@@ -198,7 +198,7 @@ Type swift::getDistributedActorSystemType(NominalTypeDecl *actor) {
198198
199199 auto DA = C.getDistributedActorDecl ();
200200 if (!DA)
201- return ErrorType::get (C); // FIXME(distributed): just use Type()
201+ return ErrorType::get (C);
202202
203203 // Dig out the actor system type.
204204 Type selfType = actor->getSelfInterfaceType ();
@@ -229,17 +229,16 @@ Type swift::getDistributedActorSerializationType(
229229 auto resultTy = getAssociatedTypeOfDistributedSystemOfActor (
230230 actorOrExtension,
231231 ctx.Id_SerializationRequirement );
232+ if (resultTy->hasError ())
233+ return resultTy;
232234
233235 // Protocols are allowed to either not provide a `SerializationRequirement`
234236 // at all or provide it in a conformance requirement.
235- if ((! resultTy || resultTy ->hasDependentMember () ) &&
237+ if (resultTy->hasDependentMember () &&
236238 actorOrExtension->getSelfProtocolDecl ()) {
237239 auto sig = actorOrExtension->getGenericSignatureOfContext ();
238240
239241 auto actorProtocol = ctx.getProtocol (KnownProtocolKind::DistributedActor);
240- if (!actorProtocol)
241- return Type ();
242-
243242 auto serializationTy =
244243 actorProtocol->getAssociatedType (ctx.Id_SerializationRequirement )
245244 ->getDeclaredInterfaceType ();
@@ -331,29 +330,40 @@ swift::getAssociatedDistributedInvocationDecoderDecodeNextArgumentFunction(
331330Type swift::getAssociatedTypeOfDistributedSystemOfActor (
332331 DeclContext *actorOrExtension, Identifier member) {
333332 auto &ctx = actorOrExtension->getASTContext ();
333+ auto getLoc = [&]() { return extractNearestSourceLoc (actorOrExtension); };
334334
335335 auto actorProtocol = ctx.getProtocol (KnownProtocolKind::DistributedActor);
336- if (!actorProtocol)
337- return Type ();
336+ if (!actorProtocol) {
337+ ctx.Diags .diagnose (getLoc (), diag::broken_stdlib_type, " DistributedActor" );
338+ return ErrorType::get (ctx);
339+ }
338340
339341 AssociatedTypeDecl *actorSystemDecl =
340342 actorProtocol->getAssociatedType (ctx.Id_ActorSystem );
341- if (!actorSystemDecl)
342- return Type ();
343+ if (!actorSystemDecl) {
344+ ctx.Diags .diagnose (getLoc (), diag::broken_distributed_actor_requirement);
345+ return ErrorType::get (ctx);
346+ }
343347
344348 auto actorSystemProtocol = ctx.getDistributedActorSystemDecl ();
345- if (!actorSystemProtocol)
346- return Type ();
349+ if (!actorSystemProtocol) {
350+ ctx.Diags .diagnose (getLoc (), diag::broken_stdlib_type,
351+ " DistributedActorSystem" );
352+ return ErrorType::get (ctx);
353+ }
347354
348355 AssociatedTypeDecl *memberTypeDecl =
349356 actorSystemProtocol->getAssociatedType (member);
350- if (!memberTypeDecl)
351- return Type ();
357+ if (!memberTypeDecl) {
358+ ctx.Diags .diagnose (getLoc (),
359+ diag::broken_distributed_actor_system_requirement);
360+ return ErrorType::get (ctx);
361+ }
352362
353363 Type memberTy = DependentMemberType::get (
354- DependentMemberType::get (actorProtocol->getSelfInterfaceType (),
355- actorSystemDecl),
356- memberTypeDecl);
364+ DependentMemberType::get (actorProtocol->getSelfInterfaceType (),
365+ actorSystemDecl),
366+ memberTypeDecl);
357367
358368 auto sig = actorOrExtension->getGenericSignatureOfContext ();
359369
@@ -365,7 +375,7 @@ Type swift::getAssociatedTypeOfDistributedSystemOfActor(
365375 lookupConformance (
366376 actorType->getDeclaredInterfaceType (), actorProtocol);
367377 if (actorConformance.isInvalid ())
368- return Type ( );
378+ return ErrorType::get (ctx );
369379
370380 auto subs = SubstitutionMap::getProtocolSubstitutions (actorConformance);
371381
@@ -432,11 +442,7 @@ swift::getDistributedSerializationRequirements(
432442}
433443
434444bool swift::checkDistributedSerializationRequirementIsExactlyCodable (
435- ASTContext &C,
436- Type type) {
437- if (!type)
438- return false ;
439-
445+ ASTContext &C, Type type) {
440446 if (type->hasError ())
441447 return false ;
442448
@@ -1352,6 +1358,42 @@ bool ValueDecl::isDistributedGetAccessor() const {
13521358 return false ;
13531359}
13541360
1361+ std::optional<SpecialDistributedProperty>
1362+ ValueDecl::isSpecialDistributedProperty (bool onlyCheckName) const {
1363+ if (!isa<VarDecl>(this ))
1364+ return std::nullopt ;
1365+
1366+ auto *DC = getDeclContext ();
1367+ auto &ctx = DC->getASTContext ();
1368+
1369+ auto kind = [&]() -> std::optional<SpecialDistributedProperty> {
1370+ auto name = getName ();
1371+ if (name.isSimpleName (ctx.Id_id ))
1372+ return SpecialDistributedProperty::Id;
1373+ if (name.isSimpleName (ctx.Id_actorSystem ))
1374+ return SpecialDistributedProperty::ActorSystem;
1375+
1376+ return std::nullopt ;
1377+ }();
1378+ if (!kind || onlyCheckName)
1379+ return kind;
1380+
1381+ // The properties can only be synthesized in the nominal itself.
1382+ auto *CD = dyn_cast<ClassDecl>(DC);
1383+ if (!CD || !CD->isDistributedActor ())
1384+ return std::nullopt ;
1385+
1386+ // The synthesized bit doesn't get preserved by serialization or module
1387+ // interfaces, we only need to check it when compiling a SourceFile though
1388+ // since we'll diagnose any conflicting user-defined versions.
1389+ if (!isSynthesized () && DC->getParentSourceFile () &&
1390+ !DC->isInSwiftinterface ()) {
1391+ return std::nullopt ;
1392+ }
1393+
1394+ return kind;
1395+ }
1396+
13551397ConstructorDecl *
13561398NominalTypeDecl::getDistributedRemoteCallTargetInitFunction () const {
13571399 auto mutableThis = const_cast <NominalTypeDecl *>(this );
0 commit comments