Commit Graph

483 Commits

Author SHA1 Message Date
Ralf Jung
46956f76ca adjust dangling-int-ptr error message 2022-07-05 08:08:24 -04: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
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
Wesley Wiser
5999f34ff6 Don't assert polymorphization has taken effect in const eval
Const eval no longer runs MIR optimizations so unless this is getting
run as part of a MIR optimization like const-prop, there can be unused
type parameters even if polymorphization is enabled.
2022-06-30 21:45:29 +02:00
Matthias Krüger
9bcf992499
Rollup merge of #98688 - RalfJung:from-mplace, r=oli-obk
interpret: add From<&MplaceTy> for PlaceTy

We have a similar instance for `&MPlaceTy` to `OpTy`. Also add the same for `&mut`.

This avoids having to write `&(*place).into()`, which we have a few times here and at least twice in Miri (and it comes up again in my current patch).

r? ```@oli-obk```
2022-06-30 19:55:54 +02:00
Ralf Jung
f60ec83779 interpret: add From<&MplaceTy> for PlaceTy 2022-06-29 17:13:13 -04:00
Matthias Krüger
921e311da2
Rollup merge of #98643 - voidc:valtree-ref-pretty, r=lcnr
Improve pretty printing of valtrees for references

This implements the changes outlined in https://github.com/rust-lang/rust/issues/66451#issuecomment-1168859638.

r? `@lcnr`
Fixes #66451
2022-06-29 20:35:01 +02:00
Dylan DPC
b2836bd34c
Rollup merge of #98554 - DrMeepster:box_unsizing_is_not_special, r=RalfJung
Fix box with custom allocator in miri

This should fix the failures in https://github.com/rust-lang/miri/pull/2072 and https://github.com/rust-lang/rust/pull/98510.

cc ```@RalfJung```
2022-06-29 17:59:35 +05:30
Dylan DPC
021d21c888
Rollup merge of #98549 - RalfJung:interpret-stacktraces, r=oli-obk
interpret: do not prune requires_caller_location stack frames quite so early

https://github.com/rust-lang/rust/pull/87000 made the interpreter skip `caller_location` frames for its stacktraces and `cur_span`. However, those functions are used for much more than just panic reporting, and e.g. when Miri reports UB somewhere, it probably wants to point inside `caller_location` frames. (And if it did not, it would want to have its own logic to decide that, not be forced into it by the core interpreter engine.) This fixes some rare ICEs in Miri that say "we should never pop more than one frame at once".

So let's remove all `caller_location` logic from the core interpreter, and instead move it to CTFE error reporting. This does not change user-visible behavior. That's the first commit.

We might additionally want to change CTFE error reporting to treat panics differently from other errors: only prune `caller_location` frames for panics. The second commit does that. But honestly I am not sure if this is an improvement.

r? ``@oli-obk``
2022-06-29 10:28:23 +05:30
Rémy Rakic
d634f14f26 avoid walk when get_ptr_alloc returns no AllocRef 2022-06-29 02:05:02 +02:00
Rémy Rakic
6d03c8d751 fix comments 2022-06-29 02:05:02 +02:00
DrMeepster
9039265c30 fix silly mistake
you should always run x.py check before pushing
2022-06-28 13:48:13 -07:00
Dominik Stolz
cd88bb332c Improve pretty printing of valtrees for references 2022-06-28 22:38:32 +02:00
Rémy Rakic
c9772d7619 const alloc interning: only check for references for arrays/slices
Checking the size/alignment of an mplace may be costly, so we only do it
on the types where the walk we want to avoid could be expensive: the larger types
like arrays and slices, rather than on all aggregates being interned.
2022-06-28 22:09:29 +02:00
Rémy Rakic
18cbc19de2 ctfe: clarify skipping the interning walk
Reorganizes the previous commits to have a single exit-point to avoid doing the
potentially costly walk. Also moves the relocations tests before the interior
mutability test: only references are important when checking for `UnsafeCell`s
and we're checking if there are any to decide to avoid the walk anyways.
2022-06-28 22:09:29 +02:00
Rémy Rakic
266bab2ab0 make get_relocations private
This limits access to the relocations data a bit (instead of increasing it just
for the purposes of interning).
2022-06-28 22:09:29 +02:00
Rémy Rakic
97a0b2e2d0 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.
2022-06-28 22:09:28 +02:00
DrMeepster
9f9c311718 Validate all fields of box instead of validating allocator specifically 2022-06-28 02:19:52 -07:00
Ralf Jung
8e73c3ed18 make AllocKind actually public 2022-06-27 10:58:30 -04:00
Ralf Jung
b094116538 interpret: refactor allocation info query
We now have an infallible function that also tells us which kind of allocation we are talking about.
Also we do longer have to distinguish between data and function allocations for liveness.
2022-06-26 22:49:40 -04:00
DrMeepster
d317988505 validate box's allocator 2022-06-26 18:54:03 -07:00
DrMeepster
6e32a16520 fix box with custom allocator in miri 2022-06-26 13:58:37 -07:00
Ralf Jung
852a111133 interpret: do not prune requires_caller_location stack frames quite so early 2022-06-26 14:42:26 -04:00
Yuki Okushi
e3ae9f5b20
Rollup merge of #98099 - RalfJung:convert_tag_add_extra, r=oli-obk
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-22 07:03:59 +09:00
bors
a25b1315ee Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obk
Remove dereferencing of Box from codegen

Through #94043, #94414, #94873, and #95328, I've been fixing issues caused by Box being treated like a pointer when it is not a pointer. However, these PRs just introduced special cases for Box. This PR removes those special cases and instead transforms a deref of Box into a deref of the pointer it contains.

Hopefully, this is the end of the Box<T, A> ICEs.
2022-06-21 11:00:39 +00:00
Michael Goulet
5373d738e8 Mention formatting macros when encountering ArgumentV1::new in const 2022-06-19 20:18:08 -07:00
Ralf Jung
1c1a60f0a3 interpret: convert_tag_add_extra, init_allocation_extra: allow tagger to raise errors 2022-06-16 09:41:07 -07:00
DrMeepster
dff1f9f6bb make sure miri ices when dereferencing a box 2022-06-15 18:39:23 -07:00