daml/daml-lf/validation
Moritz Kiefer 8ff347d8ed
Expand type synonyms lazily (#11282)
* Expand type synonyms lazily

We really only need to expand type synonyms in two cases:
1. When pattern matching e.g. to check that a projection on a struct
   really happens on a struct. In this case we can first check if we
   have a struct in which case we don’t need to expand anything. If we
   don’t, we can expand afterwards.
2. When checking two types for alphaequivalence. This PR goes for the
   simplest solution: First check alphaequivalence without expanding
   anything treating type synonyms nominally. Then if that fails
   expand everything and check again. We could be more clever and
   interleave expansion with checking for alphaequivalence but this
   seems to give us most of the performance benefits while keeping the
   logic very simple.

On my local laptop this speeds up typechecking of the full DAR from
380ms to 176ms so roughly a 2x improvement.

For comparison: The Daml-LF 1.7 DAR which still relies on nonminal
typechecking of typeclasses everywhere takes 110ms. So we are still
leaving something on the table here but we’re much closer.

I think this also gets us to the point where speedy compilation is
slower than typechecking but I need to verify that again.

changelog_begin
changelog_end

* Apply suggestions from code review

Co-authored-by: Remy <remy.haemmerle@daml.com>

* fix biuld

changelog_begin
changelog_end

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-10-19 20:48:32 +00:00
..
src Expand type synonyms lazily (#11282) 2021-10-19 20:48:32 +00:00
BUILD.bazel Add an LF typechecking benchmark (#11276) 2021-10-18 12:53:17 +00:00