-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Get linting information from Typer instead of recreating its logic #18400
Conversation
2ef4c6f
to
b4b5b9d
Compare
b4b5b9d
to
e25d0fd
Compare
I am very dubious about complexifying Typer for non-essential things like warnings. Complexity in all of these dimensions:
Is there really no other way? In my mind, even a ~5 times complexity increase elsewhere is a fair tradeoff against an increase of complexity in Typer, simply because in Typer we are already close to the thresholds of what can be understood, and what is a reasonable runtime complexity. This is because if the complexity is elsewhere people can be trained to deal with it. But if it is in Typer it becomes a bottleneck for the few people who are confident in changing Typer. I noted that is PR involves additional allocations in findRefs, which has previously been carefully optimized to avoid all such allocations. |
To get a clear picture, let's list the benefits that we get from extracting information from Typer:
This implementation will be changed to one that uses an event logging pattern to avoid increasing the complexity of the typer. This way, Typer's code may become more readable in some places. |
The time to choose "let typer tell me" was with my PR for unused imports, which was relatively simple, namely, record when an import selector is used for lookup. All the complexity in CheckUnused is due to imports checking (because it requires contexts and scopes). Everything else (correlating definitions and references) is easy because it's just symbols. I've removed the "internal traverser" from CheckUnused and used the miniphase API instead; I propose next to eliminate the stacks used to approximate scopes in favor of proper Contexts. (I did a kludge to handle args to parent constructors that happened to work; I thought fixing that would require the full rewrite.) The advantage of keeping as much as possible in a separate phase is that it helps harden all behaviors. So although I would have preferred an instrumented compiler approach, now I see the benefit of not having code comments that explain "sbt needs this" or "the presentation compiler" or "linting". At least CheckShadowing is in the same megaphase now; it's natural to want a linting megaphase where I can add a lint and rely on Context, perhaps with other linting info. |
#18366 is already fixed via another PR |
Fixes #18366
Lays the groundwork to use the information from Typer in linting instead of recalculating it (e.g.
isInImport
in WUnused).