- Notifications
You must be signed in to change notification settings - Fork 13.9k
rustc_public: Make Id types !Send / !Sync #148261
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
base: master
Are you sure you want to change the base?
Conversation
These types are Id's to a table stored in TLS, so using them from another tread will either panic, or give wrong results. Therefor, I've added a `ReferencesTls` marker type, which ensures types arn't `Send`/`Sync`. This is a breaking change for users of the `rustc_public` crate. It also changes how `DefId` and similar are `Serialize`d. Zulip Discussion: https://rust-lang.zulipchat.com/#narrow/channel/320896-project-stable-mir/topic/WDYM.20.22should.20not.20.20be.20shared.20across.20threads.22/with/547374171
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.
It's too bad we cannot use negative trait here. KMIR actually uses the serialization. See: https://github.com/runtimeverification/stable-mir-json. They use IDs to map components and correlate then AFAIK.
So can you please make sure you skip the serialization of the new field in the structs you added them?
compiler/rustc_public/src/lib.rs Outdated
| } | ||
| | ||
| #[derive(Clone, Copy, Hash, PartialEq, Eq, Default)] | ||
| #[derive(serde::Serialize)] // TODO: Don't. |
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 agree... Please don't.
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.
Done in 97e6df4. It's sadly not as simple as using #[serde(skip)], as that still moves serde from serializing just the single field, to a list containing the single field: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b4aafe4ff5312c4ddedd5e17ee361d5a
Is there somewhere that tests for this could go?
compiler/rustc_public/src/lib.rs Outdated
| pub type Symbol = String; | ||
| | ||
| /// The number that identifies a crate. | ||
| // FIXME: Make this a newtype, so it can have a `ReferencesTls` |
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.
why not include in this PR?
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 wanted to keep this PR not doing too much at once. But I've added it in 8b3ee9f
Somehow VSCode's format-on-save is formatting differently to ./x. Maybe to do with 2024 edition??
It meant that `DefId(0, ThreadLocalIndex)` would go to json as `[0, null]`, instead of just `0` (like before this PR). Now it's back to going to `0`, so this PR won't effect JSON consumers. This can't be achieved with just `#[serde(skip)]`: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b4aafe4ff5312c4ddedd5e17ee361d5a
This comment has been minimized.
This comment has been minimized.
| I'd like to squash this after approval but before merging. |
This comment has been minimized.
This comment has been minimized.
| The job Click to see the possible cause of the failure (guessed by this bot) |
These types are Id's to a table stored in TLS, so using them from another tread will either panic, or give wrong results.
Therefor, I've added a
ReferencesTlsThreadLocalIndexmarker type, which ensures types arn'tSend/Sync.This is a breaking change for users of the
rustc_publiccrate.It also changes howEDIT: Not anymore: #148261 (comment)DefIdand similar areSerialized. It would be possible to preserve the old behavior if that's needed, but I couldn't see any tests for these.Zulip Discussion: https://rust-lang.zulipchat.com/#narrow/channel/320896-project-stable-mir/topic/WDYM.20.22should.20not.20.20be.20shared.20across.20threads.22/with/547374171