Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/planner: Insert general ref head objects starting from the leaves, not root #6401

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions internal/planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ func (p *Planner) planDotOr(obj ir.Local, key ir.Operand, or stmtFactory, iter p
// | | | dot &{Source:Local<obj> Key:{Value:Local<key>} Target:Local<val>}
// | | | break 1
// | | or &{Target:Local<val>}
// | | *ir.ObjectInsertOnceStmt &{Key:{Value:Local<key>} Value:{Value:Local<val>} Object:Local<obj>}
// | iter &{Target:Local<val>} # may update Local<val>.
// | *ir.ObjectInsertStmt &{Key:{Value:Local<key>} Value:{Value:Local<val>} Object:Local<obj>}

prev := p.curr
dotBlock := &ir.Block{}
Expand All @@ -482,13 +483,16 @@ func (p *Planner) planDotOr(obj ir.Local, key ir.Operand, or stmtFactory, iter p
Stmts: []ir.Stmt{
&ir.BlockStmt{Blocks: []*ir.Block{dotBlock}}, // FIXME: Set Location
or(val),
&ir.ObjectInsertOnceStmt{Key: key, Value: op(val), Object: obj},
},
}

p.curr = prev
p.appendStmt(&ir.BlockStmt{Blocks: []*ir.Block{outerBlock}})
return iter(val)
if err := iter(val); err != nil {
return err
}
p.appendStmt(&ir.ObjectInsertStmt{Key: key, Value: op(val), Object: obj})
return nil
}

func (p *Planner) planNestedObjects(obj ir.Local, ref ast.Ref, iter planLocalIter) error {
Expand Down
38 changes: 37 additions & 1 deletion test/cases/testdata/refheads/test-refs-as-rule-heads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,40 @@ cases:
public: false
want_result:
- x:
- n1
- n1
- modules:
- |
package test
import future.keywords

p[a][b][c][d][e] if {
some a in numbers.range(1, 5)
some b in numbers.range(1, 5)
some c in numbers.range(1, 5)
some d in numbers.range(1, 5)
some e in numbers.range(1, 5)
a+b+c+d+e == 24
}
note: refheads/many-vars
query: data.test.p = x
want_result:
- x:
4:
5:
5:
5:
5: true
5:
4:
5:
5:
5: true
5:
4:
5:
5: true
5:
4:
5: true
5:
4: true