-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into reset-mem-init
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
//! Test that Kani can correctly handle match patterns joined with the `|` operator. | ||
//! It contains two equivalent methods that only differ by grouping march patterns. | ||
//! Kani used to only be able to verify one as reported in: | ||
//! <https://github.com/model-checking/kani/issues/3432> | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
#[cfg_attr(kani, derive(kani::Arbitrary))] | ||
pub enum AbstractInt { | ||
Bottom = 0, | ||
Zero = 1, | ||
Top = 2, | ||
} | ||
|
||
impl AbstractInt { | ||
/// Code with exhausive match expression where each arm contains one pattern. | ||
pub fn merge(self, other: Self) -> Self { | ||
use AbstractInt::*; | ||
match (self, other) { | ||
(Bottom, x) => x, | ||
(x, Bottom) => x, | ||
(Zero, Zero) => Zero, | ||
(Top, _) => Top, | ||
(_, Top) => Top, | ||
} | ||
} | ||
|
||
/// Code with exhausive match expression where an arm may contain multiple patterns. | ||
pub fn merge_joined(self, other: Self) -> Self { | ||
use AbstractInt::*; | ||
match (self, other) { | ||
(Bottom, x) | (x, Bottom) => x, | ||
(Zero, Zero) => Zero, | ||
(Top, _) | (_, Top) => Top, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(kani)] | ||
mod test { | ||
use super::*; | ||
|
||
#[kani::proof] | ||
fn merge_with_bottom() { | ||
let x: AbstractInt = kani::any(); | ||
assert!(x.merge(AbstractInt::Bottom) == x); | ||
assert!(AbstractInt::Bottom.merge(x) == x) | ||
} | ||
|
||
#[kani::proof] | ||
fn check_equivalence() { | ||
let x: AbstractInt = kani::any(); | ||
let y: AbstractInt = kani::any(); | ||
assert_eq!(x.merge(y), x.merge_joined(y)); | ||
} | ||
} |