Skip to content

Commit 23ad159

Browse files
committed
Bug fix: Include intermediates from receives in machine parts
1 parent ce10fe7 commit 23ad159

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
@@ -19,6 +19,7 @@ use crate::witgen::machines::dynamic_machine::DynamicMachine;
1919
use crate::witgen::machines::second_stage_machine::SecondStageMachine;
2020
use crate::witgen::machines::Connection;
2121
use crate::witgen::machines::{write_once_memory::WriteOnceMemory, MachineParts};
22+
use powdr_ast::analyzed::AlgebraicExpression;
2223

2324
use powdr_ast::analyzed::{
2425
self, AlgebraicExpression as Expression, PolyID, PolynomialReference, Reference,
@@ -138,11 +139,6 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
138139

139140
publics.add_all(machine_identities.as_slice()).unwrap();
140141

141-
let machine_intermediates = intermediates_in_identities(
142-
&machine_identities,
143-
&self.fixed.intermediate_definitions,
144-
);
145-
146142
// Connections that call into the current machine
147143
let machine_connections = all_connections
148144
.iter()
@@ -157,6 +153,14 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
157153
.collect::<BTreeMap<_, _>>();
158154
assert!(machine_connections.contains_key(&connection.id));
159155

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+
160164
let prover_functions = prover_functions
161165
.iter()
162166
.copied()
@@ -240,8 +244,10 @@ impl<'a, T: FieldElement> MachineExtractor<'a, T> {
240244
.difference(&multiplicity_columns)
241245
.cloned()
242246
.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+
);
245251

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

499505
/// Returns all intermediate columns referenced in the identities as a map to their name.
500506
/// 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>>,
503509
intermediate_definitions: &BTreeMap<AlgebraicReferenceThin, Expression<T>>,
504510
) -> HashMap<PolyID, String> {
505-
let mut queue = identities
506-
.iter()
507-
.flat_map(|id| id.all_children())
511+
let mut queue = expressions
508512
.filter_map(try_as_intermediate_ref)
509513
.collect::<BTreeSet<_>>();
510514
let mut intermediates = HashMap::new();

0 commit comments

Comments
 (0)