Skip to content

[Distributed] Enforce strict order of synthesized id and actorSystem properties; avoid wrong offset crashes #58745

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 2 commits into from
May 9, 2022

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented May 8, 2022

Resolves rdar://92712849 - the root cause of all those issues
Resolves rdar://92910719 - which disabled the still failing test since the workaround was not good enough

This is the actual solution for all our mystical offset issues -- the order of the synthesized AST fields MUST match the order IRGen enforces (and the DA needs in any case); where the id and system are the FIRST fields, and must be specifically: id, system because that's what IRGen emits and many places seem to expect the order matches between the original AST and whatever gets derived form it and IR.

This probably also resolves a few other crashers we had with similar crash reasons of weird mismatching offsets, I'll be verifying those.

@ktoso ktoso changed the title Wip init crash [Distributed] Enforce strict order of synthesized id and actorSystem properties; avoid wrong offset crashes May 8, 2022
// important. The `hint` below makes sure the system is inserted right after.
auto id = derived.Nominal->getDistributedActorIDProperty();
derived.addMemberToConformanceContext(pbDecl, /*hint=*/id);
derived.addMemberToConformanceContext(propDecl, /*hint=*/id);
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 ensures the system is always AFTER the ID

llvm_unreachable("DistributedActor.id MUST be synthesized earlier, "
"because it is forced by the Identifiable conformance. "
"If we attempted to do synthesis here, the earlier phase "
"failed and something is wrong: please report a bug.");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We had to move away from its synthesis here a while back so this was dead code;

Actually I should just delete the hangling here I guess.

@@ -27,33 +26,25 @@ import WinSDK
/// for learning about `distributed actor` isolation, as well as early
/// prototyping stages of development where a real system is not necessary yet.
@available(SwiftStdlib 5.7, *)
public struct LocalTestingDistributedActorSystem: DistributedActorSystem, @unchecked Sendable {
public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @unchecked Sendable {
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 UNDOES the workaround (which actually did not work after all).

This is NOT a change in the API of the system

@@ -286,7 +274,7 @@ func test() async {

let localDA = LocalTestingDA_Int()
print("localDA = \(localDA.id)")
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 would have crashed recently -- this patch fixes it.

@ktoso ktoso requested review from DougGregor, xedin and drexin and removed request for DougGregor May 8, 2022 10:41
@ktoso ktoso added the distributed Feature → concurrency: distributed actor label May 8, 2022
@ktoso
Copy link
Contributor Author

ktoso commented May 8, 2022

@swift-ci please test

@ktoso
Copy link
Contributor Author

ktoso commented May 9, 2022

Note that even the 32 bit watch passed here... and does not on 5.7, so we're missing something there 🤔

 PASS: Swift(watchsimulator-i386) :: Distributed/Runtime/distributed_actor_init_local.swift (1794 of 15692)

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