-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Recover statics better #125555
base: master
Are you sure you want to change the base?
Recover statics better #125555
Conversation
The const interner uses the body to intern static allocations. This means that an allocation will be mutable if the resulting type contains interior mutability. Const eval contains an assertion that types that are `Freeze` do not have mutable allocations, which was failing for cases where the type was a type error. An alternative fix for this would be to avoid the assertion in const eval for type errors, allowing those to both be mutable and immutable. This is implemented in a follow-up commit as well.
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
333296f
to
4d97ffb
Compare
This comment has been minimized.
This comment has been minimized.
Does the first commit actually have user-visible changes anywhere? |
When the type is an inferred placeholder or an error, we used to infer the type for an error message and then return `TyKind::Error`. Now we return the proper type, which helps follow-up code do more checking. The primary motivation for this was fixing the const-eval mutability assertion bug, because this commit forwards the inferred type to that assertion, but it is also just nicer in general.
We do not know whether a type error was supposed to be mutable or not.
The only change in the test suite is that it adds that one cycle error. |
4d97ffb
to
44a576c
Compare
if let Some((_, alloc)) = ecx.memory.alloc_map.get(alloc_id) { | ||
if let Some((_, alloc)) = ecx.memory.alloc_map.get(alloc_id) | ||
// For type errors, we do not know whether they are supposed to be mutable or not. | ||
&& !ty.references_error() |
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 is a bad sign that this check is needed. We should never even evaluate a static whose type references an error. So something still seems wrong here.
// Assoc consts can reference generic lifetimes from the parent generics, but treating them | ||
// as static is unlikely to cause issues. | ||
let ty = tcx.fold_regions(ty, |region, _| match region.kind() { | ||
ty::ReErased => tcx.lifetimes.re_static, |
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.
ty::ReErased => tcx.lifetimes.re_static, | |
ty::ReErased => ty::Region::new_error(tcx, guar), |
would also fix this issue without requiring any of the other changes, because then the error type is tainted, without replacing any of the types. So you'd still get the suggestions, but const eval won't attempt to run.
@rustbot author |
☔ The latest upstream changes (presumably #127358) made this pull request unmergeable. Please resolve the merge conflicts. |
@Noratrieb ping from triage - can you post your status on this PR? This PR has not received an update in a few months. |
The const interner uses the body to intern static allocations.
This means that an allocation will be mutable if the resulting type contains interior mutability.
Const eval contains an assertion that types that are
Freeze
do not have mutable allocations, which was failing for cases where the type was a type error.The first two commits fix this by forwarding the inferred type through
type_of
, while the last commit disables the assertion for remaining cases where type errors are involved.Note that the erased region mapping is not fully correct, and causes this spurious error now:
I deem that acceptable, that you may disagree.
note: the commit messages contain more information
fixes #124164
r? oli-obk