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 and children 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):

Module(
  "debug"
, [ ModelSection(
      [ Entity("Node", [])
      , FirstClassRelation(
          "NodeParentRelation"
        , [ Role("Node", "parentRelation", ZeroOrOne(), "children")
          , Role("Node", "childrenRelation", ZeroOrMore(), "parent")
          , Shortcut("parent", "children", "children", "parent")
          ]
        )
      ]
    )
  ]
)
Submitted by Daco Harkes on 10 September 2016 at 11:29


On 20 September 2016 at 16:20 Daco Harkes commented:

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

On 19 January 2017 at 11:38 Daco Harkes commented:

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.


On 15 February 2017 at 18:24 Hendrik van Antwerpen commented:

This is resolved now that we use annotations for term indices.


On 15 February 2017 at 18:24 Hendrik van Antwerpen closed this issue.

Log in to post comments