lang: core: iter: Replace graph when list length changes
The map and iter functions weren't replacing the graph if the input list length changed. This was just an oversight in coding AFAICT, as the sneaky case is that if the length stays the same, but the list contents change, then it's okay to not swap.
This commit is contained in:
@@ -449,7 +449,9 @@ func (obj *FilterFunc) Call(ctx context.Context, args []types.Value) (types.Valu
|
|||||||
|
|
||||||
// Every time the FuncValue or the length of the list changes, recreate
|
// Every time the FuncValue or the length of the list changes, recreate
|
||||||
// the subgraph, by calling the FuncValue N times on N nodes, each of
|
// the subgraph, by calling the FuncValue N times on N nodes, each of
|
||||||
// which extracts one of the N values in the list.
|
// which extracts one of the N values in the list. If the contents of
|
||||||
|
// the list change (BUT NOT THE LENGTH) then it's okay to use the
|
||||||
|
// existing graph, because the shape is the same!
|
||||||
|
|
||||||
n := len(newInputList.List())
|
n := len(newInputList.List())
|
||||||
|
|
||||||
@@ -459,10 +461,6 @@ func (obj *FilterFunc) Call(ctx context.Context, args []types.Value) (types.Valu
|
|||||||
}
|
}
|
||||||
obj.lastInputListLength = n
|
obj.lastInputListLength = n
|
||||||
|
|
||||||
if b && !c { // different length list
|
|
||||||
return types.NewNil(), nil // dummy value
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have a new function or the length of the input list has
|
// If we have a new function or the length of the input list has
|
||||||
// changed, then we need to replace the subgraph with a new one that
|
// changed, then we need to replace the subgraph with a new one that
|
||||||
// uses the new function the correct number of times.
|
// uses the new function the correct number of times.
|
||||||
|
|||||||
@@ -393,7 +393,9 @@ func (obj *MapFunc) Call(ctx context.Context, args []types.Value) (types.Value,
|
|||||||
|
|
||||||
// Every time the FuncValue or the length of the list changes, recreate
|
// Every time the FuncValue or the length of the list changes, recreate
|
||||||
// the subgraph, by calling the FuncValue N times on N nodes, each of
|
// the subgraph, by calling the FuncValue N times on N nodes, each of
|
||||||
// which extracts one of the N values in the list.
|
// which extracts one of the N values in the list. If the contents of
|
||||||
|
// the list change (BUT NOT THE LENGTH) then it's okay to use the
|
||||||
|
// existing graph, because the shape is the same!
|
||||||
|
|
||||||
n := len(newInputList.List())
|
n := len(newInputList.List())
|
||||||
|
|
||||||
@@ -403,10 +405,6 @@ func (obj *MapFunc) Call(ctx context.Context, args []types.Value) (types.Value,
|
|||||||
}
|
}
|
||||||
obj.lastInputListLength = n
|
obj.lastInputListLength = n
|
||||||
|
|
||||||
if b && !c { // different length list
|
|
||||||
return types.NewNil(), nil // dummy value
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have a new function or the length of the input list has
|
// If we have a new function or the length of the input list has
|
||||||
// changed, then we need to replace the subgraph with a new one that
|
// changed, then we need to replace the subgraph with a new one that
|
||||||
// uses the new function the correct number of times.
|
// uses the new function the correct number of times.
|
||||||
|
|||||||
Reference in New Issue
Block a user