Skip to content

Commit 296b1f2

Browse files
committed
feat: finalize generation
1 parent fb60c78 commit 296b1f2

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

crates/move-prover-boogie-backend/src/boogie_backend/lib.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#![forbid(unsafe_code)]
66

7-
use std::{collections::BTreeSet, fs};
7+
use std::{cmp::Ordering, collections::BTreeSet, fs};
88

99
use itertools::Itertools;
1010
#[allow(unused_imports)]
@@ -45,12 +45,14 @@ const TABLE_ARRAY_THEORY: &[u8] = include_bytes!("prelude/table-array-theory.bpl
4545
const BCS_MODULE: &str = "0x1::bcs";
4646
const EVENT_MODULE: &str = "0x1::event";
4747

48-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default)]
48+
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
4949
struct TypeInfo {
5050
name: String,
5151
suffix: String,
5252
has_native_equality: bool,
5353
is_bv: bool,
54+
is_number: bool,
55+
bit_width: String,
5456
}
5557

5658
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default)]
@@ -455,10 +457,38 @@ impl TypeInfo {
455457
suffix: boogie_type_suffix_bv(env, ty, bv_flag),
456458
has_native_equality: has_native_equality(env, options, ty),
457459
is_bv: bv_flag,
460+
bit_width: ty.get_bit_width().unwrap_or(8).to_string(),
461+
is_number: ty.is_number(),
458462
}
459463
}
460464
}
461465

466+
impl PartialEq for TypeInfo {
467+
fn eq(&self, other: &Self) -> bool {
468+
self.name == other.name && self.suffix == other.suffix && self.has_native_equality == other.has_native_equality
469+
}
470+
}
471+
472+
impl PartialOrd for TypeInfo {
473+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
474+
Some(self.cmp(other))
475+
}
476+
}
477+
478+
impl Ord for TypeInfo {
479+
fn cmp(&self, other: &Self) -> Ordering {
480+
match self.name.cmp(&other.name) {
481+
Ordering::Equal => match self.suffix.cmp(&other.suffix) {
482+
Ordering::Equal => self.has_native_equality.cmp(&other.has_native_equality),
483+
other => other,
484+
},
485+
other => other,
486+
}
487+
}
488+
}
489+
490+
impl Eq for TypeInfo {}
491+
462492
impl TableImpl {
463493
fn table(
464494
env: &GlobalEnv,

crates/move-prover-boogie-backend/src/boogie_backend/prelude/native.bpl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ function {:inline} $1_vector_$skip{{S}}(v: Vec ({{T}}), n: int): Vec ({{T}}) {
372372
(if n >= LenVec(v) then EmptyVec() else SliceVec(v, n, LenVec(v)))
373373
}
374374

375+
{%- if instance.is_number -%}
375376
function $0_vec_$sum{{S}}(v: Vec ({{T}}), start: int, end: int): {{T}};
376377

377378
{%- if instance.is_bv -%}
@@ -386,13 +387,13 @@ axiom (forall v: Vec ({{T}}), start1: int, end1: int, start2: int, end2: int ::
386387
// the sum over an empty range is zero
387388
axiom (forall v: Vec ({{T}}), start: int, end: int ::
388389
{ $0_vec_$sum{{S}}(v, start, end)}
389-
(start >= end ==> $0_vec_$sum{{S}}(v, start, end) == 0bv8));
390+
(start >= end ==> $0_vec_$sum{{S}}(v, start, end) == 0bv{{instance.bit_width}}));
390391

391392
// the sum of a range can be split in two
392393
axiom (forall v: Vec ({{T}}), a: int, b: int, c: int, d: int ::
393394
{ $0_vec_$sum{{S}}(v, a, b), $0_vec_$sum{{S}}(v, c, d) }
394395
0 <= a && a <= b && b == c && c <= d && d <= LenVec(v) ==>
395-
$Add'Bv8'($0_vec_$sum{{S}}(v, a, b), $0_vec_$sum{{S}}(v, c, d)) == $0_vec_$sum{{S}}(v, a, d)) ;
396+
$Add'Bv{{instance.bit_width}}'($0_vec_$sum{{S}}(v, a, b), $0_vec_$sum{{S}}(v, c, d)) == $0_vec_$sum{{S}}(v, a, d)) ;
396397

397398
// the sum over a singleton range is the vector element there
398399
axiom (forall v: Vec ({{T}}), a: int, x: int, y: int ::
@@ -403,7 +404,7 @@ axiom (forall v: Vec ({{T}}), a: int, x: int, y: int ::
403404
axiom (forall v: Vec ({{T}}), a: int, b: int, c: int, d: int ::
404405
{ $0_vec_$sum{{S}}(v, a, d), $0_vec_$sum{{S}}(v, b, c) }
405406
$IsValid'vec{{S}}'(v) && 0 <= a && a <= b && b <= c && c <= d && d <= LenVec(v) ==>
406-
$Le'Bv8'($0_vec_$sum{{S}}(v, b, c), $0_vec_$sum{{S}}(v, a, d)));
407+
$Le'Bv{{instance.bit_width}}'($0_vec_$sum{{S}}(v, b, c), $0_vec_$sum{{S}}(v, a, d)));
407408

408409
{%- else -%}
409410

@@ -437,11 +438,13 @@ axiom (forall v: Vec ({{T}}), a: int, b: int, c: int, d: int ::
437438

438439
{%- endif %}
439440

440-
procedure {:inline 1} $0_vec_sum{{S}}(v: Vec ({{T}})) returns (res: {{T}}) {
441+
procedure {:inline 1} $0_vector_iter_sum{{S}}(v: Vec ({{T}})) returns (res: {{T}}) {
441442
res := $0_vec_$sum{{S}}(v, 0, LenVec(v));
442443
}
443444

444-
procedure {:inline 1} $0_vec_slice{{S}}(v: Vec ({{T}}), start: int, end: int) returns (res: Vec ({{T}})) {
445+
{%- endif %}
446+
447+
procedure {:inline 1} $0_vector_iter_slice{{S}}(v: Vec ({{T}}), start: int, end: int) returns (res: Vec ({{T}})) {
445448
var len: int;
446449
len := LenVec(v);
447450
if (start >= len || end <= start) {

crates/sui-prover/tests/inputs/sum_slice.ok.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module 0x42::foo;
22

33
use prover::prover::ensures;
4-
use prover::vec::{slice, sum};
4+
use prover::vector_iter::{slice, sum};
55

66
#[spec(prove)]
77
fun test_slice_and_sum() {

0 commit comments

Comments
 (0)