Skip to content

Experiment: Move natvis files from src/etc/natvis to debugger_visualizer attributes#154027

Open
clarfonthey wants to merge 1 commit intorust-lang:mainfrom
clarfonthey:natvis
Open

Experiment: Move natvis files from src/etc/natvis to debugger_visualizer attributes#154027
clarfonthey wants to merge 1 commit intorust-lang:mainfrom
clarfonthey:natvis

Conversation

@clarfonthey
Copy link
Copy Markdown
Contributor

@clarfonthey clarfonthey commented Mar 18, 2026

This is the "easy part" of a massive rabbit hole that I fell into trying to figure out how the current debug visualizers for hashmaps could potentially be moved into the hashbrown crate, while still being able to leverage them for libstd.

For natvis, it's pretty easy to separate out what belongs where, and we basically already do this. This just takes it a slight step further and attempts to move them into their relevant crates, and we'll see if it breaks everything in CI. For lack of a better place, this moves the "intrinsic" (should probably be renamed to "primitive") natvis file into the libcore crate, since no_core is unstable anyway.

The Python scripts are an absolute mess, and that's going to take some asking around. So, instead of stalling this part on that being done, I decided to just offer this PR and we'll see if it can work and hopefully make it easier for people to modify the debug visualizers in the standard library, at least for Windows.


Worth also mentioning right now that I don't have a copy of Windows proper to test this on, so, I'm mostly relying on CI/others to verify that this actually doesn't break anything.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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 Mar 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 18, 2026

r? @clubby789

rustbot has assigned @clubby789.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 18, 2026

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc labels Mar 18, 2026
Comment thread src/tools/compiletest/src/lib.rs Outdated
@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented Mar 18, 2026

// This will cause the Microsoft linker to embed .natvis info into the PDB file
let natvis_dir_path = self.sess.opts.sysroot.path().join("lib\\rustlib\\etc");
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
for entry in natvis_dir {
match entry {
Ok(entry) => {
let path = entry.path();
if path.extension() == Some("natvis".as_ref()) {
let mut arg = OsString::from("/NATVIS:");
arg.push(path);
self.link_arg(arg);
}
}
Err(error) => {
self.sess.dcx().emit_warn(errors::NoNatvisDirectory { error });
}
}
}
}
can be removed after these changes, right?

@clubby789
Copy link
Copy Markdown
Contributor

clubby789 commented Apr 13, 2026

LGTM from the compiletest side once the pretty printer files changes are removed, but I don't have a Windows system to check if the above comment about the linker is true
r? compiler

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 13, 2026
@rustbot rustbot assigned JonathanBrouwer and unassigned clubby789 Apr 13, 2026
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

I also don't have windows
r? bjorn3
I think I remember you knowing things about windows?

@rustbot rustbot assigned bjorn3 and unassigned JonathanBrouwer Apr 13, 2026
@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented Apr 13, 2026

I haven't really touched Windows in years and never did any native development on it. I know some linkage related things because I was trying to get weak linkage working on Windows for EII. As such I don't think I'm a suitable reviewer.

@clubby789
Copy link
Copy Markdown
Contributor

Hmm... @michaelwoerister reviewed this code originally. Any thoughts?

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 13, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@clarfonthey
Copy link
Copy Markdown
Contributor Author

// This will cause the Microsoft linker to embed .natvis info into the PDB file
let natvis_dir_path = self.sess.opts.sysroot.path().join("lib\\rustlib\\etc");
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
for entry in natvis_dir {
match entry {
Ok(entry) => {
let path = entry.path();
if path.extension() == Some("natvis".as_ref()) {
let mut arg = OsString::from("/NATVIS:");
arg.push(path);
self.link_arg(arg);
}
}
Err(error) => {
self.sess.dcx().emit_warn(errors::NoNatvisDirectory { error });
}
}
}
}

can be removed after these changes, right?

Looking into it, this appears to be the case; the loop below this section that collects the natvis files from all compiled crates should be sufficient. Removed it.

@clarfonthey clarfonthey force-pushed the natvis branch 2 times, most recently from b14e911 to 40db624 Compare April 13, 2026 17:18
@rust-log-analyzer

This comment has been minimized.

@ChrisDenton
Copy link
Copy Markdown
Member

This looks right to me. The only possible downside I can think of is that this now loads all the natvis files into memory and then writes them out to temporary files (with more obscure file names). But a) the size is not large and b) that's just like how user natvis files are treated anyway. So I don't think it's much of a downside. If it is advantageous to optimise this then such an optimisation should be applied outside of the standard library too.

@clarfonthey
Copy link
Copy Markdown
Contributor Author

I would be truly shocked if 14KiB of XML was what broke the bank for compiling on Windows.

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

Labels

A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants