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 lint handling to be more "eager" #42511
Comments
nikomatsakis
added
A-incr-comp
E-mentor
T-compiler
labels
Jun 7, 2017
nikomatsakis
added
E-hard
E-medium
and removed
E-medium
labels
Jun 7, 2017
This comment has been minimized.
This comment has been minimized.
|
Another problem with the existing deferred lints is I don't think there is a way to make the messages rich (complex diagnostics) while emitting the diagnostics on the spot would make that trivial. |
This comment has been minimized.
This comment has been minimized.
|
@eddyb I actually added support for rich lints, but yes, it was a pain, and it shouldn't be. |
This comment has been minimized.
This comment has been minimized.
|
Cc @Manishearth , @llogiq , @mcarton We have a few lints which use a custom visitor because they need additional info. With these lints we've had problems with the attributes not working on the actual item which is linted. The way I understood this new system, such a check could become way simpler. |
This was referenced Jun 8, 2017
sanxiyn
added
the
A-lint
label
Jun 19, 2017
sanxiyn
referenced this issue
Jun 21, 2017
Closed
Skip `LintPass`es whose lints are all `Allow` #15161
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis - I'd like to have a go at this if you're still willing to mentor it. I've started familiarising myself with the existing code and I am preparing to have a go at the "step one" you suggest. |
This comment has been minimized.
This comment has been minimized.
|
I've added a function to the HIR map that naively calculates a If I understand the code correctly, there are four phases where we try to lint about things:
Which would mean the plan in the issue description expands to:
Is that still what you had in mind @nikomatsakis? |
This comment has been minimized.
This comment has been minimized.
|
@mjkillough That seems fine, expect that walking up the HIR every time can be expensive - or did you mean that HIR lowering records the information for some nodes (items?) and the HIR maps walks up for anything in between that and the node it was queried about? |
This comment has been minimized.
This comment has been minimized.
|
@eddyb - Yeah, once we calculate the levels at each node during HIR lowering, we'd just walk up from the current node to whichever node had the calculated lint levels. As I haven't touched the HIR lowering part yet, I'm currently doing the easier thing and walking all the way up to the crate each time. I don't think it'll just be items that we store the calculated lint levels on. Based on what the visitors in I also haven't put much thought into how we'd store the calculated lint levels on the HIR nodes yet - I'd planned to do that once I had something working. |
This comment has been minimized.
This comment has been minimized.
|
@mjkillough I'd do only |
This comment has been minimized.
This comment has been minimized.
|
@eddyb - OK, that makes sense. I'll have a go at doing that. Thanks! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@mjkillough any progress on this issue? I'm excited to see you were poking at it! |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis - Ah, sorry for going quiet on this! I did start making progress, but ran out of free time. I managed to get a protoype working, doing roughly what I described in my previous comment. It wasn't doing any smart caching - just walking up the HIR for every node to calculate lint levels. (It was tricky to see whether my changes broke anything, as they caused around 100 failures in the compile-fail tests because a bunch of lints are now more eager). My next steps were going to be to rejig some of the structures in I should be able to start looking at this again from the middle of next week. If someone needs to start making progress with this in the meantime, just let me know and I can push what I have. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton is keen to pick this up, so I've pushed what I had here and wrote my planned next-steps in the commit message: master...mjkillough:eager_linting_prototype It may not make sense to base changes off that branch, as it is quite rough around the edges. It'll at least give you an indication of the direction I was heading in. :) |
Mark-Simulacrum
added
the
C-cleanup
label
Jul 27, 2017
alexcrichton
referenced this issue
Jul 28, 2017
Merged
rustc: Rearchitect lints to be emitted more eagerly #43522
This comment has been minimized.
This comment has been minimized.
|
I've opened a PR for this at #43522 |
nikomatsakis commentedJun 7, 2017
Lint handling at present works like this:
NodeIdthat identifies the AST/HIR node that the lint is attached to, along with the lint name, message, etc.This is not a very good setup. Among other things:
#[allow]. Wasteful.@eddyb proposed an alternative architecture that I think is better.
The best way to store this lint table is not 100% clear. Something sparse seems obviously like a good idea, since most nodes in the HIR do not have lint-related attributes on them (and hence just inherit the settings from their parent). I think maybe having each item store a link to the "current" settings for each lint makes sense; this can be easily shared between items. Then, within an item, if we need to compute the settings for some particular node, we would walk up the parents in the HIR map, looking for lint-related attributes and -- when we reach the item -- just using the settings stored on the item itself.
Alternatively, we could just cache nothing and compute everything this way, at least to start. If more caching is desired, maybe have passes keep a local cache that would then be populated within the things within a particular item.
I'm available to mentor this. It is a bit of a "design needed" sort of job, so I'm not sure what the immediate instructions would be. The first step is obviously familiarizing yourself with the current setup. After that, I would probably try to make a commit that adds a method to the HIR map that will compute the innermost applicable lint setting for a particular node (just by walking up the parents). We could then use this and remove all the existing lint code for tracking. That should work, but be slow (O(n^2) lookups). Presumably we can then adopt some sort of caching strategy.
@eddyb also mentioned that for bonus points, we should probably "decode" attributes during HIR lowering more generally, so that we are not walking the general attribute data structures, but rather something specific to the stuff the compiler cares about.