-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Miri api refactor #50967
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
Miri api refactor #50967
Conversation
src/librustc/mir/interpret/value.rs
Outdated
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.
Should this be Pointer? Or is there a real usecase of ByRef pointing to a non-allocation?
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.
yes, it's used to preserve zst identity
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.
But this is Value, which means the address shouldn't be observable, only the value behind the pointer.
src/librustc/mir/interpret/value.rs
Outdated
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.
Scalar::Undef comment outdated?
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.
fixed
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.
Doesn't seem changed to me.
src/librustc/mir/interpret/value.rs
Outdated
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.
Should primval be replaced with scalar?
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.
yes, done
src/librustc/mir/interpret/value.rs
Outdated
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 could at least wrap layout::Integer for signed and unsigned integers, if you want to keep ScalarKind at all (as opposed to reusing layout::Primitive).
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.
done
src/librustc/ty/sty.rs
Outdated
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.
I'm not sure this is a good 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.
and it's gone!
src/librustc/mir/mod.rs
Outdated
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.
Since this is for printing, could you pass in 128? There are certainly 128 defined bits, trivially.
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.
Oh this is used for sign extension o_O.
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.
I will still be passing this as a Scalar, because the function is also called elsewhere with other variants, but I fixed the sign extension thing
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.
Can't this use .to_value_with_len?
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.
jup, done
|
☔ The latest upstream changes (presumably #50866) made this pull request unmergeable. Please resolve the merge conflicts. |
85638ee to
ca34069
Compare
src/librustc/mir/mod.rs
Outdated
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 call this bits, or, better, keep the name but do size.bits() as u8 at use sites.
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.
done
src/librustc/mir/mod.rs
Outdated
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.
Can you remove all the defined pattern-matching in here?
src/librustc/mir/mod.rs
Outdated
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 two more cases here.
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.
In fact, this specific one can ignore even whether the value is a Value::Scalar.
src/librustc/ty/layout.rs
Outdated
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 use impl<'a, 'tcx> TyCtxt<'a, 'tcx, '_> if you don't want to name the lifetime.
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.
I tried that, that doesn't compile
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.
Doesn't it need a feature-gate? in_band_lifetimes I think?
src/librustc/ty/layout.rs
Outdated
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.
Same here.
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.
Looking at this, this sort of thing probably needs to always use bitcast after LLVMConstPtrToInt, in case the latter is needed at all. You should add a test for an union used to convert a reference into a f32 / f64 (depending on #[cfg(target_pointer_width)]), which I highly suspect trips a LLVM assertion in the current state of the code.
src/librustc_mir/hair/cx/mod.rs
Outdated
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.
Can't this use some truncate function from miri?
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.
won't fix in this PR, there's an issue open for cleaning up this kind of code: #49937
src/librustc_mir/hair/cx/mod.rs
Outdated
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.
Can't this use with_len or something?
src/librustc_mir/hair/cx/mod.rs
Outdated
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.
Is this a true clamping operation (i.e. saturating), or a truncation? I actually expect truncation.
src/librustc_mir/hair/pattern/mod.rs
Outdated
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.
Note that this unwrap can fail - we should be matching on Option<Ordering> below and explicitly list all the possible cases - currently the _ success at the end of the match would catch None which would be bad.
src/librustc_mir/hair/pattern/mod.rs
Outdated
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're comparing defined again. At most these should <= relationships, not ==.
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, each of defined_a and defined_b should be larger or equal to pointer_size.bits() - why not use to_bits with usize instead?
src/librustc_mir/hair/pattern/mod.rs
Outdated
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.
Would be better to cast alloc_a.bytes.len() to u128.
src/librustc_mir/interpret/memory.rs
Outdated
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 seems wrong, shouldn't be <?
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, please cast the small type to the large one for comparisons.
src/librustc_mir/interpret/memory.rs
Outdated
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's a truncation, shouldn't be necessary nowadays.
src/librustc_mir/interpret/memory.rs
Outdated
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.
I'd write size.bits() != 0 here instead.
src/librustc_mir/interpret/memory.rs
Outdated
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.
How is it possible to get a Value::Scalar(Scalar::undef()) for a type with an Abi::ScalarPair?
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.
by reading a fat pointer from undefined bytes I'd presume
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 should produce a ScalarPair with two undefs.
src/librustc_target/abi/mod.rs
Outdated
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.
For the record, I disagree with this, in general rustc's typesystem should not include rustc_target::abi types.
|
@bors r=eddyb |
|
📌 Commit 50d3783 has been approved by |
|
⌛ Testing commit 50d3783 with merge 53fc7286e4ea16cc5909e0ad96d16e714501132c... |
|
💔 Test failed - status-appveyor |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
@bors r=eddyb |
|
📌 Commit 5f599bb has been approved by |
|
☀️ Test successful - status-appveyor, status-travis |
| let place = self.eval_place(place)?; | ||
| let discr_val = self.read_discriminant_value(place, ty)?; | ||
| self.write_primval(dest, PrimVal::Bytes(discr_val), dest_ty)?; | ||
| let defined = self.layout_of(ty).unwrap().size.bits() as u8; |
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.
I believe this causes #51086. ty is the enum of which the discriminant is taken. This should have been dest_ty
rustc_target: inline abi::FloatTy into abi::Primitive. This effectively undoes a small part of @oli-obk's rust-lang#50967, now that the rest of the compiler doesn't use the `FloatTy` definition from `rustc_target`, post-rust-lang#65884.
r? @eddyb
cc @Zoxc
based on #50916