about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-07-15coverage: Restrict `ExpressionUsed` simplification to `Code` mappingsZalathar-4/+18
In the future, branch and MC/DC mappings might have expressions that don't correspond to any single point in the control-flow graph. That makes it trickier to keep track of which expressions should expect an `ExpressionUsed` node. We therefore sidestep that complexity by only performing `ExpressionUsed` simplification for expressions associated directly with ordinary `Code` mappings.
2024-07-15coverage: Store a copy of `num_bcbs` in `ExtractedMappings`Zalathar-7/+10
This makes it possible to allocate per-BCB data structures without needing access to the whole graph.
2024-07-13Create mapped places upon seeing them in the body.Camille GILLOT-9/+13
2024-07-09Auto merge of #127234 - ZhuUx:inlined-expr, r=davidtwco,Zalatharbors-0/+6
[Coverage][MCDC] Group mcdc tests and fix panic when generating mcdc code for inlined expressions. ### Changes 1. Group all mcdc tests to one directory. 2. Since mcdc instruments different mappings for boolean expressions with normal branch coverage as #125766 introduces, it would be better also trace branch coverage results in mcdc tests. 3. So far rustc does not call `CoverageInfoBuilderMethods::init_coverage` for inlined functions. As a result, it could panic if it tries to instrument mcdc statements for inlined functions due to uninitialized cond bitmaps. We can reproduce this issue by current nightly rustc and [the test](https://github.com/rust-lang/rust/pull/127234/files#diff-c81af6bf4869aa42f5c7334e3e86344475de362f673f54ce439ec75fcb5ac3e5) with flag `--release`. This patch fixes it.
2024-07-09coverage. Fix panic when generating mcdc code for inlined functionszhuyunxing-0/+6
2024-07-08Move trait selection error reporting to its own top-level moduleMichael Goulet-1/+1
2024-07-08Auto merge of #127486 - matthiaskrgr:rollup-lvv018b, r=matthiaskrgrbors-5/+9
Rollup of 5 pull requests Successful merges: - #120248 (Make casts of pointers to trait objects stricter) - #127355 (Mark format! with must_use hint) - #127399 (Verify that allocations output by GVN are sufficiently aligned.) - #127460 (clarify `sys::unix::fd::FileDesc::drop` comment) - #127467 (bootstrap: once_cell::sync::Lazy -> std::sync::LazyLock) Failed merges: - #127357 (Remove `StructuredDiag`) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-08Rollup merge of #127399 - cjgillot:issue-127396, r=oli-obkMatthias Krüger-5/+9
Verify that allocations output by GVN are sufficiently aligned. Fixes #127396 r? `@oli-obk`
2024-07-08coverage: Extract hole spans from HIR instead of MIRZalathar-41/+87
This makes it possible to treat more kinds of nested item/code as holes, instead of being restricted to closures.
2024-07-08Auto merge of #113128 - WaffleLapkin:become_trully_unuwuable, r=oli-obk,RalfJungbors-39/+82
Support tail calls in mir via `TerminatorKind::TailCall` This is one of the interesting bits in tail call implementation — MIR support. This adds a new `TerminatorKind` which represents a tail call: ```rust TailCall { func: Operand<'tcx>, args: Vec<Operand<'tcx>>, fn_span: Span, }, ``` *Structurally* this is very similar to a normal `Call` but is missing a few fields: - `destination` — tail calls don't write to destination, instead they pass caller's destination to the callee (such that eventual `return` will write to the caller of the function that used tail call) - `target` — similarly to `destination` tail calls pass the caller's return address to the callee, so there is nothing to do - `unwind` — I _think_ this is applicable too, although it's a bit confusing - `call_source` — `become` forbids operators and is not created as a lowering of something else; tail calls always come from HIR (at least for now) It might be helpful to read the interpreter implementation to understand what `TailCall` means exactly, although I've tried documenting it too. ----- There are a few `FIXME`-questions still left, ideally we'd be able to answer them during review ':) ----- r? `@oli-obk` cc `@scottmcm` `@DrMeepster` `@JakobDegen`
2024-07-07Fix conflicts after rebaseMaybe Lapkin-1/+6
- r-l/r 126784 - r-l/r 127113 - r-l/miri 3562
2024-07-07Support tail calls in mir via `TerminatorKind::TailCall`Maybe Waffle-38/+76
2024-07-06Update compiler/rustc_mir_transform/src/gvn.rsCamille Gillot-2/+2
Co-authored-by: Michael Goulet <michael@errs.io>
2024-07-05Verify that allocations output by GVN are sufficiently aligned.Camille GILLOT-5/+9
2024-07-05Fix a few doc comment for compiler-interal API docs.Alona Enraght-Moony-10/+10
They only used `//` instead of `///` so weren't picked up by rustdoc.
2024-07-05coverage: Rename `mir::coverage::BranchInfo` to `CoverageInfoHi`Zalathar-10/+12
This opens the door to collecting and storing coverage information that is unrelated to branch coverage or MC/DC.
2024-07-04Auto merge of #127293 - ldm0:ldm_coroutine, r=saethlinbors-19/+16
Use `IndexVec` for coroutine local mapping Resolves a old FIXME
2024-07-03Rollup merge of #127294 - ldm0:ldm_coroutine2, r=lcnrMatthias Krüger-5/+2
Less magic number for corountine
2024-07-04Less magic number for corountineLiu Dingming-5/+2
2024-07-04Use `IndexVec` for coroutine local mappingLiu Dingming-19/+16
2024-07-03Auto merge of #127036 - cjgillot:sparse-state, r=oli-obkbors-5/+14
Make jump threading state sparse Continuation of https://github.com/rust-lang/rust/pull/127024 Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering: - that jump threading state is typically very sparse (at most 1 or 2 set entries); - that dataflow const-prop is disabled by default; - that place/value map is very eager, and prone to creating an overly large state. The first commit is shared with the previous PR to avoid needless conflicts. r? `@oli-obk`
2024-07-03Auto merge of #125507 - compiler-errors:type-length-limit, r=lcnrbors-2/+2
Re-implement a type-size based limit r? lcnr This PR reintroduces the type length limit added in #37789, which was accidentally made practically useless by the caching changes to `Ty::walk` in #72412, which caused the `walk` function to no longer walk over identical elements. Hitting this length limit is not fatal unless we are in codegen -- so it shouldn't affect passes like the mir inliner which creates potentially very large types (which we observed, for example, when the new trait solver compiles `itertools` in `--release` mode). This also increases the type length limit from `1048576 == 2 ** 20` to `2 ** 24`, which covers all of the code that can be reached with craterbot-check. Individual crates can increase the length limit further if desired. Perf regression is mild and I think we should accept it -- reinstating this limit is important for the new trait solver and to make sure we don't accidentally hit more type-size related regressions in the future. Fixes #125460
2024-07-02Instance::resolve -> Instance::try_resolve, and other nitsMichael Goulet-2/+2
2024-07-02Rollup merge of #127230 - hattizai:patch01, r=saethlinMatthias Krüger-3/+3
chore: remove duplicate words remove duplicate words in comments to improve readability.
2024-07-02Rollup merge of #127136 - compiler-errors:coroutine-closure-env-shim, r=oli-obkMatthias Krüger-18/+31
Fix `FnMut::call_mut`/`Fn::call` shim for async closures that capture references I adjusted async closures to be able to implement `Fn` and `FnMut` *even if* they capture references, as long as those references did not need to borrow data from the closure captures themselves. See #125259. However, when I did this, I didn't actually relax an assertion in the `build_construct_coroutine_by_move_shim` shim code, which builds the `Fn`/`FnMut`/`FnOnce` implementations for async closures. Therefore, if we actually tried to *call* `FnMut`/`Fn` on async closures, it would ICE. This PR adjusts this assertion to ensure that we only capture immutable references in closures if they implement `Fn`/`FnMut`. It also adds a bunch of tests and makes more of the async-closure tests into `build-pass` since we often care about these tests actually generating the right closure shims and stuff. I think it might be excessive to *always* use build-pass here, but 🤷 it's not that big of a deal. Fixes #127019 Fixes #127012 r? oli-obk
2024-07-02chore: remove duplicate wordshattizai-3/+3
2024-07-01Make jump threading state sparse.Camille GILLOT-5/+14
2024-07-01Avoid MIR bloat in inliningScott McMurray-2/+79
In 126578 we ended up with more binary size increases than expected. This change attempts to avoid inlining large things into small things, to avoid that kind of increase, in cases when top-down inlining will still be able to do that inlining later.
2024-07-01Auto merge of #127197 - matthiaskrgr:rollup-aqpvn5q, r=matthiaskrgrbors-5/+5
Rollup of 7 pull requests Successful merges: - #126923 (test: dont optimize to invalid bitcasts) - #127090 (Reduce merge conflicts from rustfmt's wrapping) - #127105 (Only update `Eq` operands in GVN if it can update both sides) - #127150 (Fix x86_64 code being produced for bare-metal LoongArch targets' `compiler_builtins`) - #127181 (Introduce a `rustc_` attribute to dump all the `DefId` parents of a `DefId`) - #127182 (Fix error in documentation for IpAddr::to_canonical and Ipv6Addr::to_canonical) - #127191 (Ensure `out_of_scope_macro_calls` lint is registered) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-01Rollup merge of #127105 - scottmcm:issue-127089, r=cjgillotMatthias Krüger-5/+5
Only update `Eq` operands in GVN if it can update both sides Otherwise the types might not match Fixes #127089 r? mir-opt
2024-07-01Auto merge of #126996 - oli-obk:do_not_count_errors, r=nnethercotebors-13/+13
Automatically taint InferCtxt when errors are emitted r? `@nnethercote` Basically `InferCtxt::dcx` now returns a `DiagCtxt` that refers back to the `Cell<Option<ErrorGuaranteed>>` of the `InferCtxt` and thus when invoking `Diag::emit`, and the diagnostic is an error, we taint the `InferCtxt` directly. That change on its own has no effect at all, because `InferCtxt` already tracks whether errors have been emitted by recording the global error count when it gets opened, and checking at the end whether the count changed. So I removed that error count check, which had a bit of fallout that I immediately fixed by invoking `InferCtxt::dcx` instead of `TyCtxt::dcx` in a bunch of places. The remaining new errors are because an error was reported in another query, and never bubbled up. I think they are minor enough for this to be ok, and sometimes it actually improves diagnostics, by not silencing useful diagnostics anymore. fixes #126485 (cc `@olafes)` There are more improvements we can do (like tainting in hir ty lowering), but I would rather do that in follow up PRs, because it requires some refactorings.
2024-06-30Rollup merge of #127157 - Zalathar:unexpand, r=cjgillotMatthias Krüger-66/+68
coverage: Avoid getting extra unexpansion info when we don't need it Several callers of `unexpand_into_body_span_with_visible_macro` would immediately discard the additional macro-related information, which is wasteful. We can avoid this by having them instead call a simpler method that just returns the span they care about. This PR also moves the relevant functions out of `coverage::spans::from_mir` and into a new submodule `coverage::unexpand`, so that calling them from `coverage::mappings` is less awkward. There should be no actual changes to coverage-instrumentation output, as demonstrated by the absence of test updates.
2024-06-30Auto merge of #127024 - cjgillot:jump-prof, r=oli-obkbors-43/+50
Avoid cloning jump threading state when possible The current implementation of jump threading passes most of its time cloning its state. This PR attempts to avoid such clones by special-casing the last predecessor when recursing through a terminator. This is not optimal, but a first step while I refactor the state data structure to be sparse. The two other commits are drive-by. Fixes https://github.com/rust-lang/rust/issues/116721 r? `@oli-obk`
2024-06-30coverage: Avoid getting extra unexpansion info when we don't need itZalathar-16/+21
These particular callers don't actually use the returned macro information, so they can use a simpler span-unexpansion function that doesn't return it.
2024-06-30coverage: Move span unexpansion into its own submoduleZalathar-62/+59
2024-06-29Fix FnMut/Fn shim for coroutine-closures that capture referencesMichael Goulet-18/+31
2024-06-29Move entry point to a method.Camille GILLOT-37/+42
2024-06-29Avoid cloning state when possible.Camille GILLOT-6/+8
2024-06-29Rollup merge of #127101 - matthiaskrgr:thonk, r=compiler-errorsMatthias Krüger-5/+0
remove redundant match statement from dataflow const prop
2024-06-28Only update `Eq` operands in GVN if you can update both sidesScott McMurray-5/+5
Otherwise the types might not match Fixes 127089
2024-06-29remove some amusing but redundant codeMatthias Krüger-5/+0
2024-06-28Don't inline drop shims with unsubstituted generic consts in MIR inlinerMichael Goulet-1/+11
2024-06-27Rollup merge of #126721 - Zalathar:nested-cov-attr, r=oli-obkJacob Pratt-1/+32
coverage: Make `#[coverage(..)]` apply recursively to nested functions This PR makes the (currently-unstable) `#[coverage(off)]` and `#[coverage(on)]` attributes apply recursively to all nested functions/closures, instead of just the function they are directly attached to. Those attributes can now also be applied to modules and to impl/impl-trait blocks, where they have no direct effect, but will be inherited by all enclosed functions/closures/methods that don't override the inherited value. --- Fixes #126625.
2024-06-26Split lifetimes on mir borrowck dataflowOli Scherer-13/+13
2024-06-26Auto merge of #126844 - scottmcm:more-ptr-cast-gvn, r=saethlinbors-36/+107
Remove more `PtrToPtr` casts in GVN This addresses two things I noticed in MIR: 1. `NonNull::<T>::eq` does `(a as *mut T) == (b as *mut T)`, but it could just compare the `*const T`s, so this removes `PtrToPtr` casts that are on both sides of a pointer comparison, so long as they're not fat-to-thin casts. 2. `NonNull::<T>::addr` does `transmute::<_, usize>(p as *const ())`, but so long as `T: Thin` that cast doesn't do anything, and thus we can directly transmute the `*const T` instead. r? mir-opt
2024-06-26coverage: Apply `#[coverage(..)]` recursively to nested functionsZalathar-3/+9
2024-06-26coverage: Detach `#[coverage(..)]` from codegen attribute handlingZalathar-1/+26
2024-06-24Auto merge of #126784 - scottmcm:smaller-terminator, r=compiler-errorsbors-52/+46
Save 2 pointers in `TerminatorKind` (96 → 80 bytes) These things don't need to be `Vec`s; boxed slices are enough. The frequent one here is call arguments, but MIR building knows the number of arguments from the THIR, so the collect is always getting the allocation right in the first place, and thus this shouldn't ever add the shrink-in-place overhead.
2024-06-23Make MIR inlining costs in build-std independent of config.tomlScott McMurray-7/+22
2024-06-22GVN away PtrToPtr-then-Transmute when possibleScott McMurray-13/+43