Skip to content

Make CheckUnused not slow. #20321

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

Merged
merged 10 commits into from
May 7, 2024
Next Next commit
Make unusedDataApply inline so that no closure is allocated.
It is used for every single tree in `CheckUnused`, so this is worth
it.
  • Loading branch information
sjrd committed May 6, 2024
commit 69664f7c01e0103cc02ee5fae9d63ad04abe46d7
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
import CheckUnused.*
import UnusedData.*

private def unusedDataApply[U](f: UnusedData => U)(using Context): Context =
ctx.property(_key).foreach(f)
private inline def unusedDataApply[U](inline f: UnusedData => U)(using Context): Context =
ctx.property(_key) match
case Some(ud) => f(ud)
case None => ()
ctx

override def phaseName: String = CheckUnused.phaseNamePrefix + suffix
Expand Down