diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index daac2fcd0caa..9e21ad0bbd2a 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -376,7 +376,7 @@ bool conflicting(ASTContext &ctx, /// The kind of special compiler synthesized property in a \c distributed actor, /// currently this includes \c id and \c actorSystem. -enum class SpecialDistributedProperty { +enum class SpecialDistributedActorProperty { Id, ActorSystem }; @@ -3065,8 +3065,8 @@ class ValueDecl : public Decl { /// Whether this is the special synthesized 'id' or 'actorSystem' property /// of a distributed actor. If \p onlyCheckName is set, then any /// matching user-defined property with the name is also considered. - std::optional - isSpecialDistributedProperty(bool onlyCheckName = false) const; + std::optional + isSpecialDistributedActorProperty(bool onlyCheckName = false) const; bool hasName() const { return bool(Name); } bool isOperator() const { return Name.isOperator(); } diff --git a/lib/AST/DistributedDecl.cpp b/lib/AST/DistributedDecl.cpp index 97437413869f..791f2920a728 100644 --- a/lib/AST/DistributedDecl.cpp +++ b/lib/AST/DistributedDecl.cpp @@ -1358,20 +1358,20 @@ bool ValueDecl::isDistributedGetAccessor() const { return false; } -std::optional -ValueDecl::isSpecialDistributedProperty(bool onlyCheckName) const { +std::optional +ValueDecl::isSpecialDistributedActorProperty(bool onlyCheckName) const { if (!isa(this)) return std::nullopt; auto *DC = getDeclContext(); auto &ctx = DC->getASTContext(); - auto kind = [&]() -> std::optional { + auto kind = [&]() -> std::optional { auto name = getName(); if (name.isSimpleName(ctx.Id_id)) - return SpecialDistributedProperty::Id; + return SpecialDistributedActorProperty::Id; if (name.isSimpleName(ctx.Id_actorSystem)) - return SpecialDistributedProperty::ActorSystem; + return SpecialDistributedActorProperty::ActorSystem; return std::nullopt; }(); diff --git a/lib/SILGen/SILGenDestructor.cpp b/lib/SILGen/SILGenDestructor.cpp index d80309d21a61..09a5f7bccacc 100644 --- a/lib/SILGen/SILGenDestructor.cpp +++ b/lib/SILGen/SILGenDestructor.cpp @@ -58,8 +58,6 @@ void SILGenFunction::emitDistributedRemoteActorDeinit( auto cleanupLoc = CleanupLocation(loc); - auto &C = cd->getASTContext(); - { FullExpr CleanupScope(Cleanups, cleanupLoc); ManagedValue borrowedSelf = emitManagedBeginBorrow(loc, selfValue); @@ -74,7 +72,7 @@ void SILGenFunction::emitDistributedRemoteActorDeinit( continue; // Just to double-check, we only want to destroy `id` and `actorSystem` - if (vd->isSpecialDistributedProperty()) + if (vd->isSpecialDistributedActorProperty()) destroyClassMember(cleanupLoc, borrowedSelf, vd); } diff --git a/lib/Sema/AssociatedTypeInference.cpp b/lib/Sema/AssociatedTypeInference.cpp index 407d22e48396..c473d251dd07 100644 --- a/lib/Sema/AssociatedTypeInference.cpp +++ b/lib/Sema/AssociatedTypeInference.cpp @@ -1661,7 +1661,7 @@ AssociatedTypeInference::getPotentialTypeWitnessesFromRequirement( // witnesses already being resolved. if (auto *nominal = dc->getSelfNominalTypeDecl()) { if (nominal->isDistributedActor() && - req->isSpecialDistributedProperty(/*onlyCheckName*/ true)) { + req->isSpecialDistributedActorProperty(/*onlyCheckName*/ true)) { LLVM_DEBUG(llvm::dbgs() << "skipping special distributed property\n"); return {}; } diff --git a/lib/Sema/CodeSynthesisDistributedActor.cpp b/lib/Sema/CodeSynthesisDistributedActor.cpp index 2ee00b12efdd..6ce5bbd14935 100644 --- a/lib/Sema/CodeSynthesisDistributedActor.cpp +++ b/lib/Sema/CodeSynthesisDistributedActor.cpp @@ -842,6 +842,10 @@ GetDistributedActorIDPropertyRequest::evaluate(Evaluator &evaluator, propDecl->setSynthesized(); propDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true); + // NOTE: The type for this property is lazily computed by + // `getLazilySynthesizedPattern` when type-checking, which ensures this + // request does not trigger any semantic requests since it's called by name + // lookup. Pattern *propPat = NamedPattern::createImplicit(C, propDecl); PatternBindingDecl *pbDecl = PatternBindingDecl::createImplicit( @@ -891,6 +895,10 @@ VarDecl *GetDistributedActorSystemPropertyRequest::evaluate( propDecl->setSynthesized(); propDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true); + // NOTE: The type for this property is lazily computed by + // `getLazilySynthesizedPattern` when type-checking, which ensures this + // request does not trigger any semantic requests since it's called by name + // lookup. Pattern *propPat = NamedPattern::createImplicit(C, propDecl); PatternBindingDecl *pbDecl = PatternBindingDecl::createImplicit( diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index 24538a19b4b9..aeb709869096 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -7852,7 +7852,7 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) { // The synthesized "id" and "actorSystem" are the only exceptions, // because the implementation mirrors them. if (nominal->isDistributedActor() && - !var->isSpecialDistributedProperty()) { + !var->isSpecialDistributedActorProperty()) { diagnoseAndRemoveAttr(attr, diag::nonisolated_distributed_actor_storage); return; diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 7d97e4338802..caa3bf87a9b8 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -2948,7 +2948,7 @@ static ArrayRef evaluateMembersRequest( // be in a specific order that is different from ordering by their // mangled name, so preserve the order // they were added in. - if (vd->isSynthesized() && !vd->isSpecialDistributedProperty()) { + if (vd->isSynthesized() && !vd->isSpecialDistributedActorProperty()) { synthesizedMembers.add(vd); return; } diff --git a/lib/Sema/TypeCheckDeclPrimary.cpp b/lib/Sema/TypeCheckDeclPrimary.cpp index 18da63315300..43b4c5754800 100644 --- a/lib/Sema/TypeCheckDeclPrimary.cpp +++ b/lib/Sema/TypeCheckDeclPrimary.cpp @@ -1065,7 +1065,7 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current, }); } auto *conflictDecl = current == declToDiagnose ? other : current; - if (conflictDecl->isSpecialDistributedProperty()) { + if (conflictDecl->isSpecialDistributedActorProperty()) { declToDiagnose->diagnose( diag::distributed_actor_user_defined_special_property, other->getName()); diff --git a/lib/Sema/TypeCheckStorage.cpp b/lib/Sema/TypeCheckStorage.cpp index abee23507a82..af255d6792e3 100644 --- a/lib/Sema/TypeCheckStorage.cpp +++ b/lib/Sema/TypeCheckStorage.cpp @@ -390,13 +390,13 @@ MemberwiseInitPropertiesRequest::evaluate(Evaluator &evaluator, static Type getLazyInterfaceTypeForSynthesizedVar(VarDecl *var) { // For DistributedActor, the `id` and `actorSystem` properties have their // types computed lazily. - if (auto distPropKind = var->isSpecialDistributedProperty()) { + if (auto distPropKind = var->isSpecialDistributedActorProperty()) { auto *NTD = var->getDeclContext()->getSelfNominalTypeDecl(); ASSERT(NTD); switch (distPropKind.value()) { - case SpecialDistributedProperty::Id: + case SpecialDistributedActorProperty::Id: return getDistributedActorIDType(NTD); - case SpecialDistributedProperty::ActorSystem: + case SpecialDistributedActorProperty::ActorSystem: return getDistributedActorSystemType(NTD); } llvm_unreachable("Unhandled case in switch!"); diff --git a/test/Distributed/rdar162800185.swift b/test/Distributed/rdar162800185.swift index 8d8e276b65eb..1624791c1b1c 100644 --- a/test/Distributed/rdar162800185.swift +++ b/test/Distributed/rdar162800185.swift @@ -2,9 +2,9 @@ // RUN: split-file %s %t // Make sure we can resolve the conformance to DistributedActor from a secondary. -// RUN: %target-swift-frontend -c -module-name main -target %target-swift-5.7-abi-triple %t/a.swift %t/b.swift -o %/tmp -// RUN: %target-swift-frontend -c -module-name main -target %target-swift-5.7-abi-triple -primary-file %t/a.swift %t/b.swift -o %/tmp -// RUN: %target-swift-frontend -c -module-name main -target %target-swift-5.7-abi-triple %t/a.swift -primary-file %t/b.swift -o %/tmp +// RUN: %target-swift-frontend -c -module-name main -target %target-swift-5.7-abi-triple %t/a.swift %t/b.swift -o %t/out.o +// RUN: %target-swift-frontend -c -module-name main -target %target-swift-5.7-abi-triple -primary-file %t/a.swift %t/b.swift -o %t/out.o +// RUN: %target-swift-frontend -c -module-name main -target %target-swift-5.7-abi-triple %t/a.swift -primary-file %t/b.swift -o %t/out.o // REQUIRES: concurrency // REQUIRES: distributed