-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: built-in function count is not covered when count on a rule generating sets #1421
Comments
@t83714 sorry for the delay! KubeCon EU stole a lot of cycles over the last two weeks.
To inline these rules we'd have to generate 2^n combinations (where n is the number of rules that depend on unknowns.) If n is really small, that might be OK, but in the general case, it'll be too expensive (which is why we save the expression). In some cases, it might be fine to partially evaluate the reference. A good example would be if the ref does not depend on unknowns. In this case, we can just inline the result. |
Thanks a lot for your comment 👍 |
Certain portions of Rego cannot be easily inlined when they depend on unknowns (e.g., comprehensions). In the past, if PE encountered statements that could not be inlined, PE would simply save the original statement regardless of whether that statement (or any of it's dependencies) depended on unknowns. This was the safest way to introduce PE initially and worked in many cases as long as authors were aware of the fragment of Rego that could be PE-ed. Of course, this places a burden on authors and also fails when constructs like comprehensions are required. This commit enhances the evaluator so that PE will evaluate all terms (e.g., comprehensions, references to full extent of partial sets/objects, etc.) as long as they do not depend on unknowns. This commit also enhances the evaluato to support PE on expressions that include with statements. Support for with statements is handled by disabling inlining on any references that are contained in the expression modified by the with statement. This approach was chosen over open-policy-agent#1956 because while it generates support rules it avoids the need to re-apply with statements to inlined expressions. This commit also addresses open-policy-agent#1417 because negated expressions that can be completely evaluated will be now. As part of this change, the evaluator has been refactored to maintain the inlining controls as a stack (this makes with statements easier to handle.) name old time/op new time/op delta InliningFullScan/1000-8 5.89ms ± 0% 5.92ms ± 3% ~ (p=0.548 n=5+5) InliningFullScan/10000-8 65.8ms ± 2% 65.1ms ± 0% ~ (p=0.095 n=5+5) InliningFullScan/300000-8 2.06s ± 2% 2.07s ± 5% ~ (p=0.841 n=5+5) name old alloc/op new alloc/op delta InliningFullScan/1000-8 2.68MB ± 0% 2.68MB ± 0% +0.01% (p=0.008 n=5+5) InliningFullScan/10000-8 27.4MB ± 0% 27.4MB ± 0% +0.00% (p=0.008 n=5+5) InliningFullScan/300000-8 825MB ± 0% 825MB ± 0% ~ (p=0.087 n=5+5) name old allocs/op new allocs/op delta InliningFullScan/1000-8 81.0k ± 0% 81.0k ± 0% +0.01% (p=0.008 n=5+5) InliningFullScan/10000-8 810k ± 0% 810k ± 0% +0.00% (p=0.008 n=5+5) InliningFullScan/300000-8 24.3M ± 0% 24.3M ± 0% +0.00% (p=0.008 n=5+5) Fixes open-policy-agent#1069 Fixes open-policy-agent#653 Fixes open-policy-agent#1421 Fixes open-policy-agent#1417 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Expected Behavior
Given the following rules:
We expect the following when run:
Actual Behavior
We actually got:
Additional Info
After more tests, I find that if change rules to:
The
count
is removed from thesupport
:The text was updated successfully, but these errors were encountered: