All packages, except for `cmd` and `internal`, have been moved into a new `v1` root package.
Old packages are kept for backwards-compatibility reasons. All contained code is replaced with simple type aliases and proxy functions to `v1` implementations.
Old packages default to the Rego v0 syntax, new `v1` packages default to the Rego v1 syntax.
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
This change set does away with the old way of determining which variables are
outputs. Equality is now handled with special care. Outputs that would make a
variable safe by depending on another unsafe variable are no longer included.
As a result, the occurs check in the topdown implementation is no longer
needed. This change was introduced to handle odd cases involving
comprehensions, e.g., x = y, x = [ y | y = 1 ]. In this case, without exluding
unsafe vars, the query would evaluate with x/[1]. This would violate the
semantics, because in the comprehension y/1.
Also, fix bug in reordering whereby potentially unsafe expressions were added
to the reordered body multiple times. This occurred because the expression
would be added once when the preceeding expression made it safe and then again
once the outer loop got it. With the fix, we reprocess the body each time an
expression is added to the reordered body.
- Refactored the checkSafetyBody function
* Moved reordering into separate function with well defined interface.
* Replaced ad-hoc maps to track sets of Vars with VarSet.
* Added helper functions to get Vars on expressions, rules, etc. This
makes the re-ordering much clearer.
- Updated test cases for DFS and re-ordering.
- Added comment in DFSTraversal to help callers consider whether
the Visited state needs to be reset.
Also, fixed two separate bugs:
- When computing output variables in positions that unify recursively,
variable object keys should not be included (as the unification implementation
won't unify these.)
- When computing output variables, variables found in references (other than
the head) WILL be bound, so they should be included in the result. For
example:
> a = [1,2,3], a[i] != 2
In this case, "i" will be bound so it should be included in the output
variables for the expression.