Defines X in Y, Z does not work
Currently ( Spoofax/IMP 1.2.0.0-s40852 ), defines something into something else does not appear to work. In the example below all references to
n
andt
are unresolved:Foreach(n: G.Nodes) { n.teen_cnt = Count(t:n.InNbrs)( t.age >= 10 && t.age < 20 ); }
The corresponding AST is:
ForEach( "n" , IterSource(QualifiedCall(VarRef("G"), "Nodes", [])) , None() , Block( [ Assign( PropRef(VarRef("n"), "teen_cnt") , Assign() , Reduction( Count() , "t" , IterSource(QualifiedCall(VarRef("n"), "InNbrs", [])) , Filter( And( Ge(PropRef(VarRef("t"), "age"), IntLit("10")) , Lt(PropRef(VarRef("t"), "age"), IntLit("20")) ) ) , None() ) , None() ) ] ) )
The NaBL rules involved are:
Submitted by Vlad Vergu on 20 November 2013 at 21:30ForEach(var, iter, filter, body): defines Variable var in filter, body Reduction(_, var, iter, filter, body): defines Variable var in filter, body
Issue Log
For the example code below:
Procedure pagerank(G : Graph, pg_rank : N_P<Int>(G)) { Double diff; Foreach (t : G.Nodes) (t.pg_rank > 0) { t.pg_rank <= 3 @ t; } }
The following NaBL rules are at play besides the ones in the original post:
Unit(_, _): scopes Procedure Proc(ProcHeader(k, p, InArgs(in*), OutArgs(out*), Return(ret)), sentence*): defines Procedure p scopes Variable
Let the occurrences of t in the above code be t_1, t_2, t_3. Then:
- t_1 definition URI is
URI( Language("GMR") , [ID(NablNsVariable(), "t", Unique("/Users/vladvergu/Documents/workspaces/greenmarl/foo/pagerank.gmr/0")), Anonymous("/Users/vladvergu/Documents/workspaces/greenmarl/foo/pagerank.gmr/1")] )
- t_2 lookup path is
[/ /, / anon 0 /, / Procedure:"pagerank"#0 / anon 0 /, / subsq 0 / Procedure:"pagerank"#0 / anon 0 /, / anon 0 / subsq 0 / Procedure:"pagerank"#0 / anon 0 /]
- t_3 lookup path is
[/ /, / anon 0 /, / Procedure:"pagerank"#0 / anon 0 /, / subsq 0 / Procedure:"pagerank"#0 / anon 0 /]
I’m sorry but i don’t recall whether this was resolved or not, or whether this was a problem in my implementation. Thanks.
I remember that this occurred only if the declaration was scoped in multiple scopes. It works fine if scoped in a single scope.
I inspected the code and I doubt that
defines x in y
worked for you, Vlad. The libraries have all the necessary information, but the generator does not generate the right calls to
- create scopes for the mentioned sub terms,
- create aliases for the defined name from these scopes to the actual definition.
I will check where this was lost.
Fixed in b8edf02ce5.
In the end, it was an extension in the generator, which broke the generation of scope rules. With the extension, a possibly unbound variable was used in the right-hand side of a rule, which let the rule fail in cases it was working before.
Log in to post comments