forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
planner: fix plan for 'every' (open-policy-agent#4346)
Before, we had been planing `every x in xs { BODY }` as, roughly, NOT SCAN xs NOT BODY This poses a problem: scans never fail -- they iterate _their_ bodies, and break out of their block when they are done iterating. As far as the NOT is concerned, it always looks like the SCAN was successful. We had worked around that for the "outer" SCAN by breaking out of the NOT's block at the end. However, the same trick can't be used when BODY contains another SCAN, since we can't tell beforehand how deeply we're nested, and doesn't know how far to break out again. So in this commit, we replace the NOTs by some custom "condition var" construct that works similar to how NOT gets compiled, but sets the "inner" condition variable when the BODY's plan succeeds. Likewise, the "outer" condition variable is tied to that result. We're practically using the condition variables to encode every x, y in xs { p(x,y) } ~> p(x1, y1) AND p(x2, y2) AND ... AND p(xn, yn) ~> NOT (NOT p(x1, y1) OR NOT p(x2, y2) OR ... OR NOT p(xn, yn)) The conditon variables are now implemented in the IR. (When using ir.NotStmt, they are an artifact of compiling the IR to wasm.) This is achieved by resetting a new local, and assigning it a dummy value (true) to signal the condition was met. ---- This path was taken because I could not come up with a way to deal with the "inner SCAN" situation just by using NOT blocks. The "outer" NOT/SCAN could perhaps be salvaged, but I found it easier to reason about one mechanism applied twice than to mix and match. Another abandoned path was using ir.ReturnLocalStmt in the query's plan iterator: while it worked well for simple cases, the problems considered were that we might do the wrong thing in nested sitations, like comprehensions. Also, it's not something we'd done in any other place. Signed-off-by: Stephan Renatus <[email protected]>
- Loading branch information
Showing
4 changed files
with
81 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# Exception Format is <test name>: <reason> | ||
"functions/default": "not supported in topdown, https://github.com/open-policy-agent/opa/issues/2445" | ||
"every/example every/some": "WIP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters