Skip to content

Bug: Execution reached a pruned branch for certain fold combinations #291

@stringhandler

Description

@stringhandler

Project version

0.5.0

Project

compiler

What happened?

I think this has something to do with a node being shallow cloned instead of deep cloning. I used claude to generate some tests for various combinations of list lengths. The lengths 0,2,3 work for List<T, 4>, but length 1 fails.

Minimal reproduction steps

Create unit test with the following:

#[cfg(test)]
mod tests {
    use std::borrow::Cow;

    use crate::{tests::TestCase, WitnessValues};

    // Helper: fold with addition, f(elt, acc) = acc + elt
    const ADD_FN: &str = r#"fn add(elt: u32, acc: u32) -> u32 {
    let (_, sum): (bool, u32) = jet::add_32(elt, acc);
    sum
}
"#;

    // Helper: fold that ignores the accumulator and returns the element.
    // When folded left-to-right over a non-empty list, the final result equals the LAST element.
    const LAST_FN: &str = r#"fn last(elt: u32, _acc: u32) -> u32 {
    elt
}
"#;


    fn make_prog(fns: &str, body: &str) -> String {
        format!("{fns}\nfn main() {{\n{body}\n}}\n")
    }

    fn run(prog: &str) {
        TestCase::program_text(Cow::Owned(prog.to_owned()))
            .with_witness_values(WitnessValues::default())
            .assert_run_success();
    }


    #[test]
    fn list_fold_one_element_bound4() {
        // Partition: head-block empty, tail = [5].
        run(&make_prog(
            ADD_FN,
            r#"    let list: List<u32, 4> = list![5];
    let result: u32 = fold::<add, 4>(list, 0);
    assert!(jet::eq_32(result, 5));"#,
        ));
    }

  #[test]
    fn list_fold_five_elements_bound8() {
        // Partition: outer-head=[1,2,3,4], outer-tail partition [5].
        run(&make_prog(
            ADD_FN,
            r#"    let list: List<u32, 8> = list![1, 2, 3, 4, 5];
    let result: u32 = fold::<add, 8>(list, 0);
    assert!(jet::eq_32(result, 15));"#,
        ));
    }

Expected

Tests pass

Actual


---- compile::tests::list_fold_one_element_bound4 stdout ----

thread 'compile::tests::list_fold_one_element_bound4' (17336) panicked at src\lib.rs:462:31:
Unexpected error: Execution reached a pruned branch: 9db75f9ac4b7962ccb360ef90c67a5d56438f3a1f8383480c301148bc7b0ad0c
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- compile::tests::list_fold_five_elements_bound8 stdout ----

thread 'compile::tests::list_fold_five_elements_bound8' (49112) panicked at src\lib.rs:462:31:
Unexpected error: Execution reached a pruned branch: 9db75f9ac4b7962ccb360ef90c67a5d56438f3a1f8383480c301148bc7b0ad0c

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions