Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uprefactor `used_mut_nodes` result #42384
Comments
nikomatsakis
added
A-incr-comp
T-compiler
E-medium
E-mentor
labels
Jun 2, 2017
This comment has been minimized.
This comment has been minimized.
|
I'll take this up! |
This comment has been minimized.
This comment has been minimized.
|
@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 |
This comment has been minimized.
This comment has been minimized.
|
@cynicaldevil how goes it? |
This comment has been minimized.
This comment has been minimized.
|
Still working on it, I have a few questions to ask via IRC later :) |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis I've changed the borrowck entry in |
This comment has been minimized.
This comment has been minimized.
|
@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? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@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. |
Mark-Simulacrum
added
C-bug
C-cleanup
and removed
C-bug
labels
Jul 27, 2017
This comment has been minimized.
This comment has been minimized.
|
I've modified the commit acc. to comments: cynicaldevil@df15479, and I've started working on the lint code now. |
nikomatsakis commentedJun 2, 2017
At present, when you run borrowck, it also has the side-effect of modifying the
used_mut_nodesset in thetcx:This set is used later by the lint machinery: any
mutdeclaration 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
NodeSetcontaining the list of used mut nodes within the body. Note that whether amutis 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
tcxand change the entry insrc/librustc/ty/maps.rsfor the borrowck from this:to something like this:
where
BorrowCheckResultwould 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 thetcxdirectly, 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
UnusedMutstruct that tricks the innermost body (it's type might beVec<Rc<BorrowCheckResult>>). Then we would want to modify theLateLintPassimpl, 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
mutbinding 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).