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