Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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<SpecialDistributedProperty>
isSpecialDistributedProperty(bool onlyCheckName = false) const;
std::optional<SpecialDistributedActorProperty>
isSpecialDistributedActorProperty(bool onlyCheckName = false) const;

bool hasName() const { return bool(Name); }
bool isOperator() const { return Name.isOperator(); }
Expand Down
10 changes: 5 additions & 5 deletions lib/AST/DistributedDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,20 +1358,20 @@ bool ValueDecl::isDistributedGetAccessor() const {
return false;
}

std::optional<SpecialDistributedProperty>
ValueDecl::isSpecialDistributedProperty(bool onlyCheckName) const {
std::optional<SpecialDistributedActorProperty>
ValueDecl::isSpecialDistributedActorProperty(bool onlyCheckName) const {
if (!isa<VarDecl>(this))
return std::nullopt;

auto *DC = getDeclContext();
auto &ctx = DC->getASTContext();

auto kind = [&]() -> std::optional<SpecialDistributedProperty> {
auto kind = [&]() -> std::optional<SpecialDistributedActorProperty> {
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;
}();
Expand Down
4 changes: 1 addition & 3 deletions lib/SILGen/SILGenDestructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ void SILGenFunction::emitDistributedRemoteActorDeinit(

auto cleanupLoc = CleanupLocation(loc);

auto &C = cd->getASTContext();

{
FullExpr CleanupScope(Cleanups, cleanupLoc);
ManagedValue borrowedSelf = emitManagedBeginBorrow(loc, selfValue);
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/AssociatedTypeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Expand Down
8 changes: 8 additions & 0 deletions lib/Sema/CodeSynthesisDistributedActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2948,7 +2948,7 @@ static ArrayRef<Decl *> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/TypeCheckStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
6 changes: 3 additions & 3 deletions test/Distributed/rdar162800185.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down