@@ -18,6 +18,7 @@ use crate::witgen::data_structures::identity::Identity;
18
18
use crate :: witgen:: machines:: dynamic_machine:: DynamicMachine ;
19
19
use crate :: witgen:: machines:: second_stage_machine:: SecondStageMachine ;
20
20
use crate :: witgen:: machines:: { write_once_memory:: WriteOnceMemory , MachineParts } ;
21
+ use powdr_ast:: analyzed:: AlgebraicExpression ;
21
22
22
23
use powdr_ast:: analyzed:: {
23
24
self , AlgebraicExpression as Expression , PolyID , PolynomialReference , Reference ,
@@ -136,11 +137,6 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
136
137
137
138
publics. add_all ( machine_identities. as_slice ( ) ) . unwrap ( ) ;
138
139
139
- let machine_intermediates = intermediates_in_identities (
140
- & machine_identities,
141
- & self . fixed . intermediate_definitions ,
142
- ) ;
143
-
144
140
// Connections that call into the current machine
145
141
let machine_receives = self
146
142
. fixed
@@ -158,6 +154,14 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
158
154
. collect :: < BTreeMap < _ , _ > > ( ) ;
159
155
assert ! ( machine_receives. contains_key( & bus_receive. bus_id) ) ;
160
156
157
+ let machine_intermediates = intermediates_in_expressions (
158
+ machine_identities
159
+ . iter ( )
160
+ . flat_map ( |i| i. all_children ( ) )
161
+ . chain ( machine_receives. values ( ) . flat_map ( |r| r. all_children ( ) ) ) ,
162
+ & self . fixed . intermediate_definitions ,
163
+ ) ;
164
+
161
165
let prover_functions = prover_functions
162
166
. iter ( )
163
167
. copied ( )
@@ -241,8 +245,10 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
241
245
. difference ( & multiplicity_columns)
242
246
. cloned ( )
243
247
. collect :: < HashSet < _ > > ( ) ;
244
- let main_intermediates =
245
- intermediates_in_identities ( & base_identities, & self . fixed . intermediate_definitions ) ;
248
+ let main_intermediates = intermediates_in_expressions (
249
+ base_identities. iter ( ) . flat_map ( |i| i. all_children ( ) ) ,
250
+ & self . fixed . intermediate_definitions ,
251
+ ) ;
246
252
247
253
log:: trace!(
248
254
"\n The base machine contains the following witnesses:\n {}\n identities:\n {}\n and prover functions:\n {}" ,
@@ -490,13 +496,11 @@ fn try_as_intermediate_ref<T: FieldElement>(expr: &Expression<T>) -> Option<(Pol
490
496
491
497
/// Returns all intermediate columns referenced in the identities as a map to their name.
492
498
/// Follows intermediate references recursively.
493
- fn intermediates_in_identities < T : FieldElement > (
494
- identities : & [ & Identity < T > ] ,
499
+ fn intermediates_in_expressions < ' a , T : FieldElement > (
500
+ expressions : impl Iterator < Item = & ' a AlgebraicExpression < T > > ,
495
501
intermediate_definitions : & BTreeMap < AlgebraicReferenceThin , Expression < T > > ,
496
502
) -> HashMap < PolyID , String > {
497
- let mut queue = identities
498
- . iter ( )
499
- . flat_map ( |id| id. all_children ( ) )
503
+ let mut queue = expressions
500
504
. filter_map ( try_as_intermediate_ref)
501
505
. collect :: < BTreeSet < _ > > ( ) ;
502
506
let mut intermediates = HashMap :: new ( ) ;
0 commit comments