feat(value): introduce Array storage abstraction - #63
Conversation
a76f04a to
2fe9ec2
Compare
|
@copilot Review this PR using all the review skills in this repo. Use a separate agent for each skill. |
There was a problem hiding this comment.
Pull request overview
Introduces a new value::Array storage abstraction (parallel to Object) with opaque iterator/cursor types, serde support, and an explicit lexicographic Ord, plus associated unit tests and several doctest fixes across the crate.
Changes:
- Added
src/value/array/module implementingArray, iterator newtypes, (feature-gated) cursor, and serde impls. - Added comprehensive
Arraytests tosrc/value/tests.rs. - Repaired multiple doctest imports/paths and an example target-loading snippet to keep
cargo test --doc --all-featuresworking.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/value/tests.rs | Adds unit tests covering Array constructors, mutation APIs, iteration, cursor (rvm), ordering, conversions, and serde. |
| src/value/mod.rs | Wires in the new array module and re-exports Array. |
| src/value/array/mod.rs | Core Array type and API surface, including ordering, indexing, and cursor iteration. |
| src/value/array/iter.rs | Opaque iterator newtypes and IntoIterator impls for Array and references. |
| src/value/array/serde.rs | Serialize/Deserialize implementations with allocator limit checks during decode. |
| src/schema/validate.rs | Updates doctest imports to use crate-root re-exports. |
| src/schema.rs | Adds missing doctest imports and updates example use paths. |
| src/engine.rs | Fixes a doctest indexing path into the AST JSON. |
| src/compiled_policy.rs | Fixes doctest target-loading by reading JSON then calling from_json_str. |
| docs/value/array.md | Adds documentation describing the new Array abstraction and its design goals. |
Here are the results from both review skills run in parallel:
|
872e582 to
05a1592
Compare
|
@copilot Review this PR using the skills in the repo. Use a separate agent for each skill. |
| `Array` wraps a `Vec<Value>` today but exposes only a curated method surface | ||
| (`get`, `get_mut`, `push`, `pop`, `insert`, `remove`, `iter`, `iter_mut`, | ||
| `cursor`, serde). The inner vector is private — callers cannot pattern-match it | ||
| or hand out mutable references to the backing store, so the backend can change | ||
| without churn at call sites that currently assume `Vec<Value>`. |
Completed. I ran separate agents for both repo review skills ( Validated findings:
Dropped during adversarial verification:
|
…rosoft#742) `run_opa_tests` builds `path_dir_str` from `path.strip_prefix(...).to_string_lossy()`, which on Windows yields strings with backslash separators (e.g. `v0\aggregates`). The folder filter then does an exact-string comparison against the CLI arguments: let run_test = folders.is_empty() || folders.iter().any(|f| &path_dir_str == f); CLI arguments use forward slashes (`v0/aggregates`), so on Windows the comparison never matches, no tests are selected, and the function bails with `"no matching tests found"`. This blocks the `cargo xtask pre-push` hook for any Windows contributor. Normalize `path_dir_str` to use forward slashes at construction time. Reproduces before the fix as `cargo test ... --test opa -- v1/aggregates` exiting 1 with `no matching tests found`; after the fix the same command runs 72 cases and the full hook command runs 2861 / 0 across 188 folders. The duplicate platform check at the `is_rego_v0_test` site (`path_dir_str.starts_with("v0/") || path_dir.starts_with("v0\\")`) is left intact to keep the change minimal — the backslash branch becomes redundant but is harmless. Co-authored-by: Mark Birger <markbirger@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…icrosoft#736) Builds on #57. Swap Value::Object's payload from Rc<BTreeMap<Value, Value>> to Rc<Object> and migrate all call sites to the Object API. as_object / as_object_mut keep their names but return &Object / &mut Object. The mutable accessor handles Rc::make_mut internally, so callers no longer do it themselves. Object grows into_value() and From<Object> for Value. Value's serializer now delegates to Object::serialize, dropping a duplicate non-string-key stringification path. RVM IterationState::Object is rewritten around ObjectCursor: O(log n) steps over a shared Rc<Object>, no eager pair snapshot. Snapshot independence is preserved by Rc copy-on-write; setup_next_iteration advances the cursor inline and advance() becomes a no-op for this variant. A new iteration_state_object_is_snapshot_independent_of_source test covers CoW against a mutated alias. Value::Set still wraps Rc<BTreeSet<Value>>; the matching Set abstraction and its swap ship in follow-up PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add an opaque `Array` newtype paralleling `Object`, living under `src/value/array/` with the same module structure (`mod.rs` / `iter.rs` / `serde.rs`). `Array` wraps `Vec<Value>` today but exposes only a curated surface: constructors, indexed access, push/pop/insert/ remove/truncate/sort/dedup/reverse, iteration, serde, conversion to `Value`, and a hand-written lexicographic `Ord`. The cursor type is re-exported behind the `rvm` feature so the follow-up `IterationState::Array` swap can land additively. No crate-root `Array` re-export is added; the new type lives under `regorus::value::Array`, matching the storage-abstraction namespace strategy for `Object` and `Set`. `Value::Array` is unchanged in this commit (still wraps `Rc<Vec<Value>>`); the payload swap and call-site migration ship in the next PR. Also repair pre-existing doctest examples that `cargo test --doc --all-features` exercises, so the required validation suite passes with this branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
05a1592 to
81ae161
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Addressed the outstanding Array foundation review items:
Commits:
Intentionally deferred: no Value::Array migration or removal of ergonomic Vec-like APIs in this foundation PR; the docs now call out that future backends may need to materialize those views. |
| clippy::as_conversions | ||
| )] // value helpers index paths directly for performance | ||
|
|
||
| pub mod array; |
|
@copilot Review this PR using all the review skills in this repo. Launch a separate agent for each skill. |
Ran both review skills with separate agents ( Findings:
Also noted test gaps for the memory-limit/error-path cases above in |
Addresses follow-up review on PR #63 plus our own strict re-review: - Drop the process-aborting Extend/FromIterator impls. They now match the Object convention: delegate directly to the inner container without consulting the cooperative memory limit (rely on the allocator to fail on true OOM). Limit-aware bulk insertion has explicit fallible methods. - Add Array::try_from_vec and Array::try_from_iter as the limit-aware alternatives to the From<Vec<Value>> / FromIterator pairs. - with_capacity now also consults check_memory_limit_if_needed after the inner try_reserve so capacity reservations cannot silently push usage past the cooperative ceiling. - insert now returns Result<()>: out-of-bounds and limit failures both flow through the same anyhow error channel. The limit case rolls back the inserted element so the array length is unchanged. - push and extend_from_slice roll back the pushed element(s) on a limit failure rather than leaving the array in a half-mutated state. - Make the array module itself private (was `pub mod array`); only `Array` (always) and `ArrayCursor` (rvm feature) are re-exported from `crate::value`. This matches the Object/ObjectCursor pattern and keeps the module layout out of the public API surface. - Rename the rvm-only Cursor type to ArrayCursor for symmetry with ObjectCursor and to disambiguate at the value-module level. - Update docs/value/array.md to reflect the private module, the ArrayCursor name, and the limit-enforcement contract. - Extend the test suite with try_from_vec, try_from_iter, and an insert out-of-bounds error case. Update existing insert call sites to the Result API. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Addressed the follow-up review pass (Copilot consolidated findings + line comment on Memory-limit correctness
API surface
Docs + tests
Commit: Gates green: fmt, clippy (default + all-features + wasm bindings), 627 lib tests with |
|
@copilot Review this PR using all the review skills in this repo. Launch a separate agent for each skill. |
Completed. I ran separate agents for both review skills ( Findings:
CI signal check: workflow run |
Adds an opaque
Arraynewtype parallelingObject, living undersrc/value/array/with the same module structure assrc/value/object/(mod.rs/iter.rs/serde.rs).ArraywrapsVec<Value>today but exposes only a curated surface: constructors, indexed access,first/last,push/pop,insert/remove,truncate,sort/sort_by,dedup,extend_from_slice,reverse,iter/iter_mut,cursor(resumable), serde, conversions toValue, and a hand-written lexicographicOrd. The cursor type is re-exported behind thervmfeature so the follow-upIterationState::Arrayswap can land additively.No crate-root
Arrayre-export is added; the new type lives underregorus::value::Array, matching the storage-abstraction namespace strategy forObjectandSet.Value::Arrayis unchanged in this PR (stillRc<Vec<Value>>); the payload swap and call-site migration ship in the next PR.Tests live in
src/value/tests.rsalongside the Object tests. This also repairs pre-existing doctest examples exercised bycargo test --doc --all-features, so the full requested validation suite passes.