Term attachment changes propagate outside a Stratego scope
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
Submitted by Sebastian Erdweg on 24 January 2013 at 15:06foo
does not change the input term in any way. Indeed, a call<foo> Bar
produces the termBar
, but the attachments ofBar
may have changed. In particular, when using aParentTermFactory
the parent ofBar
will beFoo
, even thought no termFoo(Bar)
exists outside the body offoo
.
Issue Log
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 theSSL_EXT_clone_and_set_parents
primitive when you need it: it clones an entire tree and then sets the parent attachments.
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 codemain = 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