Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prune polymorphic implicits more aggressively
This is a backport to 2.12.x of, #6580 In rankImplicits, before we attempt to fully typecheck the pending candidate implicit, we first attempt to partially instantiate type variables in both the candidate and the target type and check for compatibility. If the compatibility check fails we can immediately prune the the candidate without having to fully typecheck it. In the kinds of implicit searches typical of the inductive style found in shapeless and related libraries this can result in a drastic reduction in the search space and a corresponding reduction in compile times. This commit is much simpler, more generally applicable, and less invasive than my earlier work on inductive implicits in, #6481 which was doing similar pruning almost by accident. It turns out that almost all of the speedups in that earlier PR were due to the pruning rather than to any special casing of inductive patterns. The compilation benchmark (a shapeless-style "select element by type from a large HList") from that PR is carried over here (in test/induction) and shows the same performance improvements, 1) baseline - scalac 2.12.5 2) scalac 2.12.5 with matchesPtInst (1) (2) HList Size 50 4 3 100 7 4 150 14 4 200 25 5 250 46 5 300 74 6 350 118 8 400 183 10 450 298 12 500 421 15 Compile time in seconds As an added bonus users of shapeless and shapeless based libraries which use shapeless's Lazy type will see benefits immediately without needing to wait for and port to byname implicit arguments.
- Loading branch information