lang: Add modern type unification implementation
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>
This commit is contained in:
@@ -395,8 +395,8 @@ func OccursCheck(elem *types.Elem, typ *types.Type) error {
|
||||
// written based on the realization that something of this shape was needed
|
||||
// after looking at post-unification unification variables and realizing that
|
||||
// the data needed to be "bubbled upwards". It turns out the GHC Haskell has a
|
||||
// similar function for this which is called "zonk". "zonk" is the name which
|
||||
// it uses for this transformation, whimsically claiming that "zonk" is named
|
||||
// similar function for this which is called "zonk". "zonk" is the name which it
|
||||
// uses for this transformation, whimsically claiming that "zonk" is named
|
||||
// "after the sound it makes". (Thanks to Sam for the fun trivia!)
|
||||
// TODO: Untested alternate version that copies everything if anything changes.
|
||||
func Extract(typ *types.Type) *types.Type {
|
||||
|
||||
Reference in New Issue
Block a user