Skip to content

Conversation

@bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jul 20, 2025

This attribute causes the struct to be unwrapped at the debuginfo level the same way that repr(transparent) unwraps it at the ABI level. This is useful for preventing types like NonNull and Unique from making the debuginfo harder to read when pretty printers aren't used.

@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2025

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

};

if find_attr!(cx.tcx.get_all_attrs(adt_def.did()), AttributeKind::DebuginfoTransparent(..)) {
let ty = struct_type_and_layout.non_1zst_field(cx).unwrap().1.ty;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to ensure that #[debuginfo_transparent] can only be used when #[repr(transparent)] is also used? And how should I handle the case where all fields are 1zst's?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented a restriction to #[repr(transparent)] types.


// gdb-command:print plain_string
// gdb-check:$1 = alloc::string::String {vec: alloc::vec::Vec<u8, alloc::alloc::Global> {buf: alloc::raw_vec::RawVec<u8, alloc::alloc::Global> {inner: alloc::raw_vec::RawVecInner<alloc::alloc::Global> {ptr: core::ptr::unique::Unique<u8> {pointer: core::ptr::non_null::NonNull<u8> {pointer: 0x[...]}, _marker: core::marker::PhantomData<u8>}, cap: core::num::niche_types::UsizeNoHighBit (5), alloc: alloc::alloc::Global}, _marker: core::marker::PhantomData<u8>}, len: 5}}
// gdb-check:$1 = alloc::string::String {vec: alloc::vec::Vec<u8, alloc::alloc::Global> {buf: alloc::raw_vec::RawVec<u8, alloc::alloc::Global> {inner: alloc::raw_vec::RawVecInner<alloc::alloc::Global> {ptr: 0x[...], cap: 5, alloc: alloc::alloc::Global}, _marker: core::marker::PhantomData<u8>}, len: 5}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the improvement this PR causes. Further improvements could be made using future #[debuginfo_flatten] and #[debuginfo_hidden] attributes on RawVec/RawVecInner and the _marker field, which would result in

alloc::string::String {vec: alloc::vec::Vec<u8, alloc::alloc::Global> {ptr: 0x[...], cap: 5, alloc: alloc::alloc::Global, len: 5}}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar changes would need to be made for LLDB, but LLDB is broken on the dev-desktop.

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Jul 20, 2025
@bjorn3 bjorn3 force-pushed the better_debuginfo branch from 0958203 to 9c64c42 Compare July 20, 2025 15:29
@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2025

There are changes to the tidy tool.

cc @jieyouxu

@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jul 20, 2025
@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

I don't have a strong opinion on whether this attribute should be added or not.
On one hand it duplicates functionality of gdb pretty-printers or equivalents + maybe #[debugger_visualizer], on the other hand it's clearly easier to use.

I'll delegate this to the lang team, because it approves new attributes anyway.

Also, for the implementation maybe find some other reviewer more interested in debuginfo?

@petrochenkov petrochenkov added S-waiting-on-team DEPRECATED: Use the team-based variants `S-waiting-on-t-lang`, `S-waiting-on-t-compiler`, ... T-lang Relevant to the language team and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 21, 2025
@bjorn3
Copy link
Member Author

bjorn3 commented Jul 22, 2025

For the NonZero* and NonNull types it completely removes the need for the pretty-printers. I only kept their pretty-printers for backwards compatibility reasons.

@bjorn3 bjorn3 force-pushed the better_debuginfo branch from 9c64c42 to 04c4fe2 Compare August 6, 2025 15:49
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 6, 2025

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann

@rust-log-analyzer

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the better_debuginfo branch 2 times, most recently from 2fe205c to 43317da Compare August 6, 2025 16:02
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Aug 7, 2025

☔ The latest upstream changes (presumably #145020) made this pull request unmergeable. Please resolve the merge conflicts.

@bjorn3 bjorn3 force-pushed the better_debuginfo branch from 43317da to c8752f5 Compare August 7, 2025 12:35
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Aug 15, 2025

☔ The latest upstream changes (presumably #145085) made this pull request unmergeable. Please resolve the merge conflicts.

This attribute causes the struct to be unwrapped at the debuginfo level
the same way that repr(transparent) unwraps it at the ABI level. This is
useful for preventing types like NonNull and Unique from making the
debuginfo harder to read when pretty printers aren't used.
@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tidy check
Checking tidy rustdoc_json...
No error code explanation was removed!
tidy: Skipping binary file check, read-only filesystem
##[error]tidy error: /checkout/compiler/rustc_feature/src/unstable.rs:463: no tracking issue for feature debuginfo_attrs
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'venv'
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10' and 'virtualenv'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (25.1.1)
Collecting pip
---

added 291 packages in 34s
Running eslint on rustdoc JS files
info: ES-Check: there were no ES version matching errors!  🎉
some tidy checks failed
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy /checkout /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 /node/bin/npm --extra-checks=py,cpp,js` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1583:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1225:29

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:02:02
  local time: Fri Aug 15 09:00:11 UTC 2025
  network time: Fri, 15 Aug 2025 09:00:11 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@Urgau Urgau added S-waiting-on-t-lang Status: Awaiting decision from T-lang and removed S-waiting-on-team DEPRECATED: Use the team-based variants `S-waiting-on-t-lang`, `S-waiting-on-t-compiler`, ... labels Oct 6, 2025
@Walnut356
Copy link
Contributor

Walnut356 commented Oct 19, 2025

Just a heads up, LLDB would also need a backwards compatibility fix (lldb_providers.unwrap_unique_or_non_null()). I also think there are some places that don't call that function but should, meaning they will break as well (e.g. StdStringSyntheticProvider.update() which manually traverses the inner vec and its nonnull)

Weighing in from the debug info perspective, this sort of problem is the main purpose of visualizer scripts and it seems a bit odd to cater to not using them. C++ has similar issues, they just aren't as visible because (at least for LLDB) the equivalent pretty printers and SyntheticProviders exist in the debugger itself

When using a visualizer script, you can always opt-out of individual visualizers or temporarily "look through" it to see the raw layout (for LLDB, there are display options in the CLI that disable synthetics and the python API has SBValue.GetNonSyntheticValue()). Once you generate different debug nodes though, you are losing information that cannot be recovered by the debugger.

I'm not sure how much of a priority it is for the Rust team that raw debug info to be 1:1 with the Rust representation, but I do think it's somewhat important. Other cases where nodes are generated that don't match the Rust representation (e.g. enums), the justification is hard constraints imposed by the debug info format or the debuggers rather than convenience.

With the way this is implemented, AFAICT it is impossible to tell the difference at debug-time between a NonNull pointer, a Unique pointer, and a raw pointer since it inherits the full DI node. Also, any formatters, summaries, or synthetics applied to one will always be applied to the other. Wrapping the inherited DI node in a typedef might be a good middleground, as debuggers will "look through" the typedef when displaying the value, and inheriting formatters/summaries/synthetics can be opt-ed out

(lldb) help type synthetic add
Add a new synthetic provider for a type.

Syntax: type synthetic add <cmd-options> <name> [<name> [...]]
...
    -C <boolean> ( --cascade <boolean> )
            If true, cascade through typedef chains.
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-tidy Area: The tidy tool S-waiting-on-t-lang Status: Awaiting decision from T-lang T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants