-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
make *most* maps private #41368
make *most* maps private #41368
Conversation
src/librustc/ty/maps.rs
Outdated
span: Span, | ||
cycle: RefMut<'a, [(Span, Query<'tcx>)]>, | ||
cycle: Vec<(Span, Query<'tcx>)>, |
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.
Why? This is going to clone all over the place now in early coherence and whatnot.
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 wasn't sure about this change. Coherence generates (and recovers from) cycles regularly?
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.
The reason for it was that, when we call report_cycle
, we hold the borrow-mut lock, which then messes up my attempts to use try_get
from within the pretty-printing code (it fails to acquire the RefCell
lock).
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.
(Maybe we can downgrade to a read-only borrow or something...?)
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.
We don't have downgrading, but queries need mutable anyway so you wouldn't get anything.
Why do you want to query from the printing code? You could clone the stack and drop the RefMut
when reporting a cycle error if you want, that's fine (since reporting itself costs anyway).
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.
Why do you want to query from the printing code?
I don't necessarily want that. But the printing code currently pokes at the query's internal maps to find out if trait_ref
and ty
are filled out for particular def-ids (or something like that). I guess I could add an accessor for reading the current state of the query that you are really, really not supposed to use (because it lets you observe things you shouldn't be able to observe), just for use in printing things out -- but really it seems like it might make sense for printing things out to run bits of type-check that may not have run, if it is needed to pretty-print better (i.e., if we were in a totally on-demand scenario, and some error arose, it seems plausible it might need to pretty print something that hasn't yet been "collected"--- well, maybe that would never happen in practice).
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 if I added such a method I could use it for typeck_tables
too (in save analysis).
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.
Ohhh, you were talking about item_path_str
, now I know exactly what you're talking about.
Yeah just do the stack.to_vec(); drop(stack)
thing when reporting.
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.
Still unaddressed.
src/librustc/ty/mod.rs
Outdated
.expect("not an associated item") | ||
} | ||
|
||
pub fn opt_associated_item(self, def_id: DefId) -> Option<AssociatedItem> { |
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.
Can't we avoid introducing queries like these? i.e. actually check what kind of DefId
you have before calling associated_item
.
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.
Yeah, probably, is there a non-tedious way to do this that works across crates?
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.
The method would probably stay the same, I suppose, but it would be wrapped in code like "check type of def_id
then call associated_item()
".
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 check the HIR map (TraitItem
and ImplItem
) for local and describe_def
for external.
} | ||
None => f(self), | ||
} | ||
let tables = ty::queries::typeck_tables::get(self.tcx, DUMMY_SP, item_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 actually @nrc's attempt at error recovery, heh.
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 was wondering about that
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.
Do you think this will work?
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.
Oh, since it's on-demand... let me find where this was added maybe @nrc provided an example.
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.
lolsob there's no example in #39285
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.
Now that I think more about it... it will probably work anyway.
☔ The latest upstream changes (presumably #41373) made this pull request unmergeable. Please resolve the merge conflicts. |
0f3c43e
to
854a5dd
Compare
@eddyb I think I addressed all of your requests; I also rebased atop your branch. |
e2d55be
to
41ad2d2
Compare
@bors r+ |
📌 Commit 41ad2d2 has been approved by |
@bors r=eddyb |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit 41ad2d2 has been approved by |
☔ The latest upstream changes (presumably #41332) made this pull request unmergeable. Please resolve the merge conflicts. |
41ad2d2
to
054642e
Compare
@bors r=eddyb |
📌 Commit 054642e has been approved by |
…-map, r=eddyb make *most* maps private Currently we access the `DepTrackingMap` fields directly rather than using the query accessors. This seems bad. This branch removes several such uses, but not all, and extends the macro so that queries can hide their maps (so we can prevent regressions). The extension to the macro is kind of ugly :/ but couldn't find a simple way to do it otherwise (I guess I could use a nested macro...). Anyway I figure it's only temporary. r? @eddyb
⌛ Testing commit 054642e with merge 569d203... |
💔 Test failed - status-appveyor |
@bors retry Appveyor network issues https://appveyor.statuspage.io/incidents/06gzq846jl9x |
⌛ Testing commit 054642e with merge 86f699c... |
💔 Test failed - status-travis |
…-map, r=eddyb make *most* maps private Currently we access the `DepTrackingMap` fields directly rather than using the query accessors. This seems bad. This branch removes several such uses, but not all, and extends the macro so that queries can hide their maps (so we can prevent regressions). The extension to the macro is kind of ugly :/ but couldn't find a simple way to do it otherwise (I guess I could use a nested macro...). Anyway I figure it's only temporary. r? @eddyb
☔ The latest upstream changes (presumably #41598) made this pull request unmergeable. Please resolve the merge conflicts. |
Didn't get around to removing all public access.
This requires copying out the cycle error to avoid a cyclic borrow. Is this a problem? Are there paths where we expect cycles to arise and not result in errors? (In such cases, we could add a faster way to test for cycle.)
949f214
to
cb618e3
Compare
And use this in save-analysis, which used to read the map directly. This is an attempt to sidestep the failure occuring on homu that I cannot reproduce.
cb618e3
to
d7d3f19
Compare
@bors r=eddyb |
📌 Commit d7d3f19 has been approved by |
⌛ Testing commit d7d3f19 with merge 543f365... |
💔 Test failed - status-appveyor |
@bors rollup- |
make *most* maps private Currently we access the `DepTrackingMap` fields directly rather than using the query accessors. This seems bad. This branch removes several such uses, but not all, and extends the macro so that queries can hide their maps (so we can prevent regressions). The extension to the macro is kind of ugly :/ but couldn't find a simple way to do it otherwise (I guess I could use a nested macro...). Anyway I figure it's only temporary. r? @eddyb
☀️ Test successful - status-appveyor, status-travis |
Currently we access the
DepTrackingMap
fields directly rather than using the query accessors. This seems bad. This branch removes several such uses, but not all, and extends the macro so that queries can hide their maps (so we can prevent regressions). The extension to the macro is kind of ugly :/ but couldn't find a simple way to do it otherwise (I guess I could use a nested macro...). Anyway I figure it's only temporary.r? @eddyb