-
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
refactor used_mut_nodes
result
#42384
Comments
I'll take this up! |
@cynicaldevil great! Please let me know how you're doing. I try to monitor GitHub notifications, but if you want a quick answer to a question, I find it works best if you ping me on IRC (if you have a persistent connection, especially) or else gitter. And of course there is also |
@cynicaldevil how goes it? |
Still working on it, I have a few questions to ask via IRC later :) |
@nikomatsakis I've changed the borrowck entry in |
@cynicaldevil hmm, that doesn't sound quite right. I would expect borrowck to return an immutable result, for one thing. Maybe post a link to your WIP branch and I can take a look? |
@cynicaldevil gah sorry, please do ping me on IRC or gitter in the future if I have overlooked a comment of yours! I left these notes, hope it is helpful. |
I've modified the commit acc. to comments: nikhilshagri@df15479, and I've started working on the lint code now. |
This updates the borrowck query to return a result, and this result is then used to incrementally check for unused mutable nodes given sets of all the used mutable nodes. Closes rust-lang#42384
rustc: Remove `used_mut_nodes` from `TyCtxt` This updates the borrowck query to return a result, and this result is then used to incrementally check for unused mutable nodes given sets of all the used mutable nodes. Closes #42384
At present, when you run borrowck, it also has the side-effect of modifying the
used_mut_nodes
set in thetcx
:This set is used later by the lint machinery: any
mut
declaration not in this set gets a warning.This is not good, because that field is not tracking by the incremental system. The other problem is just that this very setup -- one big set -- is sort of anti-incremental, since we can't readily track which contributions to the set came from where.
I think we should refactor this so that the borrowck query, instead of yielding a unit result, as it does now, returns a
NodeSet
containing the list of used mut nodes within the body. Note that whether amut
is used is purely determinde by the function it is in, so we don't need to combine results from multiple borrowck results.In other words, we would remove that field from the
tcx
and change the entry insrc/librustc/ty/maps.rs
for the borrowck from this:to something like this:
where
BorrowCheckResult
would be a new struct defined (presumably) insrc/librustc/ty.rs
, looking something like this:We would then modify the borrow checker code (
borrowck()
insrc/librustc_borrowck/borrowck/mod.rs
) so that instead of modifying thetcx
directly, it modifies a set defined per-fn, and constructs the struct when it is done.Finally, we would have to modify the lint code that currently reads from this set (found in
src/librustc_lint/unused.rs
). This is a bit annoying, since late's don't seem to naturally want to carry state, and we don't have quite the helpers you would need to make it stateless.One option -- adding state -- would be to add a field to the
UnusedMut
struct that tricks the innermost body (it's type might beVec<Rc<BorrowCheckResult>>
). Then we would want to modify theLateLintPass
impl, which implements a "visitor-like" pattern, where you get callbacks as we descend the HIR. We would want to overridecheck_body
, so that each time we enter a fn body (etc), we can load up the borrowck results for that fn (we can keep them in a stack). Something like this:then we can check whether a given
mut
binding is "used" by invokingself.borrowck_tables.last().unwrap().contains(...)
(the vector ought to be non-empty, I think, though that could be wrong for cases like function parameters).The text was updated successfully, but these errors were encountered: