Skip to content

Commit 8089bfb

Browse files
committed
Parse <t> and <t1, t2> in annotations
1 parent c8c6cf0 commit 8089bfb

5 files changed

Lines changed: 85 additions & 0 deletions

File tree

src/annot.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,31 @@ where
502502
),
503503
_ => unimplemented!(),
504504
},
505+
TokenKind::Lt => {
506+
let (t1, s1) = self
507+
.parse_binop_2()?
508+
.into_term()
509+
.ok_or_else(|| ParseAttrError::unexpected_formula("in box/mut term"))?;
510+
511+
match self.next_token("> or ,")? {
512+
Token {
513+
kind: TokenKind::Gt,
514+
..
515+
} => FormulaOrTerm::Term(chc::Term::box_(t1), chc::Sort::box_(s1)),
516+
Token {
517+
kind: TokenKind::Comma,
518+
..
519+
} => {
520+
let (t2, _s2) = self
521+
.parse_binop_2()?
522+
.into_term()
523+
.ok_or_else(|| ParseAttrError::unexpected_formula("in mut term"))?;
524+
self.expect_next_token(TokenKind::Gt, ">")?;
525+
FormulaOrTerm::Term(chc::Term::mut_(t1, t2), chc::Sort::mut_(s1))
526+
}
527+
t => return Err(ParseAttrError::unexpected_token("> or ,", t.clone())),
528+
}
529+
}
505530
_ => {
506531
return Err(ParseAttrError::unexpected_token(
507532
"identifier, or literal",

tests/ui/fail/annot_box_term.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@error-in-other-file: Unsat
2+
//@compile-flags: -C debug-assertions=off
3+
4+
#[thrust::sig(fn(x: int) -> {r: Box<int> | r == <x>})]
5+
fn box_create(x: i64) -> Box<i64> {
6+
Box::new(x)
7+
}
8+
9+
#[thrust::requires(b == <v>)]
10+
fn box_consume(b: Box<i64>, v: i64) {
11+
assert!(*b == v);
12+
}
13+
14+
fn main() {
15+
let b = box_create(42);
16+
box_consume(b, 10);
17+
}

tests/ui/fail/annot_mut_term.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@error-in-other-file: Unsat
2+
3+
#[thrust::requires(true)]
4+
#[thrust::ensures(x == <*x, y>)]
5+
fn f(x: &mut i64, y: i64) {
6+
*x = y;
7+
}
8+
9+
fn main() {
10+
let mut a = 1;
11+
f(&mut a, 2);
12+
assert!(a == 1);
13+
}

tests/ui/pass/annot_box_term.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@check-pass
2+
//@compile-flags: -C debug-assertions=off
3+
4+
#[thrust::sig(fn(x: int) -> {r: Box<int> | r == <x>})]
5+
fn box_create(x: i64) -> Box<i64> {
6+
Box::new(x)
7+
}
8+
9+
#[thrust::requires(b == <v>)]
10+
fn box_consume(b: Box<i64>, v: i64) {
11+
assert!(*b == v);
12+
}
13+
14+
fn main() {
15+
let b = box_create(42);
16+
box_consume(b, 42);
17+
}

tests/ui/pass/annot_mut_term.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@check-pass
2+
3+
#[thrust::requires(true)]
4+
#[thrust::ensures(x == <*x, y>)]
5+
fn f(x: &mut i64, y: i64) {
6+
*x = y;
7+
}
8+
9+
fn main() {
10+
let mut a = 1;
11+
f(&mut a, 2);
12+
assert!(a == 2);
13+
}

0 commit comments

Comments
 (0)