-
Notifications
You must be signed in to change notification settings - Fork 82
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
Replace height intrinsic with is_smaller_than and make height a partial order #570
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9f1ab2d
Replace height intrinsic with is_smaller_than,
Chris-Hawblitzel 6a59936
Update .github/workflows/get-z3.sh to Z3 4.12.2
Chris-Hawblitzel b2e546c
Allow decreases on FnSpec fields
Chris-Hawblitzel bb35ccf
Add is_smaller_than_lexicographic and some comments
Chris-Hawblitzel aa9b640
Add decreases_to macro
Chris-Hawblitzel 443279d
Merge branch 'main' into is_smaller_than
Chris-Hawblitzel f75a2e2
Split is_smaller_than handling into separate function
Chris-Hawblitzel 0eedf96
Merge branch 'main' into is_smaller_than
Chris-Hawblitzel c867dc4
Restrict usage of decreases through FnSpec and Map,
Chris-Hawblitzel a5f52a4
Merge branch 'main' into is_smaller_than
Chris-Hawblitzel 5d09b6e
Merge branch 'main' into is_smaller_than
Chris-Hawblitzel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -49,6 +49,14 @@ pub enum UnaryOp { | |
BitExtract(u32, u32), | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] | ||
pub enum Relation { | ||
PartialOrder, | ||
LinearOrder, | ||
TreeOrder, | ||
PiecewiseLinearOrder, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] | ||
pub enum BinaryOp { | ||
Implies, | ||
|
@@ -59,7 +67,7 @@ pub enum BinaryOp { | |
Gt, | ||
EuclideanDiv, | ||
EuclideanMod, | ||
|
||
Relation(Relation, u64), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same - what's the u64 for? |
||
BitXor, | ||
BitAnd, | ||
BitOr, | ||
|
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
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -137,9 +137,8 @@ fn check_is_sorted_tree(tree: &Tree) -> (ret: TreeSortedness) | |
|
||
proof { | ||
sorted_tree_means_sorted_sequence(**left); | ||
sorted_tree_means_sorted_sequence(**right); | ||
} | ||
// sorted_tree_means_sorted_sequence(**right); // TODO: why is only one of these calls | ||
// necessary? | ||
|
||
// assert(equal(tree@, [email protected](seq![*value as int]).add(right@))); | ||
// assert([email protected]() > 0); | ||
|
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 |
---|---|---|
@@ -1 +1 @@ | ||
pub const EXPECTED_SOLVER_VERSION: &str = "4.10.1"; | ||
pub const EXPECTED_SOLVER_VERSION: &str = "4.12.2"; |
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
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
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 |
---|---|---|
|
@@ -568,7 +568,7 @@ fn fn_call_to_vir<'tcx>( | |
let is_signed_max = f_name == "builtin::signed_max"; | ||
let is_unsigned_max = f_name == "builtin::unsigned_max"; | ||
let is_arch_word_bits = f_name == "builtin::arch_word_bits"; | ||
let is_height = f_name == "builtin::height"; | ||
let is_smaller_than = f_name == "builtin::is_smaller_than"; | ||
|
||
let is_reveal_strlit = tcx.is_diagnostic_item(Symbol::intern("builtin::reveal_strlit"), f); | ||
let is_strslice_len = tcx.is_diagnostic_item(Symbol::intern("builtin::strslice_len"), f); | ||
|
@@ -702,7 +702,7 @@ fn fn_call_to_vir<'tcx>( | |
|| is_strslice_is_ascii | ||
|| is_closure_to_fn_spec | ||
|| is_arch_word_bits | ||
|| is_height; | ||
|| is_smaller_than; | ||
let is_spec_allow_proof_args_pre = is_spec_op | ||
|| is_builtin_add | ||
|| is_builtin_sub | ||
|
@@ -1110,10 +1110,60 @@ fn fn_call_to_vir<'tcx>( | |
return mk_expr(ExprX::UnaryOpr(UnaryOpr::IntegerTypeBound(kind, Mode::Spec), arg)); | ||
} | ||
|
||
if is_height { | ||
assert!(args.len() == 1); | ||
let arg = expr_to_vir(bctx, &args[0], ExprModifier::REGULAR)?; | ||
return mk_expr(ExprX::UnaryOpr(UnaryOpr::Height, arg)); | ||
if is_smaller_than { | ||
assert!(args.len() == 2); | ||
let args0 = extract_tuple(args[0]); | ||
let args1 = extract_tuple(args[1]); | ||
// convert is_smaller_than((x0, y0, z0), (x1, y1, z1)) into | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please extract this conversion into a separate function? |
||
// x0 < x1 || (x0 == x1 && (y0 < y1 || (y0 == y1 && z0 < z1))) | ||
// see also check_decrease in recursion.rs | ||
let tbool = Arc::new(TypX::Bool); | ||
let tint = Arc::new(TypX::Int(IntRange::Int)); | ||
let when_equalx = ExprX::Const(Constant::Bool(args1.len() < args0.len())); | ||
let when_equal = bctx.spanned_typed_new(expr.span, &tbool, when_equalx); | ||
let mut dec_exp: vir::ast::Expr = when_equal; | ||
for (i, (exp0, exp1)) in args0.iter().zip(args1.iter()).rev().enumerate() { | ||
let mk_bop = |op: BinaryOp, e1: vir::ast::Expr, e2: vir::ast::Expr| { | ||
bctx.spanned_typed_new(expr.span, &tbool, ExprX::Binary(op, e1, e2)) | ||
}; | ||
let mk_cmp = |lt: bool| -> Result<vir::ast::Expr, VirErr> { | ||
let e0 = expr_to_vir(bctx, exp0, ExprModifier::REGULAR)?; | ||
let e1 = expr_to_vir(bctx, exp1, ExprModifier::REGULAR)?; | ||
if vir::recursion::height_is_int(&e0.typ) { | ||
if lt { | ||
// 0 <= x < y | ||
let zerox = ExprX::Const(vir::ast_util::const_int_from_u128(0)); | ||
let zero = bctx.spanned_typed_new(expr.span, &tint, zerox); | ||
let op0 = BinaryOp::Inequality(InequalityOp::Le); | ||
let cmp0 = mk_bop(op0, zero, e0); | ||
let op1 = BinaryOp::Inequality(InequalityOp::Lt); | ||
let e0 = expr_to_vir(bctx, exp0, ExprModifier::REGULAR)?; | ||
let cmp1 = mk_bop(op1, e0, e1); | ||
Ok(mk_bop(BinaryOp::And, cmp0, cmp1)) | ||
} else { | ||
Ok(mk_bop(BinaryOp::Eq(Mode::Spec), e0, e1)) | ||
} | ||
} else { | ||
Ok(mk_bop(BinaryOp::HeightCompare(lt), e0, e1)) | ||
} | ||
}; | ||
if i == 0 { | ||
// i == 0 means last shared exp0/exp1, which we visit first | ||
if args1.len() < args0.len() { | ||
// if z0 == z1, we can ignore the extra args0: | ||
// z0 < z1 || z0 == z1 | ||
dec_exp = mk_bop(BinaryOp::Or, mk_cmp(true)?, mk_cmp(false)?); | ||
} else { | ||
// z0 < z1 | ||
dec_exp = mk_cmp(true)?; | ||
} | ||
} else { | ||
// x0 < x1 || (x0 == x1 && dec_exp) | ||
let and = mk_bop(BinaryOp::And, mk_cmp(false)?, dec_exp); | ||
dec_exp = mk_bop(BinaryOp::Or, mk_cmp(true)?, and); | ||
} | ||
} | ||
return Ok(dec_exp); | ||
} | ||
|
||
if is_smartptr_new { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could use some documentation