@@ -17,11 +17,7 @@ use crate::witgen::{
17
17
data_structures:: identity:: Identity , jit:: variable:: MachineCallVariable , FixedData ,
18
18
} ;
19
19
20
- use super :: {
21
- prover_function_heuristics:: ProverFunction ,
22
- variable:: Variable ,
23
- witgen_inference:: { Assignment , VariableOrValue } ,
24
- } ;
20
+ use super :: { prover_function_heuristics:: ProverFunction , variable:: Variable } ;
25
21
26
22
/// Keeps track of identities that still need to be processed and
27
23
/// updates this list based on the occurrence of updated variables
@@ -35,20 +31,9 @@ pub struct IdentityQueue<'a, T: FieldElement> {
35
31
impl < ' a , T : FieldElement > IdentityQueue < ' a , T > {
36
32
pub fn new (
37
33
fixed_data : & ' a FixedData < ' a , T > ,
38
- identities : & [ ( & ' a Identity < T > , i32 ) ] ,
39
- assignments : & [ Assignment < ' a , T > ] ,
40
- prover_functions : & [ ( ProverFunction < ' a , T > , i32 ) ] ,
34
+ items : impl IntoIterator < Item = QueueItem < ' a , T > > ,
41
35
) -> Self {
42
- let queue: BTreeSet < _ > = identities
43
- . iter ( )
44
- . map ( |( id, row) | QueueItem :: Identity ( id, * row) )
45
- . chain ( assignments. iter ( ) . map ( |a| QueueItem :: Assignment ( a. clone ( ) ) ) )
46
- . chain (
47
- prover_functions
48
- . iter ( )
49
- . map ( |( p, row) | QueueItem :: ProverFunction ( p. clone ( ) , * row) ) ,
50
- )
51
- . collect ( ) ;
36
+ let queue: BTreeSet < _ > = items. into_iter ( ) . collect ( ) ;
52
37
let mut references = ReferencesComputer :: new ( fixed_data) ;
53
38
let occurrences = Rc :: new (
54
39
queue
@@ -93,25 +78,50 @@ impl<'a, T: FieldElement> IdentityQueue<'a, T> {
93
78
#[ derive( Clone ) ]
94
79
pub enum QueueItem < ' a , T : FieldElement > {
95
80
Identity ( & ' a Identity < T > , i32 ) ,
96
- Assignment ( Assignment < ' a , T > ) ,
81
+ VariableAssignment ( VariableAssignment < ' a , T > ) ,
82
+ ConstantAssignment ( ConstantAssignment < ' a , T > ) ,
97
83
ProverFunction ( ProverFunction < ' a , T > , i32 ) ,
98
84
}
99
85
100
- /// Sorts identities by row and then by ID, preceded by assignments.
101
86
impl < T : FieldElement > Ord for QueueItem < ' _ , T > {
102
87
fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
103
88
match ( self , other) {
104
89
( QueueItem :: Identity ( id1, row1) , QueueItem :: Identity ( id2, row2) ) => {
105
90
( row1, id1. id ( ) ) . cmp ( & ( row2, id2. id ( ) ) )
106
91
}
107
- ( QueueItem :: Assignment ( a1) , QueueItem :: Assignment ( a2) ) => a1. cmp ( a2) ,
92
+ ( QueueItem :: VariableAssignment ( a1) , QueueItem :: VariableAssignment ( a2) ) => a1. cmp ( a2) ,
93
+ ( QueueItem :: ConstantAssignment ( a1) , QueueItem :: ConstantAssignment ( a2) ) => a1. cmp ( a2) ,
108
94
( QueueItem :: ProverFunction ( p1, row1) , QueueItem :: ProverFunction ( p2, row2) ) => {
109
95
( row1, p1. index ) . cmp ( & ( row2, p2. index ) )
110
96
}
111
- ( QueueItem :: Assignment ( ..) , _) => std:: cmp:: Ordering :: Less ,
112
- ( QueueItem :: Identity ( ..) , QueueItem :: Assignment ( ..) ) => std:: cmp:: Ordering :: Greater ,
113
- ( QueueItem :: Identity ( ..) , QueueItem :: ProverFunction ( ..) ) => std:: cmp:: Ordering :: Less ,
114
- ( QueueItem :: ProverFunction ( ..) , _) => std:: cmp:: Ordering :: Greater ,
97
+ ( a, b) => a. order ( ) . cmp ( & b. order ( ) ) ,
98
+ }
99
+ }
100
+ }
101
+
102
+ impl < ' a , T : FieldElement > QueueItem < ' a , T > {
103
+ pub fn constant_assignment ( lhs : & ' a Expression < T > , rhs : T , row_offset : i32 ) -> Self {
104
+ QueueItem :: ConstantAssignment ( ConstantAssignment {
105
+ lhs,
106
+ row_offset,
107
+ rhs,
108
+ } )
109
+ }
110
+
111
+ pub fn variable_assignment ( lhs : & ' a Expression < T > , rhs : Variable , row_offset : i32 ) -> Self {
112
+ QueueItem :: VariableAssignment ( VariableAssignment {
113
+ lhs,
114
+ row_offset,
115
+ rhs,
116
+ } )
117
+ }
118
+
119
+ fn order ( & self ) -> u32 {
120
+ match self {
121
+ QueueItem :: ConstantAssignment ( ..) => 0 ,
122
+ QueueItem :: VariableAssignment ( ..) => 1 ,
123
+ QueueItem :: Identity ( ..) => 2 ,
124
+ QueueItem :: ProverFunction ( ..) => 3 ,
115
125
}
116
126
}
117
127
}
@@ -130,6 +140,24 @@ impl<T: FieldElement> PartialEq for QueueItem<'_, T> {
130
140
131
141
impl < T : FieldElement > Eq for QueueItem < ' _ , T > { }
132
142
143
+ /// An equality constraint between an algebraic expression evaluated
144
+ /// on a certain row offset and a variable.
145
+ #[ derive( Clone , Ord , PartialOrd , Eq , PartialEq , Debug ) ]
146
+ pub struct VariableAssignment < ' a , T : FieldElement > {
147
+ pub lhs : & ' a Expression < T > ,
148
+ pub row_offset : i32 ,
149
+ pub rhs : Variable ,
150
+ }
151
+
152
+ /// An equality constraint between an algebraic expression evaluated
153
+ /// on a certain row offset and a constant.
154
+ #[ derive( Clone , Ord , PartialOrd , Eq , PartialEq , Debug ) ]
155
+ pub struct ConstantAssignment < ' a , T : FieldElement > {
156
+ pub lhs : & ' a Expression < T > ,
157
+ pub row_offset : i32 ,
158
+ pub rhs : T ,
159
+ }
160
+
133
161
/// Utility to compute the variables that occur in a queue item.
134
162
/// Follows intermediate column references and employs caches.
135
163
struct ReferencesComputer < ' a , T : FieldElement > {
@@ -171,17 +199,14 @@ impl<'a, T: FieldElement> ReferencesComputer<'a, T> {
171
199
) ,
172
200
Identity :: Connect ( ..) => Box :: new ( std:: iter:: empty ( ) ) ,
173
201
} ,
174
- QueueItem :: Assignment ( a) => {
175
- let vars_in_rhs = match & a. rhs {
176
- VariableOrValue :: Variable ( v) => Some ( v. clone ( ) ) ,
177
- VariableOrValue :: Value ( _) => None ,
178
- } ;
179
- Box :: new (
180
- self . variables_in_expression ( a. lhs , a. row_offset )
181
- . into_iter ( )
182
- . chain ( vars_in_rhs) ,
183
- )
184
- }
202
+ QueueItem :: ConstantAssignment ( a) => Box :: new (
203
+ self . variables_in_expression ( a. lhs , a. row_offset )
204
+ . into_iter ( ) ,
205
+ ) ,
206
+ QueueItem :: VariableAssignment ( a) => Box :: new (
207
+ std:: iter:: once ( a. rhs . clone ( ) )
208
+ . chain ( self . variables_in_expression ( a. lhs , a. row_offset ) ) ,
209
+ ) ,
185
210
QueueItem :: ProverFunction ( p, row) => Box :: new (
186
211
p. condition
187
212
. iter ( )
0 commit comments