about summary refs log tree commit diff
path: root/src/librustc_mir
AgeCommit message (Collapse)AuthorLines
2020-08-15MatchBranchSimplification: fix equal const bool assignmentsTomasz Miąsko-35/+82
The match branch simplification is applied when target blocks contain statements that are either equal or perform a const bool assignment with different values to the same place. Previously, when constructing new statements, only statements from a single block had been examined. This lead to a misoptimization when statements are equal because the assign the *same* const bool value to the same place. Fix the issue by examining statements from both blocks when deciding on replacement.
2020-08-14polymorphize: `I` used if `T` used in `I: Foo<T>`David Wood-31/+119
This commit adjusts polymorphization's handling of predicates so that after ensuring that `T` is used in `I: Foo<T>` if `I` is used, it now ensures that `I` is used if `T` is used in `I: Foo<T>`. This is necessary to mark generic parameters that only exist in impl parameters as used - thereby avoiding symbol clashes when using the new mangling scheme. Signed-off-by: David Wood <david@davidtw.co>
2020-08-14Rollup merge of #75517 - RalfJung:promo-intern-comments, r=oli-obkTyler Mandry-2/+9
Promotion and const interning comments I understood some things today which I felt should be put into comments. Cc @rust-lang/wg-const-eval
2020-08-14MatchBranchSimplification: copy discriminant instead of moving itTomasz Miąsko-1/+1
It might be necessary to use its value more than once.
2020-08-14MatchBranchSimplification: optimize when switching on copy operandTomasz Miąsko-1/+1
2020-08-14Auto merge of #75416 - richkadel:llvm-coverage-map-gen-5.3, r=richkadelbors-0/+15
LLVM IR coverage encoding aligns closer to Clang's I found some areas for improvement while attempting to debug the SegFault issue when running rust programs compiled using MSVC, with coverage instrumentation. I discovered that LLVM's coverage writer was generating incomplete function name variable names (that's not a typo: the name of the variable that holds a function name). The existing implementation used one-up numbers to distinguish variables, and correcting the names did not fix the MSVC coverage bug, but the fix in this PR makes the names and resulting LLVM IR easier to follow and more consistent with Clang's implementation. I also changed the way the `-Zinstrument-coverage` option is supported in symbol_export.rs. The original implementation was incorrect, and the corrected version matches the handling for `-Zprofile-generate`, as it turns out. (An argument could be made that maybe `-Zinstrument-coverage` should automatically enable `-Cprofile-generate`. In fact, if `-Cprofile-generate` is analagous to Clang's `-fprofile-generate`, as some documentation implies, Clang always requires this flag for its implementation of source-based code coverage. This would require a little more validation, and if implemented, would probably require updating some of the user-facing messages related to `-Cprofile-generate` to not be so specific to the PGO use case.) None of these changes fixed the MSVC coverage problems, but they should still be welcome improvements. Lastly, I added some additional FIXME comments in instrument_coverage.rs describing issues I found with the generated LLVM IR that would be resolved if the coverage instrumentation is injected with a `Statement` instead of as a new `BasicBlock`. I describe seven advantages of this change, but it requires some discussion before making a change like this. r? @tmandry
2020-08-14add a FIXME concerning interning of promotedsRalf Jung-0/+6
2020-08-14LLVM IR coverage encoding aligns closer to Clang'sRich Kadel-0/+15
I found some areas for improvement while attempting to debug the SegFault issue when running rust programs compiled using MSVC, with coverage instrumentation. I discovered that LLVM's coverage writer was generating incomplete function name variable names (that's not a typo: the name of the variable that holds a function name). The existing implementation used one-up numbers to distinguish variables, and correcting the names did not fix the MSVC coverage bug, but the fix in this PR makes the names and resulting LLVM IR easier to follow and more consistent with Clang's implementation. I also changed the way the `-Zinstrument-coverage` option is supported in symbol_export.rs. The original implementation was incorrect, and the corrected version matches the handling for `-Zprofile-generate`, as it turns out. (An argument could be made that maybe `-Zinstrument-coverage` should automatically enable `-Cprofile-generate`. In fact, if `-Cprofile-generate` is analagous to Clang's `-fprofile-generate`, as some documentation implies, Clang always requires this flag for its implementation of source-based code coverage. This would require a little more validation, and if implemented, would probably require updating some of the user-facing messages related to `-Cprofile-generate` to not be so specific to the PGO use case.) None of these changes fixed the MSVC coverage problems, but they should still be welcome improvements. Lastly, I added some additional FIXME comments in instrument_coverage.rs describing issues I found with the generated LLVM IR that would be resolved if the coverage instrumentation is injected with a `Statement` instead of as a new `BasicBlock`. I describe seven advantages of this change, but it requires some discussion before making a change like this.
2020-08-14Auto merge of #75503 - JulianKnodt:opt_opt, r=oli-obkbors-93/+72
Clean up some mir transform passes I noticed a few places where there were intermediates being created in MIR optimization passes, so I removed them. I also changed some `Some(..)` into just `..` and wrap `Some(..)` at the function end, doing early returns for `None`. I was generally looking for some easy optimizations in theses passes, and hopefully these should improve the runtime of these passes by a tinnnyyyyy bit. r? @oli-obk
2020-08-14answer an old question re: intern kindsRalf Jung-1/+2
2020-08-14mention 'lifetime extension' in promotion doc commentsRalf Jung-1/+1
2020-08-14Rm allocation in uninhabited_enum_branchingkadmin-53/+33
Also convert `uninhabited_enum_branching` `Cow<[u128]>::to_mut`
2020-08-14Add fixkadmin-9/+7
This also explicitly checks that the types are `bool`. `try_eval_bool` also appears to just succeed for `u8`, so this ensures that it actually is a bool before casting.
2020-08-13Clean up some mir transform passeskadmin-51/+50
I noticed a few places where there were intermediates being created in MIR optimization passes, so I removed them.
2020-08-13merge `as_local_hir_id` with `local_def_id_to_hir_id`Bastian Kauschke-26/+26
2020-08-13bless diffkadmin-5/+11
Just output the current bless'd MIR diff The tests are still fairly broken rn
2020-08-13Update to pick Eq or Nekadmin-13/+15
2020-08-13Update w/ comments from olikadmin-56/+39
This also updates a check to ensure that this is only applied to bools
2020-08-13Update to actually use transformkadmin-0/+1
2020-08-13First iteration of simplify match brancheskadmin-0/+103
2020-08-12fix span of stack size errorRalf Jung-12/+16
2020-08-12fix typosRalf Jung-3/+3
Co-authored-by: Oliver Scherer <github35764891676564198441@oli-obk.de>
2020-08-12more precise span for erroneous consts during CTFE/MiriRalf Jung-16/+29
2020-08-12miri: fall back to whole-function span when loc==NoneRalf Jung-11/+9
2020-08-12only set frame location during push after preamble is doneRalf Jung-1/+2
2020-08-12Rollup merge of #75394 - oli-obk:get_static, r=RalfJungYuki Okushi-17/+5
Add a function to `TyCtxt` for computing an `Allocation` for a `static` item's initializer r? @RalfJung miri-side: https://github.com/rust-lang/miri/issues/1507 split out of https://github.com/rust-lang/rust/pull/74949#discussion_r468100991 to make that PR leaner
2020-08-11Auto merge of #73656 - oli-obk:deaggregate-is-cleanup, r=wesleywiserbors-12/+29
move Deaggregate pass to post_borrowck_cleanup Reopen of #71946 Only the second commit is from this PR, the other commit is a bugfix that's in the process of getting merged. I'll rebase once that's done In #70073 MIR pass handling got reorganized, but with the goal of not changing behavior (except for disabling some optimizations on opt-level = 0). But there we realized that the Deaggregator pass, while conceptually more of a "cleanup" pass (and one that should be run before optimizations), was run in the middle of the optimization chain. Likely this is an accident of history, so I suggest we try and clean that up by making it a proper cleanup pass. This does change mir-opt output, because deaggregation now runs before const-prop instead of after. r? @wesleywiser @rust-lang/wg-mir-opt cc @RalfJung
2020-08-11move Deaggregate pass to post_borrowck_cleanupRalf Jung-12/+29
2020-08-11Add a function to `TyCtxt` for computing an `Allocation` for a `static` ↵Oliver Scherer-17/+5
item's initializer
2020-08-11Make `<*const T>::is_null` const fnOliver Scherer-3/+39
2020-08-11Rollup merge of #75338 - RalfJung:const-eval-stack-size-check, r=oli-obkYuki Okushi-5/+10
move stack size check to const_eval machine This is consistent with how we enforce the step limit. In particular, we do not want this limit checked for Miri-the-tool.
2020-08-11Rollup merge of #75333 - davidtwco:polymorphization-75260-fixes, r=lcnrYuki Okushi-4/+10
polymorphize: constrain unevaluated const handling This PR constrains the support added for handling unevaluated consts in polymorphization (introduced in #75260) by: - Skipping associated constants as this causes cycle errors. - Skipping promoted constants when they contain `Self` as this ensures `T` is used in constants of the form `<Self as Foo<T>>`. Due to an oversight on my part, when landing #75260 and #75255, some tests started failing when polymorphization was enabled that I didn't notice until after landing - this PR fixes the regressions from #75260. r? @lcnr
2020-08-11Rollup merge of #75226 - pnadon:miri-undef-uninit, r=RalfJungYuki Okushi-14/+14
Miri: Renamed "undef" to "uninit" Renamed remaining references to "undef" to "uninit" when referring to Miri. Impacted directories are: - `src/librustc_codegen_llvm/consts.rs` - `src/librustc_middle/mir/interpret/` - `src/librustc_middle/ty/print/pretty.rs` - `src/librustc_mir/` - `src/tools/clippy/clippy_lints/src/consts.rs` Upon building Miri based on the new changes it was verified that no changes needed to be made with the Miri project. Related issue #71193
2020-08-11Rollup merge of #75339 - RalfJung:eval-required, r=oli-obkDylan DPC-24/+203
evaluate required_consts when pushing stack frame in Miri engine [Just like codegen](https://github.com/rust-lang/rust/pull/70820/files#diff-32c57af5c8e23eb048f55d1e955e5cd5R194), Miri needs to make sure all `required_consts` evaluate successfully, to catch post-monomorphization errors. While at it I also moved the const_eval error reporting logic into rustc_mir::const_eval::error; there is no reason it should be in `rustc_middle`. I kept this in a separate commit for easier reviewing. Helps with https://github.com/rust-lang/miri/issues/1382. I will add a test on the Miri side (done now: https://github.com/rust-lang/miri/pull/1504). r? @oli-obk
2020-08-10polymorphize: constrain unevaluated const handlingDavid Wood-4/+10
This commit constrains the support added for handling unevaluated consts in polymorphization (introduced in #75260) by: - Skipping associated constants as this causes cycle errors. - Skipping promoted constants when they contain `Self` as this ensures `T` is used in constants of the form `<Self as Foo<T>>`. Signed-off-by: David Wood <david@davidtw.co>
2020-08-09rustc_mir: use IndexSet in PlaceholderIndicesJosh Stone-8/+7
2020-08-09rustc_mir: use IndexMap in BorrowSetJosh Stone-43/+52
2020-08-09evaluate required_consts when pushing stack frame in Miri engineRalf Jung-0/+7
2020-08-09move stack size check to const_eval machineRalf Jung-5/+10
2020-08-09move const_eval error reporting logic into rustc_mir::const_eval::errorRalf Jung-24/+196
2020-08-08Be consistent when describing a move as a 'partial' in diagnosticsAaron Hill-25/+68
When an error occurs due to a partial move, we would use the world "partial" in some parts of the error message, but not in others. This commit ensures that we use the word 'partial' in either all or none of the diagnostic messages. Additionally, we no longer describe a move out of a `Box` via `*` as a 'partial move'. This was a pre-existing issue, but became more noticable when the word 'partial' is used in more places.
2020-08-08Auto merge of #75260 - davidtwco:polymorphization-promoted-substs, r=lcnrbors-13/+32
polymorphize: unevaluated constants This PR makes polymorphization visit the promoted MIR of unevaluated constants with available promoted MIR instead of visiting the substitutions of that constant - which will mark all of the generic parameters as used; in addition polymorphization will now visit non-promoted unevaluated constants rather than visit their substs. r? @lcnr
2020-08-08Miri: Renamed "undef" to "uninit"Philippe Nadon-14/+14
Renamed remaining references to "undef" to "uninit" when referring to Miri. Impacted directories are: - src/librustc_codegen_llvm/consts.rs - src/librustc_middle/mir/interpret/ - src/librustc_middle/ty/print/pretty.rs - src/librustc_mir/ - src/tools/clippy/clippy_lints/src/consts.rs Upon building Miri based on the new changes it was verified that no changes needed to be made with the Miri project. Related issue #71193
2020-08-08Auto merge of #74932 - nnethercote:rm-ast-session-globals, r=petrochenkovbors-13/+23
Remove `librustc_ast` session globals By moving the data onto `Session`. r? @petrochenkov
2020-08-08Eliminate the `SessionGlobals` from `librustc_ast`.Nicholas Nethercote-13/+23
By moving `{known,used}_attrs` from `SessionGlobals` to `Session`. This means they are accessed via the `Session`, rather than via TLS. A few `Attr` methods and `librustc_ast` functions are now methods of `Session`. All of this required passing a `Session` to lots of functions that didn't already have one. Some of these functions also had arguments removed, because those arguments could be accessed directly via the `Session` argument. `contains_feature_attr()` was dead, and is removed. Some functions were moved from `librustc_ast` elsewhere because they now need to access `Session`, which isn't available in that crate. - `entry_point_type()` --> `librustc_builtin_macros` - `global_allocator_spans()` --> `librustc_metadata` - `is_proc_macro_attr()` --> `Session`
2020-08-08fix clippy::needless_return: remove unneeded return statementsMatthias Krüger-2/+2
2020-08-08fix clippy::clone_on_copy: don't clone types that are copyMatthias Krüger-1/+1
2020-08-07polymorphize: non-promoted unevaluated constantsDavid Wood-13/+25
This commit makes polymorphization visit non-promoted unevaluated constants rather than visit their substs directly. Signed-off-by: David Wood <david@davidtw.co>
2020-08-07Auto merge of #74821 - oli-obk:const_eval_read_uninit_fast_path, r=wesleywiserbors-60/+70
Check whether locals are too large instead of whether accesses into them are too large Essentially this stops const prop from attempting to optimize ```rust let mut x = [0_u8; 5000]; x[42] = 3; ``` I don't expect this to be a perf improvement without #73656 (which is also where the lack of this PR will be a perf regression). r? @wesleywiser
2020-08-07polymorphize: visit promoted MIRDavid Wood-0/+7
This commit makes polymorphization visited the MIR of unevaluated constants with available promoted MIR instead of visiting the substitutions of that constant - which will mark all of the generic parameters as used. Signed-off-by: David Wood <david@davidtw.co>