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

Partial-eval is broken for partial object/set ref head rules #6094

Closed
johanfylling opened this issue Jul 14, 2023 · 0 comments · Fixed by #6095
Closed

Partial-eval is broken for partial object/set ref head rules #6094

johanfylling opened this issue Jul 14, 2023 · 0 comments · Fixed by #6095
Labels

Comments

@johanfylling
Copy link
Contributor

Short description

Partial evaluation fails to generate valid optimized support modules for partial object/set ref head rules.

Steps To Reproduce

Given the policy:

package bug

p.q[x] := y {
    x := input.x
    y := input.y
}

allow {
    p.q.foo
}

1. Partial Evaluation

When running opa eval --partial -fsource --shallow-inlining -d bug.rego 'data.bug.p.q[x]', we get the output:

# Query 1
data.partial.bug.p.q[x] = _term_0_0
_term_0_0

# Module 1
package partial.bug.p

 = __local1__1 {
	__local0__1 = input.x
	__local1__1 = input.y
}

Notice how the name and key of the generated optimized rule are missing; resulting in broken Rego.

2. Build with optimization

When running opa build bug.rego -O 1 -e 'bug/allow', we get a bundle with optimized Rego included at <bundle.tar.gz>/optimized/bug/p.rego:

package bug.p

 = __local1__2 {
	__local0__2 = input.x
	__local1__2 = input.y
}

Where, similar to (1), the generated Rego has missing rule name and key.

Expected behavior

When running opa eval (1), the expected output is:

# Query 1
data.partial.bug.p.q[x] = _term_0_0
_term_0_0

# Module 1
package partial.bug.p

q[__local0__1] = __local1__1 {
	__local0__1 = input.x
	__local1__1 = input.y
}

Similarly, when running opa build (2), the expected optimized Rego is:

package bug.p

q[__local0__2] = __local1__2 {
	__local0__2 = input.x
	__local1__2 = input.y
}
johanfylling added a commit to johanfylling/opa that referenced this issue Jul 14, 2023
for partial-eval.

Fixes: open-policy-agent#6094
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
johanfylling added a commit that referenced this issue Jul 31, 2023
Inferring support module rule ref, name and key from original rule ref for partial-eval.

Fixes: #6094
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant