@@ -48,17 +48,20 @@ impl<'a, T: FieldElement> BlockMachineProcessor<'a, T> {
48
48
}
49
49
}
50
50
51
- /// Generates the JIT code for a given combination of connection and known arguments.
51
+ /// Generates the JIT code for a given combination of bus and known arguments.
52
52
/// Fails if it cannot solve for the outputs, or if any sub-machine calls cannot be completed.
53
53
pub fn generate_code (
54
54
& self ,
55
55
can_process : impl CanProcessCall < T > ,
56
- identity_id : u64 ,
56
+ bus_id : T ,
57
57
known_args : & BitVec ,
58
58
known_concrete : Option < ( usize , T ) > ,
59
59
) -> Result < ( ProcessorResult < T > , Vec < ProverFunction < ' a , T > > ) , String > {
60
- let connection = self . machine_parts . connections [ & identity_id] ;
61
- assert_eq ! ( connection. right. expressions. len( ) , known_args. len( ) ) ;
60
+ let bus_receive = self . machine_parts . bus_receives [ & bus_id] ;
61
+ assert_eq ! (
62
+ bus_receive. selected_payload. expressions. len( ) ,
63
+ known_args. len( )
64
+ ) ;
62
65
63
66
// Set up WitgenInference with known arguments.
64
67
let known_variables = known_args
@@ -73,7 +76,7 @@ impl<'a, T: FieldElement> BlockMachineProcessor<'a, T> {
73
76
let mut queue_items = vec ! [ ] ;
74
77
75
78
// In the latch row, set the RHS selector to 1.
76
- let selector = & connection . right . selector ;
79
+ let selector = & bus_receive . selected_payload . selector ;
77
80
queue_items. push ( QueueItem :: constant_assignment (
78
81
selector,
79
82
T :: one ( ) ,
@@ -83,15 +86,15 @@ impl<'a, T: FieldElement> BlockMachineProcessor<'a, T> {
83
86
if let Some ( ( index, value) ) = known_concrete {
84
87
// Set the known argument to the concrete value.
85
88
queue_items. push ( QueueItem :: constant_assignment (
86
- & connection . right . expressions [ index] ,
89
+ & bus_receive . selected_payload . expressions [ index] ,
87
90
value,
88
91
self . latch_row as i32 ,
89
92
) ) ;
90
93
}
91
94
92
95
// Set all other selectors to 0 in the latch row.
93
- for other_connection in self . machine_parts . connections . values ( ) {
94
- let other_selector = & other_connection . right . selector ;
96
+ for other_receive in self . machine_parts . bus_receives . values ( ) {
97
+ let other_selector = & other_receive . selected_payload . selector ;
95
98
if other_selector != selector {
96
99
queue_items. push ( QueueItem :: constant_assignment (
97
100
other_selector,
@@ -102,7 +105,7 @@ impl<'a, T: FieldElement> BlockMachineProcessor<'a, T> {
102
105
}
103
106
104
107
// For each argument, connect the expression on the RHS with the formal parameter.
105
- for ( index, expr) in connection . right . expressions . iter ( ) . enumerate ( ) {
108
+ for ( index, expr) in bus_receive . selected_payload . expressions . iter ( ) . enumerate ( ) {
106
109
queue_items. push ( QueueItem :: variable_assignment (
107
110
expr,
108
111
Variable :: Param ( index) ,
@@ -175,14 +178,14 @@ impl<'a, T: FieldElement> BlockMachineProcessor<'a, T> {
175
178
. generate_code ( can_process, witgen)
176
179
. map_err ( |e| {
177
180
let err_str = e. to_string_with_variable_formatter ( |var| match var {
178
- Variable :: Param ( i) => format ! ( "{} (connection param)" , & connection . right . expressions[ * i] ) ,
181
+ Variable :: Param ( i) => format ! ( "{} (receive param)" , & bus_receive . selected_payload . expressions[ * i] ) ,
179
182
_ => var. to_string ( ) ,
180
183
} ) ;
181
- log:: trace!( "\n Code generation failed for connection :\n {connection }" ) ;
184
+ log:: trace!( "\n Code generation failed for bus receive :\n {bus_receive }" ) ;
182
185
let known_args_str = known_args
183
186
. iter ( )
184
187
. enumerate ( )
185
- . filter_map ( |( i, b) | b. then_some ( connection . right . expressions [ i] . to_string ( ) ) )
188
+ . filter_map ( |( i, b) | b. then_some ( bus_receive . selected_payload . expressions [ i] . to_string ( ) ) )
186
189
. join ( "\n " ) ;
187
190
log:: trace!( "Known arguments:\n {known_args_str}" ) ;
188
191
log:: trace!( "Error:\n {err_str}" ) ;
@@ -306,7 +309,7 @@ fn written_rows_per_column<T: FieldElement>(
306
309
} )
307
310
}
308
311
309
- /// Returns, for each bus send ID, the collection of row offsets that have a machine call
312
+ /// Returns, for each bus send *identity* ID, the collection of row offsets that have a machine call
310
313
/// and if in all the calls or that row, all the arguments are known.
311
314
/// Combines calls from branches.
312
315
fn completed_rows_for_bus_send < T : FieldElement > (
@@ -330,21 +333,18 @@ fn fully_known_call<T: FieldElement>(e: &Effect<T, Variable>) -> bool {
330
333
}
331
334
}
332
335
333
- /// Returns all machine calls (bus identity and row offset) found in the effect.
336
+ /// Returns all machine calls (bus send identity ID and row offset) found in the effect.
334
337
/// Recurses into branches.
335
338
fn machine_calls < T : FieldElement > (
336
339
e : & Effect < T , Variable > ,
337
340
) -> Box < dyn Iterator < Item = ( u64 , i32 , & Effect < T , Variable > ) > + ' _ > {
338
341
match e {
339
- Effect :: MachineCall ( id , _, arguments) => match & arguments[ 0 ] {
342
+ Effect :: MachineCall ( _ , _, arguments) => match & arguments[ 0 ] {
340
343
Variable :: MachineCallParam ( MachineCallVariable {
341
344
identity_id,
342
345
row_offset,
343
346
..
344
- } ) => {
345
- assert_eq ! ( * id, * identity_id) ;
346
- Box :: new ( std:: iter:: once ( ( * identity_id, * row_offset, e) ) )
347
- }
347
+ } ) => Box :: new ( std:: iter:: once ( ( * identity_id, * row_offset, e) ) ) ,
348
348
_ => panic ! ( "Expected machine call variable." ) ,
349
349
} ,
350
350
Effect :: Branch ( _, first, second) => {
@@ -420,8 +420,8 @@ mod test {
420
420
panic ! ( "Expected exactly one matching block machine" )
421
421
} ;
422
422
let ( machine_parts, block_size, latch_row) = machine. machine_info ( ) ;
423
- assert_eq ! ( machine_parts. connections . len( ) , 1 ) ;
424
- let connection_id = * machine_parts. connections . keys ( ) . next ( ) . unwrap ( ) ;
423
+ assert_eq ! ( machine_parts. bus_receives . len( ) , 1 ) ;
424
+ let bus_id = * machine_parts. bus_receives . keys ( ) . next ( ) . unwrap ( ) ;
425
425
let processor = BlockMachineProcessor {
426
426
fixed_data : & fixed_data,
427
427
machine_parts : machine_parts. clone ( ) ,
@@ -440,7 +440,7 @@ mod test {
440
440
) ;
441
441
442
442
processor
443
- . generate_code ( & mutable_state, connection_id , & known_values, None )
443
+ . generate_code ( & mutable_state, bus_id , & known_values, None )
444
444
. map ( |( result, _) | result)
445
445
}
446
446
@@ -549,18 +549,18 @@ assert (main_binary::B[1] & 0xffffffffffff0000) == 0;
549
549
call_var(9, 0, 2) = main_binary::B_byte[0];
550
550
main_binary::B_byte[-1] = main_binary::B[0];
551
551
call_var(9, -1, 2) = main_binary::B_byte[-1];
552
- machine_call(9 , [Known(call_var(9, -1, 0)), Known(call_var(9, -1, 1)), Known(call_var(9, -1, 2)), Unknown(call_var(9, -1, 3))]);
552
+ machine_call(2 , [Known(call_var(9, -1, 0)), Known(call_var(9, -1, 1)), Known(call_var(9, -1, 2)), Unknown(call_var(9, -1, 3))]);
553
553
main_binary::C_byte[-1] = call_var(9, -1, 3);
554
554
main_binary::C[0] = main_binary::C_byte[-1];
555
- machine_call(9 , [Known(call_var(9, 0, 0)), Known(call_var(9, 0, 1)), Known(call_var(9, 0, 2)), Unknown(call_var(9, 0, 3))]);
555
+ machine_call(2 , [Known(call_var(9, 0, 0)), Known(call_var(9, 0, 1)), Known(call_var(9, 0, 2)), Unknown(call_var(9, 0, 3))]);
556
556
main_binary::C_byte[0] = call_var(9, 0, 3);
557
557
main_binary::C[1] = (main_binary::C[0] + (main_binary::C_byte[0] * 256));
558
- machine_call(9 , [Known(call_var(9, 1, 0)), Known(call_var(9, 1, 1)), Known(call_var(9, 1, 2)), Unknown(call_var(9, 1, 3))]);
558
+ machine_call(2 , [Known(call_var(9, 1, 0)), Known(call_var(9, 1, 1)), Known(call_var(9, 1, 2)), Unknown(call_var(9, 1, 3))]);
559
559
main_binary::C_byte[1] = call_var(9, 1, 3);
560
560
main_binary::C[2] = (main_binary::C[1] + (main_binary::C_byte[1] * 65536));
561
561
main_binary::operation_id_next[2] = main_binary::operation_id[3];
562
562
call_var(9, 2, 0) = main_binary::operation_id_next[2];
563
- machine_call(9 , [Known(call_var(9, 2, 0)), Known(call_var(9, 2, 1)), Known(call_var(9, 2, 2)), Unknown(call_var(9, 2, 3))]);
563
+ machine_call(2 , [Known(call_var(9, 2, 0)), Known(call_var(9, 2, 1)), Known(call_var(9, 2, 2)), Unknown(call_var(9, 2, 3))]);
564
564
main_binary::C_byte[2] = call_var(9, 2, 3);
565
565
main_binary::C[3] = (main_binary::C[2] + (main_binary::C_byte[2] * 16777216));
566
566
params[3] = main_binary::C[3];"
@@ -624,11 +624,11 @@ assert (SubM::a[0] & 0xffffffffffff0000) == 0;
624
624
params[1] = SubM::b[0];
625
625
params[2] = SubM::c[0];
626
626
call_var(1, 0, 0) = SubM::c[0];
627
- machine_call(1 , [Known(call_var(1, 0, 0))]);
627
+ machine_call(2 , [Known(call_var(1, 0, 0))]);
628
628
SubM::b[1] = SubM::b[0];
629
629
call_var(1, 1, 0) = SubM::b[1];
630
630
SubM::c[1] = SubM::c[0];
631
- machine_call(1 , [Known(call_var(1, 1, 0))]);
631
+ machine_call(2 , [Known(call_var(1, 1, 0))]);
632
632
SubM::a[1] = ((SubM::b[1] * 256) + SubM::c[1]);"
633
633
) ;
634
634
}
0 commit comments