@@ -19,6 +19,7 @@ use powdr_number::{BigUint, FieldElement};
1919
2020pub mod referenced_symbols;
2121
22+ use powdr_pil_analyzer:: try_algebraic_expression_to_expression;
2223use referenced_symbols:: { ReferencedSymbols , SymbolReference } ;
2324
2425pub fn optimize < T : FieldElement > ( mut pil_file : Analyzed < T > ) -> Analyzed < T > {
@@ -30,9 +31,7 @@ pub fn optimize<T: FieldElement>(mut pil_file: Analyzed<T>) -> Analyzed<T> {
3031 deduplicate_fixed_columns ( & mut pil_file) ;
3132 simplify_identities ( & mut pil_file) ;
3233 extract_constant_lookups ( & mut pil_file) ;
33- println ! ( "before {pil_file}" ) ;
3434 replace_linear_witness_columns ( & mut pil_file) ;
35- println ! ( "after {pil_file}" ) ;
3635 remove_constant_witness_columns ( & mut pil_file) ;
3736 remove_constant_intermediate_columns ( & mut pil_file) ;
3837 simplify_identities ( & mut pil_file) ;
@@ -545,6 +544,7 @@ fn replace_linear_witness_columns<T: FieldElement>(pil_file: &mut Analyzed<T>) {
545544 ..* poly_id
546545 } ;
547546 new_symbol. kind = SymbolKind :: Poly ( PolynomialType :: Intermediate ) ;
547+ new_symbol. stage = None ;
548548 // Add the definition to the intermediate columns
549549 pil_file
550550 . intermediate_columns
@@ -635,6 +635,10 @@ fn substitute_polynomial_references<T: FieldElement>(
635635 pil_file : & mut Analyzed < T > ,
636636 substitutions : Vec < ( ( String , PolyID ) , AlgebraicExpression < T > ) > ,
637637) {
638+ let poly_id_to_name = substitutions
639+ . iter ( )
640+ . map ( |( ( name, id) , _) | ( ( id. ptype , id. id ) , name. clone ( ) ) )
641+ . collect ( ) ;
638642 let substitutions_by_id = substitutions
639643 . iter ( )
640644 . map ( |( ( _, id) , value) | ( * id, value. clone ( ) ) )
@@ -650,7 +654,7 @@ fn substitute_polynomial_references<T: FieldElement>(
650654 ) = e
651655 {
652656 if let Some ( value) = substitutions_by_name. get ( name) {
653- * e = value . clone ( ) . into ( ) ;
657+ * e = try_algebraic_expression_to_expression ( & poly_id_to_name , value ) . unwrap ( ) ;
654658 }
655659 }
656660 } ) ;
0 commit comments