Skip to content

[Distributed] Remove @_dynamic replacements; impl remoteCall ad-hoc reqs #41036

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

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Jan 27, 2022

This gets rid of the dynamic member replacement mechanism for remote calls completely -- meaning... we don't need source generators anymore!

Remote calls are performed via synthesized SIL thunks which record call representations using an Encoder type. This is then passed to an ad-hoc protocol requirement "remoteCall" which is able to perform the call. This is a huge improvement in how actor systems can be developed and also an increase in expressive power -- we can express and call generic methods, support property wrappers on parameters and also potentially carry any additional information about the called functions with new record methods if we ever need to.

The SILGenDistributed emission is quite messy still but I will continue working on cleaning it up in the coming days.
We will also cleanup and use more of SerializationRequirement which today is hardcoded a little bit still -- pending changes that we accepted in SE-0336

Squashed commit of the following:

commit e5a05ff
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Thu Jan 27 17:45:31 2022 +0900

    cleanup

commit 1f751ce
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Thu Jan 27 14:50:33 2022 +0900

    cleanups

commit c632f32
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Thu Jan 27 14:01:09 2022 +0900

    add test for generic from actor decl

commit 09b8bd5
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Thu Jan 27 14:00:58 2022 +0900

    cleanups

commit 31f4d0c
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Thu Jan 27 11:40:51 2022 +0900

    fix test

commit ad4db2f
Merge: 97227ed 07e2dfd
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 26 23:31:41 2022 +0900

    Merge branch 'main' into wip-zzz

commit 97227ed
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 26 21:01:25 2022 +0900

    remove @_dynamic methods!

    fix tests

commit 1c79344
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 19 12:51:09 2022 +0900

    cleanup

    wip

    stuck

    fixed the stack cleanups

    cleanups pretty good now

    weird load

    rki

    works

    remove hack

    add take + throw + return

    fix test

    more tests fixed

    more tests fixed

    more tests fixed

commit 3ed494c
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Tue Jan 18 21:09:28 2022 +0900

    stack issues in SIL verification

commit 5cf43a7
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Tue Jan 18 09:19:51 2022 +0900

    about to call the remoteCall

    goot to return, but missing subs

commit df8e471
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Thu Jan 13 14:09:49 2022 +0900

    [Distributed] Refactor Invocation to Decoder/Encoder

    getting there

    done-recording

    working on the string init

    stuck trying to get String initializer SILFunction

    created the remote call target

commit fc7bd62
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 12 23:01:14 2022 +0900

    [Distributed] Pass arguments from Invocation to HBuffer

commit cafc2cc
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 12 22:08:47 2022 +0900

    works

commit a7d0183
Author: Pavel Yaskevich <[email protected]>
Date:   Tue Jan 11 15:48:58 2022 -0800

    [Distributed] Adjust interface of `swift_distributed_execute_target`

    Since this is a special function, `calleeContext` doesn't point to
    a direct parent but instead both parent context (uninitialized)
    and resume function are passed as last arguments which means that
    `callContext` has to act as an intermediate context in call to accessor.

commit c1f830b
Author: Pavel Yaskevich <[email protected]>
Date:   Tue Jan 11 17:00:08 2022 -0800

    [Distributed] Drop optionality from result buffer in `_executeDistributedTarget`

    `RawPointer?` is lowered into a two arguments since it's a struct,
    to make it easy let's just allocate an empty pointer for `Void` result.

commit c83c2c3
Author: Pavel Yaskevich <[email protected]>
Date:   Tue Jan 11 17:02:45 2022 -0800

    [Distributed] NFC: Update _remoteCall test-case to check multiple different result types

commit 29e7cf5
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 12 21:32:37 2022 +0900

    wip

commit 9128ecc
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 12 20:46:20 2022 +0900

    wip

commit a6b2a62
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 12 20:38:22 2022 +0900

    wip

commit 8b188f0
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 12 16:55:10 2022 +0900

    wip

commit 3796bec
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Jan 12 16:55:02 2022 +0900

    wip

commit 0ffc68b
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Tue Jan 11 21:44:58 2022 +0900

    [Distributed] Implementing ad-hoc protocol requirements

commit 7886257
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Thu Jan 6 18:03:54 2022 +0900

    cleanup

commit 5f4ab89
Merge: 24a628e fdda6f2
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Thu Jan 6 15:51:39 2022 +0900

    Merge branch 'main' into wip-impl-execute-swift

commit 24a628e
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Thu Jan 6 15:33:21 2022 +0900

    wip

commit 69e7fed
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Dec 22 06:36:45 2021 +0900

    [Distributed] comment out distributed_actor_remoteCall for now

commit 376733a
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Tue Dec 21 16:00:06 2021 +0900

    reimplement distributed get type info impls

commit 74ab478
Author: Konrad `ktoso` Malawski <[email protected]>
Date:   Wed Dec 15 21:37:08 2021 +0900

    [Distributed] Implement func metadata and executeDistributedTarget

    dont expose new entrypoints

    able to get all the way to calling _execute
@ktoso
Copy link
Contributor Author

ktoso commented Jan 27, 2022

@swift-ci please smoke test

@ktoso ktoso added the distributed Feature → concurrency: distributed actor label Jan 27, 2022
@ktoso ktoso force-pushed the wip-distributed-remove-dynamic-sil-remotecall-squashed branch 2 times, most recently from 2d4ff3a to 1075912 Compare January 27, 2022 10:19
@ktoso
Copy link
Contributor Author

ktoso commented Jan 27, 2022

@swift-ci please smoke test

@ktoso ktoso force-pushed the wip-distributed-remove-dynamic-sil-remotecall-squashed branch from 1075912 to 86b080f Compare January 27, 2022 10:19
@ktoso ktoso force-pushed the wip-distributed-remove-dynamic-sil-remotecall-squashed branch from 86b080f to 1dd4372 Compare January 27, 2022 10:20
@@ -1385,31 +1385,6 @@ NominalTypeDecl::lookupDirect(DeclName name,
DirectLookupRequest({this, name, flags}), {});
}

AbstractFunctionDecl*
NominalTypeDecl::lookupDirectRemoteFunc(AbstractFunctionDecl *func) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed all code about dynamic _remote funcs 🥳

@@ -1816,9 +1762,6 @@ QualifiedLookupRequest::evaluate(Evaluator &eval, const DeclContext *DC,
// Make sure we've resolved property wrappers, if we need them.
installPropertyWrapperMembersIfNeeded(current, member);

// Make sure we've resolved synthesized _remote funcs for distributed actors.
installDistributedRemoteFunctionsIfNeeded(current, member);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

less terrible hacks! 🥳

auto remoteCallTargetMetatype = getLoweredType(MetatypeType::get(remoteCallTargetTy));
auto remoteCallTargetMetatypeValue = B.createMetatype(loc, remoteCallTargetMetatype);

// %30 = string_literal utf8 "MANGLED_NAME" // user: %35
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on making this an util on SGF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! a5c2236 🥳
Proud of that one, finally figured it out...

// CHECK: {{.*}} = call i1 (i8*, i1, ...) @llvm.coro.end.async({{.*}}, i8* {{.*}}, %swift.context* {{.*}}, %swift.error* {{.*}})
// SKIP: [[THUNK_REF:%.*]] = bitcast void (%swift.context*, %T27distributed_actor_accessors7MyActorC*)* {{.*}} to i8*
// SKIP: {{.*}} = call { i8*, %swift.error* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async.sl_p0i8p0s_swift.errorss({{.*}}, i8* [[THUNK_REF]], %swift.context* {{.*}}, %T27distributed_actor_accessors7MyActorC* {{.*}})
// SKIP: {{.*}} = call i1 (i8*, i1, ...) @llvm.coro.end.async({{.*}}, i8* {{.*}}, %swift.context* {{.*}}, %swift.error* {{.*}})
Copy link
Contributor Author

@ktoso ktoso Jan 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those seem gone... and direct calls are just made

@ktoso
Copy link
Contributor Author

ktoso commented Jan 27, 2022

@swift-ci please smoke test

@@ -1072,6 +1072,13 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
SourceLocArgs
emitSourceLocationArgs(SourceLoc loc, SILLocation emitLoc);

ManagedValue
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gained comments in the next commit

@ktoso
Copy link
Contributor Author

ktoso commented Jan 27, 2022

@swift-ci please smoke test Linux

@ktoso ktoso merged commit 89b0a4c into swiftlang:main Jan 28, 2022
@ktoso ktoso deleted the wip-distributed-remove-dynamic-sil-remotecall-squashed branch January 28, 2022 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed Feature → concurrency: distributed actor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant