Commit Graph

481 Commits

Author SHA1 Message Date
Trevor Gross 490b307740 cleanup: Start splitting FIXME(f16_f128) into f16, f128, or f16,f128
Make it easier to identify which FIXMEs are blocking stabilization of
which type.
2026-01-22 23:41:57 -06:00
Jacob Pratt 512cc8d785 Rollup merge of #151442 - clubby789:crate-type-port, r=JonathanBrouwer
Port `#![crate_type]` to the attribute parser

Tracking issue: https://github.com/rust-lang/rust/issues/131229

~~Note that the actual parsing that is used in the compiler session is unchanged, as it must happen very early on; this just ports the validation logic.~~

Also added `// tidy-alphabetical-start` to `check_attr.rs` to make it a bit less conflict-prone
2026-01-22 00:37:43 -05:00
Jamie Hill-Daniel 66b78b700b Port crate_type to attribute parser 2026-01-22 02:34:28 +00:00
León Orell Valerian Liehr 558a59258e Support debuginfo for assoc const bindings 2026-01-21 18:52:08 +01:00
Nicholas Nethercote 5e510929c6 Remove useless call to erase_and_anonymize_regions.
The only thing we do with the result is consult the `.def_id` field,
which is unaffected by `erase_and_anonymize_regions`.
2026-01-12 09:22:58 +11:00
Zalathar 735a980693 Move DIBuilderBox out of ffi.rs 2025-12-19 12:32:49 +11:00
Urgau 8cbfb26383 Overhaul filename handling for cross-compiler consistency
This commit refactors `SourceMap` and most importantly `RealFileName` to
make it self-contained in order to achieve cross-compiler consistency.

This is achieved:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
 - by also making `RealFileName` holds it's working directory,
   it's embeddable name and the remapped scopes
 - by making most `FileName` and `RealFileName` methods take a scope as
   an argument

In order for `SourceMap::to_real_filename` to know which scopes to apply
`FilePathMapping` now takes the current remapping scopes to apply, which
makes `FileNameDisplayPreference` and company useless and are removed.

The scopes type `RemapPathScopeComponents` was moved from
`rustc_session::config` to `rustc_span`.

The previous system for scoping the local/remapped filenames
`RemapFileNameExt::for_scope` is no longer useful as it's replaced by
methods on `FileName` and `RealFileName`.
2025-12-12 07:33:09 +01:00
Jeremy Fitzhardinge 5f29f11a4d Add -Zannotate-moves for profiler visibility of move/copy operations
This implements a new unstable compiler flag `-Zannotate-moves` that makes
move and copy operations visible in profilers by creating synthetic debug
information. This is achieved with zero runtime cost by manipulating debug
info scopes to make moves/copies appear as calls to `compiler_move<T, SIZE>`
and `compiler_copy<T, SIZE>` marker functions in profiling tools.

This allows developers to identify expensive move/copy operations in their
code using standard profiling tools, without requiring specialized tooling
or runtime instrumentation.

The implementation works at codegen time. When processing MIR operands
(`Operand::Move` and `Operand::Copy`), the codegen creates an `OperandRef`
with an optional `move_annotation` field containing an `Instance` of the
appropriate profiling marker function. When storing the operand,
`store_with_annotation()` wraps the store operation in a synthetic debug
scope that makes it appear inlined from the marker.

Two marker functions (`compiler_move` and `compiler_copy`) are defined
in `library/core/src/profiling.rs`. These are never actually called -
they exist solely as debug info anchors.

Operations are only annotated if the type:
   - Meets the size threshold (default: 65 bytes, configurable via
     `-Zannotate-moves=SIZE`)
   - Has a non-scalar backend representation (scalars use registers,
     not memcpy)

This has a very small size impact on object file size. With the default
limit it's well under 0.1%, and even with a very small limit of 8 bytes
it's still ~1.5%. This could be enabled by default.
2025-11-06 15:39:45 -08:00
Zalathar 1081d98551 Use LLVMDIBuilderCreateGlobalVariableExpression
Note that the code in `LLVMRustDIBuilderCreateStaticVariable` that tried to
downcast `InitVal` appears to have been dead, because `llvm::ConstantInt` and
`llvm::ConstantFP` are not subclasses of `llvm::GlobalVariable`.
2025-10-12 23:36:26 +11:00
Zalathar 1db7d41665 Extract DIBuilderExt::create_static_variable 2025-10-12 23:34:44 +11:00
Zalathar 45e9ebee31 Extract DIBuilderExt::create_expression 2025-10-12 23:34:44 +11:00
Zalathar b6ea8242fd Hoist some stranded use declarations 2025-10-12 23:34:39 +11:00
Zalathar 69a975faa9 Consistently import llvm::Type and llvm::Value 2025-10-06 13:09:16 +11:00
Zalathar f955c76a5b Remove inherent methods from several LLVM FFI types
Using a helper trait allows the conversions to remain in `rustc_codegen_llvm`,
even if the FFI types are moved to a different crate.
2025-10-04 18:16:13 +10:00
bors 8b6b15b877 Auto merge of #142771 - dianqk:mir-stmt-debuginfo, r=cjgillot
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-03 11:49:42 +00:00
Zalathar 8ef9821bf2 Extract helper method global_set_metadata_node 2025-10-02 18:06:58 +10:00
Zalathar 6a58f80a3c Extract helper method global_add_metadata_node 2025-10-02 18:06:57 +10:00
dianqk 1bd89bd42e codegen: Generate dbg_value for the ref statement 2025-10-02 14:55:51 +08:00
Zalathar cc6329a9bc Replace MetadataType with the MetadataKindId constants 2025-09-30 20:10:30 +10:00
Jubilee Young 0c9d0dfe04 remove explicit deref of AbiAlign for most methods
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-28 15:02:14 -07:00
Matthias Krüger e8578c8808 Rollup merge of #146763 - Zalathar:di-builder, r=jdonszelmann
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 5)

- Part of rust-lang/rust#134001
- Follow-up to rust-lang/rust#146673

---

This is another batch of LLVMDIBuilder binding migrations, replacing some our own LLVMRust bindings with bindings to upstream LLVM-C APIs.

Some of these are a little more complex than most of the previous migrations, because they split one LLVMRust binding into multiple LLVM bindings, but nothing too fancy.

This appears to be the last of the low-hanging fruit. As noted in https://github.com/rust-lang/rust/issues/134001#issuecomment-2524979268, the remaining bindings are difficult or impossible to migrate at present.
2025-09-28 09:15:23 +02:00
Matthias Krüger d09bb02eb5 Rollup merge of #146704 - jdonszelmann:port-debug-visualizer, r=petrochenkov
port `#[debugger_visualizer]` to the new attribute system
2025-09-26 18:11:09 +02:00
Stuart Cook fab06469ee Rollup merge of #146667 - calebzulawski:simd-mono-lane-limit, r=lcnr,RalfJung
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-25 20:31:53 +10:00
Caleb Zulawski 60548ffaa3 Including spans in layout errors for all ADTs 2025-09-23 22:15:06 -04:00
Jana Dönszelmann 9acc63a48c port #[debugger_visualizer] to the new attribute system 2025-09-21 21:30:16 -07:00
Zalathar 272d336f0f Remove some unnecessary as u64 casts
In each of these casts, the LHS is already `u64`.
2025-09-19 20:56:58 +10:00
Zalathar e39e5a0d15 Use LLVMDIBuilderCreate(Auto|Parameter)Variable 2025-09-19 20:56:58 +10:00
Zalathar 9daa026cad Use LLVMDIBuilder(CreateExpression|InsertDeclareRecordAtEnd) 2025-09-19 17:15:32 +10:00
Zalathar a6d261712e Use LLVMDIBuilderGetOrCreateArray 2025-09-19 14:44:54 +10:00
Zalathar b1a9f231fe Use LLVMDIBuilderGetOrCreateSubrange 2025-09-19 14:41:18 +10:00
Zalathar 6b51f7c076 Use LLVMDIBuilderCreateTypedef 2025-09-17 22:32:22 +10:00
Zalathar 002771ab5c Use LLVMDIBuilderCreateQualifiedType 2025-09-17 22:32:22 +10:00
Zalathar bb21dbeac7 Use LLVMDIBuilderCreateStaticMemberType 2025-09-17 22:32:22 +10:00
Zalathar 923d1be6b6 Use LLVMDIBuilderCreateMemberType 2025-09-17 22:32:21 +10:00
Zalathar af88d14cac Use LLVMDIBuilderCreateStructType 2025-09-17 12:28:08 +10:00
Zalathar bae6fde270 Use LLVMDIBuilderCreatePointerType 2025-09-17 12:28:08 +10:00
Zalathar 3e9048d9a4 Use LLVMDIBuilderCreateBasicType 2025-09-17 12:28:08 +10:00
Zalathar bef8f646a6 Use LLVMDIBuilderCreateArrayType 2025-09-17 12:28:08 +10:00
Zalathar 2552deb9cd Use LLVMDIBuilderCreateUnionType 2025-09-17 12:28:08 +10:00
Zalathar 5419896111 Use LLVMDIBuilderCreateSubroutineType 2025-09-17 12:28:08 +10:00
bors 364da5d88d Auto merge of #145717 - BoxyUwU:erase_regions_rename, r=lcnr
rename erase_regions to erase_and_anonymize_regions

I find it consistently confusing that `erase_regions` does more than replacing regions with `'erased`. it also makes some code look real goofy to be writing manual folders to erase regions with a comment saying "we cant use erase regions" :> or code that re-calls erase_regions on types with regions already erased just to anonymize all the bound regions.

r? lcnr

idk how i feel about the name being almost twice as long now
2025-09-09 15:04:44 +00:00
Boxy e379c77586 erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
Martin Nordholts 2ce6154b32 compiler: Include span of too huge array with -Cdebuginfo=2
We have a few ui tests to ensure we emit an error if we encounter too
big arrays. Before this fix, compiling the tests with `-Cdebuginfo=2`
would not include the spans of the instantiation sites, because the
error is then emitted from a different code path that does not include
the span.

Propagate the span to the error also in the debuginfo case, so the tests
passes regardless of debuginfo level.
2025-08-30 11:09:29 +02:00
Martin Nordholts 4edfeb2f60 compiler: Include span of too huge enum with -Cdebuginfo=2
We have a ui test to ensure we emit an error if we encounter too big
enums. Before this fix, compiling the test with `-Cdebuginfo=2` would
not include the span of the instantiation site, because the error is
then emitted from a different code path that does not include the span.

Propagate the span to the error also in the debuginfo case, so the test
passes regardless of debuginfo level.
2025-08-28 20:37:09 +02:00
Zalathar b4e97e5d86 Rename llvm::Bool aliases to standard const case
This avoids the need for `#![allow(non_upper_case_globals)]`.
2025-08-24 23:09:54 +10:00
Jacob Pratt 537d5f40a6 Rollup merge of #145297 - adwinwhite:recursive-debuginfo, r=wesleywiser
fix(debuginfo): handle false positives in overflow check

Fixes rust-lang/rust#144636.

Duplicate wrappers and normal recursive types can lead to false positives.
```rust
struct Recursive {
	a: Box<Box<Recursive>>,
}
```
The ADT stack can be:
- `Box<Recursive>`
- `Recursive`
- `Box<Box<Recursive>>` (`Box` now detected as expanding)

We can filter them out by tracing the generic arg back through the stack, as true expanding recursive types must have their expanding arg used as generic arg throughout.

r? ````@wesleywiser````
2025-08-21 01:12:16 -04:00
Cameron Steffen d4eb0947f1 Cleanup assoc parent utils 2025-08-13 09:33:09 -05:00
Adwin White e13e1e4c0c fix(debuginfo): handle false positives in overflow check 2025-08-12 17:13:13 +08:00
bjorn3 e02cc40ec9 Revert "Preserve the .debug_gdb_scripts section"
This reverts commit 868bdde25b.
2025-08-06 18:01:07 +00:00
bjorn3 270c1a4d24 Revert "Embed GDB pretty printers in rlibs and dylibs"
This reverts commit b4d923cea0.
2025-08-06 18:00:58 +00:00