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

Arbitrary vars in rule refs #5913

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
525c93d
topdown: Adding support for multiple variables in rule refs
johanfylling Apr 6, 2023
5f70376
Merge branch 'main' into jf/5685/multi-var-rule-refs
johanfylling Jul 3, 2023
d387cfd
Updating commented-out tests.
johanfylling Jul 6, 2023
d1dcb03
Fixing yaml test expecting multiple results.
johanfylling Jul 10, 2023
2073c3d
Not running yaml test for WASM
johanfylling Jul 12, 2023
29c2a2e
Merge branch 'main' into jf/5685/multi-var-rule-refs
johanfylling Aug 1, 2023
659ef2a
Moving type merge from `typeChecker.checkRule()` to `typeTreeNode.Ins…
johanfylling Jul 4, 2023
692770e
Updating type-checker to handle generic rule refs
johanfylling Jul 4, 2023
9707e66
Updating tests
johanfylling Jul 5, 2023
391d469
Generalizing `types.Object.Merge()``
johanfylling Jul 5, 2023
ea52a01
Merging sub-objects in `types.Object.Merge()`
johanfylling Jul 5, 2023
996cdec
Removing comment in test
johanfylling Jul 10, 2023
1065755
Updating tests
johanfylling Jul 5, 2023
67ba943
Aligning hint-key and entry for general refs on virtual partial eval
johanfylling Jul 11, 2023
8ffcf1d
Enforcing no-else parser rule on general ref heads
johanfylling Aug 10, 2023
f02441d
PE impl
johanfylling Aug 14, 2023
68f9436
Removing redundant legacy PE eval branch
johanfylling Aug 14, 2023
bec96d1
Fixing issue where PE-produced query contained non-namespaced local vars
johanfylling Aug 18, 2023
33ebc2f
Adding PE tests
johanfylling Aug 18, 2023
80620a0
Invoking evalOneRulePostUnify() for any ref with unknowns overlapping…
johanfylling Aug 21, 2023
98178fb
fmt: Not using rule ref ground prefix if ref has dynamic part
johanfylling Aug 21, 2023
372def8
Fixing linter warnings
johanfylling Aug 21, 2023
9e544c6
Ignoring additional yaml tests not supported by Wasm
johanfylling Aug 22, 2023
0fa5652
Merge branch 'main' into jf/5685/multi-var-rule-refs
johanfylling Aug 22, 2023
52bb04d
Cleanup
johanfylling Aug 22, 2023
18702a3
Producing cache hint keys containing entire applicable ref for genera…
johanfylling Aug 22, 2023
d4ac3b0
Merge branch 'main' into jf/5685/multi-var-rule-refs
johanfylling Aug 29, 2023
9e46555
Updating type-tree construction
johanfylling Aug 29, 2023
e1c0a23
Merge branch 'main' into jf/5685/multi-var-rule-refs
johanfylling Aug 29, 2023
2e7121b
Removing debug print
johanfylling Aug 29, 2023
a98a6ee
Merge branch 'main' into jf/5685/multi-var-rule-refs
johanfylling Aug 30, 2023
9dcaac8
Adding docs
johanfylling Aug 30, 2023
c0d38ea
Merge branch 'main' into jf/5685/multi-var-rule-refs
johanfylling Aug 31, 2023
ebf1503
Making changes suggested by @srenatus
johanfylling Aug 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion format/format.go
Expand Up @@ -453,7 +453,7 @@ func (w *writer) writeElse(rule *ast.Rule, o fmtOpts, comments []*ast.Comment) [

func (w *writer) writeHead(head *ast.Head, isDefault, isExpandedConst bool, o fmtOpts, comments []*ast.Comment) []*ast.Comment {
ref := head.Ref()
if head.Key != nil && head.Value == nil {
if head.Key != nil && head.Value == nil && !head.HasDynamicRef() {
ref = ref.GroundPrefix()
}
if o.refHeads || len(ref) == 1 {
Expand Down
2 changes: 2 additions & 0 deletions format/format_test.go
Expand Up @@ -78,6 +78,8 @@ func TestFormatSourceError(t *testing.T) {
}

func TestFormatSource(t *testing.T) {
t.Setenv("OPA_ENABLE_GENERAL_RULE_REFS", "true")

regoFiles, err := filepath.Glob("testfiles/*.rego")
if err != nil {
panic(err)
Expand Down
7 changes: 7 additions & 0 deletions format/testfiles/test_ref_heads.rego
Expand Up @@ -11,3 +11,10 @@ q[1] = y if true
r[x] if x := 10
p.q.r[x] if x := 10
p.q.r[2] if true

g[h].i[j].k { true }
g[h].i[j].k { h := 1; j = 2 }
g[3].i[j].k = x { j := 3; x = 4 }
g[h].i[j].k[l] if { true }
g[h].i[j].k[l] contains x { x = "foo" }
g[h].i[j].k[l] contains x { h := 5; j := 6; l = 7; x = "foo" }
23 changes: 23 additions & 0 deletions format/testfiles/test_ref_heads.rego.formatted
Expand Up @@ -17,3 +17,26 @@ r[x] if x := 10
p.q.r[x] if x := 10

p.q.r[2] = true

g[h].i[j].k = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks so wrong but h and j could be rules defined somewhere in the package, right? 😅 (Not that it matters for formatting)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, this isn't internally consistent; but it's valid Rego, and for this rule we're more interested to see what the formatter does with the redundant { true } body.


g[h].i[j].k if {
h := 1
j = 2
}

g[3].i[j].k = x if {
j := 3
x = 4
}

g[h].i[j].k[l] = true

g[h].i[j].k[l] contains x if x = "foo"

g[h].i[j].k[l] contains x if {
h := 5
j := 6
l = 7
x = "foo"
}