Closed gelisam closed 1 year ago
About (4): the variable must be in the map. SetScope()
does not need to be merged with MergedGraph()
. It is normal that there is a context during type-checking which associates variables with types, and also an environment during evaluation which associates variables with values. Both the context and the environment must have an entry for every variable which is in scope.
About (5): no, we don't recur on the definition of $f
nor the definition of `$x. Both of those variables should already be in the map, so we just return the Func which the map tells us to return, we don't recur.
This PR has now been incorporated into #704. Closing.
Here is the result of today's hacking session. It builds on top of #697, so the PR will be much easier to review after that is merged.
Things I've figured out since:
func MergedGraph(ReversibleTxn, map[string]Vertex) (Graph, Func, error)
still isn't right. It should either receive aReversibleTxn
or return aGraph
, not both. In this PR I've kept theReversibleTxn
.ExprCall.Graph()
needs to be updated. It should recur on the function and the arguments, obtaining oneFunc
for the function and a list ofFunc
s for the arguments. Then construct a CallFunc with the functionFunc
as an upstream node and withArgVertices
set to the argumentFunc
s.VarExpr.Graph()
needs to be updated. This is where themap[string]Vertex
is used: if the variable is a lambda parameter, then we should return the corresponding entry from thatmap
. Since we need to return aFunc
, thatmap
should probably bemap[string]Func
.map
, then it's a lot less clear what to do. We currently recur on the variable's definition, but that will duplicate the definition for every use site instead of having the definition's node point to all the use sites. Perhaps the environment needs to include everything which is in scope, not just the lambda parameters? If so, does that mean thatSetScope()
also needs to be merged withGraph()
andFunc()
?? I hope not!$f($x + $x)
, we recur on the definition of$f
and on the argument$x + $x
. If for$f($x + $x)
we have amap
which says that$x
is a lambda parameter, then for$x + $x
that is still true, but for the definition of$f
that might not be true, depending on whether$f
is defined inside the same lambda as the$f($x + $x)
call or higher up. So we need to adjust themap
somehow.