Skip to content

expand on the Send/Sync situation for consts #33

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
Dec 27, 2019

Conversation

RalfJung
Copy link
Member

I think conceptually it makes more sense to start from "const ought to be Send" and then argue that thus, the data behind shared references should be Sync.

per-thread recomputation which would lead to different addresses. As a
consequence, non-`Send` `const` without references are fine, but once references
and thus address identity comes into play, we have a problem.

*Dynamic check.* It is unclear how the Miri engine could dynamically check this.
Copy link
Contributor

Choose a reason for hiding this comment

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

I started implementing this before we had validation because I thought we could scrap some of const qualif for a value analysis. What I was basically doing is what validation is doing, but looked for explicit unsafe impl Send or unsafe impl Sync on the type of the value currently being validated. Aggregates that got their trait impls due to the auto trait nature and not explicit impls were simply walked. This permitted Option<*const u8>::None but forbade Option<*const u8>::Some(&1)

Copy link
Member Author

Choose a reason for hiding this comment

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

I doubt we can actually get away with forbidding Option<*const u8>::Some(&1) though...

What I was basically doing is what validation is doing, but looked for explicit unsafe impl Send or unsafe impl Sync on the type of the value currently being validated.

Yeah, I had thoughts along those lines, too. Unfortunately though, negative impls aren't stable yet, so it seems plausible people might do things like add a PhantomData<*const ()> field as a "no-Sync" marker... :/

@oli-obk oli-obk merged commit 8c969a9 into rust-lang:master Dec 27, 2019
@RalfJung RalfJung deleted the const-send branch February 13, 2020 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants