about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-02-22Auto merge of #121309 - Nilstrieb:inline-all-the-fallbacks, r=oli-obkbors-0/+17
Make intrinsic fallback bodies cross-crate inlineable This change was prompted by the stage1 compiler spending 4% of its time when compiling the polymorphic-recursion MIR opt test in `unlikely`. Intrinsic fallback bodies like `unlikely` should always be inlined, it's very silly if they are not. To do this, we enable the fallback bodies to be cross-crate inlineable. Not that this matters for our workloads since the compiler never actually _uses_ the "fallback bodies", it just uses whatever was cfg(bootstrap)ped, so I've also added `#[inline]` to those. See the comments for more information. r? oli-obk
2024-02-21Rollup merge of #121261 - Zalathar:pending-dups, r=oli-obkMatthias Krüger-169/+26
coverage: Remove `pending_dups` from the span refiner When extracting coverage spans from a function's MIR, we need to decide how to handle spans that are associated with more than one node (BCB) in the coverage control flow graph. The existing code for managing those duplicate spans is very subtle and difficult to modify. But by eagerly deduplicating those extracted spans in a much simpler way, we can remove a massive chunk of complexity from the span refiner. There is a tradeoff here, in that we no longer try to retain *all* nondominating BCBs that have the same span, only the last one in the (semi-arbitrary) dominance ordering. But in practice, this produces very little difference in our coverage tests, and the simplification is so significant that I think it's worthwhile. ``@rustbot`` label +A-code-coverage
2024-02-21coverage: Simplify (non-closure) covspans truncating each otherZalathar-7/+7
2024-02-21coverage: Remove `pending_dups` from the span refinerZalathar-164/+16
2024-02-21coverage: Eagerly deduplicate covspans with the same spanZalathar-5/+10
2024-02-21Convert `delayed_bug`s to `bug`s.Nicholas Nethercote-6/+2
I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. The next commit will convert some more back, based on human judgment.
2024-02-20Rollup merge of #121286 - gurry:constprop-lint-rename, r=oli-obkNilstrieb-17/+19
Rename `ConstPropLint` to `KnownPanicsLint` `OverflowLint` is a clearer name because it communicates what the lint does instead of the underlying mechanism it uses (const propagation) which should be of secondary concern. `OverflowLint` isn't the most accurate name because the lint looks for other errors as well such as division by zero not just overflows, but I couldn't think of another equally succinct name. As a part of this change. I've also added/updated some of the comments. cc ```@RalfJung``` ```@oli-obk``` for visibility in case you go looking for the lint using the old name. Edit: Changed the name from `OverflowLint` to `KnownPanicsLint`
2024-02-20Auto merge of #120576 - nnethercote:merge-Diagnostic-DiagnosticBuilder, ↵bors-0/+3
r=davidtwco Overhaul `Diagnostic` and `DiagnosticBuilder` Implements the first part of https://github.com/rust-lang/compiler-team/issues/722, which moves functionality and use away from `Diagnostic`, onto `DiagnosticBuilder`. Likely follow-ups: - Move things around, because this PR was written to minimize diff size, so some things end up in sub-optimal places. E.g. `DiagnosticBuilder` has impls in both `diagnostic.rs` and `diagnostic_builder.rs`. - Rename `Diagnostic` as `DiagInner` and `DiagnosticBuilder` as `Diag`. r? `@davidtwco`
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-0/+3
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-20Rename `ConstPropLint` to `KnownPanicsLint`Gurinder Singh-17/+19
It is a clearer name because it communicates what the lint does instead of the underlying mechanism it uses (const propagation).
2024-02-19Make intrinsic fallback bodies cross-crate inlineableNilstrieb-0/+17
This change was prompted by the stage1 compiler spending 4% of its time when compiling the polymorphic-recursion MIR opt test in `unlikely`. Intrinsic fallback bodies like `unlikely` should always be inlined, it's very silly if they are not. To do this, we enable the fallback bodies to be cross-crate inlineable. Not that this matters for our workloads since the compiler never actually _uses_ the "fallback bodies", it just uses whatever was cfg(bootstrap)ped, so I've also added `#[inline]` to those.
2024-02-18Remove const_prop.rsGurinder Singh-168/+153
and move its content to const_prop_lint.rs and dataflow_const_prop.rs where it is used
2024-02-17Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercoteMatthias Krüger-1/+1
errors: only eagerly translate subdiagnostics Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). r? ```@nnethercote```
2024-02-17Rollup merge of #121135 - Zalathar:no-whole-body-span, r=wesleywiserGuillaume Boisseau-4/+9
coverage: Discard spans that fill the entire function body While debugging some other coverage changes, I discovered a frustrating inconsistency that occurs in functions containing closures, if they end with an implicit `()` return instead of an explicit trailing-expression. This turns out to have been caused by the corresponding node in MIR having a span that covers the entire function body. When preparing coverage spans, any span that fills the whole body tends to cause more harm than good, so this PR detects and discards those spans. (This isn't the first time whole-body spans have caused problems; we also eliminated some of them in #118525.)
2024-02-17Enable `ConstPropLint` for promotedsGurinder Singh-5/+0
This fixes the issue wherein the lint didn't fire for promoteds in the case of SHL/SHR operators in non-optimized builds and all arithmetic operators in optimized builds
2024-02-16Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkinbors-11/+9
Implement intrinsics with fallback bodies fixes #93145 (though we can port many more intrinsics) cc #63585 The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for * codegen_ssa (so llvm and gcc) * codegen_cranelift other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body). cc `@scottmcm` `@WaffleLapkin` ### todo * [ ] miri support * [x] default intrinsic name to name of function instead of requiring it to be specified in attribute * [x] make sure that the bodies are always available (must be collected for metadata)
2024-02-16coverage: Discard spans that fill the entire function bodyZalathar-4/+9
When we try to extract coverage-relevant spans from MIR, sometimes we see MIR statements/terminators whose spans cover the entire function body. Those spans tend to be unhelpful for coverage purposes, because they often represent compiler-inserted code, e.g. the implicit return value of `()`.
2024-02-16Rollup merge of #121147 - tmiasko:no-debug-body, r=compiler-errorsGuillaume Gomez-4/+2
Avoid debug logging entire MIR body If there is a need to examine the MIR body there is -Zmir-dump.
2024-02-15Auto merge of #121133 - tmiasko:skip-coroutines, r=cjgillotbors-0/+6
Skip coroutines in jump threading to avoid query cycles Fixes #121094
2024-02-15Avoid debug logging entire MIR bodyTomasz Miąsko-4/+2
If there is a need to examine the MIR body there is -Zmir-dump.
2024-02-15errors: only eagerly translate subdiagnosticsDavid Wood-1/+1
Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood <david@davidtw.co>
2024-02-15Auto merge of #116564 - oli-obk:evaluated_static_in_metadata, ↵bors-3/+2
r=RalfJung,cjgillot Store static initializers in metadata instead of the MIR of statics. This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better. The issue is that ```rust static mut FOO: &mut u32 = &mut 42; static mut BAR = unsafe { FOO }; ``` gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo. Fixes https://github.com/rust-lang/rust/issues/61345 ## Why is this being done? In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](https://github.com/rust-lang/rust/issues/57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
2024-02-15Split a bool argument into two named functionsOli Scherer-3/+2
2024-02-15Skip coroutines in jump threading to avoid query cyclesTomasz Miąsko-0/+6
2024-02-15Reinstate some delayed bugs.Nicholas Nethercote-1/+2
These were changed to `has_errors` assertions in #121071 because that seemed reasonable, but evidently not. Fixes #121103. Fixes #121108.
2024-02-14Rollup merge of #121071 - nnethercote:fewer-delayed-bugs, r=oli-obkOli Scherer-5/+6
Use fewer delayed bugs. For some cases where it's clear that an error has already occurred, e.g.: - there's a comment stating exactly that, or - things like HIR lowering, where we are lowering an error kind The commit also tweaks some comments around delayed bug sites. r? `@oli-obk`
2024-02-14Rollup merge of #121039 - cjgillot:gvn-adjust, r=compiler-errorsOli Scherer-5/+9
Correctly compute adjustment casts in GVN Fixes https://github.com/rust-lang/rust/issues/120925 r? `@oli-obk`
2024-02-14Use fewer delayed bugs.Nicholas Nethercote-5/+6
For some cases where it's clear that an error has already occurred, e.g.: - there's a comment stating exactly that, or - things like HIR lowering, where we are lowering an error kind The commit also tweaks some comments around delayed bug sites.
2024-02-13Bump `indexmap`clubby789-1/+2
`swap` has been deprecated in favour of `swap_remove` - the behaviour is the same though.
2024-02-13Fix handling of adjustment casts.Camille GILLOT-5/+9
2024-02-13coverage: Simplify code for adding `prev` to pending dupsZalathar-40/+12
If we only check for duplicate spans when `prev` is unmodified, we reduce the number of situations that `update_pending_dups` needs to handle. This could potentially change the coverage spans we produce in some unknown corner cases, but none of our current coverage tests indicate any change.
2024-02-13coverage: Move `prev_original_span` into `PrevCovspan`Zalathar-19/+11
Now that `prev` has its own dedicated struct, we can store the original span in that struct, instead of in a separate field in the refiner.
2024-02-13coverage: Split `CoverageSpan` into several distinct structsZalathar-83/+139
This requires some extra boilerplate, but in exchange it becomes much easier to see how each field and method is actually used.
2024-02-13coverage: Don't track `curr_original_span` explicitlyZalathar-11/+2
Now that we never mutate `curr.span`, we don't need to store its original span separately.
2024-02-13coverage: When merging spans, keep `prev` and merge `curr` into itZalathar-9/+3
Swapping the direction of this merge produces the same results, but means that we never need to mutate `curr`.
2024-02-12Rollup merge of #120958 - ShoyuVanilla:remove-subst, r=oli-obkMatthias Krüger-32/+30
Dejargonize `subst` In favor of #110793, replace almost every occurence of `subst` and `substitution` from rustc codes, but they still remains in subtrees under `src/tools/` like clippy and test codes (I'd like to replace them after this)
2024-02-12Rollup merge of #120950 - compiler-errors:miri-async-closurs, r=RalfJung,oli-obkMatthias Krüger-2/+2
Fix async closures in CTFE First commit renames `is_coroutine_or_closure` into `is_closure_like`, because `is_coroutine_or_closure_or_coroutine_closure` seems confusing and long. Second commit fixes some forgotten cases where we want to handle `TyKind::CoroutineClosure` the same as closures and coroutines. The test exercises the change to `ValidityVisitor::aggregate_field_path_elem` which is the source of #120946, but not the change to `UsedParamsNeedSubstVisitor`, though I feel like it's not that big of a deal. Let me know if you'd like for me to look into constructing a test for the latter, though I have no idea what it'd look like (we can't assert against `TooGeneric` anywhere?). Fixes #120946 r? oli-obk cc ``@RalfJung``
2024-02-12Teach llvm backend how to fall back to default bodiesOli Scherer-3/+4
2024-02-12Rollup merge of #120944 - compiler-errors:inliner-abi, r=oli-obkMatthias Krüger-0/+12
Check that the ABI of the instance we are inlining is correct When computing the `CallSite` in the mir inliner, double check that the instance of the function that we are inlining is compatible with the signature from the trait definition that we acquire from the MIR. Fixes #120940 r? ``@oli-obk`` or ``@cjgillot``
2024-02-12Rollup merge of #120917 - chenyukang:yukang-dead-parameters, r=compiler-errorsMatthias Krüger-13/+6
Remove a bunch of dead parameters in functions Found this kind of issue when working on https://github.com/rust-lang/rust/pull/119650 I wrote a trivial toy lint and manual review to find these.
2024-02-12Make `is_intrinsic` query return the intrinsic nameOli Scherer-8/+5
2024-02-12Dejargnonize substShoyu Vanilla-32/+30
2024-02-12remove a bunch of dead parameters in fnyukang-13/+6
2024-02-11Auto merge of #120619 - compiler-errors:param, r=lcnrbors-4/+1
Assert that params with the same *index* have the same *name* Found this bug when trying to build libcore with the new solver, since it will canonicalize two params with the same index into *different* placeholders if those params differ by name.
2024-02-11is_closure_likeMichael Goulet-2/+2
2024-02-11Check that the ABI of the instance we are inlining is correctMichael Goulet-0/+12
2024-02-11Auto merge of #120405 - cjgillot:gvn-pointer, r=oli-obkbors-19/+115
Fold pointer operations in GVN This PR proposes 2 combinations of cast operations in MIR GVN: - a chain of `PtrToPtr` or `MutToConstPointer` casts can be folded together into a single `PtrToPtr` cast; - we attempt to evaluate more ptr ops when there is no provenance. In particular, this allows to read from static slices. This is not yet sufficient to see through slice operations that use `PtrComponents` (because that's a union), but still a step forward. r? `@ghost`
2024-02-10Auto merge of #117206 - cjgillot:jump-threading-default, r=tmiaskobors-479/+1
Enable MIR JumpThreading by default Mostly for perf r? `@ghost`
2024-02-10validation: descend from consts into staticsRalf Jung-3/+4
2024-02-10Remove unnecessary `min_specialization` after bootstrapZalathar-1/+1
These crates all needed specialization for `newtype_index!`, which will no longer be necessary when the current nightly eventually becomes the next bootstrap compiler.