Skip to content

refactor: EvalContext struct to reduce parameter threading #4

Description

@dean0x

Problem

The evaluator function signatures thread 5 parameters across the codebase:

  • scope: &mut Scope
  • call_stack: &HashSet<String>
  • total_iterations: &mut u64
  • warnings: &mut Vec<String>
  • depth: usize

This parameter threading is error-prone and makes function signatures hard to read.

Solution

Bundle these into an EvalContext struct:

pub struct EvalContext {
    scope: &mut Scope,
    call_stack: &HashSet<String>,
    total_iterations: &mut u64,
    warnings: &mut Vec<String>,
    depth: usize,
}

Pass &mut EvalContext to all evaluator functions.

Files

  • src/evaluator.rs — Create struct and refactor signature threading

Benefits

  • Reduces function parameter count from 5+ to 1
  • Clearer intent (all evaluator state grouped logically)
  • Easier to add future context fields
  • Improves readability of evaluator call sites

Acceptance Criteria

  • EvalContext struct created in evaluator module
  • All evaluator functions refactored to use &mut EvalContext
  • Parameter threading reduced (verifiable through signature change)
  • All existing tests pass
  • No behavior change to evaluation semantics

Related Tech Debt

This is independent of but complements the HashSet→Vec call_stack refactoring (RUST-2).

Co-Authored-By: Claude noreply@anthropic.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions