about summary refs log tree commit diff
path: root/compiler/rustc_middle
AgeCommit message (Collapse)AuthorLines
2025-10-03Auto merge of #142771 - dianqk:mir-stmt-debuginfo, r=cjgillotbors-8/+226
Introduce debuginfo to statements in MIR The PR introduces support for debug information within dead statements. Currently, only the reference statement is supported, which is sufficient to fix rust-lang/rust#128081. I don't modify Stable MIR, as I don't think we need debug information when using it. This PR represents the debug information for the dead reference statement via `#dbg_value`. For example, `let _foo_b = &foo.b` becomes `#dbg_value(ptr %foo, !22, !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value), !26)`. You can see this here: https://rust.godbolt.org/z/d43js6adv. The general principle for handling debug information is to never provide less debug information than the optimized LLVM IR. The current rules for dropping debug information in this PR are: - If the LLVM IR cannot represent a reference address, it's replaced with poison or simply dropped. For example, see: https://rust.godbolt.org/z/shGqPec8W. I'm using poison in all such cases now. - All debuginfos is dropped when merging multiple successor BBs. An example is available here: https://rust.godbolt.org/z/TE1q3Wq6M. I doesn't drop debuginfos in `MatchBranchSimplification`, because LLVM also pick one branch for it.
2025-10-02Auto merge of #147138 - jackh726:split-canonical-bound, r=lcnrbors-25/+130
Split Bound index into Canonical and Bound See [#t-types/trait-system-refactor > perf `async-closures/post-mono-higher-ranked-hang.rs`](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/perf.20.60async-closures.2Fpost-mono-higher-ranked-hang.2Ers.60/with/541535613) for context Things compile and tests pass, but not sure if this actually solves the perf issue (edit: it does). Opening up this to do a perf (and maybe crater) run. r? lcnr
2025-10-02mir-opt: Eliminate dead statements even if they are used by debuginfosdianqk-0/+25
2025-10-02mir-opt: Eliminate trivial unnecessary storage annotationsdianqk-10/+4
2025-10-02simplifycfg: Preserve debuginfos when merging bbsdianqk-0/+8
2025-10-02mir-opt: Eliminate dead ref statementsdianqk-8/+199
2025-10-02Auto merge of #147055 - beepster4096:subtype_is_not_a_projection, r=lcnrbors-28/+14
Turn ProjectionElem::Subtype into CastKind::Subtype I noticed that drop elaboration can't, in general, handle `ProjectionElem::SubType`. It creates a disjoint move path that overlaps with other move paths. (`Subslice` does too, and I'm working on a different PR to make that special case less fragile.) If its skipped and treated as the same move path as its parent then `MovePath.place` has multiple possible projections. (It would probably make sense to remove all `Subtype` projections for the canonical place but it doesn't make sense to have this special case for a problem that doesn't actually occur in real MIR.) The only reason this doesn't break is that `Subtype` is always the sole projection of the local its applied to. For the same reason, it works fine as a `CastKind` so I figured that makes more sense than documenting and validating this hidden invariant. cc rust-lang/rust#112651, rust-lang/rust#133258 r? Icnr (bc you've been the main person dealing with `Subtype` it looks like)
2025-09-30Split Bound into Canonical and Boundjackh726-25/+130
2025-09-30Rollup merge of #147109 - BoxyUwU:rename_concrete_opaques, r=lcnrStuart Cook-8/+7
Rename various "concrete opaque type" things to say "hidden type" r? lcnr I've found "concrete opaque type" terminology to be somewhat confusing as in conversation and when explaining opaque type stuff to people I always just talk about things in terms of hidden types. Also the hidden types of opaques are very much not *concrete* in the same sense that a type without any generic parameters is concrete which is an unfortunate overlap in terminology. I've tried to update comments to also stop referring to things as concrete opaque types but this is mostly best effort as it difficult to find all such cases amongst the massive amounts of uses of "concrete" or "hidden" across the whole compiler.
2025-09-29more renameBoxy Uwu-3/+3
2025-09-28remove explicit deref of AbiAlign for most methodsJubilee Young-1/+1
Much of the compiler calls functions on Align projected from AbiAlign. AbiAlign impls Deref to its inner Align, so we can simplify these away. Also, it will minimize disruption when AbiAlign is removed. For now, preserve usages that might resolve to PartialOrd or PartialEq, as those have odd inference.
2025-09-28Rollup merge of #144197 - KMJ-007:type-tree, r=ZuseZ4Matthias Krüger-2/+224
TypeTree support in autodiff # TypeTrees for Autodiff ## What are TypeTrees? Memory layout descriptors for Enzyme. Tell Enzyme exactly how types are structured in memory so it can compute derivatives efficiently. ## Structure ```rust TypeTree(Vec<Type>) Type { offset: isize, // byte offset (-1 = everywhere) size: usize, // size in bytes kind: Kind, // Float, Integer, Pointer, etc. child: TypeTree // nested structure } ``` ## Example: `fn compute(x: &f32, data: &[f32]) -> f32` **Input 0: `x: &f32`** ```rust TypeTree(vec![Type { offset: -1, size: 8, kind: Pointer, child: TypeTree(vec![Type { offset: -1, size: 4, kind: Float, child: TypeTree::new() }]) }]) ``` **Input 1: `data: &[f32]`** ```rust TypeTree(vec![Type { offset: -1, size: 8, kind: Pointer, child: TypeTree(vec![Type { offset: -1, size: 4, kind: Float, // -1 = all elements child: TypeTree::new() }]) }]) ``` **Output: `f32`** ```rust TypeTree(vec![Type { offset: -1, size: 4, kind: Float, child: TypeTree::new() }]) ``` ## Why Needed? - Enzyme can't deduce complex type layouts from LLVM IR - Prevents slow memory pattern analysis - Enables correct derivative computation for nested structures - Tells Enzyme which bytes are differentiable vs metadata ## What Enzyme Does With This Information: Without TypeTrees (current state): ```llvm ; Enzyme sees generic LLVM IR: define float ``@distance(ptr*`` %p1, ptr* %p2) { ; Has to guess what these pointers point to ; Slow analysis of all memory operations ; May miss optimization opportunities } ``` With TypeTrees (our implementation): ```llvm define "enzyme_type"="{[]:Float@float}" float ``@distance(`` ptr "enzyme_type"="{[]:Pointer}" %p1, ptr "enzyme_type"="{[]:Pointer}" %p2 ) { ; Enzyme knows exact type layout ; Can generate efficient derivative code directly } ``` # TypeTrees - Offset and -1 Explained ## Type Structure ```rust Type { offset: isize, // WHERE this type starts size: usize, // HOW BIG this type is kind: Kind, // WHAT KIND of data (Float, Int, Pointer) child: TypeTree // WHAT'S INSIDE (for pointers/containers) } ``` ## Offset Values ### Regular Offset (0, 4, 8, etc.) **Specific byte position within a structure** ```rust struct Point { x: f32, // offset 0, size 4 y: f32, // offset 4, size 4 id: i32, // offset 8, size 4 } ``` TypeTree for `&Point` (internal representation): ```rust TypeTree(vec![ Type { offset: 0, size: 4, kind: Float }, // x at byte 0 Type { offset: 4, size: 4, kind: Float }, // y at byte 4 Type { offset: 8, size: 4, kind: Integer } // id at byte 8 ]) ``` Generates LLVM: ```llvm "enzyme_type"="{[]:Float@float}" ``` ### Offset -1 (Special: "Everywhere") **Means "this pattern repeats for ALL elements"** #### Example 1: Array `[f32; 100]` ```rust TypeTree(vec![Type { offset: -1, // ALL positions size: 4, // each f32 is 4 bytes kind: Float, // every element is float }]) ``` Instead of listing 100 separate Types with offsets `0,4,8,12...396` #### Example 2: Slice `&[i32]` ```rust // Pointer to slice data TypeTree(vec![Type { offset: -1, size: 8, kind: Pointer, child: TypeTree(vec![Type { offset: -1, // ALL slice elements size: 4, // each i32 is 4 bytes kind: Integer }]) }]) ``` #### Example 3: Mixed Structure ```rust struct Container { header: i64, // offset 0 data: [f32; 1000], // offset 8, but elements use -1 } ``` ```rust TypeTree(vec![ Type { offset: 0, size: 8, kind: Integer }, // header Type { offset: 8, size: 4000, kind: Pointer, child: TypeTree(vec![Type { offset: -1, size: 4, kind: Float // ALL array elements }]) } ]) ```
2025-09-27Rename various "concrete opaque type" terminology to say "hidden type"Boxy Uwu-8/+7
2025-09-27Rollup merge of #147075 - Lysxia:no-panic-def-path-hash, r=petrochenkovMatthias Krüger-2/+2
Make `def_path_hash_to_def_id` not panic when passed an invalid hash I'm using this function in a third-party application (Creusot) to access private items (by reverse engineering their hash). This works in the happy path, but it panics when an item does not exist. There is no way to hack it downstream because the hook `def_path_hash_to_def_id_extern` must always return a `DefId` and its implementation uses `def_path_hash_to_def_index` which is internal and which is where the panic happens.
2025-09-27Auto merge of #146636 - Mark-Simulacrum:bootstrap-bump, r=jieyouxubors-1/+0
Bump bootstrap compiler to 1.91 beta https://forge.rust-lang.org/release/process.html#default-branch-bootstrap-update-tuesday
2025-09-27Auto merge of #147074 - matthiaskrgr:rollup-sm3owsd, r=matthiaskrgrbors-7/+1
Rollup of 10 pull requests Successful merges: - rust-lang/rust#145113 (resolve: Do not finalize shadowed bindings) - rust-lang/rust#146523 (Demote both armebv7r-none-* targets.) - rust-lang/rust#146704 (port `#[debugger_visualizer]` to the new attribute system) - rust-lang/rust#146758 (Stop linking rs{begin,end} objects on x86_64-*-windows-gnu) - rust-lang/rust#146778 (Use standard attribute logic for allocator shim) - rust-lang/rust#146849 (Reduce some uses of `LegacyBang`) - rust-lang/rust#147016 (fix doc comments to be more standard) - rust-lang/rust#147027 (Add new `tyalias` intra-doc link disambiguator) - rust-lang/rust#147031 (mbe: Simplify check_redundant_vis_repetition) - rust-lang/rust#147058 (Ignore more failing ui tests for GCC backend) Failed merges: - rust-lang/rust#147046 (Rename `rust.use-lld` to `rust.bootstrap-override-lld`) r? `@ghost` `@rustbot` modify labels: rollup
2025-09-26Apply cfg(bootstrap) replacementMark Rousskov-1/+0
2025-09-26Make `def_path_hash_to_def_id` not panic when passed an invalid hashLi-yao Xia-2/+2
2025-09-26Rollup merge of #146704 - jdonszelmann:port-debug-visualizer, r=petrochenkovMatthias Krüger-7/+1
port `#[debugger_visualizer]` to the new attribute system
2025-09-26allow method calls on opaqueslcnr-0/+1
2025-09-26predefined opaques to `method_autoderef_steps`lcnr-5/+24
2025-09-26predefined opaques use `List`lcnr-50/+7
2025-09-26ProjectionElem::Subtype -> CastKind::Subtypebeepster4096-28/+14
2025-09-25Auto merge of #147019 - Zalathar:rollup-boxzbmo, r=Zalatharbors-0/+38
Rollup of 14 pull requests Successful merges: - rust-lang/rust#145067 (RawVecInner: add missing `unsafe` to unsafe fns) - rust-lang/rust#145277 (Do not materialise X in [X; 0] when X is unsizing a const) - rust-lang/rust#145973 (Add `std` support for `armv7a-vex-v5`) - rust-lang/rust#146667 (Add an attribute to check the number of lanes in a SIMD vector after monomorphization) - rust-lang/rust#146735 (unstably constify float mul_add methods) - rust-lang/rust#146737 (f16_f128: enable some more tests in Miri) - rust-lang/rust#146766 (Add attributes for #[global_allocator] functions) - rust-lang/rust#146905 (llvm: update remarks support on LLVM 22) - rust-lang/rust#146982 (Remove erroneous normalization step in `tests/run-make/linker-warning`) - rust-lang/rust#147005 (Small string formatting cleanup) - rust-lang/rust#147007 (Explicitly note `&[SocketAddr]` impl of `ToSocketAddrs`) - rust-lang/rust#147008 (bootstrap.py: Respect build.jobs while building bootstrap tool) - rust-lang/rust#147013 (rustdoc: Fix documentation for `--doctest-build-arg`) - rust-lang/rust#147015 (Use `LLVMDisposeTargetMachine`) r? `@ghost` `@rustbot` modify labels: rollup
2025-09-25Rollup merge of #146667 - calebzulawski:simd-mono-lane-limit, r=lcnr,RalfJungStuart Cook-0/+38
Add an attribute to check the number of lanes in a SIMD vector after monomorphization Allows std::simd to drop the `LaneCount<N>: SupportedLaneCount` trait and maintain good error messages. Also, extends rust-lang/rust#145967 by including spans in layout errors for all ADTs. r? ``@RalfJung`` cc ``@workingjubilee`` ``@programmerjake``
2025-09-25Auto merge of #147003 - matthiaskrgr:rollup-b5z9uiz, r=matthiaskrgrbors-2/+1
Rollup of 7 pull requests Successful merges: - rust-lang/rust#146556 (Fix duration_since panic on unix when std is built with integer overflow checks) - rust-lang/rust#146679 (Clarify Display for error should not include source) - rust-lang/rust#146753 (Improve the pretty print of UnstableFeature clause) - rust-lang/rust#146894 (Improve derive suggestion of const param) - rust-lang/rust#146950 (core: simplify `CStr::default()`) - rust-lang/rust#146958 (Fix infinite recursion in Path::eq with String) - rust-lang/rust#146971 (fix ICE in writeback due to bound regions) r? `@ghost` `@rustbot` modify labels: rollup
2025-09-24Rollup merge of #146753 - tiif:unsatisfiable-unstable-feature, r=BoxyUwUMatthias Krüger-2/+1
Improve the pretty print of UnstableFeature clause As per https://github.com/rust-lang/rust/pull/145095#discussion_r2349439492, we could make the diagnostic for unsatisfiable ``UnstableFeature`` clause better. r? `@BoxyUwU`
2025-09-24Rollup merge of #146969 - RalfJung:maybe-null-errors, r=oli-obkMatthias Krüger-4/+3
const-eval: better wording for errors involving maybe-null pointers Fixes https://github.com/rust-lang/rust/issues/146748 r? ``@oli-obk``
2025-09-24Rollup merge of #146857 - tnuha:revert_self_has_no_region_infer, r=lcnrMatthias Krüger-1/+10
revert change removing `has_infer` check. Commit conservatively patch… …es for now, but more development proceeding. Hotfix for rust-lang/rust#146852.
2025-09-24Improve the pretty print of UnstableFeature clausetiif-2/+1
2025-09-24const validation: better error for maybe-null referencesRalf Jung-0/+2
2025-09-24const-eval: improve and actually test the errors when pointers might be ↵Ralf Jung-4/+1
outside the range of a scalar
2025-09-23Add an attribute to check the number of lanes in a SIMD vector after ↵Caleb Zulawski-0/+38
monomorphization Unify zero-length and oversized SIMD errors
2025-09-23revert change removing `has_infer` check. Commit conservatively patches for ↵ash-1/+10
now, but more development proceeding. Also contains a more concise test
2025-09-21port `#[debugger_visualizer]` to the new attribute systemJana Dönszelmann-7/+1
2025-09-21Add panic=immediate-abortBen Kimock-4/+5
2025-09-19autodiff: typetree recursive depth query from enzyme with fallbackKaran Janthe-14/+7
Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
2025-09-19autodiff: recurion added for typetreeKaran Janthe-8/+68
2025-09-19autodiff: fixed test to be more precise for type tree checkingKaran Janthe-27/+9
2025-09-19autodiff: struct support in typetreeKaran Janthe-0/+32
2025-09-19autodiff: tuple support in typetreeKaran Janthe-0/+36
2025-09-19autodiff: slice support in typetreeKaran Janthe-0/+7
2025-09-19autodiff: add TypeTree support for arraysKaran Janthe-1/+41
2025-09-19added typetree support for memcpyKaran Janthe-2/+2
2025-09-19Add TypeTree metadata attachment for autodiffKaran Janthe-13/+6
- Add F128 support to TypeTree Kind enum - Implement TypeTree FFI bindings and conversion functions - Add typetree.rs module for metadata attachment to LLVM functions - Integrate TypeTree generation with autodiff intrinsic pipeline - Support scalar types: f32, f64, integers, f16, f128 - Attach enzyme_type attributes as LLVM string metadata for Enzyme Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
2025-09-19autodiff: Add basic TypeTree with NoTT flagKaran Janthe-1/+80
Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
2025-09-18Rollup merge of #146597 - modhanami:add-struct-tail-recursion-limit-span, ↵Matthias Krüger-5/+19
r=oli-obk Add span for struct tail recursion limit error Fixes rust-lang/rust#135629 Changes 1. Add span to RecursionLimitReached 2. Add ObligationCause parameter to struct_tail_raw 4. Update call sites to pass nearby ObligationCause or create one 5. Update affected .stderr
2025-09-18Rollup merge of #146434 - folkertdev:c-variadic-inherent-methods, ↵Matthias Krüger-0/+6
r=workingjubilee c-variadic: allow c-variadic inherent and trait methods tracking issue: https://github.com/rust-lang/rust/issues/44930 Continuing the work of https://github.com/rust-lang/rust/pull/146342, allow inherent and trait methods to be c-variadic. However, a trait that contains a c-variadic method is no longer dyn-compatible. There is, presumably, some way to make c-variadic methods dyn-compatible. However currently, we don't have confidence that it'll work reliably: when methods from a `dyn` object are cast to a function pointer, a `ReifyShim` is created. If that shim is c-variadic, it would need to forward the C variable argument list. That does appear to work, because the `va_list` is not represented in MIR at all in this case, so the registers from the call site are untouched by the shim and can be read by the actual implementation. That just does not seem like a solid implementation. Also, intuitively, why would c-variadic function, primarily needed for FFI, need to be used with `dyn` objects at all? We can revisit this limitation if a need arises. r? `@workingjubilee`
2025-09-18Rollup merge of #146694 - camsteffen:impl-subject, r=compiler-errorsStuart Cook-38/+1
Remove ImplSubject It only has one usage in rustdoc.
2025-09-18Rollup merge of #146664 - fmease:clean-up-dyn, r=jdonszelmannStuart Cook-25/+19
Clean up `ty::Dynamic` 1. As a follow-up to PR rust-lang/rust#143036, remove `DynKind` entirely. 2. Inside HIR ty lowering, consolidate modules `dyn_compatibility` and `lint` into `dyn_trait` * `dyn_compatibility` wasn't about dyn compatibility itself, it's about lowering trait object types * `lint` contained dyn-Trait-specific diagnostics+lints only