18 Commits

Author SHA1 Message Date
Anders Eknert 30d3346fb4 New custom SemVer implementation (#8010)
This was something I originally intended to use in another project,
but since this turned out to be a better implementation (subject of
course to review!) in terms of both performance and simplicity, I
figured we might as well use it here too. Some changes include:

- `MustParse` to parse known valid versions
- Allocates nothing in any operations other than 1 alloc in `String()`
- Ignores empty `PreRelease` and `Metadata` fields in serialization
- `encoding.TextAppender` implementation to serialize without allocating
- A whole bunch of benchmarks

Signed-off-by: Anders Eknert <anders@eknert.com>
2025-11-04 09:09:50 +01:00
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 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
Torin Sandall 16fccc9a76 ast: extend capabilities to return min compatible version
This commit adds the ability to determine the minimum compatible OPA
version for a set of capabilities. This can be coupled with the
capabilities generated by the compiler to determine the min. compatible
version of a policy/bundle. The build has been extended to generate the
version index that lets us quickly check the required version for each
builtin/feature/keyword in the capabilities.

Signed-off-by: Torin Sandall <torin@styra.com>
2023-10-30 09:36:35 -07:00
Torin Sandall 3e6f747743 internal/bundle/inspect: add required capabilities to output
This commit adds the required capabilities ot the output of the inspect
operation. This allows users who are determined enough to lookup the
capabilities for the bundle. This is just the MVP so only the JSON
format will show the capabilities.

Signed-off-by: Torin Sandall <torin@styra.com>
2023-10-30 09:36:35 -07:00
Anders Eknert 3c6a237ab6 docs: ignore deprecated built-ins in reference (#5697)
Fixes #5607

Signed-off-by: Anders Eknert <anders@styra.com>
2023-02-24 17:27:45 +01:00
Stephan Renatus 21ac58bddc build/wasm: use golang1.16 go:embed mechanism (#5123)
With the embed directive, we no longer need our custom code that predates
Go 1.16. Also, with the release of 1.19, we no longer desire compatibility
with anything predating 1.16, so this cleanup becomes possible.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-09-12 17:42:44 +02:00
Anders Eknert 1e12cc2edf Add deprecated flag to all deprecated builtins (#5078)
Additionally, propagate deprecated status (if deprecated = true)
to the builtin_metadata.json file.

Fixes #5072

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-09-01 11:55:08 +02:00
Stephan Renatus 855c6bd44a ast/builtins: fix 'type_name' type and docs (#4920)
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-07-21 09:41:17 +02:00
Stephan Renatus d5b8a6130e release process: fix metadata logic (#4836)
We got 0.42.0 twice when version/version.go already was "0.42.0".

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-07-01 14:19:43 +02:00
Stephan Renatus 3f2f6fa93d build: omit empty descriptions of function args (#4810)
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-06-23 15:05:29 +02:00
Stephan Renatus e85190f156 genbuiltinmetadata: suppress known uncategorized builtins (#4803)
This will suppress the

    WARN: not categorized: type_name

lines that we expect.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-06-22 07:22:26 +02:00
Stephan Renatus 687beb7541 build: integrate builtin_metadata.json handling in release process (#4763)
Fixes #4754.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-06-20 10:57:17 +02:00
Stephan Renatus e8deba62bd types, ast, docs: Add support for named function arg declarations
This commit adds support for named argument declarations for built-in
functions as well as additional metadata/annotations on built-in
functions (e.g., descriptions, categories, etc.) This commit allows us
to generate a data file (builtin_metadata.json) that other tools can
consume to improve the Rego authoring experience.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>

Co-authored-by: Torin Sandall <torinsandall@gmail.com>
2022-05-24 09:38:07 -07:00
Stephan Renatus 57b2a713a1 genopawasm: only unpack wasm and callgraph bytes once (#3644)
The result will always be the same, and on multiple calls to
rego.New() with the wasm target, repeating this work can be
avoided.

A quick benchmark shows this in action, first main, then this
branch:

    BenchmarkWasmCompilation-16    	     133	   8345008 ns/op	 7521141 B/op	   28041 allocs/op
    BenchmarkWasmCompilation-16    	     256	   4529514 ns/op	 3666712 B/op	   27670 allocs/op

Once Go 1.17 is out and we can do something incompatible with
1.15, we can switch to using the go:embed directive instead.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-07-13 18:03:09 +02:00
Stephan Renatus 5a1ed9c7fa wasm: replace unused functions by stub (#3206)
We're in this situation: performing dead code analysis on wasm isn't too
hard, but it requires a representation of all wasm instructions: we'd need
to be able to parse the "runtime" wasm bits, i.e., what's built using llvm
from C code. When building upon that wasm module, we process the function
bodies uninterpreted -- they are all just `[]byte` to us.

This restriction lets us get by without implementing all the wasm
instructions -- we only write what we use, and read a bare minimum to work
as outlined above.

To still be able to remove dead code, this change employs a trick: at build
time, when the aforementioned runtime wasm module is compiled, we're calling
wasm-opt on it to extract its call graph. We'll use that, together with the
functions actually planned in our wasm compiler (using the subset of
instructions that we understand), to remove all unused functions from the
name section, and replace their function bodies with `unreachable`.

We cannot really remove them, since that would require reindexing all
functions; and we cannot do that without replacing the function indices at
their call sites in the "runtime" wasm module.

Another restriction to the impact of this approach is call_indirect: We
need to keep every function that's referenced in the table -- we don't know
which function might be calling them indirectly. In a follow-up, we could
record that information and use it to further reduce the code size: we know
that if none of the regex-related builtins are used, we could also stub out
the re2-related functions.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-03-11 10:25:16 +01:00
Torin Sandall 063f1f385d ast: Add capabilities struct and file generation
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-07-23 19:35:22 -04:00
Torin Sandall 90bda056b4 Add C library implementing operations for WASM
These changes add a C library that implements low-level data operations
and JSON parsing for WASM policies. The output of the WASM build process
are checked into the repository so that OPA can easily access the
bytecode for test and other purposes.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-08 17:29:18 -07:00