18 Commits

Author SHA1 Message Date
Anders Eknert e43ef0a979 Use any in place of interface{} (#7566)
Earlier this evening I tried to run the Go
[modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize)
analyzer on OPA. That didn't go as planned:

- https://github.com/golang/go/issues/73661
- https://github.com/golang/go/issues/73663

While we wait for that to be fixed, I figured an old-fashioned
search-and-replace across the repo may work for at least the
`interface{}` to `any` conversion. That should help make it easier
to see the other fixes as applied by the modernize tool once it has
had those issues resolved.

Signed-off-by: Anders Eknert <anders@styra.com>
2025-05-12 13:57:48 +02:00
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
Stephan Renatus 20885fe4a9 golangci: bump version, addess all new findings
The previous version has been failing without any good reason for me,
so let's try this.

About the version pick: It's not the latest version (v1.62.0 at the
moment), because that would introduce a new revive rule,
redeclares-builtin-id, and that flags every variable called `min` or
`max` in the code base. I had started addressing these, but they were
just too many.

The new issues related to this version are mostly that it complains
whenever it finds a non-static string that makes its way into a printf-
like function. However, that's a common pattern in some place here, so
I've sprinkled some nolint:govet on it.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2024-11-14 20:36:50 +01:00
Johan Fylling 3a55bc8f63 rego-v1: Future-proofing dependencies pkg tests to be 1.0 compatible (#7018)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-09-13 18:04:07 +02:00
Johan Fylling e7e5b6bbfb deps: Improving deps command performance (#6688)
Improving memory footprint and execution time of deps command for policies with high dependency connectivity.

Fixes: #6685
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-04-09 19:24:37 +02:00
Anders Eknert 50d4e31d6b chore: Use t.Setenv in tests (#5321)
And enable the `tenv` linter for the future.

Also, bump version of golangci-lint and fix some new
warnings that came from that.

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-10-27 17:44:56 +02:00
Abirdcfly 520423961e fix minor code unreachability error (#4919)
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
2022-07-21 19:39:08 +02:00
Teemu Koponen a6724c7456 ast: Use pointer receivers with Array.
This is to allow future mutating functions: with value receivers this
mutating any of the member variables is not possible.

Signed-off-by: Teemu Koponen <koponen@styra.com>
2020-08-03 13:36:33 -04:00
Teemu Koponen 98119fc00c ast: Introduce Array struct.
This decouples the consumers of the Array from its implementation, and
thus, paves the way for improved (more optimized) Array
operations. Note, the array memory foot print and the allocations
required with the array operations remain the same.

Signed-off-by: Teemu Koponen <koponen@styra.com>
2020-08-03 13:36:33 -04:00
Teemu Koponen 53fe0db108 dependencies: resolveRemainingVars incorrectly does not skip the refs.
In iterating the refs, the skipping state was not resetted between
iterations.

This is an unintended regression of
c44f3d714c.

Signed-off-by: Teemu Koponen <koponen@styra.com>
2020-02-11 15:25:39 -05:00
Teemu Koponen c44f3d714c ast: Generic/BeforeAfter/Var Visitor specific Walk implementations.
Unlike the generic Walk implementations, they don't necessitate
allocating the visitor itself from heap.

This deprecates ast.Visitor, ast.BeforeAndAfterVisitor, ast.Walk, and
ast.WalkBeforeAndAfter.

Benchmarks changed:

name                                  old time/op    new time/op    delta
PartialEval/1-16                        6.41µs ± 1%    6.35µs ± 1%   -1.01%  (p=0.001 n=10+10)
PartialEval/10-16                       6.47µs ± 1%    6.37µs ± 1%   -1.48%  (p=0.000 n=10+10)
PartialEval/100-16                      6.81µs ± 1%    6.78µs ± 1%   -0.44%  (p=0.041 n=9+10)
PartialEval/1000-16                     6.64µs ± 2%    6.57µs ± 2%   -1.02%  (p=0.037 n=10+10)
PartialEvalCompile/1-16                 3.08ms ± 0%    2.99ms ± 0%   -2.73%  (p=0.000 n=8+9)
PartialEvalCompile/10-16                4.17ms ± 0%    3.97ms ± 1%   -4.67%  (p=0.000 n=9+9)
PartialEvalCompile/100-16               25.1ms ± 1%    22.9ms ± 1%   -8.67%  (p=0.000 n=9+10)
PartialEvalCompile/1000-16               1.27s ± 2%     1.20s ± 1%   -5.37%  (p=0.000 n=10+9)
InliningFullScan/1000-16                5.24ms ± 1%    4.83ms ± 1%   -7.75%  (p=0.000 n=10+10)
InliningFullScan/10000-16               55.0ms ± 0%    51.0ms ± 1%   -7.25%  (p=0.000 n=9+10)
InliningFullScan/300000-16               1.59s ± 1%     1.48s ± 1%   -6.63%  (p=0.000 n=9+9)

name                                  old alloc/op   new alloc/op   delta
Concurrency1-16                          100MB ± 0%     100MB ± 0%   -0.05%  (p=0.000 n=10+10)
Concurrency2-16                          100MB ± 0%     100MB ± 0%   -0.05%  (p=0.000 n=10+10)
Concurrency4-16                          100MB ± 0%     100MB ± 0%   -0.05%  (p=0.000 n=9+10)
Concurrency8-16                          100MB ± 0%     100MB ± 0%   -0.05%  (p=0.000 n=10+10)
Concurrency4Readers1Writer-16            100MB ± 0%     100MB ± 0%   -0.05%  (p=0.000 n=10+10)
Concurrency8Writers-16                   100MB ± 0%     100MB ± 0%   -0.05%  (p=0.000 n=10+10)
PartialEvalCompile/1-16                 1.31MB ± 0%    1.29MB ± 0%   -1.10%  (p=0.000 n=8+9)
PartialEvalCompile/10-16                1.74MB ± 0%    1.70MB ± 0%   -2.42%  (p=0.000 n=9+10)
PartialEvalCompile/100-16               8.90MB ± 0%    8.58MB ± 0%   -3.58%  (p=0.000 n=10+9)
PartialEvalCompile/1000-16               370MB ± 0%     366MB ± 0%   -0.84%  (p=0.000 n=9+9)
Walk/100-16                              361kB ± 0%     360kB ± 0%   -0.32%  (p=0.000 n=10+10)
Walk/1000-16                             413kB ± 0%     412kB ± 0%   -0.28%  (p=0.000 n=10+10)
Walk/2000-16                             471kB ± 0%     470kB ± 0%   -0.24%  (p=0.000 n=10+10)
Walk/3000-16                             527kB ± 0%     526kB ± 0%   -0.22%  (p=0.000 n=9+10)
InliningFullScan/1000-16                2.77MB ± 0%    2.68MB ± 0%   -3.18%  (p=0.000 n=9+10)
InliningFullScan/10000-16               28.2MB ± 0%    27.4MB ± 0%   -3.12%  (p=0.000 n=10+10)
InliningFullScan/300000-16               852MB ± 0%     825MB ± 0%   -3.10%  (p=0.000 n=10+9)

Signed-off-by: Teemu Koponen <koponen@styra.com>
2020-01-22 18:32:54 -05:00
Torin Sandall d402be9dc7 Update analysis to mark input as base document
Refs against the input root document were not being considered "base
document" refs. These changes update the analysis to treat all of the
root documents (i.e., input and data) as "base documents" by default.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-08-21 10:47:46 -07:00
Stephan Renatus 2f1526c672 fix misspell
Signed-off-by: Stephan Renatus <srenatus@chef.io>
2018-06-05 09:50:13 -07:00
Torin Sandall 61823a2920 Refactor set and object types in ast package
Previously, sets and objects were not interfaces and as a result,
callers were relying on the underlying structure for operations such as
iteration.

These changes refactor the ast package to expose sets and objects as
interfaces so that we can change the underlying data structures without
affecting callers.
2017-12-15 09:16:34 -08:00
Torin Sandall 3ebbeede6c Refactor topdown evaluation/unification
These changes modify topdown evaluation to use a binding list that
namespaces variables. This allows topdown to propagate partially ground
ref operands into child query evaluation.

These changes also prepare topdown evaluation to support a partial
evaluation mode.

With these changes, evaluation is no longer performed in two steps
(i.e., first pass of evaluating individual terms, second pass of
evaluating built-in expressions.) Instead, evaluation assumes queries
have been rewritten to eagerly evaluate refs and comprehension. This
way, ref and comprehension bindings do not have to be maintained
separately: they are handled by the normal variable binding list.

This commit contains some breaking changes to the topdown APIs,
namely...

1. Truth explanation has been removed. This feature was not used and the
tracing changes broke it. We can revisit in future if necessary.

2. Data indexing has been removed. Data indexing can be re-added in
future if necessary however it should be handled outside of topdown to
avoid potential memory leaks.

3. Built-in functions produce at-most-one output now. Functions that
used to produce multiple outputs (e.g., io.jwt.decode) can produce a
composite value if they need to.

Fixes #131
2017-11-09 09:07:48 -08:00
Matthew Mussomele 2de81f07c0 Refactor dependencies package to support Base and Virtual deps 2017-07-25 14:21:02 -07:00
Matthew Mussomele f5956ba34f Implement dependency analysis package for AST elements 2017-07-20 17:07:51 -07:00