strip-annos removes origin of empty lists
For example:
result = <strip-annos> empty-list
Now
result
won’t have origin information anymore.I’m happy to fix it if somebody can tell me where
Submitted by Oskar van Rest on 17 September 2013 at 20:38strip-annos
is defined.
Issue Log
It can be found here: https://github.com/metaborg/strategoxt/blob/8821a02ab7860df6f47792a04ab181bcecdb0842/stratego-libraries/lib/spec/term/annotation.str
Strange…
strip-annos
is implemented like this:strip-annos = bottomup(rm-annotations) rm-annotations : t -> t{}
if I implement it myself as
strip-annos2 = bottomup(rm-annotations2) rm-annotations2 : t -> t{}
then everything works fine.
But
strip-annos2 = bottomup(rm-annotations)
does not work.Doing a search on Github does not result in any other implementations of
rm-annotations
.
Could it be the case that STRJ has been changed recently and that the file has not been recompiled afterwards?
When I build to .jar instead of .ctree, my implementation (
strip-annos2
) also fails.
The problem is that origin information isn’t added to the empty list node; see https://github.com/metaborg/mb-rep/blob/master/org.spoofax.terms/src/org/spoofax/terms/attachments/OriginTermFactory.java#L174. It’s only added to leaf nodes of the tree; subnodes of lists. Empty lists are a corner case that’s not currently covered. A problem is that they often are just instances of the singleton object at https://github.com/metaborg/mb-rep/blob/master/org.spoofax.terms/src/org/spoofax/terms/TermFactory.java#L47, so you can’t just write an origin to it.
One runtime solution could be to create a new, unshared object for empty lists in the runtime when origin tracking is enabled. And then check each empty list’s storage type in OriginTermFactory to decide if an origin can be assigned to it. [edit]Note that you would still get a shared object for a literal
[]
in your Stratego program, since the compiler caches all literals used in fields.[/edit] Other than that, strip-annos could work for unannotated empty lists as long as it doesn’t actually rewrite those into a new object.
Thanks for your help.
I now ‘fixed’ it by changing the implementation of rm-annotations:
rm-annotations = ?[]{} <+ ?t; !t{}
This is not the ideal solution, but I tried it by changing
OriginTermFactory
as you said and got this working, but then it started failing somewhere else because of missing parent attachments (layout preservation algorithm relies on those). I had a look atParentTermFactory
to see if I can fix it there too, but gave up on that because I don’t really know what is going on there and I believe it is also unclear whether we really want to keep supporting parent attachments, so I rather not spend too much time on that.
Log in to post comments