Skip to content

Minor trimmed_def_paths improvements #119974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add some helpful comments in trimmed_def_paths.
To explain things that took me a minute to work out.
nnethercote committed Jan 14, 2024
commit 4efddb141a37577c6fc6a9a39248cc86b736750b
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
@@ -3083,7 +3083,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
let mut map: DefIdMap<Symbol> = Default::default();

if let TrimmedDefPaths::GoodPath = tcx.sess.opts.trimmed_def_paths {
// Trimming paths is expensive and not optimized, since we expect it to only be used for error reporting.
// Trimming paths is expensive and not optimized, since we expect it to only be used for
// error reporting.
//
// For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths`
// wrapper can be used to suppress this query, in exchange for full paths being formatted.
@@ -3092,6 +3093,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
);
}

// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
// non-unique pairs will have a `None` entry.
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
&mut FxHashMap::default();

@@ -3121,6 +3124,7 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
}
});

// Put the symbol from all the unique namespace+symbol pairs into `map`.
for ((_, symbol), opt_def_id) in unique_symbols_rev.drain() {
use std::collections::hash_map::Entry::{Occupied, Vacant};