-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 def_span #41593
query for def_span #41593
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (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. |
|
☔ The latest upstream changes (presumably #41598) made this pull request unmergeable. Please resolve the merge conflicts. |
@eddyb, I am not sure why this failed. I replaced the function as you suggested and included a provider. I am guessing it has to do with how I'm handling the |
src/librustc/ty/maps.rs
Outdated
@@ -547,7 +553,8 @@ define_maps! { <'tcx> | |||
pub def_symbol_name: SymbolName(DefId) -> ty::SymbolName, | |||
pub symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName, | |||
|
|||
pub describe_def: meta_data_node(DefId) -> Option<Def> | |||
pub describe_def: meta_data_node(DefId) -> Option<Def>, | |||
pub def_span: meta_data_node(DefId) -> Span |
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.
Wait, what is meta_data_node
? First off, it doesn't need a function, it could just be MetaData
.
Secondly, if you have a local crate implementation, you kind of need a node that's not MetaData
.
But if @nikomatsakis doesn't think this impacts incremental this can be left as-is for 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 was actually added as part of my last PR. I will remove it form both instances and replace it with just MetaData
.
src/librustc/ty/mod.rs
Outdated
match tcx.hir.span_if_local(def_id) { | ||
Some(span) => span, | ||
None => { | ||
let node_id = tcx.sess.cstore.item_body(tcx, def_id).id().node_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.
I'm surprised you found item_body
- that's really only meant to be used by const evaluation.
You should really be panicking if the DefId
isn't local (i.e. you can .unwrap()
the result of span_if_local
instead of handling the None
case) - because the line you added in src/librustc_metadata/cstore_impl.rs
is what actually handles that case.
Aaaaah, the stack overflow is because by default the span used in the "query cycle" printout comes from |
I've updated your suggestions, but I will need to spend some more time on the stack overflow error. |
☔ The latest upstream changes (presumably #41368) made this pull request unmergeable. Please resolve the merge conflicts. |
@eddyb I believe this addresses all your requests and the stack overflow issue. |
src/librustc/ty/maps.rs
Outdated
@@ -359,8 +365,8 @@ macro_rules! define_maps { | |||
} | |||
|
|||
// FIXME(eddyb) Get more valid Span's on queries. | |||
if span == DUMMY_SP { | |||
span = key.default_span(tcx); | |||
if span == DUMMY_SP && stringify!($name) != "def_span" { |
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 guess this is not too bad of a workaround - could you leave a comment above as to why this is done?
src/librustc/ty/maps.rs
Outdated
@@ -568,7 +574,9 @@ define_maps! { <'tcx> | |||
[] def_symbol_name: SymbolName(DefId) -> ty::SymbolName, | |||
[] symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName, | |||
|
|||
[] describe_def: meta_data_node(DefId) -> Option<Def> | |||
|
|||
[] describe_def: MetaData(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.
Unnecessary extra empty line.
You're getting failures because you're using |
@eddyb this should resolve everything. Thanks for the |
src/librustc/dep_graph/dep_node.rs
Outdated
@@ -148,6 +148,10 @@ pub enum DepNode<D: Clone + Debug> { | |||
// For proj. cache, we just keep a list of all def-ids, since it is | |||
// not a hotspot. | |||
ProjectionCache { def_ids: Vec<D> }, | |||
|
|||
// Depnodes for MetaData |
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.
Heh, you can leave the comment off - the reason we need these is because MetaData
can't be used, as it's reserved for cross-crate queries, e.g. ItemSignature(def_id)
will eventually depend on either Hir(def_id)
iff def_id.is_local()
or MetaData(def_id)
otherwise.
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.
Ah that makes sense the title of the issue was deceiving. I assumed all of these were just about crate metadata.
src/librustc/ty/maps.rs
Outdated
} | ||
|
||
fn def_span(def_id: DefId) -> DepNode<DefId> { | ||
DepNode::DefSpan(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.
These aren't needed, because they're just a DepNode
variant - the explicit functions are in cases where you can't just use DepNode::VariantName(def_id)
.
@bors r+ |
📌 Commit d3b7af0 has been approved by |
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
☀️ Test successful - status-appveyor, status-travis |
Resolves
fn def_span(&self, sess: &Session, def: DefId) -> Span;
of #41417.I had to change the query name to
def_sess_span
sincety::TyCtxt
already has a methoddef_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