Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm: Update planner to support with keyword
This change updates the planner to support the with keyword in Rego. When the planner encounters a with keyword it plans the statement value and then temporarily replaces the local referred to in the statement's target. While the statement is executing the plan sees the replaced value. Once the statement finishes and execution continues to the next statement, the local is restored. This change modifies how rules are planned to handle 'with' statements that apply to the 'data' document. Previously all rules were planned up-front in one-shot. This worked because the set of virtual documents visible to any given expression was static and would not change during planning. The 'with' keyword changes this because 'with' statements can be applied to the 'data' document that change set of virtual documents visible to the expression. To deal with this the planner has been updated to plan rules on-the-fly depth-first when references to virtual documents are encountered. On top of this, the planner will re-plan rules when 'with' statements against the 'data' document are encountered. This approach was taken because while it increases the size of the generated plan it keeps evaluation relatively simple: we don't have to propagate context through the call stack to determine whether a with modifier is in-place before executing call statements. The other part of the planner implementation that was modified is the trie that stores rules. The planned functions have been moved out of the trie and are simply stored on the policy plan/result and the mapping from virtual document path to function name has been moved into a separate structure (funcstack). This change was made simplify the data structures and improve maintainability. This change can be revisited in the future if needed without any impact on generated plans. Fixes #1116 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
- Loading branch information