about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-03-25Auto merge of #122721 - oli-obk:merge_queries, r=davidtwcobors-12/+8
Replace `mir_built` query with a hook and use mir_const everywhere instead A small perf improvement due to less dep graph handling. Mostly just a cleanup to get rid of one of our many mir queries
2024-03-24Rollup merge of #122937 - Zalathar:unbox, r=oli-obkMatthias Krüger-36/+24
Unbox and unwrap the contents of `StatementKind::Coverage` The payload of coverage statements was historically a structure with several fields, so it was boxed to avoid bloating `StatementKind`. Now that the payload is a single relatively-small enum, we can replace `Box<Coverage>` with just `CoverageKind`. This patch also adds a size assertion for `StatementKind`, to avoid accidentally bloating it in the future. ``@rustbot`` label +A-code-coverage
2024-03-24simplify_branches: add commentRalf Jung-0/+1
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-0/+3
2024-03-24Rollup merge of #122168 - compiler-errors:inline-coroutine-body-validation, ↵Matthias Krüger-6/+4
r=cjgillot Fix validation on substituted callee bodies in MIR inliner When inlining a coroutine, we will substitute the MIR body with the args of the call. There is code in the MIR validator that attempts to prevent query cycles, and will use the coroutine body directly when it detects that's the body that's being validated. That means that when inlining a coroutine body that has been substituted, it may no longer be parameterized over the original args of the coroutine, which will lead to substitution ICEs. Fixes #119064
2024-03-23refactor check_{lang,library}_ub: use a single intrinsic, put policy into ↵Ralf Jung-22/+5
library
2024-03-23Unbox and unwrap the contents of `StatementKind::Coverage`Zalathar-36/+24
The payload of coverage statements was historically a structure with several fields, so it was boxed to avoid bloating `StatementKind`. Now that the payload is a single relatively-small enum, we can replace `Box<Coverage>` with just `CoverageKind`. This patch also adds a size assertion for `StatementKind`, to avoid accidentally bloating it in the future.
2024-03-23Auto merge of #119552 - krtab:dead_code_priv_mod_pub_field, r=cjgillot,saethlinbors-4/+3
Replace visibility test with reachability test in dead code detection Fixes https://github.com/rust-lang/rust/issues/119545 Also included is a fix for an error now flagged by the lint
2024-03-22Auto merge of #122900 - matthiaskrgr:rollup-nls90mb, r=matthiaskrgrbors-199/+7
Rollup of 8 pull requests Successful merges: - #114009 (compiler: allow transmute of ZST arrays with generics) - #122195 (Note that the caller chooses a type for type param) - #122651 (Suggest `_` for missing generic arguments in turbofish) - #122784 (Add `tag_for_variant` query) - #122839 (Split out `PredicatePolarity` from `ImplPolarity`) - #122873 (Merge my contributor emails into one using mailmap) - #122885 (Adjust better spastorino membership to triagebot's adhoc_groups) - #122888 (add a couple more tests) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-22Fix validation on substituted callee bodies in MIR inlinerMichael Goulet-6/+4
2024-03-22Rollup merge of #122784 - jswrenn:tag_for_variant, r=compiler-errorsMatthias Krüger-199/+7
Add `tag_for_variant` query This query allows for sharing code between `rustc_const_eval` and `rustc_transmutability`. It's a precursor to a PR I'm working on to entirely replace the bespoke layout computations in `rustc_transmutability`. r? `@compiler-errors`
2024-03-22Add `tag_for_variant` queryJack Wrenn-199/+7
This query allows for sharing code between `rustc_const_eval` and `rustc_transmutability`. Also moves `DummyMachine` to `rustc_const_eval`.
2024-03-22Make RawPtr take Ty and Mutbl separatelyMichael Goulet-1/+1
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-1/+1
2024-03-22Ty::new_ref and Ty::new_ptr stop using TypeAndMutMichael Goulet-10/+6
2024-03-22Eagerly convert some ctors to use their specialized ctorsMichael Goulet-24/+8
2024-03-22coverage: Clean up marker statements that aren't needed laterZalathar-1/+12
Some of the marker statements used by coverage are added during MIR building for use by the InstrumentCoverage pass (during analysis), and are not needed afterwards.
2024-03-21Auto merge of #122568 - RalfJung:mentioned-items, r=oli-obkbors-2/+145
recursively evaluate the constants in everything that is 'mentioned' This is another attempt at fixing https://github.com/rust-lang/rust/issues/107503. The previous attempt at https://github.com/rust-lang/rust/pull/112879 seems stuck in figuring out where the [perf regression](https://perf.rust-lang.org/compare.html?start=c55d1ee8d4e3162187214692229a63c2cc5e0f31&end=ec8de1ebe0d698b109beeaaac83e60f4ef8bb7d1&stat=instructions:u) comes from. In https://github.com/rust-lang/rust/pull/122258 I learned some things, which informed the approach this PR is taking. Quoting from the new collector docs, which explain the high-level idea: ```rust //! One important role of collection is to evaluate all constants that are used by all the items //! which are being collected. Codegen can then rely on only encountering constants that evaluate //! successfully, and if a constant fails to evaluate, the collector has much better context to be //! able to show where this constant comes up. //! //! However, the exact set of "used" items (collected as described above), and therefore the exact //! set of used constants, can depend on optimizations. Optimizing away dead code may optimize away //! a function call that uses a failing constant, so an unoptimized build may fail where an //! optimized build succeeds. This is undesirable. //! //! To fix this, the collector has the concept of "mentioned" items. Some time during the MIR //! pipeline, before any optimization-level-dependent optimizations, we compute a list of all items //! that syntactically appear in the code. These are considered "mentioned", and even if they are in //! dead code and get optimized away (which makes them no longer "used"), they are still //! "mentioned". For every used item, the collector ensures that all mentioned items, recursively, //! do not use a failing constant. This is reflected via the [`CollectionMode`], which determines //! whether we are visiting a used item or merely a mentioned item. //! //! The collector and "mentioned items" gathering (which lives in `rustc_mir_transform::mentioned_items`) //! need to stay in sync in the following sense: //! //! - For every item that the collector gather that could eventually lead to build failure (most //! likely due to containing a constant that fails to evaluate), a corresponding mentioned item //! must be added. This should use the exact same strategy as the ecollector to make sure they are //! in sync. However, while the collector works on monomorphized types, mentioned items are //! collected on generic MIR -- so any time the collector checks for a particular type (such as //! `ty::FnDef`), we have to just onconditionally add this as a mentioned item. //! - In `visit_mentioned_item`, we then do with that mentioned item exactly what the collector //! would have done during regular MIR visiting. Basically you can think of the collector having //! two stages, a pre-monomorphization stage and a post-monomorphization stage (usually quite //! literally separated by a call to `self.monomorphize`); the pre-monomorphizationn stage is //! duplicated in mentioned items gathering and the post-monomorphization stage is duplicated in //! `visit_mentioned_item`. //! - Finally, as a performance optimization, the collector should fill `used_mentioned_item` during //! its MIR traversal with exactly what mentioned item gathering would have added in the same //! situation. This detects mentioned items that have *not* been optimized away and hence don't //! need a dedicated traversal. enum CollectionMode { /// Collect items that are used, i.e., actually needed for codegen. /// /// Which items are used can depend on optimization levels, as MIR optimizations can remove /// uses. UsedItems, /// Collect items that are mentioned. The goal of this mode is that it is independent of /// optimizations: the set of "mentioned" items is computed before optimizations are run. /// /// The exact contents of this set are *not* a stable guarantee. (For instance, it is currently /// computed after drop-elaboration. If we ever do some optimizations even in debug builds, we /// might decide to run them before computing mentioned items.) The key property of this set is /// that it is optimization-independent. MentionedItems, } ``` And the `mentioned_items` MIR body field docs: ```rust /// Further items that were mentioned in this function and hence *may* become monomorphized, /// depending on optimizations. We use this to avoid optimization-dependent compile errors: the /// collector recursively traverses all "mentioned" items and evaluates all their /// `required_consts`. /// /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee. /// All that's relevant is that this set is optimization-level-independent, and that it includes /// everything that the collector would consider "used". (For example, we currently compute this /// set after drop elaboration, so some drop calls that can never be reached are not considered /// "mentioned".) See the documentation of `CollectionMode` in /// `compiler/rustc_monomorphize/src/collector.rs` for more context. pub mentioned_items: Vec<Spanned<MentionedItem<'tcx>>>, ``` Fixes #107503
2024-03-20Rollup merge of #122764 - Zalathar:loopy, r=oli-obkJacob Pratt-35/+4
coverage: Remove incorrect assertions from counter allocation These assertions detect situations where a BCB node (in the coverage graph) would have both a physical counter and one or more in-edge counters/expressions. For most BCBs that situation would indicate an implementation bug. However, it's perfectly fine in the case of a BCB having an edge that loops back to itself. Given the complexity and risk involved in fixing the assertions, and the fact that nothing relies on them actually being true, this patch just removes them instead. Fixes #122738. `````@rustbot````` label +A-code-coverage
2024-03-20Auto merge of #122754 - Mark-Simulacrum:bootstrap-bump, r=albertlarsan68bors-1/+0
Bump to 1.78 bootstrap compiler https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-03-20step cfgsMark Rousskov-1/+0
2024-03-20mentioned_items: avoid adding str/slice unsizing castsRalf Jung-9/+16
2024-03-20mentioned_items: record all callee and coerced closure types, whether they ↵Ralf Jung-38/+45
are FnDef/Closure or not They may become FnDef during monomorphization!
2024-03-20mentioned items: also handle closure-to-fn-ptr coercionsRalf Jung-0/+16
2024-03-20mentioned items: also handle vtablesRalf Jung-1/+25
2024-03-20collector: recursively traverse 'mentioned' items to evaluate their constantsRalf Jung-2/+91
2024-03-20Update documentationOli Scherer-3/+0
2024-03-20Rename mir_const query to mir_builtOli Scherer-8/+8
2024-03-20Replace `mir_built` query with a hook and use mir_const everywhere insteadOli Scherer-7/+6
2024-03-20coverage: Tidy imports in `rustc_mir_transform::coverage::counters`Zalathar-4/+4
2024-03-20coverage: Remove incorrect assertions from counter allocationZalathar-31/+0
These assertions detect situations where a BCB node would have both a physical counter and one or more in-edge counters/expressions. For most BCBs that situation would indicate an implementation bug. However, it's perfectly fine in the case of a BCB having an edge that loops back to itself. Given the complexity and risk involved in fixing the assertions, and the fact that nothing relies on them actually being true, this patch just removes them instead.
2024-03-19Add a few more commentsMichael Goulet-0/+9
2024-03-19Fix ABI for FnMut/Fn impls for async closuresMichael Goulet-5/+19
2024-03-19Only split by-ref/by-move futures for async closuresMichael Goulet-124/+12
2024-03-19Auto merge of #122037 - oli-obk:more_new_intrinsics, r=Nilstriebbors-10/+0
Move more intrinsics to rustc_intrinsic cc https://github.com/rust-lang/rust/issues/63585
2024-03-19Auto merge of #122021 - oli-obk:delangitemification, r=compiler-errorsbors-3/+1
Use hir::Node helper methods instead of repeating the same impl multiple times I wanted to do something entirely different and stumbled upon a bunch of cleanups
2024-03-19Remove all checks of `IntrinsicDef::must_be_overridden` except for the ↵Oli Scherer-10/+0
actual overrides in codegen
2024-03-18Rollup merge of #122701 - compiler-errors:allocator-suspend, r=oli-obkMatthias Krüger-4/+10
Detect allocator for box in `must_not_suspend` lint I don't expect this to happen in practice, but better to check than not. Fixes #122643
2024-03-18Deduplicate `associated_body` and `body_id`Oli Scherer-3/+1
They match on almost the same patterns, which is fishy. Also turn `associated_body` into a method and do some cleanups nearby the call sites
2024-03-18Detect allocator for box in must_not_suspend lintMichael Goulet-4/+10
2024-03-18Rollup merge of #122647 - RalfJung:box-to-raw-retag, r=oli-obkMatthias Krüger-8/+32
add_retag: ensure box-to-raw-ptr casts are preserved for Miri In https://github.com/rust-lang/rust/pull/122233 I added `retag_box_to_raw` not realizing that we can already do `addr_of_mut!(*bx)` to turn a box into a raw pointer without an intermediate reference. We just need to ensure this information is preserved past the ElaborateBoxDerefs pass. r? ``@oli-obk``
2024-03-18Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few ↵Oli Scherer-4/+4
cases that used `None`
2024-03-18add_retag: ensure box-to-raw-ptr casts are preserved for MiriRalf Jung-8/+32
2024-03-18Rollup merge of #122656 - RalfJung:simplify-cfg, r=compiler-errorsMatthias Krüger-6/+9
simplify_cfg: rename some passes so that they make more sense I was extremely confused by `SimplifyCfg::ElaborateDrops`, since it runs way later than drop elaboration. It is used e.g. in `mir-opt/retag.rs` even though that pass doesn't care about drop elaboration at all. "Early opt" is also very confusing since that makes it sounds like it runs early during optimizations, i.e. on runtime MIR, but actually it runs way before that. So I decided to rename - early-opt -> post-analysis - elaborate-drops -> pre-optimizations I am open to other suggestions.
2024-03-17simplify_cfg: rename some passes so that they make more senseRalf Jung-6/+9
2024-03-17some minor code simplificationsMatthias Krüger-3/+2
2024-03-15Rollup merge of #122471 - RalfJung:const-eval-span, r=oli-obkMatthias Krüger-2/+5
preserve span when evaluating mir::ConstOperand This lets us show to the user where they were using the faulty const (which can be quite relevant when generics are involved). I wonder if we should change "erroneous constant encountered" to something like "the above error was encountered while evaluating this constant" or so, to make this more similar to what the collector emits when showing a "backtrace" of where things get monomorphized? It seems a bit strange to rely on the order of emitted diagnostics for that but it seems the collector already [does that](https://github.com/rust-lang/rust/blob/da8a8c9223722e17cc0173ce9490076b4a6d263d/compiler/rustc_monomorphize/src/collector.rs#L472-L475).
2024-03-14preserve span when evaluating mir::ConstOperandRalf Jung-2/+5
2024-03-14Rollup merge of #122322 - Zalathar:branch, r=oli-obkMatthias Krüger-47/+121
coverage: Initial support for branch coverage instrumentation (This is a review-ready version of the changes that were drafted in #118305.) This PR adds support for branch coverage instrumentation, gated behind the unstable flag value `-Zcoverage-options=branch`. (Coverage instrumentation must also be enabled with `-Cinstrument-coverage`.) During THIR-to-MIR lowering (MIR building), if branch coverage is enabled, we collect additional information about branch conditions and their corresponding then/else blocks. We inject special marker statements into those blocks, so that the `InstrumentCoverage` MIR pass can reliably identify them even after the initially-built MIR has been simplified and renumbered. The rest of the changes are mostly just plumbing needed to gather up the information that was collected during MIR building, and include it in the coverage metadata that we embed in the final binary. Note that `llvm-cov show` doesn't print branch coverage information in its source views by default; that needs to be explicitly enabled with `--show-branches=count` or similar. --- The current implementation doesn't have any support for instrumenting `if let` or let-chains. I think it's still useful without that, and adding it would be non-trivial, so I'm happy to leave that for future work.
2024-03-14Rollup merge of #122368 - pavedroad:master, r=oli-obkMatthias Krüger-1/+1
chore: remove repetitive words