Dsxir.Predictor.CodeExec.State (dsxir v0.3.0)

Copy Markdown

Accumulator for the Dsxir.Predictor.CodeExec.Engine reduce_while loop. Pure data. trajectory grows newest-last; each entry is one (code, outcome) attempt.

Summary

Functions

The most recent failed attempt, or nil if none have failed.

The Dune failure type to stamp on CodeExecutionError when the loop is exhausted: the shared type when every failure had the same type, else :max_iters.

Records a successful run: appends the entry, stores the result, sets done?.

Appends a failed attempt to the trajectory and bumps iter.

Types

entry()

@type entry() :: %{
  code: String.t(),
  error: String.t() | nil,
  type: atom() | nil,
  ok?: boolean()
}

result()

@type result() :: %{value: term(), inspected: String.t(), stdio: String.t()}

t()

@type t() :: %Dsxir.Predictor.CodeExec.State{
  code: String.t() | nil,
  done?: boolean(),
  iter: non_neg_integer(),
  result: result() | nil,
  trajectory: [entry()]
}

Functions

last_failure(state)

@spec last_failure(t()) :: entry() | nil

The most recent failed attempt, or nil if none have failed.

last_type(state)

@spec last_type(t()) :: atom()

The Dune failure type to stamp on CodeExecutionError when the loop is exhausted: the shared type when every failure had the same type, else :max_iters.

mark_success(state, code, result)

@spec mark_success(t(), String.t(), result()) :: t()

Records a successful run: appends the entry, stores the result, sets done?.

push_failure(state, code, error, type)

@spec push_failure(t(), String.t(), String.t(), atom()) :: t()

Appends a failed attempt to the trajectory and bumps iter.