Skip to content

Better support for fold #1823

@weaversa

Description

@weaversa

I tried this code:

pub fn array_sum_fold(x : [usize;100]) -> usize {
    x.iter().fold(0, |accumulator, current| accumulator + current)
}

pub fn array_sum_for(x : [usize;100]) -> usize {
    let mut accumulator : usize = 0;
    for i in 0..100 {
      accumulator = x[i] + accumulator
    }
    accumulator
}

#[cfg(kani)]
mod proofs {
    use super::*;

    #[kani::proof]
    fn array_sum_fold_proof() {
        let x : [usize;100] = kani::any();
        array_sum_fold(x);
    }

    #[kani::proof]
    fn array_sum_for_proof() {
        let x : [usize;100] = kani::any();
        array_sum_for(x);
    }
}

using the following command line invocation:

$ cargo kani

with Kani version: 0.13.0

I expected to see this happen: Proof runtimes for the fold and for versions of array_sum complete in roughly the same time.

Instead, this happened: kani completed the for version quite quickly and then runs until eventually crashing (out of memory?) on the fold version.

Metadata

Metadata

Assignees

Labels

T-CBMCIssue related to an existing CBMC issueT-UserTag user issues / requests[C] BugThis is a bug. Something isn't working.[E] PerformanceTrack performance improvement (Time / Memory / CPU)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions