-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathdummy.rs
More file actions
199 lines (166 loc) · 4.05 KB
/
Copy pathdummy.rs
File metadata and controls
199 lines (166 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
mod abstraction;
pub use abstraction::*;
pub mod prop;
pub use prop::*;
pub use int::*;
#[cfg(feature = "macros")]
pub use crate::proc_macros::*;
#[macro_export]
macro_rules! debug_assert {
($($arg:tt)*) => {
::core::debug_assert!($($arg)*);
};
}
#[macro_export]
macro_rules! assert {
($($arg:tt)*) => {
::core::assert!($($arg)*);
};
}
#[macro_export]
macro_rules! assert_prop {
($($arg:tt)*) => {{}};
}
#[macro_export]
macro_rules! assume {
($formula:expr) => {
()
};
}
#[doc(hidden)]
pub fn inline(_: &str) {}
#[doc(hidden)]
pub fn inline_unsafe<T>(_: &str) -> T {
unreachable!()
}
#[doc(hidden)]
pub const fn _internal_loop_invariant<T, R: Into<Prop>, P: FnOnce(T) -> R>(_: &P) {}
#[doc(hidden)]
pub const fn _internal_loop_decreases(_: int::Int) {}
pub trait Refinement {
type InnerType;
fn new(x: Self::InnerType) -> Self;
fn get(self) -> Self::InnerType;
fn get_mut(&mut self) -> &mut Self::InnerType;
fn invariant(value: Self::InnerType) -> crate::Prop;
}
pub trait RefineAs<RefinedType> {
fn into_checked(self) -> RefinedType;
}
pub mod int {
use core::ops::*;
#[macro_export]
macro_rules! int {
($lit:expr) => {
Int($lit)
};
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct Int(pub u8);
impl Int {
pub fn new(x: impl Into<u8>) -> Self {
Int(x.into())
}
pub fn get(self) -> u8 {
self.0
}
}
impl Add for Int {
type Output = Self;
fn add(self, other: Self) -> Self::Output {
Int(self.0 + other.0)
}
}
impl Sub for Int {
type Output = Self;
fn sub(self, other: Self) -> Self::Output {
Int(self.0 - other.0)
}
}
impl Mul for Int {
type Output = Self;
fn mul(self, other: Self) -> Self::Output {
Int(self.0 * other.0)
}
}
impl Div for Int {
type Output = Self;
fn div(self, other: Self) -> Self::Output {
Int(self.0 / other.0)
}
}
impl Int {
pub fn pow2(self) -> Self {
self
}
pub fn _unsafe_from_str(_s: &str) -> Self {
Int(0)
}
pub fn rem_euclid(&self, v: Self) -> Self {
Self::new(self.0.rem_euclid(v.0))
}
}
pub trait ToInt {
fn to_int(self) -> Int;
}
pub trait Abstraction {
type AbstractType;
fn lift(self) -> Self::AbstractType;
}
pub trait Concretization<T> {
fn concretize(self) -> T;
}
macro_rules! implement_abstraction {
($ty:ident) => {
impl Abstraction for $ty {
type AbstractType = Int;
fn lift(self) -> Self::AbstractType {
Int(0)
}
}
impl ToInt for $ty {
fn to_int(self) -> Int {
self.lift()
}
}
};
($($ty:ident)*) => {
$(implement_abstraction!($ty);)*
};
}
implement_abstraction!(u8 u16 u32 u64 u128 usize);
implement_abstraction!(i8 i16 i32 i64 i128 isize);
macro_rules! implement_concretize {
($ty:ident $method:ident) => {
impl Concretization<$ty> for Int {
fn concretize(self) -> $ty {
self.0 as $ty
}
}
impl Int {
pub fn $method(self) -> $ty {
self.concretize()
}
}
};
($ty:ident $method:ident, $($tt:tt)*) => {
implement_concretize!($ty $method);
implement_concretize!($($tt)*);
};
() => {};
}
implement_concretize!(
u8 to_u8,
u16 to_u16,
u32 to_u32,
u64 to_u64,
u128 to_u128,
usize to_usize,
i8 to_i8,
i16 to_i16,
i32 to_i32,
i64 to_i64,
i128 to_i128,
isize to_isize,
);
}