about summary refs log tree commit diff
path: root/src/librustc/mir/interpret
AgeCommit message (Collapse)AuthorLines
2018-08-22Allow panicking with string literal messages inside constantsOliver Schneider-2/+10
2018-08-22optimize creating a stack frameRalf Jung-0/+2
2018-08-22better error message when using NULL in to_ptrRalf Jung-1/+2
2018-08-22finally remove all traces of signs from memoryRalf Jung-13/+21
2018-08-22miri/CTFE refactorRalf Jung-126/+80
* Value gets renamed to Operand, so that now interpret::{Place, Operand} are the "dynamic" versions of mir::{Place, Operand}. * Operand and Place share the data for their "stuff is in memory"-base in a new type, MemPlace. This also makes it possible to give some more precise types in other areas. Both Operand and MemPlace have methods available to project into fields (and other kinds of projections) without causing further allocations. * The type for "a Scalar or a ScalarPair" is called Value, and again used to give some more precise types. * All of these have versions with an attached layout, so that we can more often drag the layout along instead of recomputing it. This lets us get rid of `PlaceExtra::Downcast`. MPlaceTy and PlaceTy can only be constructed in place.rs, making sure the layout is handled properly. (The same should eventually be done for ValTy and OpTy.) * All the high-level functions to write typed memory take a Place, and live in place.rs. All the high-level typed functions to read typed memory take an Operand, and live in operands.rs.
2018-08-19Fix typos found by codespell.Matthias Krüger-1/+1
2018-08-03Unify API of `Scalar` and `ScalarMaybeUndef`Oliver Schneider-2/+6
2018-08-02Second field of ScalarPair can be undef in some casesOliver Schneider-6/+5
2018-08-01Address behaviour changing review commentsOliver Schneider-18/+0
2018-08-01Address stylistic review comments and rebase falloutOliver Schneider-3/+6
2018-08-01Reintroduce `Undef` and properly check constant value sizesOliver Schneider-86/+116
2018-07-29Sanity-check all constantsOliver Schneider-1/+1
2018-07-11Auto merge of #51702 - ecstatic-morse:infinite-loop-detection, r=oli-obkbors-1/+4
Infinite loop detection for const evaluation Resolves #50637. An `EvalContext` stores the transient state (stack, heap, etc.) of the MIRI virtual machine while it executing code. As long as MIRI only executes pure functions, we can detect if a program is in a state where it will never terminate by periodically taking a "snapshot" of this transient state and comparing it to previous ones. If any two states are exactly equal, the machine must be in an infinite loop. Instead of fully cloning a snapshot every time the detector is run, we store a snapshot's hash. Only when a hash collision occurs do we fully clone the interpreter state. Future snapshots which cause a collision will be compared against this clone, causing the interpreter to abort if they are equal. At the moment, snapshots are not taken until MIRI has progressed a certain amount. After this threshold, snapshots are taken every `DETECTOR_SNAPSHOT_PERIOD` steps. This means that an infinite loop with period `P` will be detected after a maximum of `2 * P * DETECTOR_SNAPSHOT_PERIOD` interpreter steps. The factor of 2 arises because we only clone a snapshot after it causes a hash collision.
2018-07-04Shorten error message and add link to testDylan MacKenzie-2/+1
Implements @bjorn3's suggestions.
2018-07-04Derive Eq and Hash for types used in Miri's evaluatorDylan MacKenzie-1/+1
2018-07-04Explain reason behind error spanDylan MacKenzie-1/+3
We can't expand the span of the error reliably according to @oli-obk, so just mention why it points to this particular expression.
2018-07-04Add an `InfiniteLoop` variant to `EvalErrorKind`Dylan MacKenzie-0/+2
2018-07-03Update outdated comment: ByVal -> Scalar.Zach Wolfe-2/+2
2018-07-01Auto merge of #51110 - alexreg:new-static-eval-rules, r=eddybbors-0/+3
Loosened rules involving statics mentioning other statics Before this PR, trying to mention a static in any way other than taking a reference to it caused a compile-time error. So, while ```rust static A: u32 = 42; static B: &u32 = &A; ``` compiles successfully, ```rust static A: u32 = 42; static B: u32 = A; // error ``` and ```rust static A: u32 = 42; static B: u32 = *&A; // error ``` are not possible to express in Rust. On the other hand, introducing an intermediate `const fn` can presently allow one to do just that: ```rust static A: u32 = 42; static B: u32 = foo(&A); // success! const fn foo(a: &u32) -> u32 { *a } ``` Preventing `const fn` from allowing to work around the ban on reading from statics would cripple `const fn` almost into uselessness. Additionally, the limitation for reading from statics comes from the old const evaluator(s) and is not shared by `miri`. This PR loosens the rules around use of statics to allow statics to evaluate other statics by value, allowing all of the above examples to compile and run successfully. Reads from extern (foreign) statics are however still disallowed by miri, because there is no compile-time value to be read. ```rust extern static A: u32; static B: u32 = A; // error ``` This opens up a new avenue of potential issues, as a static can now not just refer to other statics or read from other statics, but even contain references that point into itself. While it might seem like this could cause subtle bugs like allowing a static to be initialized by its own value, this is inherently impossible in miri. Reading from a static causes the `const_eval` query for that static to be invoked. Calling the `const_eval` query for a static while already inside the `const_eval` query of said static will cause cycle errors. It is not possible to accidentally create a bug in miri that would enable initializing a static with itself, because the memory of the static *does not exist* while being initialized. The memory is not uninitialized, it is not there. Thus any change that would accidentally allow reading from a not yet initialized static would cause ICEs. Tests have been modified according to the new rules, and new tests have been added for writing to `static mut`s within definitions of statics (which needs to fail), and incremental compilation with complex/interlinking static definitions. Note that incremental compilation did not need to be adjusted, because all of this was already possible before with workarounds (like intermediate `const fn`s) and the encoding/decoding already supports all the possible cases. r? @eddyb
2018-07-01Auto merge of #51833 - wesleywiser:faster_large_constant_arrays, r=oli-obkbors-0/+3
Speed up compilation of large constant arrays This is a different approach to #51672 as suggested by @oli-obk. Rather than write each repeated value one-by-one, we write the first one and then copy its value directly into the remaining memory. With this change, the [toy program](https://github.com/rust-lang/rust/blob/c2f4744d2db4e162df824d0bd0b093ba4b351545/src/test/run-pass/mir_heavy_promoted.rs) goes from 63 seconds to 19 seconds on my machine. Edit: Inlining `Size::bytes()` saves an additional 6 seconds dropping the total time to 13 seconds on my machine. Edit2: Now down to 2.8 seconds. r? @oli-obk cc @nnethercote @eddyb
2018-06-30Minor refactoring.Alexander Regueiro-1/+1
2018-06-30Added miri error for evaluating foreign statics.Alexander Regueiro-0/+3
Updated tests accordingly.
2018-06-29Inline a few `UndefMask` methods.Wesley Wiser-0/+3
This saves 2.5 seconds on the test program.
2018-06-28Turn the use of erroneous constants into errors againOliver Schneider-1/+1
2018-06-28Merge `ConstVal` and `ConstValue`Oliver Schneider-13/+11
2018-06-28FixupOliver Schneider-8/+6
2018-06-28Move everything over from `middle::const_val` to `mir::interpret`Oliver Schneider-2/+121
2018-06-28Move the Lrc outside the error type and name the fieldsOliver Schneider-1/+2
2018-06-28Address review commentsOliver Schneider-2/+2
2018-06-28Eliminate old CTFE's `ErrKind`Oliver Schneider-0/+7
2018-06-05Properly report transitive errorsOliver Schneider-43/+37
2018-06-05Refactor the const eval diagnostic APIOliver Schneider-0/+36
2018-06-01Remove outdated AllocId decoding function.Michael Woerister-42/+1
2018-06-01Make const decoding from the incremental cache thread-safe.Michael Woerister-0/+169
2018-05-25Sanity abort `to_bits` if used on zstsOliver Schneider-1/+1
2018-05-25Update commentOliver Schneider-1/+1
2018-05-24Remove the last mention of `Undef`Oliver Schneider-1/+1
2018-05-24Replace `ScalarKind` with `Primitive`Oliver Schneider-67/+1
2018-05-24primval -> scalar renameOliver Schneider-4/+4
2018-05-24Formatting nitOliver Schneider-1/+1
2018-05-24change `Value::Bytes` to `Value::Bits`Oliver Schneider-88/+72
2018-05-24Remove Pointer::zero in favor of Pointer::fromOliver Schneider-4/+7
2018-05-24Rename MemoryPointer to PointerOliver Schneider-24/+24
2018-05-24Eliminate the `Pointer` wrapper typeOliver Schneider-53/+23
2018-05-24Rename ByVal(Pair) to Scalar(Pair)Oliver Schneider-16/+16
2018-05-24Rename PrimVal to ScalarOliver Schneider-70/+70
2018-05-24Add constant for `Size::from_bytes(0)`Oliver Schneider-2/+6
2018-05-24implement Ord for OutlivesPredicate and other typestoidiu-8/+8
2018-05-22Use SortedMap instead of BTreeMap for relocations in MIRI.Michael Woerister-4/+34
2018-05-22Introduce AllocType which indicates what AllocIds point toJohn Kåre Alsaker-22/+119