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:
James Shubin
2025-09-14 23:50:21 -04:00
parent 045aa8820c
commit df9849319d
2 changed files with 6 additions and 10 deletions

View File

@@ -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
// 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())
@@ -459,10 +461,6 @@ func (obj *FilterFunc) Call(ctx context.Context, args []types.Value) (types.Valu
}
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
// changed, then we need to replace the subgraph with a new one that
// uses the new function the correct number of times.

View File

@@ -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
// 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())
@@ -403,10 +405,6 @@ func (obj *MapFunc) Call(ctx context.Context, args []types.Value) (types.Value,
}
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
// changed, then we need to replace the subgraph with a new one that
// uses the new function the correct number of times.