From df9849319d2d29e08ad5a6e13e08c8f78e372dac Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 14 Sep 2025 23:50:21 -0400 Subject: [PATCH] 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. --- lang/core/iter/filter.go | 8 +++----- lang/core/iter/map.go | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lang/core/iter/filter.go b/lang/core/iter/filter.go index a92589a7..5123e06f 100644 --- a/lang/core/iter/filter.go +++ b/lang/core/iter/filter.go @@ -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. diff --git a/lang/core/iter/map.go b/lang/core/iter/map.go index e1fc6b78..40fa5050 100644 --- a/lang/core/iter/map.go +++ b/lang/core/iter/map.go @@ -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.