-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Split the node_id_to_def_id table into a per-owner table #138995
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
base: main
Are you sure you want to change the base?
Changes from all commits
9b80a68
f39d529
041a571
3a906e0
641d6fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,11 @@ use crate::stable_hasher::{ | |||||
| pub struct UnordItems<T, I: Iterator<Item = T>>(I); | ||||||
|
|
||||||
| impl<T, I: Iterator<Item = T>> UnordItems<T, I> { | ||||||
| #[inline] | ||||||
| pub fn wrap(iter: I) -> Self { | ||||||
| Self(iter) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Could you avoid |
||||||
| } | ||||||
|
|
||||||
| #[inline] | ||||||
| pub fn map<U, F: Fn(T) -> U>(self, f: F) -> UnordItems<U, impl Iterator<Item = U>> { | ||||||
| UnordItems(self.0.map(f)) | ||||||
|
|
@@ -62,6 +67,14 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> { | |||||
| UnordItems(self.0.filter_map(f)) | ||||||
| } | ||||||
|
|
||||||
| #[inline] | ||||||
| pub fn chain( | ||||||
| self, | ||||||
| other: UnordItems<T, impl Iterator<Item = T>>, | ||||||
| ) -> UnordItems<T, impl Iterator<Item = T>> { | ||||||
| UnordItems(self.0.chain(other.0)) | ||||||
| } | ||||||
|
|
||||||
| #[inline] | ||||||
| pub fn max(self) -> Option<T> | ||||||
| where | ||||||
|
|
@@ -102,10 +115,10 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> { | |||||
| #[inline] | ||||||
| pub fn flat_map<U, F, O>(self, f: F) -> UnordItems<O, impl Iterator<Item = O>> | ||||||
| where | ||||||
| U: IntoIterator<Item = O>, | ||||||
| F: Fn(T) -> U, | ||||||
| U: Iterator<Item = O>, | ||||||
| F: Fn(T) -> UnordItems<O, U>, | ||||||
| { | ||||||
| UnordItems(self.0.flat_map(f)) | ||||||
| UnordItems(self.0.flat_map(move |x| f(x).0)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the motivation behind these changes, could you explain?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The follow-up commit uses flat_map in def_id_to_node_id. To flatten |
||||||
| } | ||||||
|
|
||||||
| pub fn collect<C: From<UnordItems<T, I>>>(self) -> C { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,6 +198,21 @@ pub struct ResolverGlobalCtxt { | |
| pub stripped_cfg_items: Vec<StrippedCfgItem>, | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct PerOwnerResolverData { | ||
| pub node_id_to_def_id: NodeMap<LocalDefId>, | ||
| /// The id of the owner | ||
| pub id: ast::NodeId, | ||
| /// The `DefId` of the owner, can't be found in `node_id_to_def_id`. | ||
| pub def_id: LocalDefId, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an optimization?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting it in the hash map was a "preserve more previous behaviour" thing. Just wanted to keep the diff small. I have a commit somewhere from last year where i added the DefId here directly. In fact, it should be an OwnerId, and then we can get rid of the one from the ast lowerer. But yes, for the purposes of this PR it's an optimization. |
||
| } | ||
|
|
||
| impl PerOwnerResolverData { | ||
| pub fn new(id: ast::NodeId, def_id: LocalDefId) -> Self { | ||
| Self { node_id_to_def_id: Default::default(), id, def_id } | ||
| } | ||
| } | ||
|
|
||
| /// Resolutions that should only be used for lowering. | ||
| /// This struct is meant to be consumed by lowering. | ||
| #[derive(Debug)] | ||
|
|
@@ -215,7 +230,7 @@ pub struct ResolverAstLowering<'tcx> { | |
|
|
||
| pub next_node_id: ast::NodeId, | ||
|
|
||
| pub node_id_to_def_id: NodeMap<LocalDefId>, | ||
| pub owners: NodeMap<PerOwnerResolverData>, | ||
|
|
||
| pub trait_map: NodeMap<&'tcx [hir::TraitCandidate<'tcx>]>, | ||
| /// List functions and methods for which lifetime elision was successful. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
More idiomatic naming for the constructor.
View changes since the review