Commit Graph

1324 Commits

Author SHA1 Message Date
lcnr
3c52a3e280 subst -> instantiate 2023-09-26 09:37:55 +02:00
Camille GILLOT
44ac8dcc71 Remove GeneratorWitness and rename GeneratorWitnessMIR. 2023-09-23 13:47:30 +00:00
Oli Scherer
2ba911c832 Have a single struct for queries and hook 2023-09-22 16:26:20 +00:00
Oli Scherer
2157f31731 Add a way to decouple the implementation and the declaration of a TyCtxt method. 2023-09-22 09:23:15 +00:00
bors
0fd7ce99b0 Auto merge of #116010 - RalfJung:more-typed-immediates, r=oli-obk
interpret: more consistently use ImmTy in operators and casts

The diff in src/tools/miri/src/shims/x86/sse2.rs should hopefully suffice to explain why this is nicer. :)
2023-09-21 14:02:55 +00:00
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
0eff07b748 try to avoid some layout_of calls 2023-09-21 07:26:16 +02:00
Ralf Jung
23fd2860fa stronger consistency check in ImmTy::from_immediate 2023-09-20 22:28:46 +02:00
Ralf Jung
bdbf545f42 interpret: less debug-printing of types 2023-09-20 22:25:42 +02:00
Ralf Jung
da08a3f40c interpret: more consistently use ImmTy in operators and casts 2023-09-20 21:57:54 +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