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
Bug in partial evaluation: self-comparison missing #4848
Comments
Thanks for the report! |
One could argue that the use of That said, PE should not drop meaningful queries, that's for sure, so the bug is valid. It just strikes me as avoidable. 🤔 |
FWIW I suspect it's copy propagation, but there's no way to quickly try this just using |
📜 Just some notes, thinking aloud Looks like the bug is two-fold: copyprop fails to recognize the necessity to keep something for package p
a { input.a == input.a } eliminates it -- because when that calls copyprop, it doesn't pass 💡 When __localq0__ = input.a
__localq1__ = input.a
equal(__localq0__, __localq1__) and for that, the previous copyprop logic was sufficient. |
Before, a query of input.a == input.a would not survive copypropagation. With this change, it'll be recorded as removedEq, and subsequent processing steps ensure that it's kept in the body. Changing the sort order in sortBindings allows us to limit the unnecessary variable bindings: with the previous ordering, we'd get __local0__1 = input; __localcp0__ = input.a for the query `x := input; input.a == input.a`. Sorting the other way, we'll process `__localcp0__ = input.a` first, add it to the body, and when we check `__local0__1 = input`, we find that `input` is already contained in the body, and is thus not needed. Fixes open-policy-agent#4848. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Before, a query of input.a == input.a would not survive copypropagation. With this change, it'll be recorded as removedEq, and subsequent processing steps ensure that it's kept in the body. Changing the sort order in sortBindings allows us to limit the unnecessary variable bindings: with the previous ordering, we'd get __local0__1 = input; __localcp0__ = input.a for the query `x := input; input.a == input.a`. Sorting the other way, we'll process `__localcp0__ = input.a` first, add it to the body, and when we check `__local0__1 = input`, we find that `input` is already contained in the body, and is thus not needed. Fixes #4848. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Short description
There seems to be a bug in the partial evaluation when doing self-comparisons. Self-comparisons are missing in the result.
Steps To Reproduce
data.json
with the following content:As you can see, even though
input.a
is compared with itself, it is not guaranteed to always return true.The evaluation returns
undefined
ifa
is not supplied.input.a == input.a
is missing from the result:Expected behavior
I would expect the condition
input.a == input.a
to be in the query result since it might be false/undefined.So the expected output would be:
Additional context
I tested this with OPA v0.41.0.
The text was updated successfully, but these errors were encountered: