evaluate_table

Function evaluate_table 

Source
pub fn evaluate_table(
    lib: &JSONEval,
    eval_key: &str,
    scope_data: &EvalData,
) -> Result<Vec<Value>, String>
Expand description

Sandboxed table evaluation for safe parallel execution

All heavy operations (dependency analysis, forward reference checks) are done at parse time. This function creates an isolated scope to prevent interference between parallel table evaluations.

§Parallel Safety

This function is designed for safe parallel execution:

  • Takes scope_data as an immutable reference (read-only parent scope)
  • Creates an isolated sandbox (clone) for all table-specific mutations
  • All temporary variables ($iteration, $threshold, column vars) exist only in the sandbox
  • The parent scope_data remains unchanged, preventing race conditions
  • Multiple tables can be evaluated concurrently without interference

§Mutation Safety

ALL data mutations go through EvalData methods:

  • sandbox.set() - sets field values with version tracking
  • sandbox.push_to_array() - appends to arrays with version tracking
  • sandbox.get_table_row_mut() - gets mutable row references (followed by mark_modified)
  • sandbox.mark_modified() - explicitly marks paths as modified

This ensures proper version tracking and mutation safety throughout evaluation.

§Sandboxing Strategy

  1. Clone scope_data to create an isolated sandbox at the start
  2. All evaluations and mutations happen within the sandbox via EvalData methods
  3. Extract the final table array from the sandbox
  4. Sandbox is dropped, discarding all temporary state
  5. Parent scope remains pristine and can be safely shared across threads