-
Notifications
You must be signed in to change notification settings - Fork 13k
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
base: master
Are you sure you want to change the base?
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.
…ptrmetadata, r=davidtwco,RalfJung" This reverts commit 122a55b.
89c30c7
to
a8e871e
Compare
// We have no type corresponding to a shallow borrow, so use | ||
// `&` as an approximation. |
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 comment looks like it still needs updating.
pub enum RawPtrKind { | ||
Mut, | ||
Not, | ||
FakeForPtrMetadata, |
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.
Please add a doc comment explaining this variant.
@@ -250,8 +254,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { | |||
let src = self.eval_place(place)?; | |||
let place = self.force_allocation(&src)?; | |||
let mut val = ImmTy::from_immediate(place.to_ref(self), dest.layout); | |||
if !place_base_raw { | |||
if !place_base_raw | |||
&& span.desugaring_kind() != Some(DesugaringKind::IndexBoundsCheckReborrow) |
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.
Wasn't the point to get rid of this?
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.
You are reviewing the wrong code
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.
That is to say, you're reviewing the un-revert commit, not the functional changes on top.
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