coalton-lang / coalton

Coalton is an efficient, statically typed functional programming language that supercharges Common Lisp.
https://coalton-lang.github.io/
MIT License
1.15k stars 70 forks source link

Refactor traverse #1184

Closed amorphedstar closed 3 months ago

amorphedstar commented 3 months ago

This PR aims to refactor the codegen's traverse function in order to provide a more general structure that allows

The traversal still assumes the result is a node, which means that collecting other data out of an AST node tree still requires either mutation with traverse, or a completely different traversal function. This is fine, since the main use of traverse is to avoid rewriting methods just to recursively propagate an operation through the AST when only a few nodes need custom behavior. Defaulting to recursive traverse calls only makes sense when the result is a node.

This PR also refactors apply-ast-substitution to use traverse. It creates a specialized traverse-with-binding-list for the three usages of traverse that actually used the bound-variables. And it implements type variable collection and substitution in ASTs.