You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Difference in size of generators between rustc (with panic=unwind!) and Kani #1395
Update: the discrepancy is in fact due to Kani assuming panic=abort, but the Rust compiler assuming panic=unwind by default.
In #1378 (comment), it was observed that Kani sometimes reports a different size of a generator than the LLVM backend of rustc. Interestingly, the WASM backend seems to disagree with LLVM as well (see rust-lang/rust#62807).
The example code is the following:
#![feature(generators, generator_trait)]use std::ops::Generator;constFOO_SIZE:usize = 1024;structFoo([u8;FOO_SIZE]);implDropforFoo{fndrop(&mutself){}}fnnoop(){}fnmove_before_yield_with_noop() -> implGenerator<Yield = (),Return = ()>{static || {let first = Foo([0;FOO_SIZE]);noop();let _second = first;yield;// _second dropped here}}fnmain(){// This fails for Kani: it thinks the size is 1025, and so does the WASM backend.assert_eq!(1026, std::mem::size_of_val(&move_before_yield_with_noop()));}
@fzaiser I was taking a look at this issue, and I bumped into the following rust issue: rust-lang/rust#59123. It seems that the panic strategy can impact the generator size.
If I run the example you pasted above with the following command:
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `1026`,
right: `1025`', size.rs:26:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Why would you write that specific test though? Isn't it actually a good thing that Kani differs from LLVM? The size of a generator is a property the developer should never rely on
@giltho Kani is supposed to be bit-precise model checker, so we should get the sizes right. It's not something the user should rely on, but internally, Kani should compute the right sizes for offsets etc.
@giltho It looks like the actual difference is not LLVM vs WASM but "panic=unwind" vs "panic=abort". So we may have to update the tests. I'll update the title when I know for sure what the reason is.
changed the title [-]Difference in size of generators between rustc LLVM and Kani[/-][+]Difference in size of generators between rustc (with panic=unwind!) and Kani[/+]on Aug 30, 2022
Activity
celinval commentedon Aug 30, 2022
@fzaiser I was taking a look at this issue, and I bumped into the following rust issue: rust-lang/rust#59123. It seems that the panic strategy can impact the generator size.
If I run the example you pasted above with the following command:
The assertion fails because the size is now 1025:
giltho commentedon Aug 30, 2022
Why would you write that specific test though? Isn't it actually a good thing that Kani differs from LLVM? The size of a generator is a property the developer should never rely on
fzaiser commentedon Aug 30, 2022
@giltho Kani is supposed to be bit-precise model checker, so we should get the sizes right. It's not something the user should rely on, but internally, Kani should compute the right sizes for offsets etc.
giltho commentedon Aug 30, 2022
@fzaiser
I agree, but what is the "right" size? If WASM and LLVM disagree, why would LLVM be "right" and WASM be "wrong"?
giltho commentedon Aug 30, 2022
The test has been disabled for WASM, I don't think it's a bad thing to disable it for Kani too
fzaiser commentedon Aug 30, 2022
@giltho It looks like the actual difference is not LLVM vs WASM but "panic=unwind" vs "panic=abort". So we may have to update the tests. I'll update the title when I know for sure what the reason is.
[-]Difference in size of generators between rustc LLVM and Kani[/-][+]Difference in size of generators between rustc (with panic=unwind!) and Kani[/+]