-
Notifications
You must be signed in to change notification settings - Fork 13k
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
cache symbol names in ty::maps #41507
Conversation
src/librustc/ty/maps.rs
Outdated
#[derive(Clone)] | ||
pub struct SymbolName { | ||
// FIXME: we don't rely on interning or equality here - better have | ||
// this be a `&'tcx str`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "don't rely on interning or equality here"? Maybe you mean for equality? The main thing to be careful of (which &'tcx str
would solve) is that we hash the string contents (if you use Symbol
, things go awry).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, that comment was needed because a previous try used Symbol
there, which as you said is dangerous. I'll remove it.
@@ -164,7 +154,8 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> { | |||
/// A counter that is used for generating local symbol names | |||
local_gen_sym_counter: Cell<usize>, | |||
|
|||
symbol_cache: &'a SymbolCache<'a, 'tcx>, | |||
/// A placeholder so we can add lifetimes | |||
placeholder: PhantomData<&'a ()>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just remove 'a
? I think I added it in my PR expressly for this field. But whatever, seems fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed that. Didn't want to cause unnecessary diffs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine.
symbol_map.get(TransItem::Fn(instance)) | ||
.map(str::to_owned) | ||
.unwrap_or_else(|| symbol_name(instance, tcx)) | ||
str::to_owned(&symbol_name(instance, tcx)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we just replace this entire function with a call to symbol_name
(and change return type to InternedString
, of course)? It seems like we should remove the secondary caching performed by SymbolMap
, and instead have that also use the queries, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'm curious what you think about removing the SymbolMap
too.
let items: Vec<_> = self.items.iter().map(|(&i, &l)| (i, l)).collect(); | ||
let mut items : Vec<_> = items.iter() | ||
.map(|il| (il, item_sort_key(tcx, il.0))).collect(); | ||
items.sort_by(|&(_, ref key1), &(_, ref key2)| key1.cmp(key2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by this. Aren't there sometimes multiple items with the same node-id that nonetheless deserve a consistent ordering (e.g., different instantiations of the same instance?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Let me fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious about the sorting thing, otherwise seems good.
for cgu in cgus { | ||
debug!("CodegenUnit {}:", cgu.name); | ||
|
||
for (trans_item, linkage) in &cgu.items { | ||
let symbol_name = symbol_cache.get(*trans_item); | ||
let symbol_name = trans_item.symbol_name(tcx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to making this a method, the fn was awkward.
@@ -164,7 +154,8 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> { | |||
/// A counter that is used for generating local symbol names | |||
local_gen_sym_counter: Cell<usize>, | |||
|
|||
symbol_cache: &'a SymbolCache<'a, 'tcx>, | |||
/// A placeholder so we can add lifetimes | |||
placeholder: PhantomData<&'a ()>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine.
hasher.finish() | ||
} | ||
|
||
pub fn symbol_name<'a, 'tcx>(instance: Instance<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Total nit, but I'd expect tcx
to be the first argument. Having this be a method seems even better (didn't you do this elsewhere? Or is that just for TransItem
?) But I don't care much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was this way originally. Let me move it all the way to a method on Instance.
a8c9623
to
1199e3e
Compare
src/librustc_trans/partitioning.rs
Outdated
} else { | ||
ItemSortKey::Remote(item.symbol_name(tcx)) | ||
} | ||
}, item.symbol_name(tcx)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 simpler this way anyhow
@bors r=nikomatsakis |
📌 Commit af63f14 has been approved by |
Fixed @bors r=nikomatsakis |
📌 Commit 07d1233 has been approved by |
☔ The latest upstream changes (presumably #41504) made this pull request unmergeable. Please resolve the merge conflicts. |
this fixes a performance regression introduced in commit 39a58c3.
@bors r=nikomatsakis |
📌 Commit 07b16cb has been approved by |
⌛ Testing commit 07b16cb with merge aed35b2... |
💔 Test failed - status-appveyor |
@bors retry Appveyor network issues https://appveyor.statuspage.io/incidents/06gzq846jl9x |
⌛ Testing commit 07b16cb with merge 4961d72... |
cache symbol names in ty::maps this fixes a performance regression introduced in commit 39a58c3. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
this fixes a performance regression introduced in commit 39a58c3.
r? @nikomatsakis