about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2025-07-22Rollup merge of #144212 - bjorn3:remove_unique_lang_item, r=oli-obk许杰友 Jieyou Xu (Joe)-2/+0
Remove the ptr_unique lang item Miri no longer uses it since https://github.com/rust-lang/miri/pull/4307.
2025-07-21Auto merge of #144238 - jhpratt:rollup-xb8aida, r=jhprattbors-4/+4
Rollup of 8 pull requests Successful merges: - rust-lang/rust#144144 (tests: Skip supported-crate-types test on musl hosts) - rust-lang/rust#144159 (opt-dist: change build_dir field to be an actual build dir) - rust-lang/rust#144162 (Debug impls for DropElaborators) - rust-lang/rust#144189 (Add non-regression test for rust-lang/rust#144168) - rust-lang/rust#144216 (Don't consider unstable fields always-inhabited) - rust-lang/rust#144229 (Miri subtree update) - rust-lang/rust#144230 (Option::as_slice: fix comment) - rust-lang/rust#144235 (Fix run-make tests on musl hosts) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-21Remove Retag for Uniquebjorn3-2/+0
2025-07-20Rollup merge of #144162 - beepster4096:drop_elaborator_debug_impls, ↵Jacob Pratt-4/+4
r=compiler-errors Debug impls for DropElaborators It's a little weird that these just have a completely empty Debug impl. Now they're `ElaborateDropsCtxt { .. }` and `DropShimElaborator { .. }`.
2025-07-20Ban projecting into SIMD types [MCP838]Scott McMurray-0/+9
2025-07-19Give a message with a span on validation errorScott McMurray-8/+10
2025-07-19Auto merge of #144166 - matthiaskrgr:rollup-wccepuo, r=matthiaskrgrbors-16/+28
Rollup of 10 pull requests Successful merges: - rust-lang/rust#141076 (fix Zip unsoundness (again)) - rust-lang/rust#142444 (adding run-make test to autodiff) - rust-lang/rust#143704 (Be a bit more careful around exotic cycles in in the inliner) - rust-lang/rust#144073 (Don't test panic=unwind in panic_main.rs on Fuchsia) - rust-lang/rust#144083 (miri sleep tests: increase slack) - rust-lang/rust#144092 (bootstrap: Detect musl hosts) - rust-lang/rust#144098 (Do not lint private-in-public for RPITIT) - rust-lang/rust#144103 (Rename `emit_unless` to `emit_unless_delay`) - rust-lang/rust#144108 (Ignore tests/run-make/link-eh-frame-terminator/rmake.rs when cross-compiling) - rust-lang/rust#144115 (fix outdated comment) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-18debug impls for drop elaboratorsbeepster4096-4/+4
2025-07-18Be a bit more careful around exotic cycles in in the inlinerMichael Goulet-16/+28
2025-07-18Generalize `unsize` and `unsize_into` destinationsOli Scherer-1/+1
2025-07-18Rollup merge of #143891 - scrabsha:push-xxtttopqoprr, r=jdonszelmannMatthias Krüger-19/+13
Port `#[coverage]` to the new attribute system r? ``````@jdonszelmann``````
2025-07-18Rollup merge of #143271 - cjgillot:gvn-types, r=oli-obkMatthias Krüger-298/+255
Store the type of each GVN value MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities. This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code. Fixes rust-lang/rust#128094 Fixes rust-lang/rust#135128 r? ``````@ghost`````` for perf
2025-07-16Port `#[coverage]` to the new attribute systemSasha Pourcelot-19/+13
2025-07-10Propagate from borrowed locals in CopyPropTomasz Miąsko-20/+6
2025-07-09Auto merge of #142707 - ashivaram23:drop_wildcard, r=dianqkbors-0/+3
Apply effects to `otherwise` edge in dataflow analysis This allows `ElaborateDrops` to remove drops when a `match` wildcard arm covers multiple no-Drop enum variants. It modifies dataflow analysis to update the `MaybeUninitializedPlaces` and `MaybeInitializedPlaces` data for a block reached through an `otherwise` edge. Fixes rust-lang/rust#142705.
2025-07-08Apply effects to otherwise edge in dataflow analysisAmogh Shivaram-0/+3
2025-07-07Rollup merge of #143551 - compiler-errors:root-sub, r=cjgillot许杰友 Jieyou Xu (Joe)-9/+2
Dont resolve instance of root in `mir_callgraph_cyclic` `Instance::try_resolve` on a default trait body method will always fail, since it's still possible to further substitute. This leads to a cycle, since in `tests/mir-opt/inline_default_trait_body.rs`, both `Trait::a` and `Trait::b` need to consider the other to be cyclical, but since we couldn't resolve a body, we'd just consider *nothing* to be cyclical. The root instance we care about when computing `mir_callgraph_cyclic` is trivial to compute (it's just `InstanceKind::Item`), so just replace it with a call to `Instance::new_raw`. r? `@cjgillot` `@oli-obk` Fixes rust-lang/rust#143534
2025-07-06Dont resolve instance of root in mir_callgraph_cyclicMichael Goulet-9/+2
2025-07-06Do not unify borrowed locals in CopyProp.Camille GILLOT-2/+2
2025-07-03Auto merge of #142890 - kornelski:unused-var-debug, r=saethlinbors-2/+4
MIR inliner maintains unused var_debug_info Only `full` debuginfo level promises variable-level debug information, but the MIR inline pass needlessly preserved the local variable debug info for the `limited` level too.
2025-07-03Rollup merge of #134006 - klensy:typos, r=nnethercoteJana Dönszelmann-15/+15
setup typos check in CI This allows to check typos in CI, currently for compiler only (to reduce commit size with fixes). With current setup, exclude list is quite short, so it worth trying? Also includes commits with actual typo fixes. MCP: https://github.com/rust-lang/compiler-team/issues/817 typos check currently turned for: * ./compiler * ./library * ./src/bootstrap * ./src/librustdoc After merging, PRs which enables checks for other crates (tools) can be implemented too. Found typos will **not break** other jobs immediately: (tests, building compiler for perf run). Job will be marked as red on completion in ~ 20 secs, so you will not forget to fix it whenever you want, before merging pr. Check typos: `python x.py test tidy --extra-checks=spellcheck` Apply typo fixes: `python x.py test tidy --extra-checks=spellcheck:fix` (in case if there only 1 suggestion of each typo) Current fail in this pr is expected and shows how typo errors emitted. Commit with error will be removed after r+.
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-15/+15
2025-07-03Rollup merge of #143273 - 1c3t3a:enum-check-negative, r=SparrowLiiMatthias Krüger-4/+26
Make the enum check work for negative discriminants The discriminant check was not working correctly for negative numbers. This change fixes that by masking out the relevant bits correctly. Fixes rust-lang/rust#143218.
2025-07-02Rollup merge of #143261 - compiler-errors:explicit-pred, r=oli-obkMatthias Krüger-1/+1
Feed `explicit_predicates_of` instead of `predicates_of` Tiny nitpick, just avoiding needing to mark the `predicates_of` query as feedable since it's derived from `explicit_predicates_of`.
2025-07-02Make the enum check work for negative discriminantsBastian Kersting-4/+26
The discriminant check was not working correctly for negative numbers. This change fixes that by masking out the relevant bits correctly.
2025-07-01Auto merge of #143036 - compiler-errors:no-dyn-star, r=oli-obkbors-5/+1
Remove support for `dyn*` from the compiler This PR removes support for `dyn*` (https://github.com/rust-lang/rust/issues/102425), which are a currently un-RFC'd experiment that was opened a few years ago to explore a component that we thought was necessary for AFIDT (async fn in dyn trait). It doesn't seem like we are going to need `dyn*` types -- even in an not-exposed-to-the-user way[^1] -- for us to implement AFIDT. Given that AFIDT was the original motivating purpose of `dyn*` types, I don't really see a compelling reason to have to maintain their implementation in the compiler. [^1]: Compared to, e.g., generators whih are an unstable building block we use to implement stable syntax like `async {}`. We've learned quite a lot from `dyn*`, but I think at this point its current behavior leads to more questions than answers. For example, `dyn*` support today remains somewhat fragile; it ICEs in many cases where the current "normal" `dyn Trait` types rely on their unsizedness for their vtable-based implementation to be sound I wouldn't be surprised if it's unsound in other ways, though I didn't play around with it too much. See the examples below. ```rust #![feature(dyn_star)] trait Foo { fn hello(self); } impl Foo for usize { fn hello(self) { println!("hello, world"); } } fn main() { let x: dyn* Foo = 1usize; x.hello(); } ``` And: ```rust #![feature(dyn_star)] trait Trait { type Out where Self: Sized; } fn main() { let x: <dyn* Trait as Trait>::Out; } ``` ...and probably many more problems having to do with the intersection of dyn-compatibility and `Self: Sized` bounds that I was too lazy to look into like: * GATs * Methods with invalid signatures * Associated consts Generally, `dyn*` types also end up getting in the way of working with [normal `dyn` types](https://github.com/rust-lang/rust/issues/102425#issuecomment-1712604409) to an extent that IMO outweighs the benefit of experimentation. I recognize that there are probably other, more creative usages of `dyn*` that are orthogonal to AFIDT. However, I think any work along those lines should first have to think through some of the more fundamental interactions between `dyn*` and dyn-compatibility before we think about reimplementing them in the type system. --- I'm planning on removing the `DynKind` enum and the `PointerLike` built-in trait from the compiler after this PR lands. Closes rust-lang/rust#102425. cc `@eholk` `@rust-lang/lang` `@rust-lang/types` Closes rust-lang/rust#116979. Closes rust-lang/rust#119694. Closes rust-lang/rust#134591. Closes rust-lang/rust#104800.
2025-07-01Remove support for dyn*Michael Goulet-5/+1
2025-07-01Rollup merge of #143262 - dianqk:non_exhaustive, r=oli-obkGuillaume Gomez-25/+24
mir: Mark `Statement` and `BasicBlockData` as `#[non_exhaustive]` Ensure they are always created using constructors. r? oli-obk
2025-07-01Avoid computing layouts inside coroutines.Camille GILLOT-1/+8
2025-07-01Remove extraneous types.Camille GILLOT-130/+79
2025-07-01Store a full Ty with each Value.Camille GILLOT-130/+114
2025-07-01Introduce Value::RawPtr as it behaves differently from other aggregates.Camille GILLOT-55/+67
2025-07-01Simplify assignments.Camille GILLOT-28/+33
2025-07-01Feed explicit_predicates_of instead of predicates_ofMichael Goulet-1/+1
2025-07-01mir: Mark `Statement` and `BasicBlockData` as `#[non_exhaustive]`dianqk-25/+24
Ensure they are always created using constructors.
2025-06-30Rollup merge of #143140 - RalfJung:ptr-into-parts, r=oli-obkMatthias Krüger-1/+1
give Pointer::into_parts a more scary name and offer a safer alternative `into_parts` is a bit too innocent of a name for a somewhat subtle operation. r? `@oli-obk`
2025-06-29mir: Use the `new` method for `BasicBlockData`dianqk-203/+166
2025-06-29mir: Add a `new` method to `statement`dianqk-269/+235
Avoid introducing a large number of changes when adding optional initialization fields.
2025-06-29give Pointer::into_parts a more scary name and offer a safer alternativeRalf Jung-1/+1
2025-06-28Auto merge of #142625 - cjgillot:inline-nocycle, r=oli-obkbors-128/+152
Only compute recursive callees once. Inlining MIR in a cyclic call graph may create query cycles, which are ICEs. The current implementation `mir_callgraph_reachable(inlining_candidate, being_optimized)` checks if calling `inlining_candidate` may cycle back to `being_optimized` that we are currently inlining into. This PR replaces this device with query `mir_callgraph_cyclic(being_optimized)` which searches the call graph for all cycles going back to `being_optimized`, and returns the set of functions involved in those cycles. This is a tradeoff: - in the current implementation, we perform more walks, but shallower; - in this new implementation, we perform fewer walks, but exhaust the graph. I'd have liked to compute this using some kind of SCC, but generic parameters make resolution path-dependent, so usual graph algorithms do not apply.
2025-06-28Keep inlined var_debug_info only when full debug info is usedKornel-2/+4
2025-06-28Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlinbors-0/+503
Insert checks for enum discriminants when debug assertions are enabled Similar to the existing null-pointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following: ```rust let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) }; ``` An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++. This check is similar to Miri's capabilities of checking for valid construction of enum values. This PR is inspired by saethlin@'s PR https://github.com/rust-lang/rust/pull/104862. Thank you so much for keeping this code up and the detailed comments! I also pair-programmed large parts of this together with vabr-g@. r? `@saethlin`
2025-06-27Rollup merge of #143046 - RalfJung:zst-unsafe-cell, r=lcnr,oli-obkMatthias Krüger-1/+1
const validation: properly ignore zero-sized UnsafeCell Fixes https://github.com/rust-lang/rust/issues/142948 r? `@oli-obk`
2025-06-27Add InterpCx::layout_of with tracing, shadowing LayoutOfStypox-3/+1
2025-06-27Insert checks for enum discriminants when debug assertions are enabledBastian Kersting-0/+503
Similar to the existing nullpointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following: ```rust let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) }; ``` An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++. This check is similar to Miri's capabilities of checking for valid construction of enum values. This PR is inspired by saethlin@'s PR https://github.com/rust-lang/rust/pull/104862. Thank you so much for keeping this code up and the detailed comments! I also pair-programmed large parts of this together with vabr-g@.
2025-06-26make size_and_align_of_mplace work on all projectableRalf Jung-1/+1
2025-06-25Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obkJana Dönszelmann-0/+4
Add runtime check to avoid overwrite arg in `Diag` ## Origin PR description At first, I set up a `debug_assert` check for the arg method to make sure that `args` in `Diag` aren't easily overwritten, and I added the `remove_arg()` method, so that if you do need to overwrite an arg, then you can explicitly call `remove_arg()` to remove it first, then call `arg()` to overwrite it. For the code before the rust-lang/rust#142015 change, it won't compile because it will report an error ``` arg `instance`already exists. ``` This PR also modifies all diagnostics that fail the check to pass the check. There are two cases of check failure: 1. ~~Between *the parent diagnostic and the subdiagnostic*, or *between the subdiagnostics* have the same field between them. In this case, I renamed the conflicting fields.~~ 2. ~~For subdiagnostics stored in `Vec`, the rendering may iteratively write the same arg over and over again. In this case, I changed the auto-generation with `derive(SubDiagnostic)` to manually implementing `SubDiagnostic` and manually rendered it with `eagerly_translate()`, similar to https://github.com/rust-lang/rust/issues/142031#issuecomment-2984812090, and after rendering it I manually deleted useless arg with the newly added `remove_arg` method.~~ ## Final Decision After trying and discussing, we made a final decision. For `#[derive(Subdiagnostic)]`, This PR made two changes: 1. After the subdiagnostic is rendered, remove all args of this subdiagnostic, which allows for usage like `Vec<Subdiag>`. 2. Store `diag.args` before setting arguments, so that you can restore the contents of the main diagnostic after deleting the arguments after subdiagnostic is rendered, to avoid deleting the main diagnostic's arg when they have the same name args.
2025-06-25Add runtime check to avoid overwrite arg easily in diag and store and ↵xizheyin-0/+4
restore snapshot when set subdiag arg Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-23Only store the LocalDefId instead of the whole instance.Camille GILLOT-5/+10
2025-06-22Only compute recursive callees once.Camille GILLOT-128/+147