-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Some comments and documentation for name resolution crate #48693
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Sorry, missed this. Will review. |
src/librustc_resolve/lib.rs
Outdated
@@ -662,6 +670,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder { | |||
} | |||
} | |||
|
|||
// This thing walks the whole crate in DFS manner, visiting each item, resolving names as it goes. |
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.
You can use doc comments. They'll show up on the impl in the docs.
src/librustc_resolve/lib.rs
Outdated
/// Different [rib kinds](enum.RibKind) are transparent for different names. | ||
/// | ||
/// The resolution keeps a separate stack of ribs as it traverses the AST for each namespace. When | ||
/// resolving, the name is looked from inside out. |
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.
nit: looked up
src/librustc_resolve/lib.rs
Outdated
@@ -1122,7 +1152,8 @@ impl<'a> NameBinding<'a> { | |||
resolver.get_macro(self.def_ignoring_ambiguity()) | |||
} | |||
|
|||
// We sometimes need to treat variants as `pub` for backwards compatibility | |||
// We sometimes need to treat variants as `pub` for backwards compatibility (eg. in enum | |||
// variants) |
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 change doesn't seem to clarify more. variants
are already mentioned
src/librustc_resolve/lib.rs
Outdated
} | ||
} | ||
|
||
// This is the interface through which the rest of the compiler asks about name resolution after | ||
// the whole AST has been indexed. |
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.
again, this can be a doc comment
Good to know I can put a comment on trait implementation, I always thought it shows the description of the trait. Should I squash the fixup once it looks good? |
Yes, please squash the fixup. Lgtm now |
src/librustc_resolve/lib.rs
Outdated
@@ -909,7 +935,11 @@ enum PathResult<'a> { | |||
} | |||
|
|||
enum ModuleKind { | |||
/// Inline `mod something { ... }`. |
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.
ModuleKind::Block
is an anonymous module, i.e. a block:
fn main() {
fn f() {} // (1)
{
f(); // This resolves to (2)
fn f() {} // (2)
}
}
Whether a module is inline or not has no effect on name resolution.
src/librustc_resolve/lib.rs
Outdated
Block(NodeId), | ||
/// Module from another file. | ||
/// | ||
/// Also called a normal module in the following code. |
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.
A normal module is a mod
module (inline or not). ModuleKind::Def
could also be a trait or an enum.
@@ -1359,6 +1394,7 @@ pub struct Resolver<'a> { | |||
injected_crate: Option<Module<'a>>, | |||
} | |||
|
|||
/// Nothing really interesting here, it just provides memory for the rest of the crate. |
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.
nit: memory -> arenas
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 think it is obvious it contains arenas, my point was that these arenas are there to allocate memory. Should I still change it?
src/librustc_resolve/lib.rs
Outdated
} | ||
} | ||
|
||
/// This is the interface through which the rest of the compiler asks about name resolution after | ||
/// the whole AST has been indexed. |
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::lowering::Resolver
is used to resolve HIR paths generated due to desugaring during AST->HIR lowering, and to look up the resolution AST paths during lowering (get_resolution
). After lowering, resolution information is embedded in the HIR; this is what the rest of the compiler uses. The Resolver
is destroyed shortly after lowering.
@@ -864,6 +875,16 @@ enum RibKind<'a> { | |||
} | |||
|
|||
/// One local scope. | |||
/// | |||
/// A rib represents a scope names can live in. Note that these appear in many places, not just | |||
/// around braces. At any place where the list of accessible names (of the given namespace) |
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's probably better to say it more explicitly - the list of accessible names changes or new restrictions on name accessibility are added.
r=me after addressing the comments |
Ping from triage @vorner ! You have pending feedback to address; will you be able to address it soon? |
I know, I keep track of it. It seems the comments will need some more research on my side, so I postponed it. I hope to find the time during this weekend. |
OK, added one more fixup commit. |
@bors r+ rollup |
📌 Commit 433a03e has been approved by |
…chenkov Some comments and documentation for name resolution crate Hello I'm trying to get a grasp of how the name resolution crate works, as part of helping with rust-lang/rustc-dev-guide#16. Not that I'd be succeeding much, but as I was reading the code, I started to put some notes into it, to help me understand. I guess I didn't get very far yet, but I'd like to share what I have, in case it might be useful for someone else. I hope these are correct (even if incomplete), but I'll be glad for a fast check in case I put something misleading there.
…chenkov Some comments and documentation for name resolution crate Hello I'm trying to get a grasp of how the name resolution crate works, as part of helping with rust-lang/rustc-dev-guide#16. Not that I'd be succeeding much, but as I was reading the code, I started to put some notes into it, to help me understand. I guess I didn't get very far yet, but I'd like to share what I have, in case it might be useful for someone else. I hope these are correct (even if incomplete), but I'll be glad for a fast check in case I put something misleading there.
Hello
I'm trying to get a grasp of how the name resolution crate works, as part of helping with rust-lang/rustc-dev-guide#16. Not that I'd be succeeding much, but as I was reading the code, I started to put some notes into it, to help me understand.
I guess I didn't get very far yet, but I'd like to share what I have, in case it might be useful for someone else. I hope these are correct (even if incomplete), but I'll be glad for a fast check in case I put something misleading there.