Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too many addressed objects in RAII example #561

Open
adpaco-aws opened this issue Oct 18, 2021 · 4 comments
Open

Too many addressed objects in RAII example #561

adpaco-aws opened this issue Oct 18, 2021 · 4 comments
Assignees
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] Performance Track performance improvement (Time / Memory / CPU)

Comments

@adpaco-aws
Copy link
Contributor

Currently, the Rust by Example/Scoping rules/RAII/11.rs fails to verify with default CBMC values. See the example below:

#![allow(unused)]
// raii.rs
fn create_box() {
    // Allocate an integer on the heap
    let _box1 = Box::new(3i32);

    // `_box1` is destroyed here, and memory gets freed
}

pub fn main() {
    // Allocate an integer on the heap
    let _box2 = Box::new(5i32);

    // A nested scope:
    {
        // Allocate an integer on the heap
        let _box3 = Box::new(4i32);

        // `_box3` is destroyed here, and memory gets freed
    }

    // Creating lots of boxes just for fun
    // There's no need to manually free memory!
    for _ in 0u32..1_000 {
        create_box();
    }

    // `_box2` is destroyed here, and memory gets freed
}

The create_box creates a box, then frees its memory since it goes out of scope.

One needs to use --cbmc-args --object-bits 13 in order to successfully verify this example, but even then it takes 5 minutes to do so.

As far as I can tell, this is a good candidate for verification optimizations.

@adpaco-aws adpaco-aws added Area: verification [F] Crash Kani crashed [E] Performance Track performance improvement (Time / Memory / CPU) labels Oct 18, 2021
@zhassan-aws
Copy link
Contributor

Still takes ~5 minutes with af11d38d93a.

@celinval celinval removed Pri: low [F] Crash Kani crashed labels Nov 9, 2022
@tedinski tedinski added the [C] Feature / Enhancement A new feature request or enhancement to an existing feature. label Nov 14, 2022
@tautschnig
Copy link
Member

What would be deemed "acceptable" for this harness? With #2301 this takes 150 seconds (2.5 minutes).

@adpaco-aws
Copy link
Contributor Author

It depends on where the time is being spent. What I'd expect to see for this example is near-zero time spent on solving (we create objects that are independent), and I'd consider the time you posted acceptable if >2mins are spent on unwinding.

Then there's also the problem of requiring --cbmc-args --object-bits 13: the program doesn't allocate more than 2 objects in the heap at any point in time, but CBMC appears to not be reusing free'd memory addresses. Is that a limitation of its memory model?

@zhassan-aws
Copy link
Contributor

This is not real code, so I wouldn't worry about it too much. I think what was surprising is that even though the test does nothing but allocate and deallocate memory a number of times, it takes long to analyze.

@tautschnig tautschnig self-assigned this Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] Performance Track performance improvement (Time / Memory / CPU)
Projects
None yet
Development

No branches or pull requests

5 participants