air_script_core/trace.rs
1use super::Identifier;
2
3// TYPES
4// ================================================================================================
5pub type TraceSegment = u8;
6
7/// [IndexedTraceAccess] is used to represent accessing an element in the execution trace during
8/// constraint evaluation. The trace_segment specifies
9/// how many trace commitments have preceded the specified segment. `col_idx` specifies the index
10/// of the column within that trace segment, and `row_offset` specifies the offset from the current
11/// row. For example, an element in the "next" row of the "main" trace would be specified by
12/// a trace_segment of 0 and a row_offset of 1.
13#[derive(Debug, Eq, PartialEq, Clone, Copy)]
14pub struct IndexedTraceAccess {
15 trace_segment: TraceSegment,
16 col_idx: usize,
17 row_offset: usize,
18}
19
20impl IndexedTraceAccess {
21 pub fn new(trace_segment: TraceSegment, col_idx: usize, row_offset: usize) -> Self {
22 Self {
23 trace_segment,
24 col_idx,
25 row_offset,
26 }
27 }
28
29 /// Gets the trace segment of this [IndexedTraceAccess].
30 pub fn trace_segment(&self) -> TraceSegment {
31 self.trace_segment
32 }
33
34 /// Gets the column index of this [IndexedTraceAccess].
35 pub fn col_idx(&self) -> usize {
36 self.col_idx
37 }
38
39 /// Gets the row offset of this [IndexedTraceAccess].
40 pub fn row_offset(&self) -> usize {
41 self.row_offset
42 }
43}
44
45/// [NamedTraceAccess] is used to indicate a column in the trace by specifying its index within a
46/// set of trace columns with the given identifier. If the identifier refers to a single column
47/// then the index is always zero.
48#[derive(Debug, Clone, Eq, PartialEq)]
49pub struct NamedTraceAccess {
50 name: Identifier,
51 idx: usize,
52 row_offset: usize,
53}
54
55impl NamedTraceAccess {
56 pub fn new(name: Identifier, idx: usize, row_offset: usize) -> Self {
57 Self {
58 name,
59 idx,
60 row_offset,
61 }
62 }
63
64 pub fn name(&self) -> &str {
65 self.name.name()
66 }
67
68 pub fn idx(&self) -> usize {
69 self.idx
70 }
71
72 /// Gets the row offset of this [NamedTraceAccess].
73 pub fn row_offset(&self) -> usize {
74 self.row_offset
75 }
76}