-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Handle statics in MIR as const pointers #66587
Conversation
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.
This is great, a much more principled approach than what I was attempting
@matthewjasper great work, indeed I'm working on the first 3. |
☔ The latest upstream changes (presumably #66607) made this pull request unmergeable. Please resolve the merge conflicts. |
c87e5ef
to
bccc59a
Compare
IMO this is ready to r+, would leave this up to @oli-obk though |
@bors r+ |
📌 Commit bccc59a has been approved by |
…t, r=oli-obk Handle statics in MIR as const pointers This is the first PR towards the goal of removing `PlaceBase::Static`. In this PR: * Statics are lowered to dereferencing a const pointer. * The temporaries holding such pointers are tracked in MIR, for the most part this is only used for diagnostics. There are two exceptions: * The borrow checker has some checks for thread-locals that directly use this data. * Const checking will suppress "cannot dereference raw pointer" diagnostics for pointers to `static mut`/`extern static`. This is to maintain the current behaviour (12 tests fail otherwise). The following are left to future PRs (I think that @spastorino will be working on the first 3): * Applying the same treatments to promoted statics. * Removing `PlaceBase::Static`. * Replacing `PlaceBase` with `Local`. * Moving the ever growing collection of metadata that we have for diagnostics in MIR passes somewhere more appropriate. r? @oli-obk
Rollup of 8 pull requests Successful merges: - #66183 (*Syntactically* permit visibilities on trait items & enum variants) - #66566 (Document pitfall with `impl PartialEq<B> for A`) - #66575 (Remove pretty printing of specific nodes in AST) - #66587 (Handle statics in MIR as const pointers) - #66619 (follow the convention in this file to use third-person singular verbs) - #66633 (Error code's long explanation cleanup) - #66637 (fix reoccuring typo: dereferencable -> dereferenceable) - #66639 (resolve: more declarative `fresh_binding`) Failed merges: r? @ghost
They now look the same in the MIR after rust-lang#66587.
Before this PR is was possible to always force a |
Do pointers track the TLS-ness of what they point to? If so, we can make const alloc codegen add those markers |
No. Only when an alloc gets directly referenced from a function, does the I have been able to solve the problem for cg_clif in bjorn3/rustc_codegen_cranelift@30de2a0. That commit makes the logic more like cg_llvm. |
So... the status is you solved the problem, but we could still improve on it by making this part of codegen_ssa to duplicate less code? |
Yes
cg_ssa already does this, but I can't use it much in cg_clif yet, as it depends to much on several llvm properties. |
This is the first PR towards the goal of removing
PlaceBase::Static
. In this PR:static mut
/extern static
. This is to maintain the current behaviour (12 tests fail otherwise).The following are left to future PRs (I think that @spastorino will be working on the first 3):
PlaceBase::Static
.PlaceBase
withLocal
.r? @oli-obk