Commit Graph

1315 Commits

Author SHA1 Message Date
Guillaume Gomez
208f6ed95c
Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obk
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const

Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`.

Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all.

However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish...

``@oli-obk`` any ideas?
2023-09-21 13:25:39 +02:00
Oli Scherer
9c762b58ba Prevent promotion of const fn calls in inline consts 2023-09-21 09:00:22 +00:00
Ralf Jung
c94410c145 rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const 2023-09-21 08:12:30 +02:00
Ralf Jung
a2374e65aa the Const::eval_bits methods don't need to be given the Ty 2023-09-20 07:27:21 +02:00
Ralf Jung
ea22adbabd adjust constValue::Slice to work for arbitrary slice types 2023-09-19 20:17:43 +02:00
Ralf Jung
5a0a1ff0cd move ConstValue into mir
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-19 11:11:02 +02:00
bors
cebb9cfd4f Auto merge of #115748 - RalfJung:post-mono, r=oli-obk
move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) https://github.com/rust-lang/rust/issues/115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
2023-09-18 19:41:21 +00:00
Ralf Jung
06a76ab415 make interpreter type Debug impl independent of Ty debug impl 2023-09-15 09:54:06 +02:00
Ralf Jung
9ac8b363e3 don't point at const usage site for resolution-time errors
also share the code that emits the actual error
2023-09-14 22:34:05 +02:00
Ralf Jung
89ac57db4d move required_consts check to general post-mono-check function 2023-09-14 22:30:42 +02:00
bors
e437e57954 Auto merge of #115804 - RalfJung:valtree-to-const-val, r=oli-obk
consistently pass ty::Const through valtrees

Some drive-by things extracted from https://github.com/rust-lang/rust/pull/115748.
2023-09-14 15:34:31 +00:00
Ralf Jung
7aa44eee99 don't force all slice-typed ConstValue to be ConstValue::Slice 2023-09-14 11:56:55 +02:00
Ralf Jung
06947be196 valtree_to_const_value: add fast-path for Scalar tuples/structs 2023-09-14 07:40:05 +02:00
Ralf Jung
430c386821 make it more clear which functions create fresh AllocId 2023-09-14 07:27:31 +02:00
Ralf Jung
0f8908da27 cleanup op_to_const a bit; rename ConstValue::ByRef → Indirect 2023-09-14 07:27:30 +02:00
Ralf Jung
551f481ffb use AllocId instead of Allocation in ConstValue::ByRef 2023-09-14 07:26:24 +02:00
Ralf Jung
3aedb85a27 a bit of cleanup in valtree_to_const_value 2023-09-14 07:22:44 +02:00
bors
eb2446a57e Auto merge of #115820 - matthiaskrgr:rollup-kyglvpu, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #115736 (Remove `verbose_generic_activity_with_arg`)
 - #115771 (cleanup leftovers of const_err lint)
 - #115798 (add helper method for finding the one non-1-ZST field)
 - #115812 (Merge settings.css into rustdoc.css)
 - #115815 (fix: return early when has tainted in mir pass)
 - #115816 (Disabled socketpair for Vita)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-13 18:19:15 +00:00
Matthias Krüger
565b9c2264
Rollup merge of #115798 - RalfJung:non_1zst_field, r=wesleywiser
add helper method for finding the one non-1-ZST field
2023-09-13 18:37:42 +02:00
Matthias Krüger
1ec29fb24f
Rollup merge of #115771 - RalfJung:no-more-const-err-lint, r=oli-obk
cleanup leftovers of const_err lint

Some code / comments seem to not have been updated when const_err was turned into a hard error, so we can do a bit of cleanup here.

r? `@oli-obk`
2023-09-13 18:37:42 +02:00
Camille GILLOT
054ed8e7eb Introduce Machine::POST_MONO_CHECKS. 2023-09-12 20:17:52 +00:00
Ralf Jung
60091fe924 add helper method for finding the one non-1-ZST field 2023-09-12 20:52:05 +02:00
Ralf Jung
fd91dfb494 cleanup leftovers of const_err lint 2023-09-12 13:41:42 +02:00
bors
cc7a9d6972 Auto merge of #115705 - cjgillot:const-prop-aggregate, r=oli-obk
Read from non-scalar constants and statics in dataflow const-prop

DataflowConstProp is designed to handle scalar values. When MIR features an assignment from a non-scalar constant, we need to manually decompose it into the custom state space.

This PR tweaks interpreter callbacks to allow reusing `eval_mir_constant` without having a stack frame to get a span from.

r? `@oli-obk`
cc `@jachris`
2023-09-12 09:02:27 +00:00
Camille GILLOT
6984030f80 Use write_immediate. 2023-09-11 16:29:42 +00:00
Camille GILLOT
bcfe1a4bf2 Remove cur_span hook. 2023-09-11 16:29:42 +00:00
Camille GILLOT
4901893721 Inline callback. 2023-09-11 16:29:41 +00:00
Camille GILLOT
d278ce126c Return ImmTy in discriminant_for_variant. 2023-09-11 16:29:41 +00:00
Camille GILLOT
6ad6b4381c Support non-scalar constants. 2023-09-11 16:29:41 +00:00
Ralf Jung
e00120906e handle/hack for arbitrary-self dyn receivers 2023-09-09 15:38:23 +02:00
Ralf Jung
a38a3bfc6d implement and test ABI compatibility for transparent wrappers around NPO types 2023-09-09 15:36:44 +02:00
Ralf Jung
b5bab2b1cc implement and test fn ptr ABI compatibility rules 2023-09-09 15:36:44 +02:00
Ralf Jung
f993ddc079 give extra context to ABI mismatch errors 2023-09-09 15:36:44 +02:00
Ralf Jung
897a65804d interpret: change ABI-compat test to be type-based, so the test is consistent across targets 2023-09-09 15:36:44 +02:00
bors
cd71a37f32 Auto merge of #115372 - RalfJung:abi-assert-eq, r=davidtwco
add rustc_abi(assert_eq) to test some guaranteed or at least highly expected ABI compatibility guarantees

This new repr(transparent) test is super useful, it would have found https://github.com/rust-lang/rust/issues/115336 and found https://github.com/rust-lang/rust/issues/115404, https://github.com/rust-lang/rust/issues/115481, https://github.com/rust-lang/rust/issues/115509.
2023-09-08 11:56:08 +00:00
Ralf Jung
b0cf4c28ea turns out Layout has some more things to worry about -- move ABI comparison into helper function
like is_bool, and some special magic extra fields
2023-09-08 09:14:07 +02:00
Ralf Jung
c3e14edd8b accept some differences for rustc_abi(assert_eq), so that we can test more things to be compatible 2023-09-08 08:59:55 +02:00
bors
3d249706aa Auto merge of #115608 - RalfJung:fn-arg-validity, r=oli-obk
miri: catch function calls where the argument is caller-invalid / the return value callee-invalid

When doing a type-changing copy, we must validate the data both at the old and new type.

Fixes https://github.com/rust-lang/miri/issues/3017
2023-09-08 04:10:14 +00:00
Ralf Jung
73d8dcb803 miri: catch function calls where the argument is caller-invalid / the return value callee-invalid 2023-09-06 16:36:00 +02:00
Camille GILLOT
26c48e6f95 Refactor how MIR represents composite debuginfo. 2023-09-05 17:20:07 +00:00
Ralf Jung
fa5f13775a interpret: make MemPlace, Place, Operand types private to the interpreter 2023-09-04 17:53:38 +02:00
Ralf Jung
efc759238d miri ABI check: fix handling of 1-ZST; don't accept sign differences 2023-08-31 17:27:23 +02:00
Ralf Jung
c37bd09d88 miri function ABI check: specifically look for repr(transparent) 2023-08-30 17:07:25 +02:00
Ralf Jung
1e95aa0c49 interpret: make sure we accept transparent newtypes as ABI-compatible
also we were missing the case for Vector arguments, so handle those as well
2023-08-30 17:04:54 +02:00
Ralf Jung
6d1ce9bd13 storage_live: avoid computing the layout unless necessary 2023-08-30 13:46:55 +02:00
Ralf Jung
f87e91de7d unify passing of sized and unsized function arguments :-) 2023-08-30 13:46:55 +02:00
Ralf Jung
7cdeff266c a bit of meta-related cleanup on Projectable 2023-08-30 13:46:55 +02:00
Ralf Jung
a09df43d9f move marking-locals-live out of push_stack_frame, so it happens with argument passing
this entirely avoids even creating unsized locals in Immediate::Uninitialized state
2023-08-30 13:46:54 +02:00
Ralf Jung
bdd5855b8e interpret: fix projecting into an unsized field of a local
new invariant: Place::Local never refers to something unsized
2023-08-30 13:43:34 +02:00
Matthias Krüger
23f86255ef
Rollup merge of #115272 - RalfJung:miri-error-print, r=saethlin
miri/diagnostics: don't forget to print_backtrace when ICEing on unexpected errors

This should fix the missing output encountered [here](https://github.com/rust-lang/rust/issues/115145#issuecomment-1694334410).

r? `@saethlin`
2023-08-30 07:18:11 +02:00