summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/interpret
AgeCommit message (Collapse)AuthorLines
2022-09-17Auto merge of #98588 - b-naber:valtrees-cleanup, r=lcnrbors-2/+2
Use only ty::Unevaluated<'tcx, ()> in type system r? `@lcnr`
2022-09-15Replace more manual TypeFoldable and TypeVisitable impls with derivesOli Scherer-1/+1
2022-09-15derive various Lift impl instead of hand rolling themOli Scherer-18/+2
2022-09-13use ty::Unevaluated<'tcx, ()> in type systemb-naber-2/+2
2022-08-28improve OFFSET_IS_ADDR docsRalf Jung-2/+6
2022-08-27interpret: make read-pointer-as-bytes *always* work in MiriRalf Jung-95/+83
and show some extra information when it happens in CTFE
2022-08-27interpret: rename relocation → provenanceRalf Jung-95/+92
2022-08-26remove now-unused ScalarMaybeUninitRalf Jung-134/+1
2022-08-26make read_immediate error immediately on uninit, so ImmTy can carry ↵Ralf Jung-17/+8
initialized Scalar
2022-08-26remove some now-unnecessary parameters from check_bytesRalf Jung-19/+4
2022-07-30avoid assertion failures in try_to_scalar_intRalf Jung-1/+3
2022-07-23now we can make scalar_to_ptr a method on ScalarRalf Jung-0/+18
2022-07-20various nits from reviewRalf Jung-1/+1
2022-07-20consistently use VTable over Vtable (matching stable stdlib API RawWakerVTable)Ralf Jung-14/+14
2022-07-20make use of symbolic vtables in interpreterRalf Jung-18/+9
2022-07-20rename get_global_alloc to try_get_global_allocRalf Jung-5/+12
2022-07-20add a Vtable kind of symbolic allocationsRalf Jung-4/+40
2022-07-19interpret: rename Tag/PointerTag to Prov/ProvenanceRalf Jung-95/+97
Let's avoid using two different terms for the same thing -- let's just call it "provenance" everywhere. In Miri, provenance consists of an AllocId and an SbTag (Stacked Borrows tag), which made this even more confusing.
2022-07-13get rid of MemPlaceMeta::PoisonRalf Jung-0/+2
MPlaceTy::dangling still exists, but now it is only called in places that actually conceptually allocate something new, so that's fine.
2022-07-09tweak names and output and blessRalf Jung-3/+3
2022-07-09review feedbackRalf Jung-3/+3
2022-07-09don't allow ZST in ScalarIntRalf Jung-8/+6
There are several indications that we should not ZST as a ScalarInt: - We had two ways to have ZST valtrees, either an empty `Branch` or a `Leaf` with a ZST in it. `ValTree::zst()` used the former, but the latter could possibly arise as well. - Likewise, the interpreter had `Immediate::Uninit` and `Immediate::Scalar(Scalar::ZST)`. - LLVM codegen already had to special-case ZST ScalarInt. So instead add new ZST variants to those types that did not have other variants which could be used for this purpose.
2022-07-06interpret: use AllocRange in UninitByteAccessRalf Jung-60/+51
also use nice new format string syntax in interpret/error.rs
2022-07-06Auto merge of #98206 - eggyal:align-to-chalk-folding-api, r=jackh726bors-2/+2
Split TypeVisitable from TypeFoldable Impl of rust-lang/compiler-team#520 following MCP approval. r? `@ghost`
2022-07-06Update TypeVisitor pathsAlan Egerton-1/+1
2022-07-05impl TypeVisitable in type traversal macrosAlan Egerton-1/+1
2022-07-05adjust dangling-int-ptr error messageRalf Jung-12/+25
2022-07-05Rollup merge of #98811 - RalfJung:interpret-alloc-range, r=oli-obkDylan DPC-25/+21
Interpret: AllocRange Debug impl, and use it more consistently The two commits are pretty independent but it did not seem worth having two PRs for them. r? ``@oli-obk``
2022-07-02more use of format! variable captureRalf Jung-2/+2
Co-authored-by: Joe ST <joe@fbstj.net>
2022-07-02Auto merge of #97585 - lqd:const-alloc-intern, r=RalfJungbors-6/+11
CTFE interning: don't walk allocations that don't need it The interning of const allocations visits the mplace looking for references to intern. Walking big aggregates like big static arrays can be costly, so we only do it if the allocation we're interning contains references or interior mutability. Walking ZSTs was avoided before, and this optimization is now applied to cases where there are no references/relocations either. --- While initially looking at this in the context of #93215, I've been testing with smaller allocations than the 16GB one in that issue, and with different init/uninit patterns (esp. via padding). In that example, by default, `eval_to_allocation_raw` is the heaviest query followed by `incr_comp_serialize_result_cache`. So I'll show numbers when incremental compilation is disabled, to focus on the const allocations themselves at 95% of the compilation time, at bigger array sizes on these minimal examples like `static ARRAY: [u64; LEN] = [0; LEN];`. That is a close construction to parts of the `ctfe-stress-test-5` benchmark, which has const allocations in the megabytes, while most crates usually have way smaller ones. This PR will have the most impact in these situations, as the walk during the interning starts to dominate the runtime. Unicode crates (some of which are present in our benchmarks) like `ucd`, `encoding_rs`, etc come to mind as having bigger than usual allocations as well, because of big tables of code points (in the hundreds of KB, so still an order of magnitude or 2 less than the stress test). In a check build, for a single static array shown above, from 100 to 10^9 u64s (for lengths in powers of ten), the constant factors are lowered: (log scales for easier comparisons) ![plot_log](https://user-images.githubusercontent.com/247183/171422958-16f1ea19-3ed4-4643-812c-1c7c60a97e19.png) (linear scale for absolute diff at higher Ns) ![plot_linear](https://user-images.githubusercontent.com/247183/171401886-2a869a4d-5cd5-47d3-9a5f-8ce34b7a6917.png) For one of the alternatives of that issue ```rust const ROWS: usize = 100_000; const COLS: usize = 10_000; static TWODARRAY: [[u128; COLS]; ROWS] = [[0; COLS]; ROWS]; ``` we can see a similar reduction of around 3x (from 38s to 12s or so). For the same size, the slowest case IIRC is when there are uninitialized bytes e.g. via padding ```rust const ROWS: usize = 100_000; const COLS: usize = 10_000; static TWODARRAY: [[(u64, u8); COLS]; ROWS] = [[(0, 0); COLS]; ROWS]; ``` then interning/walking does not dominate anymore (but means there is likely still some interesting work left to do here). Compile times in this case rise up quite a bit, and avoiding interning walks has less impact: around 23%, from 730s on master to 568s with this PR.
2022-07-02add AllocRange Debug impl; remove redundant AllocId Display implRalf Jung-25/+21
2022-06-29Auto merge of #98520 - RalfJung:invalid, r=compiler-errorsbors-2/+4
interpret: adjust error from constructing an invalid value
2022-06-29interpret: adjust error from constructing an invalid valueRalf Jung-2/+4
2022-06-28Improve pretty printing of valtrees for referencesDominik Stolz-7/+1
2022-06-28make `get_relocations` privateRémy Rakic-6/+11
This limits access to the relocations data a bit (instead of increasing it just for the purposes of interning).
2022-06-22Rollup merge of #98099 - RalfJung:convert_tag_add_extra, r=oli-obkYuki Okushi-6/+6
interpret: convert_tag_add_extra: allow tagger to raise errors Needed for https://github.com/rust-lang/miri/issues/2234 r? `@oli-obk`
2022-06-19Use `ensure` for `UnusedBrokenConst`.Camille GILLOT-1/+34
2022-06-17Auto merge of #98097 - lqd:const-alloc-hash, r=oli-obkbors-2/+75
ctfe: limit hashing of big const allocations when interning Const allocations are only hashed for interning. However, they can be large, making the hashing expensive especially since it uses `FxHash`: it's better suited to short keys, not potentially big buffers like the actual bytes of allocation and the associated 1/8th sized `InitMask`. We can partially hash these fields when they're large, hashing the length, and head and tail of these buffers, to limit possible collisions while avoiding most of the hashing work. r? `@ghost`
2022-06-16adjust const alloc interning partial hash commentsRémy Rakic-4/+8
2022-06-16ctfe: limit hashing of big const allocations when interningRémy Rakic-2/+71
Big const allocations hash a large amount of data for interning: the whole bytes buffer, and the 1/8th sized initmask, with FxHash. This hash function is made for shorter keys. This only hashes the length, and head and tail of these buffers, to limit possible collisions while avoiding most of the hashing work.
2022-06-16interpret: convert_tag_add_extra, init_allocation_extra: allow tagger to ↵Ralf Jung-6/+6
raise errors
2022-06-14address reviewb-naber-20/+4
2022-06-14address reviewb-naber-2/+1
2022-06-14implement valtrees as the type-system representation for constant valuesb-naber-7/+74
2022-06-11Try out `yeet` in the MIR interpreterScott McMurray-5/+5
2022-06-09Auto merge of #97740 - RalfJung:ctfe-cycle-spans, r=lcnrbors-3/+16
use precise spans for recursive const evaluation This fixes https://github.com/rust-lang/rust/issues/73283 by using a `TyCtxtAt` with a more precise span when the interpreter recursively calls itself. Hopefully such calls are sufficiently rare that this does not cost us too much performance. (In theory, cycles can also arise through layout computation, as layout can depend on consts -- but layout computation happens all the time so we'd have to do something to not make this terrible for performance.)
2022-06-08Use delayed error handling for `Encodable` and `Encoder` infallible.Nicholas Nethercote-8/+7
There are two impls of the `Encoder` trait: `opaque::Encoder` and `opaque::FileEncoder`. The former encodes into memory and is infallible, the latter writes to file and is fallible. Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a bit verbose and has non-trivial cost, which is annoying given how rare failures are (especially in the infallible `opaque::Encoder` case). This commit changes how `Encoder` fallibility is handled. All the `emit_*` methods are now infallible. `opaque::Encoder` requires no great changes for this. `opaque::FileEncoder` now implements a delayed error handling strategy. If a failure occurs, it records this via the `res` field, and all subsequent encoding operations are skipped if `res` indicates an error has occurred. Once encoding is complete, the new `finish` method is called, which returns a `Result`. In other words, there is now a single `Result`-producing method instead of many of them. This has very little effect on how any file errors are reported if `opaque::FileEncoder` has any failures. Much of this commit is boring mechanical changes, removing `Result` return values and `?` or `unwrap` from expressions. The more interesting parts are as follows. - serialize.rs: The `Encoder` trait gains an `Ok` associated type. The `into_inner` method is changed into `finish`, which returns `Result<Vec<u8>, !>`. - opaque.rs: The `FileEncoder` adopts the delayed error handling strategy. Its `Ok` type is a `usize`, returning the number of bytes written, replacing previous uses of `FileEncoder::position`. - Various methods that take an encoder now consume it, rather than being passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-06Auto merge of #97684 - RalfJung:better-provenance-control, r=oli-obkbors-29/+54
interpret: better control over whether we read data with provenance The resolution in https://github.com/rust-lang/unsafe-code-guidelines/issues/286 seems to be that when we load data at integer type, we implicitly strip provenance. So let's implement that in Miri at least for scalar loads. This makes use of the fact that `Scalar` layouts distinguish pointer-sized integers and pointers -- so I was expecting some wild bugs where layouts set this incorrectly, but so far that does not seem to happen. This does not entirely implement the solution to https://github.com/rust-lang/unsafe-code-guidelines/issues/286; we still do the wrong thing for integers in larger types: we will `copy_op` them and then do validation, and validation will complain about the provenance. To fix that we need mutating validation; validation needs to strip the provenance rather than complaining about it. This is a larger undertaking (but will also help resolve https://github.com/rust-lang/miri/issues/845 since we can reset padding to `Uninit`). The reason this is useful is that we can now implement `addr` as a `transmute` from a pointer to an integer, and actually get the desired behavior of stripping provenance without exposing it!
2022-06-05interpret: better control over whether we read data with provenance, and ↵Ralf Jung-29/+54
implicit provenance stripping where possible
2022-06-04use precise spans for recursive const evaluationRalf Jung-3/+16