about summary refs log tree commit diff
path: root/src/librustc_mir/interpret
AgeCommit message (Collapse)AuthorLines
2018-08-01Address behaviour changing review commentsOliver Schneider-38/+58
2018-08-01Address stylistic review comments and rebase falloutOliver Schneider-78/+36
2018-08-01Simplify the char correctness checkOliver Schneider-5/+3
2018-08-01Fix `try_read_value` not working for enumsOliver Schneider-8/+21
2018-08-01Reintroduce `Undef` and properly check constant value sizesOliver Schneider-304/+313
2018-07-30Auto merge of #52805 - ljedrz:format_str_literal, r=petrochenkovbors-1/+1
Don't format!() string literals Prefer `to_string()` to `format!()` take 2, this time targetting string literals. In some cases (`&format!("...")` -> `"..."`) also removes allocations. Occurences of `format!("")` are changed to `String::new()`.
2018-07-29Sanity-check all constantsOliver Schneider-110/+371
2018-07-28Don't format!() string literalsljedrz-1/+1
2018-07-27Use slices where a vector is not necessaryljedrz-1/+1
2018-07-23Promoteds are statics and statics have a place, not just a valueOliver Schneider-15/+21
2018-07-18Move the const casting code into its dedicated fileOliver Schneider-131/+145
2018-07-17Pull out a statement that all match arms are executingOliver Schneider-5/+4
2018-07-15CTFE: use binary_op to compare integer with match disriminantRalf Jung-4/+9
2018-07-04Move `Eq + Hash + Clone` bounds to `Machine`Dylan MacKenzie-14/+6
2018-07-04Avoid overflow in step counterDylan MacKenzie-26/+27
This removes the `usize` argument to `inc_step_counter`. Now, the step counter increments by exactly one for every terminator evaluated. After `STEPS_UNTIL_DETECTOR_ENABLED` steps elapse, the detector is run every `DETECTOR_SNAPSHOT_PERIOD` steps. The step counter is only kept modulo this period.
2018-07-04Rename `bloom` to `hashes`Dylan MacKenzie-10/+10
2018-07-04Enable loop detector in step loopDylan MacKenzie-13/+35
The detector runs every `DETECTOR_SNAPSHOT_PERIOD` steps. Since the number of steps can increase by more than 1 (I'd like to remove this), the detector may fail if the step counter is incremented past the scheduled detection point during the loop.
2018-07-04Add an `InfiniteLoop` variant to `EvalErrorKind`Dylan MacKenzie-3/+3
2018-07-04Improve correctness of `Frame` and `Memory` equalityDylan MacKenzie-12/+12
Incorporate a subset of the suggestions from @oli-obk. More to come.
2018-07-04Revert "Refactor EvalContext stack and heap into inner struct"Dylan MacKenzie-173/+131
This reverts commit 59d21c526c036d7097d05edd6dffdad9c5b1cb62, and uses tuple to store the mutable parts of an EvalContext (which now includes `Machine`). This requires that `Machine` be `Clone`.
2018-07-04Add miri infinite loop detectionDylan MacKenzie-14/+71
Use the approach suggested by @oli-obk, a table holding `EvalState` hashes and a table holding full `EvalState` objects. When a hash collision is observed, the state is cloned and put into the full table. If the collision was not spurious, it will be detected during the next iteration of the infinite loop.
2018-07-04Implement Clone, Eq and Hash for the heap and stackDylan MacKenzie-8/+170
I use a pattern binding in each custom impl, so that adding fields to `Memory` or `Frame` will cause a compiler error instead of causing e.g. `PartialEq` to become invalid. This may be too cute. This adds several requirements to `Machine::MemoryData`. These can be removed if we don't want this associated type to be part of the equality of `Memory`.
2018-07-04Refactor EvalContext stack and heap into inner structDylan MacKenzie-98/+110
Change surrounding code to use accessor methods to refer to these fields. Similar changes have not yet been made in tools/miri
2018-07-02Removed `uninitialized_statics` field from `Memory` struct in miri.Alexander Regueiro-93/+64
Refactored code accordingly.
2018-07-01Auto merge of #51110 - alexreg:new-static-eval-rules, r=eddybbors-3/+7
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-25/+59
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-30Fixed bug with miri const evaluation where allocation is recursively borrowed.Alexander Regueiro-1/+2
2018-06-30Added miri error for evaluating foreign statics.Alexander Regueiro-2/+5
Updated tests accordingly.
2018-06-30Copy undef_masks correctly for repeated bytesWesley Wiser-5/+9
2018-06-30Fix relocations to include repeated valuesWesley Wiser-7/+15
2018-06-29Optimize `copy_undef_mask()` to use one passWesley Wiser-17/+8
This saves 0.5 seconds on the test compilation.
2018-06-29Optimize `copy_undef_mask()` by lifting some loop invariant operationsWesley Wiser-9/+18
This saves 4.5 seconds and takes the compile time down to 5.5 seconds.
2018-06-28Rollup merge of #51839 - oli-obk:const_shift_overflow, r=nikomatsakisMark Rousskov-1/+2
Detect overflows of non u32 shifts
2018-06-28Merge `ConstVal` and `ConstValue`Oliver Schneider-56/+29
2018-06-28Move everything over from `middle::const_val` to `mir::interpret`Oliver Schneider-6/+6
2018-06-28Move the Lrc outside the error type and name the fieldsOliver Schneider-9/+14
2018-06-28Address review commentsOliver Schneider-2/+2
2018-06-28Eliminate old CTFE's `ErrKind`Oliver Schneider-14/+10
2018-06-27Don't use `ParamEnv::reveal_all()` if there is a real one availableOliver Schneider-1/+1
2018-06-27Detect overflows of non u32 shiftsOliver Schneider-1/+2
2018-06-26Speed up compilation of large constant arraysWesley Wiser-8/+30
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.
2018-06-14rustc: rename ty::maps to ty::query.Eduard-Mihai Burtescu-2/+2
2018-06-05Properly report transitive errorsOliver Schneider-23/+8
2018-06-05Refactor the const eval diagnostic APIOliver Schneider-107/+32
2018-06-04Simplify value field accessOliver Schneider-36/+27
2018-06-02Correctly access ScalarPair fields during const evalOliver Schneider-60/+34
2018-06-01Auto merge of #51225 - oli-obk:miri_oob_ptr, r=eddybbors-15/+30
Fix the miri submodule cc @bjorn3 r? @eddyb
2018-05-31Rename num -> bits and num -> out_valLinus Färnstrand-6/+6
2018-05-31Rename bytes -> bitsLinus Färnstrand-8/+8
2018-05-31Rewrite numeric_intrinsic without macroLinus Färnstrand-28/+11