about summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform
AgeCommit message (Collapse)AuthorLines
2020-09-18use matches!() macro for simple if let conditionsMatthias Krüger-3/+2
2020-09-18initial working stateBastian Kauschke-1/+5
2020-09-17Default to implicit (not explicit) rules for promotability in `const fn`Dylan MacKenzie-1/+8
2020-09-17[mir-opt] Disable the `ConsideredEqual` logic in SimplifyBranchSame optWesley Wiser-2/+9
The logic is currently broken and we need to disable it to fix a beta regression (see #76803)
2020-09-16Error if an unstable const eval feature is used in a stable const fnDylan MacKenzie-6/+33
2020-09-16Give name to extra `Span` in `LiveDrop` errorDylan MacKenzie-4/+6
2020-09-16Use helper function for searching `allow_internal_unstable`Dylan MacKenzie-5/+10
2020-09-16Use enum for status of non-const opsDylan MacKenzie-51/+61
2020-09-16Rollup merge of #76756 - matthiaskrgr:cl123ppy, r=Dylan-DPCTyler Mandry-1/+1
fix a couple of stylistic clippy warnings namely: clippy::redundant_pattern_matching clippy::redundant_pattern clippy::search_is_some clippy::filter_next clippy::into_iter_on_ref clippy::clone_on_copy clippy::needless_return
2020-09-16Fix underflow when calculating the number of no-op jumps foldedTomasz Miąsko-9/+10
When removing unwinds to no-op blocks and folding jumps to no-op blocks, remove the unwind target first. Otherwise we cannot determine if target has been already folded or not. Previous implementation incorrectly assumed that all resume targets had been folded already, occasionally resulting in an underflow: remove_noop_landing_pads: removed 18446744073709551613 jumps and 3 landing pads
2020-09-16Rollup merge of #75304 - Aaron1011:feature/diag-deref-move-out, r=estebankDylan DPC-1/+1
Note when a a move/borrow error is caused by a deref coercion Fixes #73268 When a deref coercion occurs, we may end up with a move error if the base value has been partially moved out of. However, we do not indicate anywhere that a deref coercion is occuring, resulting in an error message with a confusing span. This PR adds an explicit note to move errors when a deref coercion is involved. We mention the name of the type that the deref-coercion resolved to, as well as the `Deref::Target` associated type being used.
2020-09-15fix a couple of stylistic clippy warningsMatthias Krüger-1/+1
namely: clippy::redundant_pattern_matching clippy::redundant_pattern clippy::search_is_some clippy::filter_next clippy::into_iter_on_ref clippy::clone_on_copy clippy::needless_return
2020-09-14Add pass names to some common dataflow analysesDylan MacKenzie-2/+9
2020-09-14Auto merge of #76541 - matthiaskrgr:unstable_sort, r=davidtwcobors-2/+2
use sort_unstable to sort primitive types It's not important to retain original order if we have &[1, 1, 2, 3] for example. clippy::stable_sort_primitive
2020-09-14Auto merge of #76123 - tmiasko:inline-args-storage, r=wesleywiserbors-8/+28
inliner: Emit storage markers for introduced arg temporaries When introducing argument temporaries during inlining, emit storage marker statements just before the assignment and in the beginning of the return block. This ensures that such temporaries will not be considered live across yield points after inlining inside a generator. Fixes #71793.
2020-09-13Auto merge of #76244 - vandenheuvel:remove__paramenv__def_id, r=nikomatsakisbors-1/+2
Removing the `def_id` field from hot `ParamEnv` to make it smaller This PR addresses https://github.com/rust-lang/rust/issues/74865.
2020-09-13Fix #76432Simon Vandel Sillesen-21/+22
Only insert StorageDeads if we actually removed one. Fixes an issue where we added StorageDead to a place with no StorageLive
2020-09-13Auto merge of #76306 - tmiasko:nrvo-debuginfo, r=ecstatic-morsebors-4/+5
NRVO: Allow occurrences of the return place in var debug info The non-use occurrence of the return place in var debug info does not currently inhibit NRVO optimization, but it will fail assertion in `visit_place` when optimization is performed. Relax assertion check to allow the return place in var debug info. This case might be impossible to hit in optimization pipelines as of now, but can be encountered in customized mir-opt-level=2 pipeline with copy propagation disabled. For example in: ```rust pub fn b(s: String) -> String { a(s) } #[inline] pub fn a(s: String) -> String { let x = s; let y = x; y } ```
2020-09-10Note when a a move/borrow error is caused by a deref coercionAaron Hill-1/+1
Fixes #73268 When a deref coercion occurs, we may end up with a move error if the base value has been partially moved out of. However, we do not indicate anywhere that a deref coercion is occuring, resulting in an error message with a confusing span. This PR adds an explicit note to move errors when a deref coercion is involved. We mention the name of the type that the deref-coercion resolved to, as well as the `Deref::Target` associated type being used.
2020-09-10Rollup merge of #76567 - matthiaskrgr:clone_on_copy, r=varkorTyler Mandry-1/+1
use push(char) to add chars (single-char &strs) to strings instead of push_str(&str)
2020-09-10Rollup merge of #76565 - matthiaskrgr:box_place, r=oli-obkTyler Mandry-1/+1
take reference to Place directly instead of taking reference to Box<Place> clippy::borrowed_box
2020-09-10Rollup merge of #76548 - tmiasko:validate, r=davidtwcoTyler Mandry-2/+26
Validate removal of AscribeUserType, FakeRead, and Shallow borrow Those statements are removed by CleanupNonCodegenStatements pass in drop lowering phase, and should not occur afterwards.
2020-09-10use String::from instead of format!() macro to craft string ↵Matthias Krüger-1/+1
clippy::useless_format
2020-09-10take reference to Place directly instead of taking reference to Box<Place>Matthias Krüger-1/+1
clippy::borrowed_box
2020-09-10Auto merge of #75573 - Aaron1011:feature/const-mutation-lint, r=oli-obkbors-0/+116
Add CONST_ITEM_MUTATION lint Fixes #74053 Fixes #55721 This PR adds a new lint `CONST_ITEM_MUTATION`. Given an item `const FOO: SomeType = ..`, this lint fires on: * Attempting to write directly to a field (`FOO.field = some_val`) or array entry (`FOO.array_field[0] = val`) * Taking a mutable reference to the `const` item (`&mut FOO`), including through an autoderef `FOO.some_mut_self_method()` The lint message explains that since each use of a constant creates a new temporary, the original `const` item will not be modified.
2020-09-10Validate removal of AscribeUserType, FakeRead, and Shallow borrowTomasz Miąsko-2/+26
Those statements are removed by CleanupNonCodegenStatements pass in drop lowering phase, and should not occur afterwards.
2020-09-09Rollup merge of #76313 - richkadel:mir-spanview-2, r=wesleywiserTyler Mandry-1/+1
Improved the MIR spanview output * Adds missing "tail" spans (spans that continue beyond the end of overlapping spans) * Adds a caret to highlight empty spans associated with MIR elements that have a position, but otherwise would not be visible. * Adds visual pointing brackets at the beginning and end of each span <img width="590" alt="Screen Shot 2020-09-03 at 8 38 08 PM" src="https://user-images.githubusercontent.com/3827298/92202571-25510c00-ee34-11ea-89bc-89eea939476d.png"> <img width="1061" alt="Screen Shot 2020-09-03 at 8 41 04 PM" src="https://user-images.githubusercontent.com/3827298/92202629-49145200-ee34-11ea-8fda-fc6e62c80736.png"> <img width="1113" alt="Screen Shot 2020-09-06 at 5 42 57 PM" src="https://user-images.githubusercontent.com/3827298/92339198-ca085f00-f069-11ea-96d1-c01ced50e2ba.png"> <img width="1692" alt="Screen Shot 2020-09-06 at 5 45 54 PM" src="https://user-images.githubusercontent.com/3827298/92339209-d4c2f400-f069-11ea-94c0-b4d36c200878.png"> r? @tmandry FYI: @wesleywiser
2020-09-10use sort_unstable to sort primitive typesMatthias Krüger-2/+2
It's not important to retain original order if we have &[1, 1, 2, 3] for example. clippy::stable_sort_primitive
2020-09-09Remove def_id field from ParamEnvBram van den Heuvel-1/+2
2020-09-08Auto merge of #76308 - wesleywiser:enable_simplifyarmidentity_mir_opt, r=oli-obkbors-5/+1
Enable the SimplifyArmIdentity MIR optimization at mir-opt-level=1 r? `@ghost`
2020-09-08Auto merge of #75585 - RalfJung:demotion, r=oli-obkbors-16/+2
Do not promote &mut of a non-ZST ever Since ~pre-1.0~ 1.36, we have accepted code like this: ```rust static mut TEST: &'static mut [i32] = { let x = &mut [1,2,3]; x }; ``` I tracked it back to https://github.com/rust-lang/rust/pull/21744, but unfortunately could not find any discussion or RFC that would explain why we thought this was a good idea. And it's not, it breaks all sorts of things -- see https://github.com/rust-lang/rust/issues/75556. To fix https://github.com/rust-lang/rust/issues/75556, we have to stop promoting non-ZST mutable references no matter the context, which is what this PR does. It's a breaking change. Notice that this still works, since it does not rely on promotion: ```rust static mut TEST: &'static mut [i32] = &mut [0,1,2]; ``` Cc `@rust-lang/wg-const-eval`
2020-09-07Auto merge of #76044 - ecstatic-morse:dataflow-lattice, r=oli-obkbors-18/+17
Support dataflow problems on arbitrary lattices This PR implements last of the proposed extensions I mentioned in the design meeting for the original dataflow refactor. It extends the current dataflow framework to work with arbitrary lattices, not just `BitSet`s. This is a prerequisite for dataflow-enabled MIR const-propagation. Personally, I am skeptical of the usefulness of doing const-propagation pre-monomorphization, since many useful constants only become known after monomorphization (e.g. `size_of::<T>()`) and users have a natural tendency to hand-optimize the rest. It's probably worth exprimenting with, however, and others have shown interest cc `@rust-lang/wg-mir-opt.` The `Idx` associated type is moved from `AnalysisDomain` to `GenKillAnalysis` and replaced with an associated `Domain` type that must implement `JoinSemiLattice`. Like before, each `Analysis` defines the "bottom value" for its domain, but can no longer override the dataflow join operator. Analyses that want to use set intersection must now use the `lattice::Dual` newtype. `GenKillAnalysis` impls have an additional requirement that `Self::Domain: BorrowMut<BitSet<Self::Idx>>`, which effectively means that they must use `BitSet<Self::Idx>` or `lattice::Dual<BitSet<Self::Idx>>` as their domain. Most of these changes were mechanical. However, because a `Domain` is no longer always a powerset of some index type, we can no longer use an `IndexVec<BasicBlock, GenKillSet<A::Idx>>>` to store cached block transfer functions. Instead, we use a boxed `dyn Fn` trait object. I discuss a few alternatives to the current approach in a commit message. The majority of new lines of code are to preserve existing Graphviz diagrams for those unlucky enough to have to debug dataflow analyses. I find these diagrams incredibly useful when things are going wrong and considered regressing them unacceptable, especially the pretty-printing of `MovePathIndex`s, which are used in many dataflow analyses. This required a parallel `fmt` trait used only for printing dataflow domains, as well as a refactoring of the `graphviz` module now that we cannot expect the domain to be a `BitSet`. Some features did have to be removed, such as the gen/kill display mode (which I didn't use but existed to mirror the output of the old dataflow framework) and line wrapping. Since I had to rewrite much of it anyway, I took the opportunity to switch to a `Visitor` for printing dataflow state diffs instead of using cursors, which are error prone for code that must be generic over both forward and backward analyses. As a side-effect of this change, we no longer have quadratic behavior when writing graphviz diagrams for backward dataflow analyses. r? `@pnkfelix`
2020-09-07Add CONST_ITEM_MUTATION lintAaron Hill-0/+116
Fixes #74053 Fixes #55721 This PR adds a new lint `CONST_ITEM_MUTATION`. Given an item `const FOO: SomeType = ..`, this lint fires on: * Attempting to write directly to a field (`FOO.field = some_val`) or array entry (`FOO.array_field[0] = val`) * Taking a mutable reference to the `const` item (`&mut FOO`), including through an autoderef `FOO.some_mut_self_method()` The lint message explains that since each use of a constant creates a new temporary, the original `const` item will not be modified.
2020-09-06Improved the MIR spanview outputRich Kadel-1/+1
* Adds missing "tail" spans (spans that continue beyond the end of overlapping spans) * Adds a caret to highlight empty spans associated with MIR elements that have a position, but otherwise would not be visible. * Adds visual pointing brackets at the beginning and end of each span
2020-09-06do not premote non-ZST mutable references everRalf Jung-16/+2
2020-09-06Generalize to Eq(true, _place) and Eq(_place, true)Simon Vandel Sillesen-15/+30
2020-09-06Add peephold optimization that simplifies Ne(_1, false) and Ne(false, _1) ↵Simon Vandel Sillesen-2/+38
into _1 This was observed emitted from the MatchBranchSimplification pass.
2020-09-05Rollup merge of #76263 - tmiasko:inline-codegen-fn-attrs, r=ecstatic-morseDylan DPC-5/+17
inliner: Check for codegen fn attributes compatibility * Check for target features compatibility * Check for no_sanitize attribute compatibility Fixes #76259.
2020-09-04Change ty.kind to a methodLeSeulArtichaut-38/+38
2020-09-04Auto merge of #76004 - richkadel:llvm-coverage-map-gen-6b.5, r=tmandrybors-28/+272
Tools, tests, and experimenting with MIR-derived coverage counters Leverages the new mir_dump output file in HTML+CSS (from #76074) to visualize coverage code regions and the MIR features that they came from (including overlapping spans). See example below. The `run-make-fulldeps/instrument-coverage` test has been refactored to maximize test coverage and reduce code duplication. The new tests support testing with and without `-Clink-dead-code`, so Rust coverage can be tested on MSVC (which, currently, only works with `link-dead-code` _disabled_). New tests validate coverage region generation and coverage reports with multiple counters per function. Starting with a simple `if-else` branch tests, coverage tests for each additional syntax type can be added by simply dropping in a new Rust sample program. Includes a basic, MIR-block-based implementation of coverage injection, available via `-Zexperimental-coverage`. This implementation has known flaws and omissions, but is simple enough to validate the new tools and tests. The existing `-Zinstrument-coverage` option currently enables function-level coverage only, which at least appears to generate accurate coverage reports at that level. Experimental coverage is not accurate at this time. When branch coverage works as intended, the `-Zexperimental-coverage` option should be removed. This PR replaces the bulk of PR #75828, with the remaining parts of that PR distributed among other separate and indentpent PRs. This PR depends on two of those other PRs: #76002, #76003 and #76074 Rust compiler MCP rust-lang/compiler-team#278 Relevant issue: #34701 - Implement support for LLVMs code coverage instrumentation ![Screen-Recording-2020-08-21-at-2](https://user-images.githubusercontent.com/3827298/90972923-ff417880-e4d1-11ea-92bb-8713c6198f6d.gif) r? @tmandry FYI: @wesleywiser
2020-09-03Enable the SimplifyArmIdentity MIR optimization at mir-opt-level=1Wesley Wiser-5/+1
2020-09-04NRVO: Allow occurrences of the return place in var debug infoTomasz Miąsko-4/+5
The non-use occurrence of the return place in var debug info does not currently inhibit NRVO optimization, but it will fail assertion in `visit_place` when optimization is performed. Relax assertion check to allow the return place in var debug info. This case might be impossible to hit in optimization pipelines as of now, but can be encountered in customized mir-opt-level=2 pipeline with copy propagation disabled. For example in: ``` pub fn b(s: String) -> String { a(s) } #[inline] pub fn a(s: String) -> String { let x = s; let y = x; y } ```
2020-09-04inliner: Check for no_sanitize attribute compatibilityTomasz Miąsko-3/+6
2020-09-04inliner: Check for target features compatibilityTomasz Miąsko-2/+11
2020-09-03inliner: Emit storage markers for introduced arg temporariesTomasz Miąsko-8/+28
When introducing argument temporaries during inlining, emit storage marker statements just before the assignment and in the beginning of the return block. This ensures that such temporaries will not be considered live across yield points after inlining inside a generator.
2020-09-03Tools, tests, and experimenting with MIR-derived coverage countersRich Kadel-28/+272
Adds a new mir_dump output file in HTML/CSS to visualize code regions and the MIR features that they came from (including overlapping spans). See example below: Includes a basic, MIR-block-based implementation of coverage injection, available via `-Zexperimental-coverage`. This implementation has known flaws and omissions, but is simple enough to validate the new tools and tests. The existing `-Zinstrument-coverage` option currently enables function-level coverage only, which at least appears to generate accurate coverage reports at that level. Experimental coverage is not accurate at this time. When branch coverage works as intended, the `-Zexperimental-coverage` option should be removed. This PR replaces the bulk of PR #75828, with the remaining parts of that PR distributed among other separate and indentpent PRs. This PR depends on three of those other PRs: #76000, #76002, and Rust compiler MCP rust-lang/compiler-team#278 Relevant issue: #34701 - Implement support for LLVMs code coverage instrumentation ![Screen-Recording-2020-08-21-at-2](https://user-images.githubusercontent.com/3827298/90972923-ff417880-e4d1-11ea-92bb-8713c6198f6d.gif)
2020-09-02inliner: Avoid query cycles when optimizing generatorsTomasz Miąsko-2/+8
The HIR Id trick is insufficient to prevent query cycles when optimizing generators, since merely requesting a layout of a generator also computes its `optimized_mir`. Make no attempts to inline functions into generators within the same crate to avoid query cycles.
2020-08-30Update dataflow analyses to use new interfaceDylan MacKenzie-18/+17
2020-08-30mv compiler to compiler/mark-0/+13372