Changes to a term’s attachment propagates even if this changed was scoped in Stratego. Example:

foo = where(\ x -> Foo(x) \)

The expected behavior is that the execution of the foo does not change the input term in any way. Indeed, a call <foo> Bar produces the term Bar, but the attachments of Bar may have changed. In particular, when using a ParentTermFactory the parent of Bar will be Foo, even thought no term Foo(Bar) exists outside the body of foo.

Submitted by Sebastian Erdweg on 24 January 2013 at 15:06

On 24 January 2013 at 17:19 Gabriël Konat tagged stratego

On 25 January 2013 at 19:19 Lennart Kats commented:

Term attachments are mutable and can therefore cause this kind of behavior. I’m not sure if there’s much we can do about it at the Stratego level, as there is no knowledge of the attachments there.

In the specific case of parent attachments, there is no efficient way of working with them in Stratego without mutability :( Enforcing immutability for parent attachments would make performance of rewriting on big trees prohibitive. Instead of using a ParentTermFactory, I would consider using the SSL_EXT_clone_and_set_parents primitive when you need it: it clones an entire tree and then sets the parent attachments.


On 13 February 2013 at 16:35 Sebastian Erdweg commented:

Implementing parent attachments via mutation is fine. I just think changes to the attachment should be undone after a scope is left, that is, the original parent should be reset before leaving the where scope. Otherwise you might very easily end up in a state where attachments have become meaningless. For example, the code

main = where(some-complicated-check)

may break any assumptions on attachments. Just to be sure, I would have to recompute any attachment (e.g., parents) I am interested in.

Log in to post comments