melt-umn / silver

An attribute grammar-based programming language for composable language extensions
http://melt.cs.umn.edu/silver/
GNU Lesser General Public License v3.0
57 stars 7 forks source link

Avoid excessive laziness in production application #788

Closed krame505 closed 1 year ago

krame505 commented 1 year ago

Changes

I noticed in the translation for large nested terms, every subterm production constructor call is being wrapped in a thunk. This is a waste as the only work being deferred is the creation of the node; the arguments to a production are already lazy. A similar situation exists for list literals.

Instead, make the "lazy translation" of constructor calls and cons be eager. This shouldn't affect the semantics or create cycles since any function calls/references to locals or attributes as the leaves of a term literal are still be lazy. At the most this may mean we create some subterms that are never used, if only a portion of a specified term is demanded - but this is presumably fairly rare.

I believe this mirrors what a lazy language with a more intelligent strictness analysis would do.

Documentation

Added some comments.