Skip to content

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Feb 3, 2022

Improves the matching of ad-hoc protocol requirements remoteCall / remoteCallVoid.

Dealing with the generics there is a pain in the neck but we're almost there...
This isn't a complete impl still, it has to check the param of the Act and the SerializationRequirements still

@ktoso ktoso force-pushed the wip-improved-adhoc-checks branch from 506092e to 2355c17 Compare February 3, 2022 10:23
@ktoso ktoso requested review from xedin and drexin February 3, 2022 10:25
@ktoso ktoso added the distributed Feature → concurrency: distributed actor label Feb 3, 2022
@ktoso
Copy link
Contributor Author

ktoso commented Feb 3, 2022

@swift-ci please smoke test and merge

lib/AST/Decl.cpp Outdated

size_t expectedRequirementsNum = 3;
if (!isVoidReturn) {
// TODO(distributed): support alternative SerializationRequirements here
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is an alternative way to check this:

  1. Lookup declaring type - should be an implementation of DistributedActorSystem
  2. Find a concrete serialization requirement associated with it e.g. Codable
  3. Find a concrete InvocationDecoder type
  4. Extract either a single protocol type or a set of protocols (if requirement is a ProtocolCompositionType)
  5. Structural checks:
    • async + throws
    • Has 3 generic parameters
    • Has required number of parameters,
    • labels match (!)
    • result type is represented by a generic parameter or Void
  6. Check that parameter at index 0 is a generic parameter and it conforms to DistributedActor
  7. Check that parameter at index 1 is a known type - RemoteCallTarget (you'd have to make that type known to the compiler)
  8. Check that parameter at index 2 is equal to concrete type of InvocationDecoder and parameter is inout
  9. Check that parameter at index 3 is a metatype of a generic parameter or Void and if it's former that it "covers" all of the protocols from step 3 (you can get a set of requirements associated with a given generic parameter via GenericSignature::RequiredProtocols getRequiredProtocols(Type type) const;).
  10. Check that parameter at index 4 is a metatype of generic parameter and generic parameter has a requirement for Error (same getRequiredProtocols call).

Copy link
Contributor

Choose a reason for hiding this comment

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

You could either check the label list of equivalence or do per-parameter label checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks -- getting back to this now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the hints this makes it much cleaner; Only halfway through so far since i implemented dealing with the serialization req a bit more. Shaping up well tho

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 and more cleanups along the way.

@ktoso
Copy link
Contributor Author

ktoso commented Feb 10, 2022

Made good progress here -- lots of cleanup and moving around utilities to work with the associated types (serialization req) and desugaring it etc... I think I should have this complete tomorrow.

@ktoso ktoso force-pushed the wip-improved-adhoc-checks branch from 2355c17 to 8549764 Compare February 10, 2022 14:19
@ktoso ktoso force-pushed the wip-improved-adhoc-checks branch from 8549764 to 0fec1b3 Compare February 11, 2022 10:26
@ktoso
Copy link
Contributor Author

ktoso commented Feb 11, 2022

@swift-ci please smoke test

@ktoso ktoso requested a review from xedin February 11, 2022 10:29
@ktoso
Copy link
Contributor Author

ktoso commented Feb 11, 2022

Did a good next pass here, all checks on remote calls are done I think.

Will continue with the other ones which will be pretty simple.

There is still a bit code duplication around dealing with types... I'll be cleaning up more and more as follow up as I implement the rest -- maybe tomorrow

Copy link
Contributor

@xedin xedin left a 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 so far! Please don't forgot to remove all of the fprintf debug logging. Also FYI you can use llvm::errs() to make it simpler for yourself since it works the same way as std::cout and doesn't require format strings :)

@ktoso
Copy link
Contributor Author

ktoso commented Feb 14, 2022

Thanks -- done a lot here and going to try to get this step in; there's one more protocol to handle the result handler with its onReturn but I'll do this in a small PR

@ktoso
Copy link
Contributor Author

ktoso commented Feb 14, 2022

@swift-ci please smoke test

@ktoso ktoso force-pushed the wip-improved-adhoc-checks branch from 4e199b7 to 29357be Compare February 14, 2022 13:08
@ktoso ktoso force-pushed the wip-improved-adhoc-checks branch from 29357be to 1caa0b1 Compare February 14, 2022 13:08
return fd;
}

return nullptr;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved all these to requests and implemented properly

@@ -43,6 +43,7 @@ add_swift_host_library(swiftAST STATIC
DiagnosticConsumer.cpp
DiagnosticEngine.cpp
DiagnosticList.cpp
DistributedDecl.cpp
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new common place for all our "get this, get that"

@ktoso
Copy link
Contributor Author

ktoso commented Feb 14, 2022

@swift-ci please smoke test

// Act.ID == ActorID
{
Act.ID == ActorID,
Err: Error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

uncommented and requiring those properly now

@ktoso
Copy link
Contributor Author

ktoso commented Feb 15, 2022

Had some issues with the mutable checking but will revisit this later

@ktoso
Copy link
Contributor Author

ktoso commented Feb 15, 2022

@swift-ci please smoke test and merge

@ktoso ktoso force-pushed the wip-improved-adhoc-checks branch from 2262286 to 30c18a9 Compare February 15, 2022 22:16
@ktoso ktoso force-pushed the wip-improved-adhoc-checks branch from 30c18a9 to b02f9c7 Compare February 15, 2022 23:18
@ktoso
Copy link
Contributor Author

ktoso commented Feb 15, 2022

@swift-ci please smoke test and merge

@ktoso
Copy link
Contributor Author

ktoso commented Feb 16, 2022

@swift-ci please smoke test and merge

@ktoso
Copy link
Contributor Author

ktoso commented Feb 16, 2022

Flaky lldb tests:


  lldb-api :: lang/swift/implementation_only_imports/library_resilient/TestLibraryResilient.py
  lldb-shell :: SwiftREPL/BreakpointSimple.test

@ktoso
Copy link
Contributor Author

ktoso commented Feb 16, 2022

@swift-ci please smoke test macOS

@ktoso
Copy link
Contributor Author

ktoso commented Feb 16, 2022

  lldb-api :: lang/swift/implementation_only_imports/library_resilient/TestLibraryResilient.py

@ktoso
Copy link
Contributor Author

ktoso commented Feb 16, 2022

@swift-ci please smoke test macOS

3 similar comments
@ktoso
Copy link
Contributor Author

ktoso commented Feb 16, 2022

@swift-ci please smoke test macOS

@ktoso
Copy link
Contributor Author

ktoso commented Feb 16, 2022

@swift-ci please smoke test macOS

@ktoso
Copy link
Contributor Author

ktoso commented Feb 16, 2022

@swift-ci please smoke test macOS

@ktoso
Copy link
Contributor Author

ktoso commented Feb 16, 2022

@swift-ci please build toolchain

@ktoso ktoso merged commit 7c145cc into swiftlang:main Feb 17, 2022
@ktoso ktoso deleted the wip-improved-adhoc-checks branch February 17, 2022 00:16
@ktoso
Copy link
Contributor Author

ktoso commented Feb 18, 2022

resolves rdar://88111680

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.

2 participants