-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Lower index bounds checking to PtrMetadata
, this time with the right fake borrow semantics 😸
#135748
Conversation
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri This PR changes Stable MIR cc @oli-obk, @celinval, @ouz-a Some changes occurred to the CTFE machinery cc @rust-lang/wg-const-eval Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @vakaras The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
// though. FIXME: Do we really *need* to count this as a use? | ||
// Could partial array tracking work off something else instead? | ||
self.cfg.push_fake_read(block, source_info, FakeReadCause::ForIndex, place); | ||
let const_ = Const::from_ty_const(*len_const, usize_ty, self.tcx); |
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.
With things like #134371 and #134352, you might want something here to handle weirdness.
Not sure what the right way to do that is, but you could consider something like
let const_ = Const::from_ty_const(*len_const, usize_ty, self.tcx); | |
let const_ = | |
if let Some(err) = self.infcx.is_tainted_by_errors() { | |
Const::new_error(self.tcx, err) | |
} else { | |
Const::from_ty_const(*len_const, usize_ty, self.tcx) | |
}; |
(or whatever context is the right place to check for problems that we've already detected -- maybe self.tcx.dcx().has_errors()
is better? No idea.)
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.
Right, this inadvertently reapplies that bug I pointed out. I can fix that too.
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.
Also, I don't really know what this has to do with error tainting?
Lowering this directly to a mir::Const::Ty
causes ICEs even on code that's expected to pass, like when doing reads on a slice of &[(); T::ASSOC_CONST]
when GCE is enabled (seetests/ui/const-generics/issues/issue-89146.rs
) .
Anyways, this ICE is unrelated, and I'm going to fix it separately. I'm tracking that work in #135753. Either that one lands first, which will cause a conflict on this, or this one lands first and I'll fix the approach in this PR -- I don't think it needs to block this PR in any case.
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.
The case that has to do with error tainting is when you get a len_const
that's not actually a usize
, like in the repro in #134352 where the len_const
is actually a u64
. There's already been an error about the type being wrong, but that doesn't keep the MIR from being very unhappy about a type mismatch after building returns a u64
constant for something that's supposed to be usize
.
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.
Thanks for putting this together, and so quickly too! Much appreciated.
89c30c7
to
a8e871e
Compare
a8e871e
to
7176c19
Compare
ef8afa1
to
2f77014
Compare
2f77014
to
16f4106
Compare
This comment has been minimized.
This comment has been minimized.
16f4106
to
8b487a1
Compare
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.
The const-checking and interpreter changes LGTM.
☔ The latest upstream changes (presumably #135753) made this pull request unmergeable. Please resolve the merge conflicts. |
r? oli-obk |
8b487a1
to
7b9f0cb
Compare
This comment has been minimized.
This comment has been minimized.
7b9f0cb
to
dcd4784
Compare
…ptrmetadata, r=davidtwco,RalfJung" This reverts commit 122a55b.
dcd4784
to
eeecb56
Compare
@bors r=RalfJung,oli-obk |
…oli-obk Lower index bounds checking to `PtrMetadata`, this time with the right fake borrow semantics 😸 Change `Rvalue::RawRef` to take a `RawRefKind` instead of just a `Mutability`. Then introduce `RawRefKind::FakeForPtrMetadata` and use that for lowering index bounds checking to a `PtrMetadata`. This new `RawRefKind::FakeForPtrMetadata` acts like a shallow fake borrow in borrowck, which mimics the semantics of the old `Rvalue::Len` operation we're replacing. We can then use this `RawRefKind` instead of using a span desugaring hack in CTFE. cc `@scottmcm` `@RalfJung`
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#133151 (Trim extra whitespace in fn ptr suggestion span) - rust-lang#133829 (Implement `AtomicT::update` & `AtomicT::try_update`) - rust-lang#135367 (Enable `unreachable_pub` lint in `alloc`) - rust-lang#135748 (Lower index bounds checking to `PtrMetadata`, this time with the right fake borrow semantics 😸) - rust-lang#135805 (Add missing allocator safety in alloc crate) - rust-lang#135886 (Document purpose of closure in from_fn.rs more clearly) - rust-lang#135961 (Fix 2/4 tests skipped by opt-dist) - rust-lang#136012 (Document powf and powi values that are always 1.0) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#135748 - compiler-errors:len-2, r=RalfJung,oli-obk Lower index bounds checking to `PtrMetadata`, this time with the right fake borrow semantics 😸 Change `Rvalue::RawRef` to take a `RawRefKind` instead of just a `Mutability`. Then introduce `RawRefKind::FakeForPtrMetadata` and use that for lowering index bounds checking to a `PtrMetadata`. This new `RawRefKind::FakeForPtrMetadata` acts like a shallow fake borrow in borrowck, which mimics the semantics of the old `Rvalue::Len` operation we're replacing. We can then use this `RawRefKind` instead of using a span desugaring hack in CTFE. cc ``@scottmcm`` ``@RalfJung``
… r=compiler-errors Implement RustcInternal for RawPtrKind Implement `RustcInternal` for `RawPtrKind`. rust-lang#135748 introduced a `Stable` implementation [here](https://github.com/rust-lang/rust/pull/135748/files#diff-60f5e8edf69e04e89ef0c7f576363a91fa141e1db969484cef00063ed39c62e4R235).
Rollup merge of rust-lang#136590 - carolynzech:raw-ptr-kind-internal, r=compiler-errors Implement RustcInternal for RawPtrKind Implement `RustcInternal` for `RawPtrKind`. rust-lang#135748 introduced a `Stable` implementation [here](https://github.com/rust-lang/rust/pull/135748/files#diff-60f5e8edf69e04e89ef0c7f576363a91fa141e1db969484cef00063ed39c62e4R235).
Change
Rvalue::RawRef
to take aRawRefKind
instead of just aMutability
. Then introduceRawRefKind::FakeForPtrMetadata
and use that for lowering index bounds checking to aPtrMetadata
. This newRawRefKind::FakeForPtrMetadata
acts like a shallow fake borrow in borrowck, which mimics the semantics of the oldRvalue::Len
operation we're replacing.We can then use this
RawRefKind
instead of using a span desugaring hack in CTFE.cc @scottmcm @RalfJung