TC-5 Improvements
- Maximal node sharing
The proposed implementation of
Treecreates new nodes for equal expressions; for instance two uses of the variablefoolead to two equal instantiations oftree::Temp. The same applies to more complex constructs such as the same translation iffoois actually a frame resident variable etc. Because memory consumption may have a negative impact on performances, it is desirable to implement maximal sharing: whenever aTreeis needed, we first check whether it already exists and then reuse it. This must be done recursively: the translation of(x + x) * (x + x)should have a single instantiation ofx + xinstead of two, but also a single instantiation ofxinstead of four.Node sharing makes some algorithms, such as rewriting, more complex, especially wrt memory management. Garbage collection is almost required, but fortunately the node of
Treeare reference counted! Therefore, almost everything is ready to implement maximal node sharing. See SPOT, for an explanation on how this approach was successfully implemented. See The ATerm library for a general implementation of maximally shared trees.