-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Possible regression for dynamic dispatch + nested comprehensions #2497
Comments
I did a little bit of bisecting and it seems to have been introduced in 4dd119b, but I haven't been able to dig into the root cause yet. |
So I realize what is happening -- the conditions around when an comprehension is
It is possible to safely evaluate the inner comprehension, since
However, if we do this, we change the semantics of the original code, since I think there are two possible directions I can look at for a fix:
|
@jaspervdj-luminal thanks for digging into this. I'll take a look today. |
@tsandall Thanks! I'm happy to help with the fix as well. Here is a case that makes it simpler to reproduce, since it turns out that
|
@jaspervdj-luminal I spent a little bit of time looking at the issue this afternoon. I agree with your assessment. When the comprehensions are evaluated to build the cache, the evaluator does not provide bindings for variables in the outer scope and the wrong value is produced for the nested comprehension. Modifying the evaluator to provide bindings for variables in the outer scope would be difficult as the caches would need to be invalidated if there were multiple assignments to the variables that are closed over. IMO, this precludes the second solution because the nested comprehension would have to evaluated with the correct binding whereas today we just evaluate the comprehensions because we should be able to assume it's safe to do so. This leaves the option of making the index identification step more strict. I think you've outlined it well though I think we could say intersection between candidates and any variable (not just outputs) in the nested comprehensions will disqualify. I can work on this tomorrow morning. Shouldn't be too difficult to fix. |
In v0.20. we added support for indexing and caching of comprehensions in certain cases. There was a bug in the index construction that allowed for comprehensions to be indexed and cached incorrectly. Specifically, if any of the candidate keys appear in nested comprehensions, indexing should not be performed because the evaluator does not close over variable bindings from the outer scope when evaluating the comprehension (because this would require cache invalidation if there were multiple assignments to the variables in the outer scope). This fix updates the compiler to check if the candidates appear inside of any nested comprehensions. If a match is found, no indexing is performed. Fixes open-policy-agent#2497 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
In v0.20. we added support for indexing and caching of comprehensions in certain cases. There was a bug in the index construction that allowed for comprehensions to be indexed and cached incorrectly. Specifically, if any of the candidate keys appear in nested comprehensions, indexing should not be performed because the evaluator does not close over variable bindings from the outer scope when evaluating the comprehension (because this would require cache invalidation if there were multiple assignments to the variables in the outer scope). This fix updates the compiler to check if the candidates appear inside of any nested comprehensions. If a match is found, no indexing is performed. Fixes #2497 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
In v0.20. we added support for indexing and caching of comprehensions in certain cases. There was a bug in the index construction that allowed for comprehensions to be indexed and cached incorrectly. Specifically, if any of the candidate keys appear in nested comprehensions, indexing should not be performed because the evaluator does not close over variable bindings from the outer scope when evaluating the comprehension (because this would require cache invalidation if there were multiple assignments to the variables in the outer scope). This fix updates the compiler to check if the candidates appear inside of any nested comprehensions. If a match is found, no indexing is performed. Fixes open-policy-agent#2497 Signed-off-by: Torin Sandall <torinsandall@gmail.com> (cherry picked from commit e9779eb)
In v0.20. we added support for indexing and caching of comprehensions in certain cases. There was a bug in the index construction that allowed for comprehensions to be indexed and cached incorrectly. Specifically, if any of the candidate keys appear in nested comprehensions, indexing should not be performed because the evaluator does not close over variable bindings from the outer scope when evaluating the comprehension (because this would require cache invalidation if there were multiple assignments to the variables in the outer scope). This fix updates the compiler to check if the candidates appear inside of any nested comprehensions. If a match is found, no indexing is performed. Fixes #2497 Signed-off-by: Torin Sandall <torinsandall@gmail.com> (cherry picked from commit e9779eb)
Expected Behavior
Through fugue/regula#51, I found a possible regression in
OPA 0.20 & 0.21. The test case involves using dynamic dispatch as well as nested
comprehensions. I've tried to reduce it as much as possible, but it's still somewhat
complex and seems to require the combination of these two features.
Using
opa-0.19.2
:This is the correct result.
Actual Behavior
Using
opa-0.21.0
:Steps to Reproduce the Problem
The following files were used in this bug:
Additional Info
It's late here so I didn't spend that much time debugging this. My intuition says that
there is some issue with
pkg
being considered a free variable in the nestedcomprehension. Fortunately the bug is easy to reproduce so I can easily figure
out where exactly the regression happened using
git bisect
. I'll try to take a lookat that next week.
The text was updated successfully, but these errors were encountered: