Test / Debug graph
Turns out the SExpr based serialization / deserialization mentioned in #5 doesn't really make writing tests easier. So the next, more involved step would be to have a little DSL, that expresses a test graph, which makes it easy to create graph, and test for equalness.
I think of a standard "test" node and "test" edges that could be expressed in a macro that implements the graph building for us.
Equalness is then a new property of the graph that can be tested for graphs where N
and E
implement PartialEq
.
The macro could look a little like the dot
format, but with the explicit structural character of the RVSDG.
Example fig 3.a)
test_graph!(
omega{
max = lambda{
gt = "gt";
gm = gamma{
a -> c
}{
b -> c
};
a -> gt.a;
gt.c -> gm.pred;
a -> gm.a;
b -> gt.b;
b -> gm.b;
gm.c -> c;
};
dlt = delta{
m = "m";
a = "a";
x = "x";
end = "\0";
con = "aryconst";
m.a -> con.a;
a.a -> con.b;
x.a -> con.c;
end.a -> con.d;
con.e -> delta_out
};
f = lambda{
call_max = apply;
call_put = apply;
cv_0 -> call_max.pred;
cv_1 -> call_put.pred;
a -> call_max.a;
b -> call_max.c;
cv_2 -> call_put.a;
c => call_put.b;
}
max.c -> f.cv_0;
put -> f.cv_1;
dlt.delta_out -> f.cv_2;
f.def -> export_f;
}
)
So far the rules are as follows:
- any node with "x" creates a simple node x, all others are parsed to the equivalent RVSDG-node
-
a -> b
creates a value edge from the region's argumenta
to the region's argumentb
- if
a
is of the forma.x
then nodea
's outputx
is used.- if
x
is "def", then the definition-port of a lambda node is used. - if
x
is prefixed with "rv" then the equivalent recursion variable is used
- if
- if
b
is of the formb.x
then nodeb
's inputx
is used.- if
x
is "pred", then the predicate (of a gamma node), or the function definition port of an apply-node is used - if
x
is prefixed with "cv" then the equivalent context variable is used - if
x
is prefixed with "rv" then the equivalent recursion variable is used
- if
- if
a
is prefixed with "cv" then the equivalent context variable is used - if
a
is prefixed with "rv" then the equivalent recursion variable is used - if
b
is prefixed with "rv" then the equivalent recursion variable is used
- if
-
a => b
creates a state edge, all sub rules of 2) apply