JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
88 stars 4 forks source link

Use constraints to type check language #195

Closed JSAbrahams closed 4 years ago

JSAbrahams commented 4 years ago

Relevant issues

Resolves #166 Resolves #150

Summary

Use typing constraints for proper type inference. This is all done in two stages:

  1. Generation stage, where we generate constraints
  2. Unification stage, where we solve these constraints like a set of equations. We also make use of substitution.

All this should also make it easier to type-check more complex language constructs in future.

We remove the old type inference logic, as well as any old (helper) functions which were used by the old type inference stage.

With regards to the Node class itself, we also did some cleanup by making mutable and the type properties of function arguments and variable definitions directly. This means we don't constantly have to recursively check whether the identifier stored within these was an IdType.

We also make TypeName and InferType top-level in the type checker as these are universal constructs within the type checker.

Added Tests

A few.

Removed Tests

Some old tests have been removed due to them being to difficult to implement in one go. We will gradually be re-adding language functionality, using these ignored tests as a roadmap.