Skip to content
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

query for describe_def #41534

Merged
merged 1 commit into from
Apr 28, 2017
Merged

query for describe_def #41534

merged 1 commit into from
Apr 28, 2017

Conversation

hackeryarn
Copy link
Contributor

Resolves fn describe_def(&self, def: DefId) -> Option<Def>; of #41417.

r? @nikomatsakis I would greatly appreciate a review. I hope I covered everything described in the pr.

@rust-highfive
Copy link
Collaborator

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

@hackeryarn
Copy link
Contributor Author

I apologize, looks like my check didn't fully finish before the push. There was a runtime error at the end of compilation. I am working to try and resolve it now.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

This looks good, modulo the question of naming. I'd bet that @eddyb has an opinion on that. :)

@@ -432,7 +432,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// (See issue #38412)
fn skip_stability_check_due_to_privacy(self, mut def_id: DefId) -> bool {
// Check if `def_id` is a trait method.
match self.sess.cstore.describe_def(def_id) {
match ty::queries::describe_def::get(self, DUMMY_SP, def_id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I guess that since @eddyb's #41504 has not landed yet, this is still the correct form. Perhaps though we want to name the query def_of, in anticipation of that PR's new conventions? (And this would then become self.def_of(def_id).)

@hackeryarn
Copy link
Contributor Author

hackeryarn commented Apr 25, 2017

@nikomatsakis I am actually a bit stuck. I would greatly appreciate any assistance here. I seem to be getting a fairly cryptic error which I am not sure how to fix. All the basic check pass fine, but then it fails further down the compilation path.

Compiling std_unicode v0.0.0 (file:///Users/achernyak/dev/rust/src/libstd_unicode)
error: internal compiler error: src/librustc/ty/maps.rs:388: tcx.maps.describe_def(DefId { krate: CrateNum(1), node: DefIndex(25) => core/6436b
dfbb8ae081f8c267683c0924cd8::isize[0] }) unsupported by its crate

Similar error in a few other places.

error: Could not compile `alloc`.
Build failed, waiting for other jobs to finish...
error: internal compiler error: src/librustc/ty/maps.rs:388: tcx.maps.describe_def(DefId { krate: CrateNum(1), node: DefIndex(3068) => core/643
6bdfbb8ae081f8c267683c0924cd8::fmt[0] }) unsupported by its crate

@@ -120,11 +120,6 @@ impl CrateStore for cstore::CStore {
self.get_crate_data(krate)
}

fn describe_def(&self, def: DefId) -> Option<Def> {
Copy link
Member

Choose a reason for hiding this comment

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

You didn't move this to the macro invocation at the top of this file so there's no way for it to actually do anything right now.

@eddyb
Copy link
Member

eddyb commented Apr 25, 2017

Also, it'd be nice if the current crate supported the query, but this PR doesn't have to do it.

@nikomatsakis
Copy link
Contributor

@achernyak

I am actually a bit stuck. I would greatly appreciate any assistance here. I seem to be getting a fairly cryptic error which I am not sure how to fix. All the basic check pass fine, but then it fails further down the compilation path.

As @eddyb's comment indicated, you have to add the provider code into the provide! macro located a few lines above. Something like this should suffice:

describe_def => { cdata.get_def(def_id.index) }

@hackeryarn
Copy link
Contributor Author

@eddyb I think this would be a great place for the current crate to support the query. This is part of a PR that would result in a lot of queries being added. I think it would be nice to not backtrack on all of them to add support.

If we go that direction, I might need a little bit of assistance on how to support the query since I am new to the code base.

@eddyb
Copy link
Member

eddyb commented Apr 25, 2017

@achernyak You could take at look in src/librustc/ty/mod.rs to see the providers there.
The only tricky part is turning a hir::map::Node into a Def, which we don't do anywhere directly (librustc_resolve creates Def from the AST but it's nothing like this).

@hackeryarn
Copy link
Contributor Author

This should have fixed all the issue on the basic implementation I will have to dig into the providers tomorrow.

@@ -68,7 +68,7 @@ pub fn lookup_const_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
_ => Some((def_id, substs))
}
} else {
match tcx.sess.cstore.describe_def(def_id) {
match ty::queries::describe_def::get(tcx, DUMMY_SP, def_id) {
Copy link
Contributor Author

@hackeryarn hackeryarn Apr 26, 2017

Choose a reason for hiding this comment

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

@eddyb this might be a dumb question but, when implementing a provider in src/librustc/ty/mod.rs, why don't we just call the query in this manner and passing it tcx?

It seems to provide the same type and perform a similar function.

Copy link
Member

Choose a reason for hiding this comment

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

A provider provides... the query implementation 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha everything makes a lot more sense now 😊

Copy link
Member

Choose a reason for hiding this comment

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

@achernyak Hmm, any chance you can squash all of those commits into one and rebase on top of master? At this point I believe your branch doesn't conflict in the diff, but #41504 changed how queries are involved (i.e. it'd be just tcx.describe_def(def_id) now, here and in the two other places).

fn describe_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
-> Option<Def> {
ty::queries::describe_def::get(tcx, DUMMY_SP, 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.

This is just an infinite loop though. You're providing the describe_def query for the local crate as querying describe_def again with the same key.

@aidanhs aidanhs added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 26, 2017
let id = tcx.hir.as_local_node_id(def_id).unwrap();
let item = tcx.hir.expect_item(id);
match item.node{
hir::ItemTrait(..) => Some(Def::Trait(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.

This appears to be correct, although expect_item above is too restrictive and there's a dozen or so cases left to handle, of course.

However, I'd like to merge the original PR, without this change, as we're not using this right now.

let item = tcx.hir.expect_item(id);
match item.node{
hir::ItemTrait(..) => Some(Def::Trait(def_id)),
_ => None
Copy link
Contributor Author

@hackeryarn hackeryarn Apr 27, 2017

Choose a reason for hiding this comment

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

@eddyb I hope this is the implementation you had in mind. It's the only way I could see of turning the hir::map::Node into a Def.

I also wasn't sure what would be the appropriate Def type to use for an hir::ItemImpl therefore I left it as None, but I would be happy to change it to any type you would suggest.

Copy link
Member

Choose a reason for hiding this comment

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

There are way more Def variants than that ;). Anyway, see #41534 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right that was only the traits node I was looking at. There has to be a better way to handle this matching than to hand roll all these matchers... I will just have to leave that to someone more familiar than me.

@hackeryarn
Copy link
Contributor Author

Everything has been squashed and query calls updated.

@eddyb @nikomatsakis Thank you both so much for all the help on this PR. I learned a lot and look forward making my way through the other conversions.

@@ -432,7 +432,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// (See issue #38412)
fn skip_stability_check_due_to_privacy(self, mut def_id: DefId) -> bool {
// Check if `def_id` is a trait method.
match self.sess.cstore.describe_def(def_id) {
match self.describe_def::get(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.

You can just remove the ::get.

@eddyb
Copy link
Member

eddyb commented Apr 27, 2017

@bors r+ Thanks!

@bors
Copy link
Contributor

bors commented Apr 27, 2017

📌 Commit 73c25b2 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Apr 27, 2017

⌛ Testing commit 73c25b2 with merge d23ef77...

@bors
Copy link
Contributor

bors commented Apr 27, 2017

💔 Test failed - status-appveyor

@aidanhs
Copy link
Member

aidanhs commented Apr 27, 2017

@bors retry

Appveyor network issues https://appveyor.statuspage.io/incidents/06gzq846jl9x

arielb1 pushed a commit to arielb1/rust that referenced this pull request Apr 27, 2017
query for describe_def

Resolves `fn describe_def(&self, def: DefId) -> Option<Def>;` of rust-lang#41417.

r? @nikomatsakis I would greatly appreciate a review. I hope I covered everything described in the pr.
@bors
Copy link
Contributor

bors commented Apr 27, 2017

☔ The latest upstream changes (presumably #41507) made this pull request unmergeable. Please resolve the merge conflicts.

@eddyb
Copy link
Member

eddyb commented Apr 27, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Apr 27, 2017

📌 Commit e24003f has been approved by eddyb

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 27, 2017
query for describe_def

Resolves `fn describe_def(&self, def: DefId) -> Option<Def>;` of rust-lang#41417.

r? @nikomatsakis I would greatly appreciate a review. I hope I covered everything described in the pr.
@hackeryarn hackeryarn mentioned this pull request Apr 28, 2017
@bors
Copy link
Contributor

bors commented Apr 28, 2017

⌛ Testing commit e24003f with merge 1229b46...

@frewsxcv
Copy link
Member

@bors retry - prioritizing rollup

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 28, 2017
query for describe_def

Resolves `fn describe_def(&self, def: DefId) -> Option<Def>;` of rust-lang#41417.

r? @nikomatsakis I would greatly appreciate a review. I hope I covered everything described in the pr.
bors added a commit that referenced this pull request Apr 28, 2017
Rollup of 4 pull requests

- Successful merges: #41534, #41546, #41571, #41583
- Failed merges:
@bors bors merged commit e24003f into rust-lang:master Apr 28, 2017
bors added a commit that referenced this pull request Apr 30, 2017
query for def_span

Resolves `fn def_span(&self, sess: &Session, def: DefId) -> Span;` of  #41417.

I had to change the query name to `def_sess_span` since `ty::TyCtxt` already has a method `def_span` implemented.

This also will probably have merge conflicts with  #41534 but I will resolves those once it's merged and wanted to start a code review on this one now.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants