Skip to content

Changes required to help facilitate a refactoring tool #27493

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 7 commits into from
Aug 19, 2015

Conversation

GSam
Copy link
Contributor

@GSam GSam commented Aug 3, 2015

In order to test the validity of identifiers, exposing the name resolution module is necessary. Other changes mostly comprise of exposing modules publicly like parts of save-analysis, so they can be called appropriately.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (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. 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.

@GSam
Copy link
Contributor Author

GSam commented Aug 3, 2015

r? @nrc

@rust-highfive rust-highfive assigned nrc and unassigned huonw Aug 3, 2015
@nrc
Copy link
Member

nrc commented Aug 3, 2015

cc @rust-lang/compiler - some minor changes to resolve to make it usable from external tools. Anyone passionately object to this? Or can think of a better way to offer the facility?

let mut loader = self.file_loader.borrow_mut();
*loader = file_loader;
}

Copy link
Member

Choose a reason for hiding this comment

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

Glad to see someone made use of this before I got back to my IDE-like project!
Any specific reason why you need to swap the file loader after initialization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly because it seemed to be an issue trying to plumb down the file loader through the session in the compiler API, including modifying the entry point. The remaining fields for the codemap follow similar access, so it didn't seem too extreme.

Copy link
Member

Choose a reason for hiding this comment

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

Don't you need a custom diagnostics handler? In my custom rustc driver I had to create everything myself, so it didn't seem unreasonable to have to pass the file loader when creating the CodeMap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using a different entry point, but I see what you've done. I think I can remove this change, although I need to add some other changes to my code to do the same thing.

@eddyb
Copy link
Member

eddyb commented Aug 3, 2015

Not sure how I feel about a callback being employed, what's the intended usecase here?
It seems to me that the same functionality could be achieved with a custom Visitor passing only some nodes to the Resolver.

@GSam
Copy link
Contributor Author

GSam commented Aug 5, 2015

@eddyb
The problem is that a custom visitor isn't trivial to plug-in either, I sincerely tried. The idea is to call resolve_path at a certain point in the AST. Unfortunately, to do so seems to mean replicating the entire resolver. But even that is awkward, due to some other dependencies from the reduced graph module present as well. This approach seemed to be the least intrusive of what I tried.

@eddyb
Copy link
Member

eddyb commented Aug 5, 2015

@GSam Why would you have to replicate anything?
Maybe you would need to make certain methods public, but surely you can initialize the Resolver, compute the "reduced module graph", and call, e.g. visit_expr on an ExprPath?

EDIT: It seems I had forgotten about rib scopes. My bad, I'll ponder on this some more, but if you don't hear from me, feel free to proceed with this approach.

@nikomatsakis
Copy link
Contributor

So, this requirement seems well-served by the plan that @nrc and I have kicked about for separating resolve into one component which builds up "name tables", indicating what identifiers are imported into modules, and one component for resolving paths. That service would be readily exportable, since the rest of the compiler would have to use it as well.

I haven't looked at the changes in this particular patch -- but in general I don't have objections except that there is the usual caveat that everything in the compiler is hyper unstable and hence plugin authors should be prepared for us to tear it all up and throw it all out.

@@ -1110,6 +1140,11 @@ pub struct Resolver<'a, 'tcx:'a> {

used_imports: HashSet<(NodeId, Namespace)>,
used_crates: HashSet<CrateNum>,

// Callback function for intercepting walks
Copy link
Contributor

Choose a reason for hiding this comment

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

I think some more docs are in order. For example, what is the purpose of this boolean flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to allow the walker to fall out while preserving the ribs (to call resolve_path afterwards). I've added a few more comments now.

@eddyb
Copy link
Member

eddyb commented Aug 9, 2015

@nikomatsakis I believe it would be more of a "scope tree" due to blocks in functions being able to have their own imports (and then there's all the type parameters and whatnot, adding identifiers to ribs).

I really want something like that to replace the hacky "trait map" (which maps certain expressions to traits in scope those expressions might use) and eventually allow for cleaner error messages, printing types with the shortest form available in scope.

@nikomatsakis
Copy link
Contributor

@eddyb

I believe it would be more of a "scope tree" due to blocks in functions being able to have their own imports (and then there's all the type parameters and whatnot, adding identifiers to ribs).

Yes.

if callback(ast_map::Node::NodeLocal(&*local.pat), &mut self.resolved) {
return;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a macro for this repeated idiom?

@nrc
Copy link
Member

nrc commented Aug 9, 2015

lgtm, r+ with a macro

@GSam
Copy link
Contributor Author

GSam commented Aug 10, 2015

Not too familiar with macros, is the new patch sort of what you wanted?

@GSam
Copy link
Contributor Author

GSam commented Aug 16, 2015

@nrc

@nrc
Copy link
Member

nrc commented Aug 19, 2015

@GSam yep, looks good, thanks!

@bors: r+

@bors
Copy link
Collaborator

bors commented Aug 19, 2015

📌 Commit fc9ecae has been approved by nrc

@bors
Copy link
Collaborator

bors commented Aug 19, 2015

⌛ Testing commit fc9ecae with merge e47eb7c...

bors added a commit that referenced this pull request Aug 19, 2015
In order to test the validity of identifiers, exposing the name resolution module is necessary. Other changes mostly comprise of exposing modules publicly like parts of save-analysis, so they can be called appropriately.
@bors bors merged commit fc9ecae into rust-lang:master Aug 19, 2015
jseyfried added a commit to jseyfried/rust that referenced this pull request Apr 29, 2016
bors added a commit that referenced this pull request May 2, 2016
resolve: improve diagnostics and lay groundwork for resolving before ast->hir

This PR improves diagnostics in `resolve` and lays some groundwork for resolving before ast->hir.

More specifically,
 - It removes an API in `resolve` intended for external refactoring tools (see #27493) that appears not to be in active use. The API is incompatible with resolving before ast->hir, but could be rewritten in a more compatible and less intrusive way.
 - It improves the diagnostics for pattern bindings that conflict with `const`s.
 - It improves the diagnostics for modules used as expressions (fixes #33186).
 - It refactors away some uses of the hir map, which is unavavailable before ast->hir lowering.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants