Commit Graph

533 Commits

Author SHA1 Message Date
Oli Scherer
ec8d01fdcc Allow iterators instead of requiring slices that will get turned into iterators 2022-11-21 20:33:55 +00:00
Cameron Steffen
cc8dddbac9 Factor out conservative_is_privately_uninhabited 2022-11-20 19:04:11 -06:00
Matthias Krüger
820a41580e
Rollup merge of #104564 - RalfJung:either, r=oli-obk
interpret: use Either over Result when it is not representing an error condition

r? `@oli-obk`
2022-11-20 18:21:48 +01:00
Dylan DPC
00876c68c4
Rollup merge of #104411 - lcnr:bivariance-nll, r=compiler-errors
nll: correctly deal with bivariance

fixes #104409

when in a bivariant context, relating stuff should always trivially succeed. Also changes the mir validator to correctly deal with higher ranked regions.

r? types cc ``@RalfJung``
2022-11-19 11:54:44 +05:30
Ralf Jung
09a887cebf review feedback 2022-11-18 14:24:48 +01:00
Ralf Jung
4101889786 interpret: use Either over Result when it is not representing an error condition 2022-11-18 10:18:32 +01:00
bors
7c75fe4c85 Auto merge of #104170 - cjgillot:hir-def-id, r=fee1-dead
Record `LocalDefId` in HIR nodes instead of a side table

This is part of an attempt to remove the `HirId -> LocalDefId` table from HIR.
This attempt is a prerequisite to creation of `LocalDefId` after HIR lowering (https://github.com/rust-lang/rust/pull/96840), by controlling how `def_id` information is accessed.

This first part adds the information to HIR nodes themselves instead of a table.
The second part is https://github.com/rust-lang/rust/pull/103902
The third part will be to make `hir::Visitor::visit_fn` take a `LocalDefId` as last parameter.
The fourth part will be to completely remove the side table.
2022-11-17 07:42:27 +00:00
Ralf Jung
1115ec601a cleanup and dedupe CTFE and Miri error reporting 2022-11-16 10:13:29 +01:00
bors
79146baa9c Auto merge of #102570 - cjgillot:deagg-debuginfo, r=oli-obk
Perform simple scalar replacement of aggregates (SROA) MIR opt

This is a re-open of https://github.com/rust-lang/rust/pull/85796

I copied the debuginfo implementation (first commit) from `@eddyb's` own SROA PR.

This pass replaces plain field accesses by simple locals when possible.
To be eligible, the replaced locals:
- must not be enums or unions;
- must not be used whole;
- must not have their address taken.

The storage and deinit statements are duplicated on each created local.

cc `@tmiasko` who reviewed the former version of this PR.
2022-11-15 23:52:22 +00:00
Camille GILLOT
779007da06 Enable SROA by at mir-opt level 3. 2022-11-15 17:59:36 +00:00
Camille GILLOT
e4f343191a Flatten aggregates into locals. 2022-11-15 17:55:11 +00:00
Camille GILLOT
b550eabfa6 Introduce composite debuginfo. 2022-11-15 17:53:50 +00:00
bors
a00f8ba7fc Auto merge of #104054 - RalfJung:byte-provenance, r=oli-obk
interpret: support for per-byte provenance

Also factors the provenance map into its own module.

The third commit does the same for the init mask. I can move it in a separate PR if you prefer.

Fixes https://github.com/rust-lang/miri/issues/2181

r? `@oli-obk`
2022-11-15 17:37:15 +00:00
lcnr
6aa611a84c mv utility methods into separate module 2022-11-15 13:50:13 +01:00
lcnr
45f441a7b4 nll: correctly deal with bivariance 2022-11-15 13:34:08 +01:00
bors
357f660729 Auto merge of #101168 - jachris:dataflow-const-prop, r=oli-obk
Add new MIR constant propagation based on dataflow analysis

The current constant propagation in `rustc_mir_transform/src/const_prop.rs` fails to handle many cases that would be expected from a constant propagation optimization. For example:
```rust
let x = if true { 0 } else { 0 };
```
This pull request adds a new constant propagation MIR optimization pass based on the existing dataflow analysis framework. Since most of the analysis is not unique to constant propagation, a generic framework has been extracted. It works on top of the existing framework and could be reused for other optimzations.

Closes #80038. Closes #81605.

## Todo
### Essential
- [x] [Writes to inactive enum variants](https://github.com/rust-lang/rust/pull/101168#pullrequestreview-1089493974). Resolved by rejecting the registration of places with downcast projections for now. Could be improved by flooding other variants if mutable access to a variant is observed.
- [X] Handle [`StatementKind::CopyNonOverlapping`](https://github.com/rust-lang/rust/pull/101168#discussion_r957774914). Resolved by flooding the destination.
- [x] Handle `UnsafeCell` / `!Freeze` correctly.
- [X] Overflow propagation of `CheckedBinaryOp`: Decided to not propagate if overflow flag is `true` (`false` will still be propagated)
- [x] More documentation in general.
- [x] Arguments for correctness, documentation of necessary assumptions.
- [x] Better performance, or alternatively, require `-Zmir-opt-level=3` for now.

### Extra
- [x]  Add explicit unreachability, i.e. upgrading the lattice from $\mathbb{P} \to \mathbb{V}$ to $\set{\bot} \cup (\mathbb{P} \to \mathbb{V})$.
- [x] Use storage statements to improve precision.
- [ ] Consider opening issue for duplicate diagnostics: https://github.com/rust-lang/rust/pull/101168#issuecomment-1276609950
- [ ] Flood moved-from places with $\bot$ (requires some changes for places with tracked projections).
- [ ] Add downcast projections back in.
- [ ] [Algebraic simplifications](https://github.com/rust-lang/rust/pull/101168#discussion_r957967878) (possibly with a shared API; done by old const prop).
- [ ] Propagation through slices / arrays.
- [ ] Find other optimizations that are done by old `const_prop.rs`, but not by this one.
2022-11-15 09:38:05 +00:00
Ralf Jung
68af46c112 assert that we are (de)seiralizing ProvenanceMap correctly 2022-11-14 18:26:40 +01:00
Camille GILLOT
9d20aca983 Store a LocalDefId in hir::Variant & hir::Field. 2022-11-13 14:06:51 +00:00
Ralf Jung
c78021709a add is_sized method on Abi and Layout, and use it 2022-11-13 12:23:53 +01:00
Jannis Christopher Köhl
ea23585c91 Disable limits if mir-opt-level >= 4 2022-11-12 20:14:34 +01:00
Jannis Christopher Köhl
d66a00a7b1 Expand upon comment regarding self-assignment 2022-11-12 20:05:52 +01:00
Jannis Christopher Köhl
74d53ab912 Require -Zmir-opt-level >= 3 for now 2022-11-12 15:24:23 +01:00
Jannis Christopher Köhl
b3f648958d Add comment for guessed constants 2022-11-12 14:07:54 +01:00
Jannis Christopher Köhl
8ecb276735 Simplify creation of map 2022-11-10 19:12:10 +01:00
Michael Goulet
31157def1a Don't ICE when encountering ConstKind::Error in RequiredConstsVisitor 2022-11-10 05:14:04 +00:00
Jannis Christopher Köhl
9766ee0b20 Fix struct field tracking and add tests for it 2022-11-09 18:21:42 +01:00
Jannis Christopher Köhl
bfbca6c75c Completely remove tracking of references for now 2022-11-09 18:03:30 +01:00
Jakob Degen
ba359d8a51 Add support for custom MIR parsing 2022-11-08 23:13:15 -08:00
Jannis Christopher Köhl
72196ee666 Limit number of basic blocks and tracked places to 100 for now 2022-11-07 10:35:26 +01:00
Jannis Christopher Köhl
b478fcf270 Use new cast methods 2022-11-07 10:35:26 +01:00
Jannis Christopher Köhl
630e17d3e4 Limit number of tracked places, and some other perf improvements 2022-11-07 10:35:26 +01:00
Jannis Christopher Köhl
1f82a9f89e Move HasTop and HasBottom into lattice.rs 2022-11-07 10:35:25 +01:00
Jannis Christopher Köhl
f29533b4e0 Small documentation changes 2022-11-07 10:35:25 +01:00
Jannis Christopher Köhl
efc7ca8c7d Use ParamEnv consistently 2022-11-07 10:35:25 +01:00
Jannis Christopher Köhl
d86acdd72a Prevent propagation of overflow if overflow occured 2022-11-07 10:35:24 +01:00
Jannis Christopher Köhl
062053ba79 Fix unimplemented binary_ptr_op 2022-11-07 10:35:24 +01:00
Jannis Christopher Köhl
274a49132b Improve documentation, plus some small changes 2022-11-07 10:35:23 +01:00
Jannis Christopher Köhl
931d99f61f Make overflow handling more precise 2022-11-07 10:35:23 +01:00
Jannis Christopher Köhl
be9013f02b Make overflow flag propagation conditional 2022-11-07 10:35:23 +01:00
Jannis Christopher Köhl
890fae9c60 Fix rebased CastKind 2022-11-07 10:35:22 +01:00
Jannis Christopher Köhl
5696d06e22 Use the same is_enabled as the current const prop 2022-11-07 10:35:21 +01:00
Jannis Christopher Köhl
111324e17c Prevent registration inside references if target is !Freeze 2022-11-07 10:35:20 +01:00
Jannis Christopher Köhl
7ab1ba95de Remove Unknown state in favor of Value(Top) 2022-11-07 10:35:20 +01:00
Jannis Christopher Köhl
bc82c13e97 Track Scalar instead of ScalarInt for const prop 2022-11-07 10:35:16 +01:00
Jannis Christopher Köhl
fe84bbf844 Add tracking of unreachability 2022-11-07 10:35:13 +01:00
Jannis Christopher Köhl
16dedba1c8 Ignore terminators explicitly 2022-11-07 10:35:13 +01:00
Jannis Christopher Köhl
47a00d5337 Flood with bottom instead of top for unreachable branches 2022-11-07 10:35:12 +01:00
Jannis Christopher Köhl
ad99d2e15d Move handling of references and simplify flooding 2022-11-07 10:35:11 +01:00
Jannis Christopher Köhl
4f9c30fb67 Add initial version of value analysis and dataflow constant propagation 2022-11-07 10:35:08 +01:00
bors
a4ab2e0643 Auto merge of #103975 - oli-obk:tracing, r=jackh726
Some tracing and comment cleanups

Pulled out of https://github.com/rust-lang/rust/pull/101900 to see if that is the perf impact
2022-11-06 02:21:34 +00:00