Commit Graph

509 Commits

Author SHA1 Message Date
Michael Goulet
934079fd9e Migrate unstable-in-stable diagnostic 2022-07-08 03:39:08 +00:00
Matthias Krüger
90641470be
Rollup merge of #98979 - RalfJung:more-alloc-range, r=oli-obk
interpret: use AllocRange in UninitByteAccess

also use nice new format string syntax in `interpret/error.rs`, and use the `#` flag to add `0x` prefixes where applicable.

r? ``@oli-obk``
2022-07-07 20:33:26 +02:00
Dylan DPC
71b3fbdb47
Rollup merge of #98930 - tmiasko:pub-basic-blocks, r=oli-obk
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-07 18:06:53 +05:30
Dylan DPC
f6bbe280bf
Rollup merge of #96856 - DrMeepster:fix_projection_validation, r=Icnr
Fix ProjectionElem validation

`TypeChecker::visit_projection_elem` was not actually being called.
2022-07-07 18:06:48 +05:30
Tomasz Miąsko
c9dd1d9983 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-07 08:11:49 +02:00
bors
8824d13161 Auto merge of #98831 - RalfJung:no-more-unsized-locals, r=oli-obk
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-06 22:50:29 +00:00
Guillaume Gomez
d712f67897
Rollup merge of #98519 - TaKO8Ki:add-head-span-field-to-item-and-impl-item, r=cjgillot
Replace some `guess_head_span` with `def_span`

This patch fixes a part of #97417.
r? `@cjgillot`
2022-07-06 20:43:24 +02:00
Ralf Jung
e685530b07 deduplicate some copy_op code 2022-07-06 14:11:41 -04:00
Ralf Jung
47cb276ab8 support passing unsized fn arguments 2022-07-06 14:03:20 -04:00
Ralf Jung
8ef0caa23c interpret: remove LocalValue::Unallocated, add Operand::Uninit
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-06 14:03:20 -04:00
Ralf Jung
27b7b3dcd6 interpret: use AllocRange in UninitByteAccess
also use nice new format string syntax in interpret/error.rs
2022-07-06 10:55:06 -04:00
Takayuki Maeda
83dea35384 replace guess_head_span with def_span 2022-07-06 19:09:47 +09:00
Dylan DPC
7f62a719af
Rollup merge of #98968 - RalfJung:scalar-sanity, r=oli-obk
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-06 14:49:13 +05:30
Dylan DPC
56667b5a07
Rollup merge of #98964 - RalfJung:typo, r=Dylan-DPC
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-06 14:49:11 +05:30
DrMeepster
a2799b2de8 fix projectionelem validation 2022-07-06 01:59:16 -07:00
bors
5b8cf49c51 Auto merge of #98206 - eggyal:align-to-chalk-folding-api, r=jackh726
Split TypeVisitable from TypeFoldable

Impl of rust-lang/compiler-team#520 following MCP approval.

r? `@ghost`
2022-07-06 05:48:11 +00:00
Alan Egerton
4f0a64736b
Update TypeVisitor paths 2022-07-06 06:41:53 +01:00
Ralf Jung
8f867c5445 finally enable Scalar layout sanity checks 2022-07-05 22:26:26 -04:00
Ralf Jung
4687afa480 fix type in function name 2022-07-05 17:48:43 -04:00
Alan Egerton
e9e5d0685b
Relax constrained generics to TypeVisitable 2022-07-05 22:25:43 +01:00
Matthias Krüger
cca43fe8e2
Rollup merge of #98888 - RalfJung:interpret-checked-bin, r=oli-obk
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-05 17:08:11 +02:00
Matthias Krüger
69195c026e
Rollup merge of #98860 - RalfJung:dangling-int-ptr, r=davidtwco
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-05 17:08:10 +02:00
Ralf Jung
46956f76ca adjust dangling-int-ptr error message 2022-07-05 08:08:24 -04:00
Ralf Jung
2f6e996662 always check overflow in CheckedBinOp in CTFE 2022-07-05 07:32:38 -04:00
bors
53792b9c5c Auto merge of #96862 - oli-obk:enum_cast_mir, r=RalfJung
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-05 09:36:29 +00:00
Dylan DPC
7702c50ea5
Rollup merge of #98847 - RalfJung:box-is-special, r=oli-obk
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-05 10:42:57 +05:30
Dylan DPC
522d52cef7
Rollup merge of #98811 - RalfJung:interpret-alloc-range, r=oli-obk
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-05 10:42:55 +05:30
Ralf Jung
6f01ff61b3 interpret: fix CheckedBinOp behavior when overflow checking is disabled 2022-07-04 23:29:41 -04:00
bors
4008dd8c6d Auto merge of #98846 - RalfJung:alignment-is-a-type-thing, r=oli-obk
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-05 01:23:09 +00:00
bors
27eb6d7018 Auto merge of #98627 - RalfJung:interpret-arith, r=lcnr
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-04 20:00:41 +00:00
Ralf Jung
0850bad94d extra assertion, extra sure 2022-07-04 09:12:22 -04:00
Ralf Jung
b1568e6f34 clarify comment 2022-07-04 09:05:23 -04:00
Ralf Jung
d7edf66a5a move Box mess handling into general visitor 2022-07-03 22:55:25 -04:00
Ralf Jung
7fc77806d4 fix interpreter validity check on Box 2022-07-03 22:42:50 -04:00
Ralf Jung
8955686e05 interpret: track place alignment together with the type, not the value 2022-07-03 10:22:37 -04:00
Ralf Jung
595dd976bd interpret: don't rely on ScalarPair for overflowed arithmetic 2022-07-03 09:56:31 -04:00
Ralf Jung
0832d1d022
more use of format! variable capture
Co-authored-by: Joe ST <joe@fbstj.net>
2022-07-02 13:37:24 -04:00
bors
750d6f8545 Auto merge of #97585 - lqd:const-alloc-intern, r=RalfJung
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-02 17:05:13 +00:00
Ralf Jung
d31cbb5150 make AllocRef APIs more consistent 2022-07-02 11:41:16 -04:00
Ralf Jung
c36572c11e add AllocRange Debug impl; remove redundant AllocId Display impl 2022-07-02 11:41:16 -04:00
bors
0075bb4fad Auto merge of #91743 - cjgillot:enable_mir_inlining_inline_all, r=oli-obk
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-02 11:24:17 +00:00
Dylan DPC
7a4f33bec9
Rollup merge of #98783 - RalfJung:jumpscares, r=fee1-dead
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-02 12:23:42 +05:30
Dylan DPC
05aebf8f69
Rollup merge of #98766 - lcnr:mir-visit-pass_by_value, r=oli-obk
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-02 12:23:41 +05:30
Dylan DPC
d287726aa0
Rollup merge of #98639 - camsteffen:no-node-binding, r=compiler-errors
Factor out `hir::Node::Binding`
2022-07-02 12:23:38 +05:30
Ralf Jung
65944ce522 interpret: make a comment less scary 2022-07-01 17:57:32 -04:00
Cameron Steffen
ec82bc1996 Factor out hir::Node::Binding 2022-07-01 10:04:19 -05:00
Dylan DPC
6404620f18
Rollup merge of #98756 - TaKO8Ki:use-const-instead-of-function, r=Dylan-DPC
Use const instead of function and make it private
2022-07-01 20:19:21 +05:30
lcnr
cf9c0a5935 cleanup mir visitor for rustc::pass_by_value 2022-07-01 16:21:21 +02:00
Takayuki Maeda
f791ac6a79 use const instead of function and make it private 2022-07-01 16:55:23 +09:00
Camille GILLOT
0161ecd13f Recover when failing to normalize closure signature. 2022-06-30 21:45:29 +02:00