Skip to content

Commit 89fc507

Browse files
committed
Support more annotation expressions
1 parent 9f0eb6a commit 89fc507

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

src/analyze/annot_fn.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ impl<'tcx> AnnotFnTranslator<'tcx> {
220220
let rhs = self.to_formula(rhs);
221221
return FormulaOrTerm::Formula(lhs.and(rhs));
222222
}
223+
rustc_hir::BinOpKind::Add => {
224+
let lhs = self.to_term(lhs);
225+
let rhs = self.to_term(rhs);
226+
return FormulaOrTerm::Term(lhs.add(rhs));
227+
}
228+
rustc_hir::BinOpKind::Sub => {
229+
let lhs = self.to_term(lhs);
230+
let rhs = self.to_term(rhs);
231+
return FormulaOrTerm::Term(lhs.sub(rhs));
232+
}
233+
rustc_hir::BinOpKind::Mul => {
234+
let lhs = self.to_term(lhs);
235+
let rhs = self.to_term(rhs);
236+
return FormulaOrTerm::Term(lhs.mul(rhs));
237+
}
223238
_ => {}
224239
}
225240

@@ -268,6 +283,19 @@ impl<'tcx> AnnotFnTranslator<'tcx> {
268283
unimplemented!("unsupported path in formula: {:?}", qpath);
269284
}
270285
}
286+
ExprKind::Tup(exprs) => {
287+
let terms = exprs.iter().map(|e| self.to_term(e)).collect();
288+
FormulaOrTerm::Term(chc::Term::tuple(terms))
289+
}
290+
ExprKind::Field(expr, field) => {
291+
let index = field
292+
.name
293+
.as_str()
294+
.parse::<usize>()
295+
.expect("tuple field index must be a non-negative integer");
296+
let term = self.to_term(expr);
297+
FormulaOrTerm::Term(term.tuple_proj(index))
298+
}
271299
ExprKind::Block(block, _) => {
272300
if block.stmts.is_empty() {
273301
self.to_formula_or_term(block.expr.expect("expected an expression in block"))

std.rs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,97 @@ mod thrust_models {
1212
#[thrust::def::int_model]
1313
pub struct Int;
1414

15+
impl<T> PartialEq<T> for Int where T: super::Model<Ty = Self> {
16+
#[thrust::ignored]
17+
fn eq(&self, _other: &T) -> bool {
18+
unimplemented!()
19+
}
20+
}
21+
22+
impl<T> PartialOrd<T> for Int where T: super::Model<Ty = Self> {
23+
#[thrust::ignored]
24+
fn partial_cmp(&self, _other: &T) -> Option<std::cmp::Ordering> {
25+
unimplemented!()
26+
}
27+
}
28+
29+
impl<T> std::ops::Add<T> for Int where T: super::Model<Ty = Self> {
30+
type Output = Self;
31+
32+
#[thrust::ignored]
33+
fn add(self, _rhs: T) -> Self::Output {
34+
unimplemented!()
35+
}
36+
}
37+
38+
impl<T> std::ops::Sub<T> for Int where T: super::Model<Ty = Self> {
39+
type Output = Self;
40+
41+
#[thrust::ignored]
42+
fn sub(self, _rhs: T) -> Self::Output {
43+
unimplemented!()
44+
}
45+
}
46+
47+
impl<T> std::ops::Mul<T> for Int where T: super::Model<Ty = Self> {
48+
type Output = Self;
49+
50+
#[thrust::ignored]
51+
fn mul(self, _rhs: T) -> Self::Output {
52+
unimplemented!()
53+
}
54+
}
55+
56+
impl std::ops::Neg for Int {
57+
type Output = Self;
58+
59+
#[thrust::ignored]
60+
fn neg(self) -> Self::Output {
61+
unimplemented!()
62+
}
63+
}
64+
1565
#[thrust::def::mut_model]
1666
pub struct Mut<T>(PhantomData<T>);
1767

68+
impl<T> Mut<T> {
69+
#[thrust::def::mut_new]
70+
pub fn new(_a: T, _b: T) -> Self {
71+
unimplemented!()
72+
}
73+
}
74+
75+
impl<T> std::ops::Deref for Mut<T> {
76+
type Target = T;
77+
fn deref(&self) -> &Self::Target {
78+
unimplemented!()
79+
}
80+
}
81+
82+
impl<T> std::ops::Not for Mut<T> {
83+
type Output = T;
84+
fn not(self) -> Self::Output {
85+
unimplemented!()
86+
}
87+
}
88+
1889
#[thrust::def::box_model]
1990
pub struct Box<T>(PhantomData<T>);
2091

92+
impl<T> Box<T> {
93+
#[thrust::def::box_new]
94+
pub fn new(_x: T) -> Self {
95+
unimplemented!()
96+
}
97+
}
98+
99+
impl<T> std::ops::Deref for Box<T> {
100+
type Target = T;
101+
fn deref(&self) -> &Self::Target {
102+
unimplemented!()
103+
}
104+
}
105+
21106
#[thrust::def::array_model]
22107
pub struct Array<I, T>(PhantomData<I>, PhantomData<T>);
23108

@@ -27,6 +112,10 @@ mod thrust_models {
27112
pub struct Vec<T>(pub Array<Int, T>, pub usize);
28113
}
29114

115+
impl Model for model::Int {
116+
type Ty = model::Int;
117+
}
118+
30119
impl Model for isize {
31120
type Ty = model::Int;
32121
}
@@ -75,6 +164,10 @@ mod thrust_models {
75164
type Ty = (<T0 as Model>::Ty, <T1 as Model>::Ty, <T2 as Model>::Ty);
76165
}
77166

167+
impl<T0, T1, T2, T3> Model for (T0, T1, T2, T3) where T0: Model, T1: Model, T2: Model, T3: Model {
168+
type Ty = (<T0 as Model>::Ty, <T1 as Model>::Ty, <T2 as Model>::Ty, <T3 as Model>::Ty);
169+
}
170+
78171
impl<'a, T> Model for &'a mut T where T: Model {
79172
type Ty = model::Mut<<T as Model>::Ty>;
80173
}

0 commit comments

Comments
 (0)