about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
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
2025-06-22Leave from CopyProp early when there are no replacementsTomasz Miąsko-8/+10
2025-06-22Auto merge of #142675 - tmiasko:preserve-cache, r=oli-obkbors-1/+1
Preserve caches in a call to shrink_to_fit A small follow up to rust-lang/rust#142542.
2025-06-21Auto merge of #142546 - cjgillot:reachable-jump, r=compiler-errorsbors-1/+1
Only traverse reachable blocks in JumpThreading. Fixes https://github.com/rust-lang/rust/issues/131451 We only compute loop headers for reachable blocks. We shouldn't try to perform an opt on unreachable blocks anyway.
2025-06-20Rollup merge of #142571 - cjgillot:borrowed-classes, r=oli-obkTrevor Gross-27/+30
Reason about borrowed classes in CopyProp. Fixes https://github.com/rust-lang/rust/issues/141122 The current implementation of `CopyProp` avoids unifying two borrowed locals, as this would change the result of address comparison. However, the implementation was inconsistent with the general algorithm, which identifies equivalence classes of locals and then replaces all locals by a single representative of their equivalence class. This PR fixes it by forbidding the unification of two *classes* if any of those contain a borrowed local.
2025-06-18Rollup merge of #135656 - joshtriplett:hint-mostly-unused, r=saethlinUrgau-0/+7
Add `-Z hint-mostly-unused` to tell rustc that most of a crate will go unused This hint allows the compiler to optimize its operation based on this assumption, in order to compile faster. This is a hint, and does not guarantee any particular behavior. This option can substantially speed up compilation if applied to a large dependency where the majority of the dependency does not get used. This flag may slow down compilation in other cases. Currently, this option makes the compiler defer as much code generation as possible from functions in the crate, until later crates invoke those functions. Functions that never get invoked will never have code generated for them. For instance, if a crate provides thousands of functions, but only a few of them will get called, this flag will result in the compiler only doing code generation for the called functions. (This uses the same mechanisms as cross-crate inlining of functions.) This does not affect `extern` functions, or functions marked as `#[inline(never)]`. This option has already existed in nightly as `-Zcross-crate-inline-threshold=always` for some time, and has gotten testing in that form. However, this option is still unstable, to give an opportunity for wider testing in this form. Some performance numbers, based on a crate with many dependencies having just *one* large dependency set to `-Z hint-mostly-unused` (using Cargo's `profile-rustflags` option): A release build went from 4m07s to 2m04s. A non-release build went from 2m26s to 1m28s.
2025-06-18Preserve caches in a call to shrink_to_fitTomasz Miąsko-1/+1
2025-06-17Rollup merge of #142542 - cjgillot:invalidate-simplify-cfg, r=SparrowLiiJubilee-3/+16
Manually invalidate caches in SimplifyCfg. The current `SimplifyCfg` pass unconditionally invalidates CFG caches. This is unfortunate if there are no modifications that require this invalidation.
2025-06-16Reason about borrowed classes in CopyProp.Camille GILLOT-27/+30
2025-06-16Add comment.Camille GILLOT-0/+3
2025-06-15Rollup merge of #142347 - azhogin:azhogin/async-drop-storage-live-dead-fix, ↵León Orell Valerian Liehr-5/+30
r=oli-obk Async drop - fix for StorageLive/StorageDead codegen for pinned future Fixes: rust-lang/rust#140429, Fixes: rust-lang/rust#140531, Fixes: rust-lang/rust#141761, Fixes: rust-lang/rust#141409. StorageLive/StorageDead codegen is corrected for pinned async drop future.
2025-06-15Only traverse reachable blocks in JumpThreading.Camille GILLOT-1/+1
2025-06-15Manually invalidate caches in SimplifyCfg.Camille GILLOT-3/+13
2025-06-14Rollup merge of #141811 - mejrs:bye_locals, r=compiler-errorsMatthias Krüger-12/+3
Unimplement unsized_locals Implements https://github.com/rust-lang/compiler-team/issues/630 Tracking issue here: https://github.com/rust-lang/rust/issues/111942 Note that this just removes the feature, not the implementation, and does not touch `unsized_fn_params`. This is because it is required to support `Box<dyn FnOnce()>: FnOnce()`. There may be more that should be removed (possibly in follow up prs) - the `forget_unsized` function and `forget` intrinsic. - the `unsized_locals` test directory; I've just fixed up the tests for now - various codegen support for unsized values and allocas cc ``@JakobDegen`` ``@oli-obk`` ``@Noratrieb`` ``@programmerjake`` ``@bjorn3`` ``@rustbot`` label F-unsized_locals Fixes rust-lang/rust#79409
2025-06-14Async drop - fix for StorageLive/StorageDead codegen for pinned async drop ↵Andrew Zhogin-5/+30
future
2025-06-13Unimplement unsized_localsmejrs-12/+3
2025-06-12intrinsics: rename min_align_of to align_ofRalf Jung-2/+2
2025-06-11Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwUbors-1/+1
`FIXME(-Znext-solver)` triage r? `@BoxyUwU`
2025-06-10Auto merge of #142299 - fmease:rollup-u86s80a, r=fmeasebors-29/+19
Rollup of 16 pull requests Successful merges: - rust-lang/rust#134442 (Specify the behavior of `file!`) - rust-lang/rust#140372 (Exhaustively handle parsed attributes in CheckAttr) - rust-lang/rust#140766 (Stabilize keylocker) - rust-lang/rust#141642 (Note the version and PR of removed features when using it) - rust-lang/rust#141818 (Don't create .msi installer for gnullvm hosts) - rust-lang/rust#141909 (Add central execution context to bootstrap) - rust-lang/rust#141992 (use `#[naked]` for `__rust_probestack`) - rust-lang/rust#142101 (core::ptr: deduplicate more method docs) - rust-lang/rust#142102 (docs: Small clarification on the usage of read_to_string and read_to_end trait methods) - rust-lang/rust#142124 (Allow transmute casts in pre-runtime-MIR) - rust-lang/rust#142240 (deduplicate the rest of AST walker functions) - rust-lang/rust#142258 (platform-support.md: Mention specific Linux kernel version or later) - rust-lang/rust#142262 (Mark `core::slice::memchr` as `#[doc(hidden)]`) - rust-lang/rust#142271 (compiler: fn ptrs should hit different lints based on ABI) - rust-lang/rust#142275 (rustdoc: Refractor `clean_ty_generics`) - rust-lang/rust#142288 (const_eval: fix some outdated comments) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-10Rollup merge of #142124 - oli-obk:transmute-cast, r=scottmcmLeón Orell Valerian Liehr-29/+19
Allow transmute casts in pre-runtime-MIR r? ``@scottmcm`` cc ``@BoxyUwU`` turns out in https://github.com/rust-lang/rust/pull/138393 I erroneously used transmute casts in https://github.com/rust-lang/rust/blob/fd3da4bebdff63b7529483ff7025986ef16bf463/compiler/rustc_mir_build/src/builder/matches/test.rs#L209 I don't think they have any issues using them before runtime, we just checked for them because we didn't have code exercising those code paths
2025-06-10Auto merge of #141485 - dianqk:early_otherwise_branch_loop, r=oli-obkbors-29/+3
mir-opt: Do not create storage marks in EarlyOtherwiseBranch Fixes #141212. The first commit add `StorageDead` by creating new indirect BB that makes CFG more complicated, but I think it's better to just not create storage marks. r? mir-opt
2025-06-08Remove all unused feature gates from the compilerbjorn3-3/+0