Skip to content

Commit 1e69078

Browse files
authored
Align dummy column and APC column order (#3451)
In direct write to APC trace witgen, it's required that the order of original columns in original instruction execution order should match the order of post-optimization APC columns. This wasn't the case because previously we use an `AllChildren` visitor that chains `AlgebraicExpressions` in all constraints and bus interactions, whose `AlgebraicReference` don't necessarily follow the order of `StructReflection` of orignal airs columns. However, thanks to `StructReflection`, `poly_id` of original air columns are dispensed in the same order as the struct, and `globalize_reference` also keeps the same order before optimization. Therefore, the only work needed is to sort the unique columns returned by the `AllChildren` implementation of `SymbolicMachine` in the same order as the `poly_id` of original air columns. This turns out to be quite efficient as well via a `BTreeMap`, as explained in the comment below.
1 parent 8387f8b commit 1e69078

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

autoprecompiles/src/powdr.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub trait UniqueReferences<'a, T: 'a> {
3939
}
4040

4141
impl<'a, T: 'a, E: AllChildren<AlgebraicExpression<T>>> UniqueReferences<'a, T> for E {
42+
// Output unique column references sorted by ascending id of original instruction columns
4243
fn unique_references(&'a self) -> impl Iterator<Item = AlgebraicReference> {
4344
self.all_children()
4445
.filter_map(|e| {
@@ -48,7 +49,9 @@ impl<'a, T: 'a, E: AllChildren<AlgebraicExpression<T>>> UniqueReferences<'a, T>
4849
None
4950
}
5051
})
51-
.unique()
52+
.map(|r| (r.id, r))
53+
.collect::<BTreeMap<_, _>>()
54+
.into_values()
5255
}
5356
}
5457

0 commit comments

Comments
 (0)