Commit 360d473
authored
Make CheckUnused not slow. (#20321)
It doesn't mean that it's *fast* yet, but it is already a significant
step in that direction. In particular, this goes in the direction of
addressing #19671.
The most important commit is "Simplify the logic for checking unused
imports.", whose commit message follows:
Instead of dealing with entire `tpd.Import`s at the end of the scope, we
eagerly flatten them into individual `ImportSelector`s. We store them
along with some data, including a mutable flag for whether a selector
has been used.
This allows to dramatically simplify `isInImport`, as well as more
aggressively cache the resolution of selectors. We also get rid of the
`IdentityHashMap`.
The algorithm is still `O(n*m)` where n is the number of imports in a
scope, and m the number of references found in that scope. It is not
entirely clear to me whether the previous logic was already `O(n*m)` or
worse (it may have included an additional `p` factor for the number of
possible selections from a given qualifier).
Regardless, it is already quite a bit faster than before, thanks to
smaller constant factors.File tree
2 files changed
+209
-160
lines changed- compiler/src/dotty/tools/dotc/transform
- tests/warn
2 files changed
+209
-160
lines changed
0 commit comments