-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Distributed] Implement distributed computed properties via special accessor #59700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Distributed] Implement distributed computed properties via special accessor #59700
Conversation
@DougGregor and @ktoso this is still a draft but it's functional. I'd probably need to cherry-pick some of the changes from original implementation to make it complete. Please let me know what you think. |
97d1f15
to
c0cea20
Compare
ff3c70f
to
b9a616d
Compare
|
||
/// The access is to a computed distributed property, and thus the | ||
/// get-accessor is a distributed thunk which may perform a remote call. | ||
DispatchToDistributedThunk, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
b9a616d
to
f67b09f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Though needs a @DougGregor review as well to see if it looks good now :)
@swift-ci please test |
@swift-ci please test Linux platform |
Cherry picked it over: #59774 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned about the mangling, but the rest is polish.
include/swift/AST/Attr.def
Outdated
@@ -735,6 +735,12 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(_local, KnownToBeLocal, | |||
APIBreakingToAdd | APIBreakingToRemove, | |||
130) | |||
|
|||
SIMPLE_DECL_ATTR(_distributed_thunk, DistributedThunk, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an attribute rather than a bit on the Decl? It'll never be user-spelled, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, cannot be spelled. It could be an attribute on the decl, wasn't sure which one is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to use a bit in the declaration and changed serialization accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
GetDistributedThunkRequest, | ||
FuncDecl *(llvm::PointerUnion<VarDecl *, AbstractFunctionDecl *>), | ||
RequestFlags::Cached> { | ||
using Originator = llvm::PointerUnion<VarDecl *, AbstractFunctionDecl *>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we'll be replacing VarDecl
with AbstractStorageDecl
to get subscripts at some point :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generalized Originator
to accept AbstractStorageDecl
and AbstractFunctionDecl
.
lib/AST/ASTMangler.cpp
Outdated
appendContextOf(decl); | ||
appendDeclName(accessor->getStorage()); | ||
appendDeclType(accessor, FunctionMangling); | ||
appendOperator("F"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mangling changes need to update docs/ABI/Mangling.rst
, the demangler, the remanglers, and add a test (e.g., in test/Demangle/Inputs/manglings.txt
) to make sure the whole round-trip works. Also, is F
here actually unused? I would have expected that the ACCESSOR
production would be extended for this case, so distributed thunks would go through appendAccessorEntity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Distributed thunk accessors are mangled the same way as distributed funcs because runtime needs a function type, if we want to add a new mangling for accessor thunks we'd need to rework a runtime aspects of remote calls. I'm going to add a comment here explaining this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment about this.
lib/Sema/TypeCheckConcurrency.cpp
Outdated
// which are allowed, but subject to the same implicit throws/async | ||
// as all other distributed function declarations. | ||
if (var->isDistributed()) { | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This surprises me, and I don't think we should make this change here. varIsSafeAcrossActors
is meant to mean "you can access this without hopping to the actor", which is not the case for distributed properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ktoso I removed the check because as Doug mentioned it doesn't seem correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right that seemed wrong -- thank you!
lib/Sema/TypeCheckConcurrency.cpp
Outdated
.fixItInsert(decl->getAttributeInsertionLoc(true), "distributed "); | ||
// Cannot reference subscripts, or stored properties. | ||
auto var = dyn_cast<VarDecl>(decl); | ||
if (isa<SubscriptDecl>(decl) || var) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rewritten logic here silently accepts declaration kinds it doesn't understand. I'm not sure if I can trigger a bug based on this, but the prior formulation (!func || !func->isDistributed()
) was more robust. Can we use more straightforward logic here like:
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
handle funcs and return
}
if (auto var = dyn_cast<VarDecl>(decl)) {
handle vars and return
}
diagnose and return None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
`DistributedThunk` is to be used while accessing 'distributed' computed property outside of its actor context.
This strategy is used to dispatch accesses to 'distributed' computed property to distributed thunk accessor instead of a regular getter when access happen outside actor isolation context.
The flag is used to distinguish between regular functions/accessors and synthesized distributed thunks.
… computed properties
…uted thunks Distributed thunks have to refer to the "local" version of the property directly with implicit `self.` base.
…Decl` One step towards future distributed subscripts.
Only distributed functions and computed properties should be accepted, everything else is invalid.
f67b09f
to
d9a0130
Compare
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
@swift-ci please test |
// appendOperator("F"); | ||
// appendSymbolKind(SymbolKind::DistributedThunk); | ||
// return finalize(); | ||
// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the TODO, that's on me after we fixed the SILDeclRefs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no worries!
It used to be an accessor but that is not required because SILDeclRef controls mangling which is the most imprortant and could be used to emit the right reference.
ac582b2
to
2480c99
Compare
@swift-ci please test |
I'll cherry pick it over to 5.7 👍 |
@swift-ci please test Windows platform |
This is an alternative implementation of distributed computed properties that introduces
a new
DistributedThunk
accessor kind, new access strategy, and semantics.A reference to a getter of a distributed computed property is transparently replaced by
its thunk during SILGen (the semantics are the same for both distributed methods and
distributed computed properties).
rdar://91283164