Stratego string-sharing NaBL2 attachments -> multiple identifiers have same identity
Because of stratego string sharing the attachments made on the identifiers in the program overlap if an identifier is desugared into a 2nd place in the ast.
In the following sugared example identifiers
parent
andchildren
are copied to two places.The desugared syntax has no analysis errors (because there are no identifiers copied), the sugared syntax has analysis errors (that the type of both places where the identical identifiers occur cannot be unified).
Fix suggested by Gabriel: disable string sharing in Stratego term factory.
Desugared syntax:
module debug model entity Node{ } relation NodeParentRelation { Node.parentRelation ? -> children Node.childrenRelation * -> parent parent.children <-> children.parent }
Sugar syntax:
module debug model entity Node{ } relation Node.parent ? <-> * Node.children { }
Desugared AST (identical for both):
Submitted by Daco Harkes on 10 September 2016 at 11:29Module( "debug" , [ ModelSection( [ Entity("Node", []) , FirstClassRelation( "NodeParentRelation" , [ Role("Node", "parentRelation", ZeroOrOne(), "children") , Role("Node", "childrenRelation", ZeroOrMore(), "parent") , Shortcut("parent", "children", "children", "parent") ] ) ] ) ] )
Issue Log
This may be fixed in https://github.com/metaborg/mb-rep/commit/754572276bade096014d6e5e3b1153a9eddad229
Nope, this did not fix it.
Eclipse: org.eclipse.platform.ide 4.6.0.I20160606-1100 Spoofax: org.metaborg.spoofax.eclipse 2.1.0.20160919-225254-master System: Mac OS X x86_64 10.11.6
Still an issue in:
Eclipse: org.eclipse.platform.ide 4.6.2.M20161124-1400 Spoofax: org.metaborg.spoofax.eclipse 2.2.0.20170119-015338-master System: Mac OS X x86_64 10.12.2
Work around: explode and implode strings to ensure that these are unique objects in the stratego runtime:
copy-string = keep-origin(explode-string;implode-string)
shortcutrel-to-rel: scr@ShortcutRelation(e1, s1, m1, o1, m2, o2, e2, s2, attrs) -> result with relname := <custom-origin(|e1)>$[[e1][<ucfirst>s1]Relation]; invname1 := <custom-origin(|e1)>$[[s2]Relation]; invname2 := <custom-origin(|e2)>$[[s1]Relation] with result := <custom-origin(|scr)>FirstClassRelation( relname , [ <custom-origin(|e2)>Role(e1, invname2, m1, o1, s2) , <custom-origin(|e1)>Role(e2, invname1, m2, o2, s1) , <custom-origin(|e1)>Shortcut(<copy-string>s1, <copy-string>s2, <copy-string>s2, <copy-string>s1) | attrs ] )
Suggested fix: go over the AST before (or during) adding attachments, and make sure all AST nodes are unique objects.
Suggested fix (2): use annotations instead of attachments. On changing annotations new objects are created.
This is resolved now that we use annotations for term indices.
Log in to post comments