mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
refactor(value): migrate Value::Object to Object storage abstraction (#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>
This commit is contained in:
committed by
GitHub
parent
bd90453dd3
commit
ed6ae465b0
@@ -544,16 +544,14 @@ fn make_context(case: &TestCase) -> Result<Value> {
|
||||
let map = ctx.as_object_mut()?;
|
||||
// Only inject if the caller didn't already provide requestContext
|
||||
// in the context object, to avoid clobbering custom test setups.
|
||||
map.entry(Value::from("requestContext")).or_insert(rc_val);
|
||||
map.get_or_insert_with(Value::from("requestContext"), || rc_val);
|
||||
} else if let Some(ref api_ver) = case.api_version {
|
||||
let map = ctx.as_object_mut()?;
|
||||
if let std::collections::btree_map::Entry::Vacant(e) =
|
||||
map.entry(Value::from("requestContext"))
|
||||
{
|
||||
if !map.contains_key(&Value::from("requestContext")) {
|
||||
let mut req_ctx = Value::new_object();
|
||||
let rc_map = req_ctx.as_object_mut()?;
|
||||
rc_map.insert(Value::from("apiVersion"), Value::from(api_ver.clone()));
|
||||
e.insert(req_ctx);
|
||||
map.insert(Value::from("requestContext"), req_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,3 +137,45 @@ cases:
|
||||
- "Return { value: 7 }" # Return result set
|
||||
want_result:
|
||||
set!: [1, null, 2]
|
||||
|
||||
# Set iteration resumes from `Bound::Excluded(current_item)`, so the
|
||||
# ComprehensionAdd path must snapshot the current value into
|
||||
# `IterationState::Set.current_item` before advancing — otherwise
|
||||
# iteration stops after the first element. This case exercises
|
||||
# Set-source comprehension end-to-end to lock that requirement in.
|
||||
- note: set_source_visits_all_elements
|
||||
description: Comprehension over a Set source must yield every element, not just the first
|
||||
example_rego: |
|
||||
src := {1, 2, 3, 4}
|
||||
{x | x := src[_]} # {1, 2, 3, 4}
|
||||
literals:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- 4
|
||||
instruction_params:
|
||||
comprehension_start_params:
|
||||
- mode: "Set"
|
||||
collection_reg: 0
|
||||
key_reg: 4
|
||||
value_reg: 5
|
||||
result_reg: 7
|
||||
body_start: 11
|
||||
comprehension_end: 13
|
||||
instructions:
|
||||
- "SetNew { dest: 0 }" # Build source set {1,2,3,4} in register 0
|
||||
- "Load { dest: 1, literal_idx: 0 }"
|
||||
- "SetAdd { set: 0, value: 1 }"
|
||||
- "Load { dest: 2, literal_idx: 1 }"
|
||||
- "SetAdd { set: 0, value: 2 }"
|
||||
- "Load { dest: 3, literal_idx: 2 }"
|
||||
- "SetAdd { set: 0, value: 3 }"
|
||||
- "Load { dest: 6, literal_idx: 3 }"
|
||||
- "SetAdd { set: 0, value: 6 }"
|
||||
- "SetNew { dest: 7 }" # Initialize result set
|
||||
- "ComprehensionStart { params_index: 0 }" # Iterate over Set source
|
||||
- "ComprehensionAdd { value_reg: 5 }" # Add current value to result
|
||||
- "Halt"
|
||||
- "Return { value: 7 }"
|
||||
want_result:
|
||||
set!: [1, 2, 3, 4]
|
||||
|
||||
Reference in New Issue
Block a user