Skip to content

[Distributed] Allow overloads with different types; mangling can handle it #69595

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

Merged
merged 3 commits into from
Nov 6, 2023

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Nov 2, 2023

Description: We too aggressively prevented overloads; The code's intention was to prevent overloads ONLY on the effects of a function (async / throws), since it complicates the relationship with thunks. Overloads ARE allowed and work just fine, so this patch fixes the too naive type system checking.
Risk: Low, loosens up the too restrictive checks made on distributed funcs. The mangling scheme can handle these with no problem.
Reward: Adopters are able to write APIs in the style they're used to, e.g. "distributed func received(SomeEvent)" and "distributed func received(OtherEvent)".
Impact: Small; Only distributed function overloads are affected.
Review by: @xedin @slavapestov
Testing: CI testing; added tests to cover the situation.
Radar: rdar://117818281

@ktoso
Copy link
Contributor Author

ktoso commented Nov 2, 2023

@swift-ci please smoke test

for (size_t i = 0; i < candidateFunc->getParameters()->size(); ++i) {
auto lhs = firstDecl->getParameters()->get(i);
auto rhs = candidateFunc->getParameters()->get(i);
if (!lhs->getInterfaceType()->isEqual(rhs->getInterfaceType())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me wonder whether instead we should augment re-declaration checker to discount async and throws on distributed func, I think that would give us the behavior we want here instead of trying to equate stuff in ad-hoc way i.e. it would diagnose

distributed func test<T>(a: T) {}
distrbiuted func test<U>(a: U) async {}

With a custom message instead of the default "invalid redeclaration of".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah maybe that's easier hmmm... I'll see if I can find where that is done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very nice, that simplified things a lot!

@ktoso ktoso requested a review from slavapestov as a code owner November 6, 2023 04:00
@ktoso ktoso requested a review from xedin November 6, 2023 04:08
@ktoso
Copy link
Contributor Author

ktoso commented Nov 6, 2023

I managed to remove a lot of "custom" code here, thanks for the review @xedin

@ktoso
Copy link
Contributor Author

ktoso commented Nov 6, 2023

@swift-ci please smoke test

@ktoso ktoso added the distributed Feature → concurrency: distributed actor label Nov 6, 2023
if (sig1.IsDistributed || sig2.IsDistributed) {
if (sig1.IsAsyncFunction != sig2.IsAsyncFunction)
return true;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't this be simplified to:

  if (sig1.IsAsyncFunction != sig2.IsAsyncFunction)
    return sig1.IsDistributed || sig2.IsDistributed;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah but perhaps a bit harder to understand? I thought "if any of them is distributed we handle differently" was a bit easier 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

For me it’s easier to understand a more concise version - if async is different return true if one of the signatures is distributed and false otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems this logic is incorrect slightly, Doug reviewed the other PR. Will do a follow up here asap

@ktoso
Copy link
Contributor Author

ktoso commented Nov 6, 2023

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 62a24b5 into swiftlang:main Nov 6, 2023
@ktoso ktoso deleted the wip-distributed-overloads branch November 7, 2023 06:31
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.

3 participants