Rip out rustc_layout_scalar_valid_range_* attribute support#155433
Rip out rustc_layout_scalar_valid_range_* attribute support#155433oli-obk wants to merge 6 commits intorust-lang:mainfrom
Conversation
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred to the CTFE machinery The Miri subtree was changed cc @rust-lang/miri Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer This PR changes a file inside |
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Happy to review this r? me |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
c6053aa to
cc13e2c
Compare
|
There is some prose in the dev guide that will no longer apply.
https://rustc-dev-guide.rust-lang.org/unsafety-checking.html?other-checks-involving-unsafe |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cc13e2c to
663f77e
Compare
This comment has been minimized.
This comment has been minimized.
663f77e to
c01a244
Compare
|
The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes. |
c01a244 to
07e6d54
Compare
This comment has been minimized.
This comment has been minimized.
07e6d54 to
cbd6780
Compare
This comment has been minimized.
This comment has been minimized.
cbd6780 to
4fb465f
Compare
This comment has been minimized.
This comment has been minimized.
| // *After* all of this, check further information stored in the layout. | ||
| // On leaf types like `!` or empty enums, this will raise the error. | ||
| // This means that for types wrapping such a type, we won't ever get here, but it's | ||
| // just the simplest way to check for this case. | ||
| // | ||
| // FIXME: We could avoid some redundant checks here. For newtypes wrapping | ||
| // scalars, we do the same check on every "level" (e.g., first we check | ||
| // MyNewtype and then the scalar in there). | ||
| // the fields of MyNewtype, and then we check MyNewType again). |
There was a problem hiding this comment.
This seems mostly outdated now, and the FIXME is resolved because there are no longer any redundant checks.
The only question that remains is why we need an is_uninhabited check here. Can this even be reached? Maybe it can be turned into an assertion that just double-checks that indeed we caught all uninhabited types above?
There was a problem hiding this comment.
the uninhabited check is still reachable and it's sufficiently unrelated to pattern types and layout attributes that I've decided to leave the fixme and try it in a separate PR once this one lands
| match val.layout.backend_repr { | ||
| BackendRepr::Scalar(scalar_layout) => { | ||
| if !scalar_layout.is_uninit_valid() { | ||
| // There is something to check here. | ||
| // We read directly via `ecx` since the read cannot fail -- we already read | ||
| // this field above when recursing into the field. | ||
| let scalar = self.ecx.read_scalar(val)?; | ||
| self.visit_scalar(scalar, scalar_layout)?; | ||
| } | ||
| } | ||
| BackendRepr::ScalarPair(a_layout, b_layout) => { | ||
| // We can only proceed if *both* scalars need to be initialized. | ||
| // FIXME: find a way to also check ScalarPair when one side can be uninit but | ||
| // the other must be init. | ||
| if !a_layout.is_uninit_valid() && !b_layout.is_uninit_valid() { | ||
| // We read directly via `ecx` since the read cannot fail -- we already read | ||
| // this field above when recursing into the field. | ||
| let (a, b) = self.ecx.read_immediate(val)?.to_scalar_pair(); | ||
| self.visit_scalar(a, a_layout)?; | ||
| self.visit_scalar(b, b_layout)?; | ||
| } | ||
| } | ||
| BackendRepr::SimdVector { .. } | BackendRepr::SimdScalableVector { .. } => { | ||
| // No checks here, we assume layout computation gets this right. | ||
| // (This is harder to check since Miri does not represent these as `Immediate`. We | ||
| // also cannot use field projections since this might be a newtype around a vector.) | ||
| } | ||
| BackendRepr::Memory { .. } => { | ||
| // Nothing to do. | ||
| } | ||
| } |
There was a problem hiding this comment.
This crucially relies on the fact that layout computation will never make a type's layout more restrictive than a field. Is there some way we can debug-assert this to avoid soundness bugs in the future where we emit range information to LLVM that Miri never checks?
There was a problem hiding this comment.
I readded it as an assertion for now, there's probably something we can do nicer
| // we won't see optimizations actually breaking such programs. | ||
| ty::PatternKind::Or(_patterns) => {} | ||
| } | ||
| match val.layout.backend_repr { |
There was a problem hiding this comment.
| match val.layout.backend_repr { | |
| // FIXME(pattern_types): Instead of checking the resulting layout, we should be checking | |
| // the pattern directly. | |
| match val.layout.backend_repr { |
Fine for now but structurally it'd make a lot more sense to check the pattern rather than the layout (and then somehow have a sanity check that the layout does not add extra restrictions not covered by the pattern).
There was a problem hiding this comment.
it does, but I haven't figured out how to do that without just repeating a lot of logic. Tho I guess we can just not look at whether is_uninit_valid is set, because if your pattern type is the full range of what the base type allows, that's so rare, that the small perf hit is fine to take
4fb465f to
28fa32d
Compare
|
r? RalfJung |
|
|
|
Sorry, that won't work. I have too many other things on my plate already. I only looked at the const-eval part and left some comments related to that. @rustbot reroll |
Ralf already reviewed the const eval parts and I addressed those |
|
Yeah I will take a look at the const-eval parts again to review the revision. |
This comment has been minimized.
This comment has been minimized.
28fa32d to
e993ad9
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
View all comments
And either removes tests for it or replaces the uses with pattern types.
primarily fixes #135996
fixes #147761
fixes #133652