Commit Graph

7 Commits

Author SHA1 Message Date
Johan Fylling a179a24c48 v1 API
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>
2024-12-12 15:27:34 +01:00
Johan Fylling 7bb6dbe36b Preparing for v1 API
Moving (most) source to v1 root package to prepare for v0/v1 API separation.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:09:03 +01:00
Emre Savcı eb0fa70869 ast: add cap to array initialization when known (#5037)
This adds the cap where it's known for capabilities and VarSet.

Signed-off-by: Emre Savcı <emre.savci@trendyol.com>
2022-08-23 09:00:31 +02:00
Torin Sandall 0472ff45d2 ast: Add sort helper to VarSet
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2019-05-18 21:27:32 -07:00
Torin Sandall cf4f71b474 Add var walker helper 2016-11-20 20:25:42 -08:00
Torin Sandall 0decd227ab Add safety check on closures/array comprehensions
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.
2016-06-21 09:09:35 -07:00
Torin Sandall 480281741b Address PR comments
- 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.
2016-05-25 16:36:14 -07:00