This PR aims to refactor the codegen's traverse function in order to provide a more general structure that allows
operations performed uniformly on every node, and in particular, type variable collection and substitution for inlining multiple copies of polymorphic functions (this can also be used for syntactic inlining heuristics like node count), and
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.
This PR aims to refactor the codegen's
traverse
function in order to provide a more general structure that allowsbound-variables
list, to allow for various applications like constant propagation ( see https://github.com/coalton-lang/coalton/pull/1029/commits/8d9c0995d7eb03cd84a2163dae62af57126b1e01#diff-d5c2bd51ab00b09becf60d0d656f35fd12dec0c8e7e0fb377f9eabfebcfe3b99R155-R156 ) and so that immutable data can be used withtraverse
, instead of requiring mutation like the:before-*
push
and:after-*
pop
used in several applications oftraverse
.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 withtraverse
, or a completely different traversal function. This is fine, since the main use oftraverse
is to avoid rewriting methods just to recursively propagate an operation through the AST when only a few nodes need custom behavior. Defaulting to recursivetraverse
calls only makes sense when the result is a node.This PR also refactors
apply-ast-substitution
to usetraverse
. It creates a specializedtraverse-with-binding-list
for the three usages oftraverse
that actually used thebound-variables
. And it implements type variable collection and substitution in ASTs.