Skip to content

Commit

Permalink
refactor: add trace_len_summary to VmStateIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Oct 10, 2023
1 parent 4afbbe8 commit 4e953d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 52 deletions.
5 changes: 2 additions & 3 deletions miden/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ where
.map_err(ProgramError::AssemblyError)?;
let mut execution_details = ExecutionDetails::default();

let (vm_state_iterator, trace_len_summary) =
processor::execute_iter_with_trace_len(&program, stack_inputs, host);
execution_details.set_trace_len_summary(&trace_len_summary);
let vm_state_iterator = processor::execute_iter(&program, stack_inputs, host);
execution_details.set_trace_len_summary(vm_state_iterator.trace_len_summary());

for state in vm_state_iterator {
let vm_state = state.map_err(ProgramError::ExecutionError)?;
Expand Down
33 changes: 8 additions & 25 deletions processor/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,11 @@ pub struct VmStateIterator {
clk: u32,
asmop_idx: usize,
forward: bool,
trace_len_summary: TraceLenSummary,
}

impl VmStateIterator {
pub(super) fn new<H>(process: Process<H>, result: Result<StackOutputs, ExecutionError>) -> Self
where
H: Host,
{
let (system, decoder, stack, _, chiplets, _) = process.into_parts();
Self {
chiplets,
decoder,
stack,
system,
error: result.err(),
clk: 0,
asmop_idx: 0,
forward: true,
}
}

/// Returns a new instance of [VmStateIterator] together with [TraceLenSummary].
pub(super) fn new_with_trace_len<H>(
process: Process<H>,
result: Result<StackOutputs, ExecutionError>,
) -> (Self, TraceLenSummary)
where
H: Host,
{
Expand All @@ -93,7 +73,7 @@ impl VmStateIterator {
let trace_len_summary =
TraceLenSummary::new(clk as usize, range_table_len, ChipletsLengths::new(&chiplets));

let state_iterator = Self {
Self {
chiplets,
decoder,
stack,
Expand All @@ -102,9 +82,8 @@ impl VmStateIterator {
clk: 0,
asmop_idx: 0,
forward: true,
};

(state_iterator, trace_len_summary)
trace_len_summary,
}
}

/// Returns the asm op info corresponding to this vm state and whether this is the start of
Expand Down Expand Up @@ -203,6 +182,10 @@ impl VmStateIterator {
pub fn into_parts(self) -> (System, Decoder, Stack, Chiplets, Option<ExecutionError>) {
(self.system, self.decoder, self.stack, self.chiplets, self.error)
}

pub fn trace_len_summary(&self) -> &TraceLenSummary {
&self.trace_len_summary
}
}

impl Iterator for VmStateIterator {
Expand Down
24 changes: 0 additions & 24 deletions processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,6 @@ where
VmStateIterator::new(process, result)
}

/// Returns a tuple with VM state iterator and trace lengths summary.
pub fn execute_iter_with_trace_len<H>(
program: &Program,
stack_inputs: StackInputs,
host: H,
) -> (VmStateIterator, TraceLenSummary)
where
H: Host,
{
let mut process = Process::new_debug(program.kernel().clone(), stack_inputs, host);
let stack_outputs = process.execute(program);
if stack_outputs.is_ok() {
assert_eq!(
program.hash(),
process.decoder.program_hash().into(),
"inconsistent program hash"
);
}
let (state_iterator, trace_len_summary) =
VmStateIterator::new_with_trace_len(process, stack_outputs);

(state_iterator, trace_len_summary)
}

// PROCESS
// ================================================================================================

Expand Down

0 comments on commit 4e953d3

Please sign in to comment.