Skip to content

Commit

Permalink
fixup codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
grjte committed Jan 26, 2023
1 parent d6c22a6 commit 49f2fd8
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions codegen/winterfell/src/air/boundary_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,8 @@ pub(super) fn add_fn_get_assertions(impl_ref: &mut Impl, ir: &AirIR) {
.arg_ref_self()
.ret("Vec<Assertion<Felt>>");

// declare the result vector to be returned.
let last_row = "last_step";
get_assertions.line("let mut result = Vec::new();");
get_assertions.line(format!("let {last_row} = self.last_step();"));

// add the boundary constraints
for constraint in ir.boundary_constraints(0) {
let (trace_access, expr_root) = ir
.constraint_graph()
.split_boundary_constraint(constraint.node_index())
.expect("failed to split boundary constraint");
debug_assert!(trace_access.trace_segment() == 0);

let assertion = format!(
"result.push(Assertion::single({}, {}, {}));",
trace_access.col_idx(),
domain_to_str(constraint.domain(), last_row),
expr_root.to_string(ir, ElemType::Felt)
);
get_assertions.line(assertion);
}
add_assertions(get_assertions, ir, 0);

// return the result
get_assertions.line("result");
Expand All @@ -50,30 +31,43 @@ pub(super) fn add_fn_get_aux_assertions(impl_ref: &mut Impl, ir: &AirIR) {
.arg("aux_rand_elements", "&AuxTraceRandElements<E>")
.ret("Vec<Assertion<E>>");

// add the boundary constraints
add_assertions(get_aux_assertions, ir, 1);

// return the result
get_aux_assertions.line("result");
}

/// Declares a result vector and adds assertions for boundary constraints to it for the specified
/// trace segment
fn add_assertions(func_body: &mut codegen::Function, ir: &AirIR, trace_segment: u8) {
let elem_type = if trace_segment == 0 {
ElemType::Felt
} else {
ElemType::E
};

// declare the result vector to be returned.
let last_row = "last_step";
get_aux_assertions.line("let mut result = Vec::new();");
get_aux_assertions.line(format!("let {last_row} = self.last_step();"));
func_body.line("let mut result = Vec::new();");
func_body.line(format!("let {last_row} = self.last_step();"));

// add the auxiliary boundary constraints
for constraint in ir.boundary_constraints(1) {
// add the boundary constraints
for constraint in ir.boundary_constraints(trace_segment) {
let (trace_access, expr_root) = ir
.constraint_graph()
.split_boundary_constraint(constraint.node_index())
.expect("failed to split boundary constraint");
debug_assert!(trace_access.trace_segment() == 1);
debug_assert!(trace_access.trace_segment() == trace_segment);

let assertion = format!(
"result.push(Assertion::single({}, {}, {}));",
trace_access.col_idx(),
domain_to_str(constraint.domain(), last_row),
expr_root.to_string(ir, ElemType::E)
expr_root.to_string(ir, elem_type)
);
get_aux_assertions.line(assertion);
func_body.line(assertion);
}

// return the result
get_aux_assertions.line("result");
}

/// Returns a string slice representing the provided constraint domain.
Expand Down

0 comments on commit 49f2fd8

Please sign in to comment.