Skip to content

Commit f50e99d

Browse files
committed
Bug fix: Include intermediates from receives in machine parts
1 parent dc96fdd commit f50e99d

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

executor/src/witgen/machines/machine_extractor.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::witgen::data_structures::identity::Identity;
1818
use crate::witgen::machines::dynamic_machine::DynamicMachine;
1919
use crate::witgen::machines::second_stage_machine::SecondStageMachine;
2020
use crate::witgen::machines::{write_once_memory::WriteOnceMemory, MachineParts};
21+
use powdr_ast::analyzed::AlgebraicExpression;
2122

2223
use powdr_ast::analyzed::{
2324
self, AlgebraicExpression as Expression, PolyID, PolynomialReference, Reference,
@@ -136,11 +137,6 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
136137

137138
publics.add_all(machine_identities.as_slice()).unwrap();
138139

139-
let machine_intermediates = intermediates_in_identities(
140-
&machine_identities,
141-
&self.fixed.intermediate_definitions,
142-
);
143-
144140
// Connections that call into the current machine
145141
let machine_receives = self
146142
.fixed
@@ -158,6 +154,14 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
158154
.collect::<BTreeMap<_, _>>();
159155
assert!(machine_receives.contains_key(&bus_receive.bus_id));
160156

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+
161165
let prover_functions = prover_functions
162166
.iter()
163167
.copied()
@@ -241,8 +245,10 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
241245
.difference(&multiplicity_columns)
242246
.cloned()
243247
.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+
);
246252

247253
log::trace!(
248254
"\nThe 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
490496

491497
/// Returns all intermediate columns referenced in the identities as a map to their name.
492498
/// 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>>,
495501
intermediate_definitions: &BTreeMap<AlgebraicReferenceThin, Expression<T>>,
496502
) -> HashMap<PolyID, String> {
497-
let mut queue = identities
498-
.iter()
499-
.flat_map(|id| id.all_children())
503+
let mut queue = expressions
500504
.filter_map(try_as_intermediate_ref)
501505
.collect::<BTreeSet<_>>();
502506
let mut intermediates = HashMap::new();

0 commit comments

Comments
 (0)