-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Store HIR ForeignItem in a side table #79318
Conversation
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
didn't look through it completely yet, but from what I can see this is really awesome and what I should have done a few months ago while I was looking into this 👍 good job |
Is this enough to close #37713? |
☔ The latest upstream changes (presumably #79388) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
It may take me a little while to get to this, as it's quite busy for me at the moment, so if someone else is happy to review, do go ahead. Otherwise I'll get to it as soon as I can! |
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 624f07fed26127b737495cfe15719ecd9d273a34 with merge 30a62b3f272e155d4aba84177ea7147d78f85afc... |
☀️ Try build successful - checks-actions |
Queued 30a62b3f272e155d4aba84177ea7147d78f85afc with parent aefcf1f, future comparison URL. |
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
some small nits
compiler/rustc_hir/src/arena.rs
Outdated
@@ -29,6 +29,7 @@ macro_rules! arena_types { | |||
[] field_pat: rustc_hir::FieldPat<$tcx>, | |||
[] fn_decl: rustc_hir::FnDecl<$tcx>, | |||
[] foreign_item: rustc_hir::ForeignItem<$tcx>, | |||
[] foreign_item_ref: rustc_hir::ForeignItemRef<$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.
would it make sense to use [few]
here?
Don't know how big of an impact this has but foreign items are probably quite rare.
compiler/rustc_hir/src/intravisit.rs
Outdated
@@ -277,6 +289,14 @@ pub trait Visitor<'v>: Sized { | |||
walk_list!(self, visit_impl_item, opt_item); | |||
} | |||
|
|||
/// Like `visit_nested_item()`, but for impl items. See |
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.
/// Like `visit_nested_item()`, but for impl items. See | |
/// Like `visit_nested_item()`, but for foreign items. See |
@@ -1225,7 +1225,7 @@ impl EncodeContext<'a, 'tcx> { | |||
hir::ItemKind::Mod(ref m) => { | |||
return self.encode_info_for_mod(item.hir_id, m, &item.attrs); | |||
} | |||
hir::ItemKind::ForeignMod(_) => EntryKind::ForeignMod, | |||
hir::ItemKind::ForeignMod{..} => EntryKind::ForeignMod, |
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.
hir::ItemKind::ForeignMod{..} => EntryKind::ForeignMod, | |
hir::ItemKind::ForeignMod { .. } => EntryKind::ForeignMod, |
auto formatting inside of macros
@@ -447,6 +447,8 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { | |||
fn visit_impl_item(&mut self, _item: &hir::ImplItem<'_>) { | |||
// ignore: we are handling this in `visit_item` above | |||
} | |||
|
|||
fn visit_foreign_item(&mut self, _item: &'v hir::ForeignItem<'v>) {} |
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.
This is currently incorrect, but already was so before this PR.
#[repr(C)]
struct Type(u8);
extern "C" {
#[allow(dead_code)]
fn hey(t: Type);
}
shouldn't warn for Type
because type is used by fn hey
.
Should probably open a separate issue for this unless you quickly want to fix this in a followup PR
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.
Investigating in a follow-up PR.
@@ -37,6 +37,8 @@ impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> { | |||
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) { | |||
self.observe_item(&impl_item.attrs, impl_item.hir_id); | |||
} | |||
|
|||
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {} |
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.
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {} | |
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) { | |
self.observe_item(foreign_item.attrs, foreign_item.hir_id); | |
} |
we currently do this manually in line 107, but should just do this here.
compiler/rustc_passes/src/entry.rs
Outdated
@@ -45,6 +45,8 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { | |||
fn visit_impl_item(&mut self, _impl_item: &'tcx ImplItem<'tcx>) { | |||
// Entry fn is never a trait item. | |||
} | |||
|
|||
fn visit_foreign_item(&mut self, _: &'tcx ForeignItem<'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.
fn visit_foreign_item(&mut self, _: &'tcx ForeignItem<'tcx>) {} | |
fn visit_foreign_item(&mut self, _: &'tcx ForeignItem<'tcx>) { | |
// Entry fn is never a foreign item. | |
} |
comments are fun 🤷
@@ -378,6 +378,8 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx | |||
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { | |||
// processed in visit_item above | |||
} | |||
|
|||
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {} |
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.
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {} | |
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) { | |
// We never export foreign functions as they have no body to export. | |
} |
At least that's how I understand this, not completely sure about that 😆
@@ -499,7 +499,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { | |||
// optional. They inherit stability from their parents when unannotated. | |||
if !matches!( | |||
i.kind, | |||
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod(..) | |||
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod{..} |
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.
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod{..} | |
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod { .. } |
formatting 🤷
r? @lcnr |
Finished benchmarking try commit (30a62b3f272e155d4aba84177ea7147d78f85afc): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
30aa3f7
to
9679fa2
Compare
thanks 👍 @bors r+ rollup=never |
📌 Commit d6b22fa has been approved by |
☀️ Test successful - checks-actions |
@cjgillot @lcnr this change caused a ~4% regression in the |
With this PR we now have an additional allocation for each extern item as well as a Building the additional tree in hir lowering is probably the cause of the slowdown of the This PR reduces the amount of false edges in the query graph, meaning that changing the definition of an extern item shouldn't invalidate as many queries as before as seen in the changes to our incremental tests. That should result in perf improvements in some cases. Would it make sense add an incremental test changing the definition of an extern item to the It is also a improvement to the way we deal with extern items, which can be seen in #79318 (comment) where it allowed us to easily detect a bug. |
Can you explain the nature of the change to the definition that you'd want to see? I'm not sure I fully follow. |
The relevant changes would change So afaict possible changes would be
cc @cjgillot we store the |
Store HIR ForeignItem in a side table In a similar fashion to Item, ImplItem and TraitItem.
Visit ForeignItems when marking dead code Follow-up to rust-lang#79318 r? `@lcnr`
In a similar fashion to Item, ImplItem and TraitItem.