Skip to content

save-analysis: add parents to imports #46540

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
Dec 16, 2017
Merged

Conversation

euclio
Copy link
Contributor

@euclio euclio commented Dec 6, 2017

This PR populates the parent field added to Import in rls-data 0.14.

I'm not quite sure if I handled nested imports' parents correctly: this is a new feature to me.

r? @nrc

cc rust-dev-tools/rls-analysis#123

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 6, 2017
@carols10cents
Copy link
Member

review ping for you @nrc !

Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this. Sorry it took a while for me to get to the review. The code has changed a bit since I worked on it, so I'm a bit confused about what is going on here. Questions inline.

@@ -1233,10 +1233,13 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
fn process_use_tree(&mut self,
use_tree: &'l ast::UseTree,
id: NodeId,
parent_item: &'l ast::Item,
root_item: &'l ast::Item,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment to the function here explaining what the root_item is please? Also perhaps what a use_tree is.

let access = access_from!(self.save_ctxt, root_item);
let parent = self.save_ctxt.tcx.hir.opt_local_def_id(id)
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
.map(::id_from_def_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on what the tcx regards as the parent for a nested import - is it the enclosing module? Or the outer import? It seems like Rustdoc always wants the former. Which I would imagine is either the root_item or the parent of the root_item. But perhaps id is the id of the root item? Or the tcx always gives the module?

Anyway, could you explain what you think is going on here please?

Copy link
Contributor Author

@euclio euclio Dec 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @pietroalbini, who might have some ideas on how to best handle this. My intuition was that we would want to store the parent imports as the parents, but I think that we would have to then store the nested parents as well. I'm not sure that rls-data has the right struct to represent this.

For now, it probably makes sense to just store the enclosing module as the parent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parent_def_id of a nested import should be the parent of the enclosing thing, regardless of the nesting level (no defs are added for the use item, and no extra parents are set while creating the use tree's defs).

I don't see why the parent imports should be stored, since each import already has the full path in it, but I'm not familiar with rls at all so I don't know how it uses those things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that logically rustdoc wants a list imports and the module they are imported into. I.e., the imports are flattened for the RLS.

The parent here is the module (or function or block, whatever) where the import is declared and is the context into which the imported name is added. It's not 'parent import'.

So, it sounds like we are doing the right thing here.

@@ -1399,6 +1404,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
span,
name: item.ident.to_string(),
value: String::new(),
parent: None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought you'd want the module with the extern crate in would be the parent here, why is that not the case?

@euclio
Copy link
Contributor Author

euclio commented Dec 15, 2017

@nrc Comments addressed.

@nrc
Copy link
Member

nrc commented Dec 15, 2017

Thanks!

@bors: r+

@bors
Copy link
Collaborator

bors commented Dec 15, 2017

📌 Commit f93c10e has been approved by nrc

@bors
Copy link
Collaborator

bors commented Dec 15, 2017

🔒 Merge conflict

@euclio
Copy link
Contributor Author

euclio commented Dec 15, 2017

Rebased and fixed the merge conflict in Cargo.lock.

@estebank
Copy link
Contributor

@bors r=nrc

@bors
Copy link
Collaborator

bors commented Dec 15, 2017

📌 Commit 6321349 has been approved by nrc

@bors
Copy link
Collaborator

bors commented Dec 15, 2017

🔒 Merge conflict

@euclio
Copy link
Contributor Author

euclio commented Dec 15, 2017

Rebased again, conflict in Cargo.lock.

@estebank
Copy link
Contributor

@bors r=nrc

@bors
Copy link
Collaborator

bors commented Dec 15, 2017

📌 Commit b82d280 has been approved by nrc

@bors
Copy link
Collaborator

bors commented Dec 15, 2017

⌛ Testing commit b82d280 with merge abab763...

bors added a commit that referenced this pull request Dec 15, 2017
save-analysis: add parents to imports

This PR populates the `parent` field added to `Import` in `rls-data` 0.14.

I'm not quite sure if I handled nested imports' parents correctly: this is a new feature to me.

r? @nrc

cc rust-dev-tools/rls-analysis#123
@bors
Copy link
Collaborator

bors commented Dec 16, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nrc
Pushing abab763 to master...

@bors bors merged commit b82d280 into rust-lang:master Dec 16, 2017
@euclio euclio deleted the import-parents branch February 7, 2019 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants