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

Add tests for constant-evaluated intrinsics #1042

Merged
merged 10 commits into from
Apr 14, 2022
58 changes: 35 additions & 23 deletions tests/kani/Intrinsics/ConstEval/type_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

// Check that the `type_id` intrinsic is supported with common data types
// and that there are no duplicate type IDs
#![feature(core_intrinsics)]
use std::intrinsics::type_id;

Expand All @@ -11,27 +12,38 @@ enum MyEnum {}

#[kani::proof]
fn main() {
// Scalar types
let _ = type_id::<i8>();
let _ = type_id::<i16>();
let _ = type_id::<i32>();
let _ = type_id::<i64>();
let _ = type_id::<i128>();
let _ = type_id::<isize>();
let _ = type_id::<u8>();
let _ = type_id::<u16>();
let _ = type_id::<u32>();
let _ = type_id::<u64>();
let _ = type_id::<u128>();
let _ = type_id::<usize>();
let _ = type_id::<f32>();
let _ = type_id::<f64>();
let _ = type_id::<bool>();
let _ = type_id::<char>();
// Compound types (tuple and array)
let _ = type_id::<(i32, i32)>();
let _ = type_id::<[i32; 5]>();
// Custom data types (struct and enum)
let _ = type_id::<MyStruct>();
let _ = type_id::<MyEnum>();
let type_ids = [
// Scalar types
type_id::<i8>(),
type_id::<i16>(),
type_id::<i32>(),
type_id::<i64>(),
type_id::<i128>(),
type_id::<isize>(),
type_id::<u8>(),
type_id::<u16>(),
type_id::<u32>(),
type_id::<u64>(),
type_id::<u128>(),
type_id::<usize>(),
type_id::<f32>(),
type_id::<f64>(),
type_id::<bool>(),
type_id::<char>(),
// Compound types (tuple and array)
type_id::<(i32, i32)>(),
type_id::<[i32; 5]>(),
// Custom data types (struct and enum)
type_id::<MyStruct>(),
type_id::<MyEnum>(),
];

// Check that there are no duplicate type IDs
let i: usize = kani::any();
let j: usize = kani::any();
kani::assume(i < type_ids.len());
kani::assume(j < type_ids.len());
if i != j {
assert_ne!(type_ids[i], type_ids[j]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

}
}