about summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform
AgeCommit message (Collapse)AuthorLines
2021-04-30Rebuilt out of date tests and fixed an old bug now exposedRich Kadel-8/+25
2021-04-29don't let const_fn feature flag affect impl-block-level trait boundsRalf Jung-11/+2
2021-04-28addressed review feedbackRich Kadel-12/+40
2021-04-28More improvements to macro coverageRich Kadel-51/+112
2021-04-28Drop branching blocks with same span as expanded macroRich Kadel-17/+80
Fixes: #84561
2021-04-28Auto merge of #84562 - richkadel:issue-83601, r=tmandrybors-0/+6
Adds feature-gated `#[no_coverage]` function attribute, to fix derived Eq `0` coverage issue #83601 Derived Eq no longer shows uncovered The Eq trait has a special hidden function. MIR `InstrumentCoverage` would add this function to the coverage map, but it is never called, so the `Eq` trait would always appear uncovered. Fixes: #83601 The fix required creating a new function attribute `no_coverage` to mark functions that should be ignored by `InstrumentCoverage` and the coverage `mapgen` (during codegen). Adding a `no_coverage` feature gate with tracking issue #84605. r? `@tmandry` cc: `@wesleywiser`
2021-04-28Rollup merge of #84529 - richkadel:issue-84180, r=tmandryYuki Okushi-1/+11
Improve coverage spans for chained function calls Fixes: #84180 For chained function calls separated by the `?` try operator, the function call following the try operator produced a MIR `Call` span that matched the span of the first call. The `?` try operator started a new span, so the second call got no span. It turns out the MIR `Call` terminator has a `func` `Operand` for the `Constant` representing the function name, and the function name's Span can be used to reset the starting position of the span. r? `@tmandry` cc: `@wesleywiser`
2021-04-27Derived Eq no longer shows uncoveredRich Kadel-0/+6
The Eq trait has a special hidden function. MIR `InstrumentCoverage` would add this function to the coverage map, but it is never called, so the `Eq` trait would always appear uncovered. Fixes: #83601 The fix required creating a new function attribute `no_coverage` to mark functions that should be ignored by `InstrumentCoverage` and the coverage `mapgen` (during codegen). While testing, I also noticed two other issues: * spanview debug file output ICEd on a function with no body. The workaround for this is included in this PR. * `assert_*!()` macro coverage can appear covered if followed by another `assert_*!()` macro. Normally they appear uncovered. I submitted a new Issue #84561, and added a coverage test to demonstrate this issue.
2021-04-27Auto merge of #84532 - richkadel:issue-83792, r=tmandrybors-1/+1
Fix coverage ICE because fn_sig can have a span that crosses file bou… Fixes: #83792 MIR `InstrumentCoverage` assumed the `FnSig` span was contained within a single file, but this is not always the case. Some macro constructions can result in a span that starts in one `SourceFile` and ends in a different one. The `FnSig` span is included in coverage results as long as that span is in the same `SourceFile` and the same macro context, but by assuming the `FnSig` span's `hi()` and `lo()` were in the same file, I took this for granted, and checked only that the `FnSig` `hi()` was in the same `SourceFile` as the `body_span`. I actually drop the `hi()` though, and extend the `FnSig` span to the `body_span.lo()`, so I really should have simply checked that the `FnSig` span's `lo()` was in the `SourceFile` of the `body_span`. r? `@tmandry` cc: `@wesleywiser`
2021-04-25unsafety checking: no longer care about is_min_const_fnRalf Jung-50/+17
Rejecting the forbidden unsafe ops is done by const checking, not by unsafety checking
2021-04-24Improve spans for chained function callsRich Kadel-1/+11
Fixes: #84180 For chained function calls separated by the `?` try operator, the function call following the try operator produced a MIR `Call` span that matched the span of the first call. The `?` try operator started a new span, so the second call got no span. It turns out the MIR `Call` terminator has a `func` `Operand` for the `Constant` representing the function name, and the function name's Span can be used to reset the starting position of the span.
2021-04-24Auto merge of #84310 - RalfJung:const-fn-feature-flags, r=oli-obkbors-32/+22
further split up const_fn feature flag This continues the work on splitting up `const_fn` into separate feature flags: * `const_fn_trait_bound` for `const fn` with trait bounds * `const_fn_unsize` for unsizing coercions in `const fn` (looks like only `dyn` unsizing is still guarded here) I don't know if there are even any things left that `const_fn` guards... at least libcore and liballoc do not need it any more. `@oli-obk` are you currently able to do reviews?
2021-04-24Fix coverage ICE because fn_sig can have a span that crosses file boundariesRich Kadel-1/+1
Fixes: #83792 MIR `InstrumentCoverage` assumed the `FnSig` span was contained within a single file, but this is not always the case. Some macro constructions can result in a span that starts in one `SourceFile` and ends in a different one. The `FnSig` span is included in coverage results as long as that span is in the same `SourceFile` and the same macro context, but by assuming the `FnSig` span's `hi()` and `lo()` were in the same file, I took this for granted, and checked only that the `FnSig` `hi()` was in the same `SourceFile` as the `body_span`. I actually drop the `hi()` though, and extend the `FnSig` span to the `body_span.lo()`, so I really should have simply checked that the `FnSig` span's `lo()` was in the `SourceFile` of the `body_span`.
2021-04-25Rollup merge of #83519 - oli-obk:assign_shrink_your_normal_code, r=pnkfelixYuki Okushi-15/+4
Implement a lint that highlights all moves larger than a configured limit Tracking issue: #83518 [MCP 420](https://github.com/rust-lang/compiler-team/issues/420) still ~blazing~ in progress r? ```@pnkfelix``` The main open issue I see with this minimal impl of the feature is that the lint is immediately "stable" (so it can be named on stable), even if it is never executed on stable. I don't think we have the concept of unstable lint names or hiding lint names without an active feature gate, so that would be a bigger change.
2021-04-22Fix ICE if original_span(fn_sig) returns a span not in body sourcefileRich Kadel-8/+4
Fixes: #84421
2021-04-20TidyOli Scherer-3/+3
2021-04-20Implement a lint that highlights all moves larger than 1000 bytesOli Scherer-13/+2
2021-04-20Auto merge of #84323 - richkadel:uncovered-functions, r=tmandrybors-3/+8
coverage of async function bodies should match non-async This fixes some missing coverage within async function bodies. Commit 1 demonstrates the problem in the fixed issue, and commit 2 corrects it. Fixes: #83985
2021-04-19compute fn_sig span from body call_site, and use body ctxt, not rootRich Kadel-4/+9
2021-04-19remove E0723 error codeRalf Jung-8/+6
2021-04-19fix few typosklensy-4/+4
2021-04-19add gate tests and pacify tidyRalf Jung-1/+1
2021-04-18Fixes the issue with uncovered source in async function bodiesRich Kadel-2/+2
The body_span was assumed to be in the Span root context, but this was not the case for async function bodies.
2021-04-18separate feature flag for unsizing casts in const fnRalf Jung-22/+9
2021-04-18move 'trait bounds on const fn' to separate feature gateRalf Jung-3/+8
2021-04-09Auto merge of #83870 - jackh726:binder-refactor-fix, r=nikomatsakisbors-3/+4
Don't concatenate binders across types Partially addresses #83737 There's actually two issues that I uncovered in #83737. The first is that we are concatenating bound vars across types, i.e. in ``` F: Fn(&()) -> &mut (dyn Future<Output = ()> + Unpin) ``` the bound vars on `Future` get set as `for<anon>` since those are the binders on `Fn(&()`. This is obviously wrong, since we should only concatenate directly nested trait refs. This is solved here by introducing a new `TraitRefBoundary` scope, that we put around the "syntactical" trait refs and basically don't allow concatenation across. Now, this alone *shouldn't* be a super terrible problem. At least not until you consider the other issue, which is a much more elusive and harder to design a "perfect" fix. A repro can be seen in: ``` use core::future::Future; async fn handle<F>(slf: &F) where F: Fn(&()) -> &mut (dyn for<'a> Future<Output = ()> + Unpin), { (slf)(&()).await; } ``` Notice the `for<'a>` around `Future`. Here, `'a` is unused, so the `for<'a>` Binder gets changed to a `for<>` Binder in the generator witness, but the "local decl" still has it. This has heavy intersections with region anonymization and erasing. Luckily, it's not *super* common to find this unique set of circumstances. It only became apparently because of the first issue mentioned here. However, this *is* still a problem, so I'm leaving #83737 open. r? `@nikomatsakis`
2021-04-07Rollup merge of #83916 - Amanieu:asm_anonconst, r=petrochenkovDylan DPC-68/+18
Use AnonConst for asm! constants This replaces the old system which used explicit promotion. See #83169 for more background. The syntax for `const` operands is still the same as before: `const <expr>`. Fixes #83169 Because the implementation is heavily based on inline consts, we suffer from the same issues: - We lose the ability to use expressions derived from generics. See the deleted tests in `src/test/ui/asm/const.rs`. - We are hitting the same ICEs as inline consts, for example #78174. It is unlikely that we will be able to stabilize this before inline consts are stabilized.
2021-04-06Use AnonConst for asm! constantsAmanieu d'Antras-68/+18
2021-04-05Don't concatenate binders across typesJack Huey-3/+4
2021-04-02Reduce size of statementsRoxane-2/+2
2021-03-31Track bound varsJack Huey-3/+6
2021-03-27Rollup merge of #82917 - cuviper:iter-zip, r=m-ou-seDylan DPC-11/+7
Add function core::iter::zip This makes it a little easier to `zip` iterators: ```rust for (x, y) in zip(xs, ys) {} // vs. for (x, y) in xs.into_iter().zip(ys) {} ``` You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and `iter()`, respectively. This can also support arbitrary nesting, where it's easier to see the item layout than with arbitrary `zip` chains: ```rust for ((x, y), z) in zip(zip(xs, ys), zs) {} for (x, (y, z)) in zip(xs, zip(ys, zs)) {} // vs. for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {} for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {} ``` It may also format more nicely, especially when the first iterator is a longer chain of methods -- for example: ```rust iter::zip( trait_ref.substs.types().skip(1), impl_trait_ref.substs.types().skip(1), ) // vs. trait_ref .substs .types() .skip(1) .zip(impl_trait_ref.substs.types().skip(1)) ``` This replaces the tuple-pair `IntoIterator` in #78204. There is prior art for the utility of this in [`itertools::zip`]. [`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
2021-03-27make unaligned_refereces future-incompat lint warn-by-default, and remove ↵Ralf Jung-143/+77
the safe_packed_borrows lint that it replaces
2021-03-26Use iter::zip in compiler/Josh Stone-11/+7
2021-03-25Auto merge of #83445 - erikdesjardins:rmunion, r=RalfJungbors-1/+33
RemoveZsts: don't touch unions This should fix a Miri ICE r? `@RalfJung`
2021-03-25Auto merge of #83307 - richkadel:cov-unused-functions-1.1, r=tmandrybors-27/+25
coverage bug fixes and optimization support Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to address multiple, somewhat related issues. Fixed a significant flaw in prior coverage solution: Every counter generated a new counter variable, but there should have only been one counter variable per function. This appears to have bloated .profraw files significantly. (For a small program, it increased the size by about 40%. I have not tested large programs, but there is anecdotal evidence that profraw files were way too large. This is a good fix, regardless, but hopefully it also addresses related issues. Fixes: #82144 Invalid LLVM coverage data produced when compiled with -C opt-level=1 Existing tests now work up to at least `opt-level=3`. This required a detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR when compiled with coverage, and a lot of trial and error with codegen adjustments. The biggest hurdle was figuring out how to continue to support coverage results for unused functions and generics. Rust's coverage results have three advantages over Clang's coverage results: 1. Rust's coverage map does not include any overlapping code regions, making coverage counting unambiguous. 2. Rust generates coverage results (showing zero counts) for all unused functions, including generics. (Clang does not generate coverage for uninstantiated template functions.) 3. Rust's unused functions produce minimal stubbed functions in LLVM IR, sufficient for including in the coverage results; while Clang must generate the complete LLVM IR for each unused function, even though it will never be called. This PR removes the previous hack of attempting to inject coverage into some other existing function instance, and generates dedicated instances for each unused function. This change, and a few other adjustments (similar to what is required for `-C link-dead-code`, but with lower impact), makes it possible to support LLVM optimizations. Fixes: #79651 Coverage report: "Unexecuted instantiation:..." for a generic function from multiple crates Fixed by removing the aforementioned hack. Some "Unexecuted instantiation" notices are unavoidable, as explained in the `used_crate.rs` test, but `-Zinstrument-coverage` has new options to back off support for either unused generics, or all unused functions, which avoids the notice, at the cost of less coverage of unused functions. Fixes: #82875 Invalid LLVM coverage data produced with crate brotli_decompressor Fixed by disabling the LLVM function attribute that forces inlining, if `-Z instrument-coverage` is enabled. This attribute is applied to Rust functions with `#[inline(always)], and in some cases, the forced inlining breaks coverage instrumentation and reports. FYI: `@wesleywiser` r? `@tmandry`
2021-03-24RemoveZsts: don't touch unionsErik Desjardins-1/+33
2021-03-23Auto merge of #83177 - erikdesjardins:zstassign, r=oli-obkbors-52/+86
Remove assignments to ZST places instead of marking ZST return place as unused partially reverts #83118 requested by `@tmiasko` in https://github.com/rust-lang/rust/pull/83118#issuecomment-799692574 r? `@oli-obk`
2021-03-22only run RemoveZsts at mir-opt-level 3 and aboveErik Desjardins-0/+3
2021-03-22Rollup merge of #83351 - RalfJung:precise-const-drop, r=oli-obkDylan DPC-1/+7
post-drop-elab check-const: explain why we still check qualifs r? `@oli-obk`
2021-03-21post-drop-elab check-const: explain why we still check qualifsRalf Jung-1/+7
2021-03-21Rollup merge of #83327 - tmiasko:visit-lhs, r=davidtwcoDylan DPC-1/+3
Extend comment in `UsedLocals::visit_lhs`
2021-03-20extract `ConstKind::Unevaluated` into a structlcnr-8/+12
2021-03-19avoid calling for types which can't be ZSTsErik Desjardins-12/+30
2021-03-19coverage bug fixes and optimization supportRich Kadel-27/+25
Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to address multiple, somewhat related issues. Fixed a significant flaw in prior coverage solution: Every counter generated a new counter variable, but there should have only been one counter variable per function. This appears to have bloated .profraw files significantly. (For a small program, it increased the size by about 40%. I have not tested large programs, but there is anecdotal evidence that profraw files were way too large. This is a good fix, regardless, but hopefully it also addresses related issues. Fixes: #82144 Invalid LLVM coverage data produced when compiled with -C opt-level=1 Existing tests now work up to at least `opt-level=3`. This required a detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR when compiled with coverage, and a lot of trial and error with codegen adjustments. The biggest hurdle was figuring out how to continue to support coverage results for unused functions and generics. Rust's coverage results have three advantages over Clang's coverage results: 1. Rust's coverage map does not include any overlapping code regions, making coverage counting unambiguous. 2. Rust generates coverage results (showing zero counts) for all unused functions, including generics. (Clang does not generate coverage for uninstantiated template functions.) 3. Rust's unused functions produce minimal stubbed functions in LLVM IR, sufficient for including in the coverage results; while Clang must generate the complete LLVM IR for each unused function, even though it will never be called. This PR removes the previous hack of attempting to inject coverage into some other existing function instance, and generates dedicated instances for each unused function. This change, and a few other adjustments (similar to what is required for `-C link-dead-code`, but with lower impact), makes it possible to support LLVM optimizations. Fixes: #79651 Coverage report: "Unexecuted instantiation:..." for a generic function from multiple crates Fixed by removing the aforementioned hack. Some "Unexecuted instantiation" notices are unavoidable, as explained in the `used_crate.rs` test, but `-Zinstrument-coverage` has new options to back off support for either unused generics, or all unused functions, which avoids the notice, at the cost of less coverage of unused functions. Fixes: #82875 Invalid LLVM coverage data produced with crate brotli_decompressor Fixed by disabling the LLVM function attribute that forces inlining, if `-Z instrument-coverage` is enabled. This attribute is applied to Rust functions with `#[inline(always)], and in some cases, the forced inlining breaks coverage instrumentation and reports.
2021-03-20Extend comment in `UsedLocals::visit_lhs`Tomasz Miąsko-1/+3
2021-03-19Rollup merge of #83277 - spastorino:early_otherwise-opt-unsound, r=oli-obkDylan DPC-0/+5
Mark early otherwise optimization unsound r? `@oli-obk` cc `@tmiasko` Related to #78496 and #82905 Should I also bump this one to level 3 or 4 or given that is unsound it doesn't matter?. Probably need to adjust some tests.
2021-03-18Mark early otherwise optimization unsoundSantiago Pastorino-0/+5
2021-03-18Remove unwrap_none/expect_none from compiler/.Mara Bos-8/+6
2021-03-17remove inhabitedness checkErik Desjardins-1/+1