about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/interpret
AgeCommit message (Collapse)AuthorLines
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
2022-06-03Use serde_json for target spec jsonbjorn3-1/+1
2022-05-28Make TyCtxt implement Interner, make HashStable generic and move to ↵Michael Goulet-7/+7
rustc_type_ir
2022-05-28Move things to rustc_type_irWilco Kusee-7/+7
2022-05-24Add the transmute and asm checks to typeck as deferred checksOli Scherer-7/+0
2022-05-22Lifetime variance fixes for rustcMichael Goulet-18/+18
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-2/+2
2022-05-20Rollup merge of #97185 - RalfJung:number-validity, r=oli-obkGuillaume Gomez-4/+7
interpret/validity: separately control checking numbers for being init and non-ptr This lets Miri control this in a more fine-grained way. r? `@oli-obk`
2022-05-19interpret/validity: separately control checking numbers for being init and ↵Ralf Jung-4/+7
non-ptr
2022-05-16use GlobalId in eval_to_valtree query and introduce query for ↵b-naber-5/+17
valtree_to_const_val
2022-05-14Auto merge of #95826 - carbotaniuman:miri-permissive-provenance, r=RalfJungbors-5/+8
Initial work on Miri permissive-exposed-provenance Rustc portion of the changes for portions of a permissive ptr-to-int model for Miri. The main changes here are changing `ptr_get_alloc` and `get_alloc_id` to return an Option, and also making ptr-to-int casts have an expose side effect.
2022-05-13Rustc changes for permissive provenancecarbotaniuman-5/+8
2022-05-02fix most compiler/ doctestsElliot Roberts-5/+5
2022-04-21deduplicate a lot of codeb-naber-5/+1
2022-04-21implement valtree -> constvalue conversionb-naber-1/+6
2022-04-20Rollup merge of #96160 - RalfJung:interpret-debug, r=oli-obkDylan DPC-0/+8
Miri/interpreter debugging tweaks Some changes I made to make debugging Miri with trace logging less terrible. r? ``@oli-obk``
2022-04-19Rollup merge of #96165 - RalfJung:miri-provenance-cleanup, r=oli-obkDylan DPC-0/+17
Miri provenance cleanup Reviewing https://github.com/rust-lang/rust/pull/95826 by ``@carbotaniuman`` made me realize that we could clean things up a little here. ``@carbotaniuman`` please let me know if you're okay with landing this (it will create a lot of conflicts with your PR), or if you'd prefer incorporating the ideas from this PR into yours. I think we want to end up in a situation where the function you called `ptr_reify_alloc` returns just two things, a concrete tag and an offset. Getting an `AllocId` from a concrete tag should be infallible like now. However a concrete tag and `Tag` don't have to be the same type. r? ``@oli-obk``
2022-04-18avoid an unnecessary call to Pointer::into_parts, and caution against ↵Ralf Jung-0/+4
into_pointer_or_addr
2022-04-18add method to get absolute address of a pointer (useful only for Miri)Ralf Jung-0/+10
2022-04-18avoid pairing up AllocId and PointerTag, which is redundantRalf Jung-0/+3
2022-04-17explain why prepare_relocation_copy works the way it doesRalf Jung-4/+11
2022-04-17add caution to some commentsRalf Jung-1/+7
2022-04-17when writing uninit to an allocation, also clear relocations like other ↵Ralf Jung-3/+9
writes do
2022-04-17add log warnings for when we overwrite parts of a pointer, and de-init the restRalf Jung-0/+8
2022-04-09Rollup merge of #95785 - RalfJung:interpret-size-mismatch, r=oli-obkDylan DPC-16/+46
interpret: err instead of ICE on size mismatches in to_bits_or_ptr_internal We did this a while ago already for `to_i32()` and friends, but missed this one. That became quite annoying when I was debugging an ICE caused by `read_pointer` in a Miri shim where the code was passing an argument at the wrong type. Having `scalar_to_ptr` be fallible is consistent with all the other `Scalar::to_*` methods being fallible. I added `unwrap` only in code outside the interpreter, which is no worse off than before now in terms of panics. r? ````@oli-obk````
2022-04-07interpret: err instead of ICE on size mismatches in to_bits_or_ptr_internalRalf Jung-16/+46
2022-04-05trivial cfg(bootstrap) changesPietro Albini-1/+1
2022-03-31interpret: make isize::MAX the limit for dynamic value sizesRalf Jung-0/+5
2022-03-30Rollup merge of #95461 - nyurik:spelling, r=lcnrDylan DPC-1/+1
Spellchecking some comments This PR attempts to clean up some minor spelling mistakes in comments
2022-03-30Spellchecking compiler codeYuri Astrakhan-1/+1
Address some spelling mistakes in strings, private function names, and function params.
2022-03-30Spellchecking some commentsYuri Astrakhan-1/+1
This PR attempts to clean up some minor spelling mistakes in comments
2022-03-25Rollup merge of #95179 - b-naber:eval-in-try-unify, r=lcnrDylan DPC-0/+11
Try to evaluate in try unify and postpone resolution of constants that contain inference variables We want code like that in [`ui/const-generics/generic_const_exprs/eval-try-unify.rs`](https://github.com/rust-lang/rust/compare/master...b-naber:eval-in-try-unify?expand=1#diff-8027038201cf07a6c96abf3cbf0b0f4fdd8a64ce6292435f01c8ed995b87fe9b) to compile. To do that we need to try to evaluate constants in `try_unify_abstract_consts`, this requires us to be more careful about what constants we try to resolve, specifically we cannot try to resolve constants that still contain inference variables. r? `@lcnr`
2022-03-22erase region in ParamEnvAnd and make ConstUnifyCtxt privateb-naber-1/+4
2022-03-22fix previous failures and address reviewb-naber-1/+1
2022-03-21stall on on constants that contain infer vars in const_eval_resolveb-naber-0/+8