about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
AgeCommit message (Collapse)AuthorLines
2022-07-07make a name less ambiguousRalf Jung-7/+7
2022-07-07Rollup merge of #98930 - tmiasko:pub-basic-blocks, r=oli-obkDylan DPC-2/+3
Make MIR basic blocks field public This makes it possible to mutably borrow different fields of the MIR body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`. To preserve validity of control flow graph caches in the presence of modifications, a new struct `BasicBlocks` wraps together basic blocks and control flow graph caches. The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`. On the other hand a mutable access requires explicit `as_mut()` call.
2022-07-07Rollup merge of #96856 - DrMeepster:fix_projection_validation, r=IcnrDylan DPC-6/+43
Fix ProjectionElem validation `TypeChecker::visit_projection_elem` was not actually being called.
2022-07-07`UnsafeCell` now has no niches, ever.Oli Scherer-4/+4
2022-07-07Make MIR basic blocks field publicTomasz Miąsko-2/+3
This makes it possible to mutably borrow different fields of the MIR body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`. To preserve validity of control flow graph caches in the presence of modifications, a new struct `BasicBlocks` wraps together basic blocks and control flow graph caches. The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`. On the other hand a mutable access requires explicit `as_mut()` call.
2022-07-06Auto merge of #98831 - RalfJung:no-more-unsized-locals, r=oli-obkbors-223/+243
interpret: remove support for unsized_locals I added support for unsized_locals in https://github.com/rust-lang/rust/pull/59780 but the current implementation is a crude hack and IMO definitely not the right way to have unsized locals in MIR. It also [causes problems](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Missing.20Layout.20Check.20in.20.60interpret.2Foperand.2Ers.60.3F). and what codegen does is unsound and has been for years since clearly nobody cares (so I hope nobody actually relies on that implementation and I'll be happy if Miri ensures they do not). I think if we want to have unsized locals in Miri/MIR we should add them properly, either by having a `StorageLive` that takes metadata or by having an `alloca` that returns a pointer (making the ptr indirection explicit) or something like that. So, this PR removes the `LocalValue::Unallocated` hack. It adds `Immediate::Uninit`, for several reasons: - This lets us still do fairly little work in `push_stack_frame`, in particular we do not actually have to create any allocations. - If/when I remove `ScalarMaybeUninit`, we will need something like this to have an "optimized" representation of uninitialized locals. Without this we'd have to put uninitialized integers into the heap! - const-prop needs some way to indicate "I don't know the value of this local'; it used to use `LocalValue::Unallocated` for that, now it can use `Immediate::Uninit`. There is still a fundamental difference between `LocalValue::Unallocated` and `Immediate::Uninit`: the latter is considered a regular local that you can read from and write to, it just has a more optimized representation when compared with an actual `Allocation` that is fully uninit. In contrast, `LocalValue::Unallocated` had this really odd behavior where you would write to it but not read from it. (This is in fact what caused the problems mentioned above.) While at it I also did two drive-by cleanups/improvements: - In `pop_stack_frame`, do the return value copying and local deallocation while the frame is still on the stack. This leads to better error locations being reported. The old errors were [sometimes rather confusing](https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Cron.20Job.20Failure.202022-06-24/near/287445522). - Deduplicate `copy_op` and `copy_op_transmute`. r? `@oli-obk`
2022-07-06Rollup merge of #98519 - TaKO8Ki:add-head-span-field-to-item-and-impl-item, ↵Guillaume Gomez-3/+2
r=cjgillot Replace some `guess_head_span` with `def_span` This patch fixes a part of #97417. r? `@cjgillot`
2022-07-06deduplicate some copy_op codeRalf Jung-87/+74
2022-07-06support passing unsized fn argumentsRalf Jung-12/+54
2022-07-06interpret: remove LocalValue::Unallocated, add Operand::UninitRalf Jung-149/+140
Operand::Uninit is an *allocated* operand that is fully uninitialized. This lets us lazily allocate the actual backing store of *all* locals (no matter their ABI). I also reordered things in pop_stack_frame at the same time. I should probably have made that a separate commit...
2022-07-06fix ICE in ConstPropRalf Jung-5/+5
2022-07-06add track_caller to some interpreter functionsRalf Jung-0/+4
2022-07-06interpret: use AllocRange in UninitByteAccessRalf Jung-2/+2
also use nice new format string syntax in interpret/error.rs
2022-07-06replace `guess_head_span` with `def_span`Takayuki Maeda-3/+2
2022-07-06Rollup merge of #98968 - RalfJung:scalar-sanity, r=oli-obkDylan DPC-4/+3
assert Scalar sanity With https://github.com/rust-lang/rust/pull/96814 having landed, finally our `Scalar` layouts have the invariants they deserve. :)
2022-07-06Rollup merge of #98964 - RalfJung:typo, r=Dylan-DPCDylan DPC-3/+3
fix typo in function name I don't know what I was doing when I named that function... follow-up to #98888 r? `@oli-obk`
2022-07-06fix projectionelem validationDrMeepster-6/+43
2022-07-06Auto merge of #98206 - eggyal:align-to-chalk-folding-api, r=jackh726bors-5/+5
Split TypeVisitable from TypeFoldable Impl of rust-lang/compiler-team#520 following MCP approval. r? `@ghost`
2022-07-06Update TypeVisitor pathsAlan Egerton-6/+4
2022-07-05finally enable Scalar layout sanity checksRalf Jung-4/+3
2022-07-05fix type in function nameRalf Jung-3/+3
2022-07-05Relax constrained generics to TypeVisitableAlan Egerton-2/+4
2022-07-05Rollup merge of #98888 - RalfJung:interpret-checked-bin, r=oli-obkMatthias Krüger-2/+23
interpret: fix CheckedBinOp behavior when overflow checking is disabled Adjusts the interpreter to https://github.com/rust-lang/rust/pull/98738. r? `@oli-obk`
2022-07-05Rollup merge of #98860 - RalfJung:dangling-int-ptr, r=davidtwcoMatthias Krüger-3/+3
adjust dangling-int-ptr error message based on suggestions by `@saethlin` in https://github.com/rust-lang/miri/issues/2163 Fixes https://github.com/rust-lang/miri/issues/2163 I also did a bit of refactoring on this, so we have a helper method to create a `Pointer` with `None` provenance.
2022-07-05adjust dangling-int-ptr error messageRalf Jung-3/+3
2022-07-05always check overflow in CheckedBinOp in CTFERalf Jung-1/+10
2022-07-05Auto merge of #96862 - oli-obk:enum_cast_mir, r=RalfJungbors-27/+30
Change enum->int casts to not go through MIR casts. follow-up to https://github.com/rust-lang/rust/pull/96814 this simplifies all backends and even gives LLVM more information about the return value of `Rvalue::Discriminant`, enabling optimizations in more cases.
2022-07-05Rollup merge of #98847 - RalfJung:box-is-special, r=oli-obkDylan DPC-12/+56
fix interpreter validity check on Box Follow-up to https://github.com/rust-lang/rust/pull/98554: avoid walking over parts of the value twice. And then move all that logic into the general visitor so not each visitor implementation has to deal with it...
2022-07-05Rollup merge of #98811 - RalfJung:interpret-alloc-range, r=oli-obkDylan DPC-36/+22
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-04interpret: fix CheckedBinOp behavior when overflow checking is disabledRalf Jung-2/+14
2022-07-05Auto merge of #98846 - RalfJung:alignment-is-a-type-thing, r=oli-obkbors-95/+118
interpret: track place alignment together with the type, not the value This matches how I handle alignment in [MiniRust](https://github.com/RalfJung/minirust). I think it makes conceptually a lot more sense. Fixes https://github.com/rust-lang/rust/issues/63085 r? `@oli-obk`
2022-07-04Auto merge of #98627 - RalfJung:interpret-arith, r=lcnrbors-2/+17
interpret: don't rely on ScalarPair for overflowed arithmetic This is for https://github.com/rust-lang/rust/pull/97861. Cc `@eddyb` I would like to avoid making this depend on `dest.layout.abi` to avoid a branch that we are not usually covering both sides of. Though OTOH this seems like fairly straight-forward code. But let's benchmark this option first to see how bad that extra `force_allocation` really is.
2022-07-04extra assertion, extra sureRalf Jung-0/+1
2022-07-04clarify commentRalf Jung-1/+2
2022-07-03move Box mess handling into general visitorRalf Jung-34/+55
2022-07-03fix interpreter validity check on BoxRalf Jung-6/+29
2022-07-03interpret: track place alignment together with the type, not the valueRalf Jung-95/+117
2022-07-03interpret: don't rely on ScalarPair for overflowed arithmeticRalf Jung-2/+16
2022-07-02more use of format! variable captureRalf Jung-3/+1
Co-authored-by: Joe ST <joe@fbstj.net>
2022-07-02Auto merge of #97585 - lqd:const-alloc-intern, r=RalfJungbors-2/+50
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-02make AllocRef APIs more consistentRalf Jung-11/+13
2022-07-02add AllocRange Debug impl; remove redundant AllocId Display implRalf Jung-23/+9
2022-07-02Auto merge of #91743 - cjgillot:enable_mir_inlining_inline_all, r=oli-obkbors-17/+6
Enable MIR inlining Continuation of https://github.com/rust-lang/rust/pull/82280 by `@wesleywiser.` #82280 has shown nice compile time wins could be obtained by enabling MIR inlining. Most of the issues in https://github.com/rust-lang/rust/issues/81567 are now fixed, except the interaction with polymorphization which is worked around specifically. I believe we can proceed with enabling MIR inlining in the near future (preferably just after beta branching, in case we discover new issues). Steps before merging: - [x] figure out the interaction with polymorphization; - [x] figure out how miri should deal with extern types; - [x] silence the extra arithmetic overflow warnings; - [x] remove the codegen fulfilment ICE; - [x] remove the type normalization ICEs while compiling nalgebra; - [ ] tweak the inlining threshold.
2022-07-02Rollup merge of #98783 - RalfJung:jumpscares, r=fee1-deadDylan DPC-1/+1
interpret: make a comment less scary This slipped past my review: "has no meaning" could be read as "is undefined behavior". That is certainly not what we mean so be more clear.
2022-07-02Rollup merge of #98766 - lcnr:mir-visit-pass_by_value, r=oli-obkDylan DPC-10/+10
cleanup mir visitor for `rustc::pass_by_value` by changing `& $($mutability)?` to `$(& $mutability)?` I also did some formatting changes because I started doing them for the visit methods I changed and then couldn't get myself to stop xx, I hope that's still fairly easy to review.
2022-07-02Rollup merge of #98639 - camsteffen:no-node-binding, r=compiler-errorsDylan DPC-1/+1
Factor out `hir::Node::Binding`
2022-07-01interpret: make a comment less scaryRalf Jung-1/+1
2022-07-01Factor out hir::Node::BindingCameron Steffen-1/+1
2022-07-01Rollup merge of #98756 - TaKO8Ki:use-const-instead-of-function, r=Dylan-DPCDylan DPC-5/+3
Use const instead of function and make it private
2022-07-01cleanup mir visitor for `rustc::pass_by_value`lcnr-10/+10