-
Notifications
You must be signed in to change notification settings - Fork 52
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
Replace unification-fd
with a custom implementation of unification
#1802
Conversation
Replace with modern standard implementations of `Free` and `Fix`.
Now getting weird compile-time errors from some quasiquotes
Now it compiles but almost everything in the test suite is failing =)
Composition of substitutions is not commutative!
Compared to the naive implementation, this brings down the time to run the whole test suite from ~190 to ~140 seconds---though still slower than unification-fd (~120s), which is to be expected.
Co-authored-by: Restyled.io <[email protected]>
…warm into refactor/custom-unification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of my depth, but exciting nonetheless!
-- unification is subtly wrong; fortunately, a single integration test | ||
-- in the Swarm test suite failed, leading to discovering the bug. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which test, out of curiosity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was Challenges/Sliding Puzzles/_sliding-puzzle/solution.sw
that failed to typecheck, specifically the getInitialBlankDestination
function. Something about the way it involved inferring the type of a higher-order function that took tuple projections as an argument tickled the type inference algorithm in just the right way to trigger the bug. So thanks for writing that code! 😄
Closes #1661; towards #154.
unification-fd
is very powerful, and extremely fast, but it was written a long time ago and its age shows. It was not possible to incorporate it into our effects system in a nice way, necessitating the use of concrete monad transformers in the typechecking code. In addition it is impossible to customize, and we have been contemplating new type system features such as #153 and #154 that turn out to require hooking into the way the unification algorithm works (see #154 (comment) for more details).This PR thus removes the dependency on
unification-fd
and implements our own version of unification. It is not quite as fast asunification-fd
but I consider the slowdown acceptable in order to gain e.g. recursive types. And of course there is also room to optimize it.The custom
UTerm
fromunification-fd
is replaced with the standardFree
(free monad) construction from thefree
package, and the customFix
fromunification-fd
is replaced with the one fromdata-fix
.We also get rid of the
unifyCheck
function, which used to be a quick short-circuiting way to check whether two types definitely did not unify or might unify, allowing us to give better error messages more quickly. Now, the=:=
unification operator itself just does this.