Skip to content

A more readable debug map for IndexMaps - #159792

Open
dingxiangfei2009 wants to merge 1 commit into
rust-lang:mainfrom
dingxiangfei2009:coro-debug-map
Open

A more readable debug map for IndexMaps#159792
dingxiangfei2009 wants to merge 1 commit into
rust-lang:mainfrom
dingxiangfei2009:coro-debug-map

Conversation

@dingxiangfei2009

@dingxiangfei2009 dingxiangfei2009 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Let's ship #135527 more.

To help future debugging, let us print the maps with a more readable format.

r? @cjgillot

@rustbot

rustbot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rustbot rustbot added 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. labels Jul 23, 2026
@rust-log-analyzer

This comment has been minimized.

@cjgillot cjgillot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

}
entries.finish()
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we just make this the impl for IndexVec and IndexSlice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, life happened and it took me a while to come back to this.

Yes, we could potentially. I figured that I frequently need to search the value under one particular index in a slice and it has not been possible.

The printout would be a bit verbose, however. Let's see how the dev ergonomics would be.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, since we do not have min_specialization in this crate yet, I will print the keys even when the index type is u32. The debug print seems to be more readable now and I like how layout printout looks like given that indices are clearly labelled.

@dingxiangfei2009 dingxiangfei2009 Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, probably this is still not a good idea.

It turns out, out of convenience, MIR pretty-print uses debug print of IndexVec and IndexSlice. My smaller local tests did not catch this. With this MIR dump got noisier than I felt comfortable.

I would call this impl switch a deferred upgrade then. We probably would fix the MIR printing in another PR, I can imagine.

@rustbot

rustbot commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

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.

@rust-log-analyzer

This comment has been minimized.

This small utility provides a familiar key-value view of an `IndexMap`
in the debugging output.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
@dingxiangfei2009

Copy link
Copy Markdown
Contributor Author

Due to MIR pretty-printing using {:?} debug-format on IndexSlice for array notation, I will have to defer switching the debug-formatting to the saner representation. I think the array notation needs a proper designated formatter on its own rather than relying on debug formatting in which we do not promise to stick to one presentation. PR pending.

@bors r=cjgillot

@rust-bors

rust-bors Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 6072e64 has been approved by cjgillot

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 4, 2026
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
…=cjgillot

A more readable debug map for IndexMaps

Let's ship rust-lang#135527 more.

To help future debugging, let us print the maps with a more readable format.

r? @cjgillot
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
…=cjgillot

A more readable debug map for IndexMaps

Let's ship rust-lang#135527 more.

To help future debugging, let us print the maps with a more readable format.

r? @cjgillot
rust-bors Bot pushed a commit that referenced this pull request Sep 4, 2026
Rollup of 25 pull requests

Successful merges:

 - #159074 ([PAC] FnAbi, llvm.ptrauth.resign and Session API change (2/8))
 - #159792 (A more readable debug map for IndexMaps)
 - #161895 (std::sys::pal::sgx: fix mismatched alloc/free alignment)
 - #161900 (bootstrap: Include feature-gated items in bootstrap tool docs)
 - #161940 (Promote `wasm32-wasip3` to a tier 2 target)
 - #162072 (Add new Tier-3 target: `powerpc64-sony-ps3`)
 - #162179 (type system const items via direct rhs)
 - #162277 (Introduce `rustc_middle::middel::resolve`)
 - #162285 (box: fixup map/try_map deallocate calls)
 - #162286 (string: don't unwind prematurely)
 - #162289 (alloc: a bunch of safety comments)
 - #162292 (Update `askama` version to `0.16.1`)
 - #160509 (Remove `RegionExt`; move methods to `Region` in `rustc_type_ir`)
 - #160906 (Suggest usize instead of placeholder type for array length constants)
 - #160936 (traits: Represent live alias arguments as bitsets)
 - #161400 (Improve diagnostics for references to closures)
 - #161656 (Suggest mutable references for FnMut closure arguments)
 - #161711 (Add more splat fn type tests)
 - #161786 (Make `tcx.def_id_partial_cmp` public)
 - #161953 (sanitizers: Implicitly disable mutually exclusive sanitizers)
 - #162155 (add suggestion for `rustc_allowed_through_unstable_modules` attribute)
 - #162212 (Implement `Rng` for `Box`)
 - #162246 (Fix incorrect meta span)
 - #162266 (std: fix typo)
 - #162291 (Add regression test from 1.98.1)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
…=cjgillot

A more readable debug map for IndexMaps

Let's ship rust-lang#135527 more.

To help future debugging, let us print the maps with a more readable format.

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

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants