-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
query for describe_def #41534
Conversation
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. |
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. |
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 looks good, modulo the question of naming. I'd bet that @eddyb has an opinion on that. :)
src/librustc/middle/stability.rs
Outdated
@@ -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) { |
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.
@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.
Similar error in a few other places.
|
@@ -120,11 +120,6 @@ impl CrateStore for cstore::CStore { | |||
self.get_crate_data(krate) | |||
} | |||
|
|||
fn describe_def(&self, def: DefId) -> Option<Def> { |
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 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.
Also, it'd be nice if the current crate supported the query, but this PR doesn't have to do it. |
As @eddyb's comment indicated, you have to add the provider code into the describe_def => { cdata.get_def(def_id.index) } |
@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. |
@achernyak You could take at look in |
This should have fixed all the issue on the basic implementation I will have to dig into the providers tomorrow. |
src/librustc_const_eval/eval.rs
Outdated
@@ -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) { |
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.
@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.
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 provider provides... the query implementation 😆
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.
haha everything makes a lot more sense now 😊
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.
@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).
src/librustc/ty/mod.rs
Outdated
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) |
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 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.
src/librustc/ty/mod.rs
Outdated
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)), |
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 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.
src/librustc/ty/mod.rs
Outdated
let item = tcx.hir.expect_item(id); | ||
match item.node{ | ||
hir::ItemTrait(..) => Some(Def::Trait(def_id)), | ||
_ => None |
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.
@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.
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.
There are way more Def
variants than that ;). Anyway, see #41534 (comment)
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 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.
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. |
src/librustc/middle/stability.rs
Outdated
@@ -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) { |
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 just remove the ::get
.
@bors r+ Thanks! |
📌 Commit 73c25b2 has been approved by |
⌛ Testing commit 73c25b2 with merge d23ef77... |
💔 Test failed - status-appveyor |
@bors retry Appveyor network issues https://appveyor.statuspage.io/incidents/06gzq846jl9x |
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.
☔ The latest upstream changes (presumably #41507) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors r+ |
📌 Commit e24003f has been approved by |
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.
⌛ Testing commit e24003f with merge 1229b46... |
@bors retry - prioritizing rollup |
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.
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
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.