-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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 method accessors #40270
Conversation
9afd36c
to
bae23b0
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.
Can you add an IRGen test that checks that we emit the distributed thunk, the underlying function , and the remote accessor? And check that the remote accessor calls the distributed thunk.
@aschwaighofer Yeah, that's the next step for me here, adding IRGen tests for combinations of arguments/result to make sure that everything is generated correctly. Just wanted to figure out whether I'm on the right track here before I continue... |
Ok. This looks good to me |
f3a99bf
to
febe80f
Compare
distributed func complex(_: [Int], _: Obj, _: String?, _: LargeStruct) -> LargeStruct { | ||
fatalError() | ||
} | ||
} |
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.
@DougGregor and @aschwaighofer Please take a look and let me know what else would be useful to add for the initial concrete-type only implementation. What ever it is has to be able to conform to Codable though...
1fe2207
to
06f8315
Compare
06f8315
to
dd3bd6d
Compare
@swift-ci please clean test |
@swift-ci please clean test macOS platform |
@swift-ci please clean test macOS platform |
Build failed |
@swift-ci please clean test macOS platform |
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.
Build failed |
Build failed |
@swift-ci please clean 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.
I was reviewing this but don't have much to add other than that it looks good and I hope to connect it all up shortly :-)
|
||
SWIFT_RUNTIME_STDLIB_SPI const AccessibleFunctionRecord * | ||
swift_findAccessibleFunction(const char *targetNameStart, | ||
size_t targetNameLength); |
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.
Ok... so this is good since it just says "name" and not exactly what shape of name it is (mangled, or just full name of the base etc). I remain a little worried worried about how we'll know what name to register methods under (today we do mangled names, but what if we want to do the other scheme -- we'd have to annotate methods I guess), but I guess it'll work out since we'd need annotations for the other scheme anyway perhaps 🤔
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.
We might use flags to detect new scheme of naming if we switch to something other than mangled names.
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.
My worry is about both "sides" having to use the same scheme so they'd have to be compiled using the same flags, but I guess that's just what we'll live with 🤔
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, that's the unfortunate reality of the situation.
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.
Heh yeah... that's what I kept bringing up as "we change it later" being a problem... so we'll be forever stuck emitting the mangled type names as identifiers, and may be able to–in addition to those–add some shorter names... Unless we know "all sides" of the peers and can decide on a scheme to use with a compilation flag... I guess there's ways out of this corner but it'll be annoying :-/
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, I think if we just wanted to drop all of the type information then it would be pretty easy to handle at runtime because we could just read mangled name from the record, remove the type information and match against the name provided by the caller. We'd only have to do that transformation once per method and cache it, but for other schemes it would be tricker.
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.
Hmmm, I wonder if we could get away with recording using the "full name" and then compare the mangled name if we have it to disambiguate any potential stores with the same name... 🤔
Not a blocker for merging this, but just something to continue thinking about :-)
addUsedGlobal(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.
Very cool 👍
Build failed |
Instead of using the distributed method directly, let's always call distributed thunk instead which is safe option because actor could not be local (e.g. issue with routing) but only distributed thunk would know that and take appropriate action.
…tive schema If parameter type's size is `0` then we don't want to perform a load at the current position in the buffer and have to move to the next non-empty element.
… the last element
…sors Test multiple scenarios - value types, reference types, optionals, arrays, direct and indirect returns.
A "accessible" function that can be looked up based on a string key, and then called through a fully-abstracted entry point whose arguments can be constructed in code.
Uses a dedicated section in the binary to emit records about functions that can be looked up by name at the runtime, and then called through a fully-abstracted entry point whose arguments can be constructed in code.
…g to load If underlying function does not have any parameter, then let's exit early and avoid stack allocating the argument buffer cursor.
`findAccessibleFunction` has to be accessible from Concurrency and Distributed modules to be able to lookup distributed accessors.
…ssor Direct pointer to the accessor cannot be called at runtime, so here is how everything is stored: - For `distributed` and `async` functions -> async function pointer; - For regular functions -> function pointer.
The implementation is as follows: - Looks up distributed accessor by the given target name - Extracts information required to setup async context from async function pointer stored in accessor record - Allocates context and calls accessor
…lt into a provided buffer Instead of trying to return result from distributed thunk directly, modify accessor to store result into the caller-provided buffer. Doing so helps us avoid boxing the result into `Any`.
…et` from `DistributedActor.swift` The function should be (and is) declared in `DistributedActorSystem.swift`
…` instead of `Transport`
It's incorrect to load from the pointer directly, instead accessor should use `loadAsCopy` for loadable types.
…ave correct ownership Use parameter convention information to determine ownership of the extracted arguments.
I don't have access to Windows machine so there is no way for me to debug and fix them.
ede5448
to
d6d9b55
Compare
@swift-ci please clean 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.
lgtm
Make it possible to reach and call distributed methods via runtime mechanism
that would look them up by originating method name at runtime and apply with
the given arguments.