morphismtech / squeal

Squeal, a deep embedding of SQL in Haskell
352 stars 32 forks source link

fix very slow `Has` introduced by new type errors #304

Closed Sciencei closed 2 years ago

Sciencei commented 2 years ago

I updated a personal project to use squeal 0.8.1.0 and was alarmed that one slightly larger file ran out of memory when trying to compile. This was rather surprising as I expected no change when the file compiled. After some experimentation, I tracked it to the following:

So between all of those, it was blowing up compile time memory usage and time.

To fix it, we use another layer of type families to check for our found equaling our expected first, and only then worry about calculating pretty printing info. This means that calculation is relegated to the error case.

HasParameter doesn't have the same issue because it doesn't pretty print, and LookupFailedError doesn't either because it's part of the constraints for an instance head that is only matched in the case of an error.