This adds a modern type unification algorithm, which drastically improves performance, particularly for bigger programs. This required a change to the AST to add TypeCheck methods (for Stmt) and Infer/Check methods (for Expr). This also changed how the functions express their invariants, and as a result this was changed as well. This greatly improves the way we express these invariants, and as a result it makes adding new polymorphic functions significantly easier. This also makes error output for the user a lot better in pretty much all scenarios. The one downside of this patch is that a good chunk of it is merged in this giant single commit since it was hard to do it step-wise. That's not the end of the world. This couldn't be done without the guidance of Sam who helped me in explaining, debugging, and writing all the sneaky algorithmic parts and much more. Thanks again Sam! Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
14 lines
580 B
Plaintext
14 lines
580 B
Plaintext
-- main.mcl --
|
|
import "fmt"
|
|
import "math"
|
|
# FIXME: floats don't print nicely: https://github.com/golang/go/issues/46118
|
|
# FIXME: This means that we see "42" for both, instead of 42.0 ...
|
|
# NOTE: It's important that we have both of these in the same test so that we
|
|
# can catch old unification bugs that saw ExprTopLevel as the same for both!
|
|
# This happened because we weren't copying the type signature being unified!
|
|
test [fmt.printf("int: %d", math.fortytwo()),] {}
|
|
test [fmt.printf("float: %f", math.fortytwo()),] {}
|
|
-- OUTPUT --
|
|
Vertex: test[float: 42]
|
|
Vertex: test[int: 42]
|