Sun Feb 14 13:41:51 CET 2010
Environment is only necessary during threading
Let's rephrase... What is important? When flattening an expression
tree/graph, it needs to be determined which nodes are the same.
What should an environment do?
- provide an ANF/SSA view of expression graph
Anything else is implementation. In first approximation this means:
an environment should keep track of sharing based on some form of
equivalence, i.e. object equivalence (as a consequence of data
sharing at the meta level) or other equivalences.
So basically, we never need to _merge_ environments, as there is only
one instance that is threaded through the flattening. It looks like
the problem is simpler this way.
Ok, this works pretty well.
- given terms, compute a fold over them to accumulate the sharing
environment, and replace all terms with shared variants.
- provide conversion of environment to node-naming function (for
obtaining register names)
- provide fold over nodes in environment
This then gives a way to convert a term (with sharing and possibly
other equivalence relation) to a flat ANF-style structure.