Skip to content
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

Update Creusot #42

Merged
merged 9 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ tests/2018/
*.bak
/playground
tests/probs
/mir_dump/
99 changes: 72 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CreuSAT/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
#clap = "4.0.18"
clap = "2.33.3"
rand = "*"
creusot-contracts = { git = "https://github.com/xldenis/creusot", version = "^0", rev = "5cc6cdd6" }
creusot-contracts = { git = "https://github.com/xldenis/creusot", version = "^0", rev = "1357cc97" }

[dev-dependencies]
termcolor = "1.1"
Expand Down
4 changes: 2 additions & 2 deletions CreuSAT/src/assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl Assignments {
#[ensures((forall<j: Int> 0 <= j && j < [email protected]() && j != lit.index_logic() ==> self@[j] == (^self)@[j]))]
#[ensures(lit.sat(^self))]
pub fn set_assignment(&mut self, lit: Lit, _f: &Formula, _t: &Vec<Step>) {
let old_self: Ghost<&mut Assignments> = ghost! { self };
//self.0[lit.index()] = lit.is_positive() as u8;
let old_self: Snapshot<&mut Assignments> = snapshot! { self };
//self.clauses[lit.index()] = lit.is_positive() as u8;
if lit.is_positive() {
self.0[lit.index()] = 1;
} else {
Expand Down
15 changes: 7 additions & 8 deletions CreuSAT/src/clause.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate creusot_contracts;
use creusot_contracts::{std::*, Clone, Ghost, *};
use creusot_contracts::{std::*, Clone, Snapshot, *};

use crate::{assignments::*, formula::*, lit::*, solver::*, trail::*};
use ::std::ops::{Index, IndexMut};
Expand Down Expand Up @@ -61,10 +61,7 @@ impl Clause {
}
i += 1;
}
if self.no_duplicates() {
return true;
}
false
return self.no_duplicates();
}

#[cfg_attr(feature = "trust_clause", trusted)]
Expand Down Expand Up @@ -161,14 +158,16 @@ impl Clause {
#[cfg_attr(feature = "trust_clause", trusted)]
#[requires([email protected]() > j@)]
#[requires([email protected]() > k@)]
#[requires(_f.invariant())]
#[maintains((mut self).invariant(_f.num_vars@))]
#[maintains((mut self).equisat_extension(*_f))]
#[ensures([email protected]() == (^self)@.len())]
#[ensures((^self)@.exchange(self@, j@, k@))]
pub fn swap_lits_in_clause(&mut self, _f: &Formula, j: usize, k: usize) {
let old_c: Ghost<&mut Clause> = ghost! { self };
let old_c: Snapshot<&mut Clause> = snapshot! { self };
self.lits.swap(j, k);
proof_assert!(eventually_sat_complete(((_f@.0).push(*self), [email protected])) ==>
eventually_sat_complete((([email protected]).push(*old_c.inner()), [email protected])));
proof_assert!(lemma_permuted_clause_maintains_equisat(_f@, *old_c.inner(), *self); true);
proof_assert!(dup_stable_on_permut(*old_c.inner(), *self); true);
}

#[cfg_attr(feature = "trust_clause", trusted)]
Expand Down
16 changes: 8 additions & 8 deletions CreuSAT/src/conflict_analysis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate creusot_contracts;
use creusot_contracts::{std::*, vec, Ghost, *};
use creusot_contracts::{std::*, vec, Snapshot, *};

use crate::{assignments::*, clause::*, decision::*, formula::*, lit::*, trail::*};

Expand Down Expand Up @@ -54,10 +54,10 @@ fn resolve(
_f: &Formula, c: &mut Clause, o: &Clause, idx: usize, c_idx: usize, trail: &Trail, seen: &mut Vec<bool>,
path_c: &mut usize, to_bump: &mut Vec<usize>,
) {
let old_c: Ghost<&mut Clause> = ghost!(c);
let old_seen: Ghost<&mut Vec<bool>> = ghost!(seen);
let old_path_c: Ghost<&mut usize> = ghost!(path_c);
let old_to_bump: Ghost<&mut Vec<usize>> = ghost!(to_bump);
let old_c: Snapshot<&mut Clause> = snapshot!(c);
let old_seen: Snapshot<&mut Vec<bool>> = snapshot!(seen);
let old_path_c: Snapshot<&mut usize> = snapshot!(path_c);
let old_to_bump: Snapshot<&mut Vec<usize>> = snapshot!(to_bump);

proof_assert!(c.clause_is_seen(*seen));

Expand All @@ -68,7 +68,7 @@ fn resolve(

proof_assert!(^seen == ^old_seen.inner());
proof_assert!(c.clause_is_seen(*seen));
let old_c2: Ghost<&mut Clause> = ghost!(c);
let old_c2: Snapshot<&mut Clause> = snapshot!(c);
proof_assert!(!old_c@[c_idx@].lit_in(*c));
proof_assert!(^c == ^old_c.inner());
proof_assert!(forall<j: Int> 0 <= j && j < [email protected]()
Expand All @@ -89,7 +89,7 @@ fn resolve(
#[invariant([email protected]() == _f.num_vars@)]
#[invariant(elems_less_than(to_bump@, _f.num_vars@))]
while i < o.len() {
let old_c3: Ghost<&mut Clause> = ghost!(c);
let old_c3: Snapshot<&mut Clause> = snapshot!(c);
proof_assert!(^c == ^old_c3.inner());

if !idx_in(&c.lits, o[i].index(), &seen) {
Expand Down Expand Up @@ -127,7 +127,7 @@ fn resolve(
None => (^i)@ == 0
})]
fn choose_literal(c: &Clause, trail: &Trail, i: &mut usize, _f: &Formula, seen: &Vec<bool>) -> Option<usize> {
let old_i: Ghost<&mut usize> = ghost! {i};
let old_i: Snapshot<&mut usize> = snapshot! {i};
#[invariant(0 <= i@ && i@ <= [email protected]())]
while *i > 0 {
*i -= 1;
Expand Down
7 changes: 4 additions & 3 deletions CreuSAT/src/decision.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate creusot_contracts;
use creusot_contracts::{ensures, ghost, invariant, maintains, proof_assert, requires, std::vec, Clone, Ghost, Int, *};
use creusot_contracts::{ensures, invariant, maintains, proof_assert, requires, std::vec, Clone, Int, Snapshot, *};

use crate::{assignments::*, formula::*, util::*};

Expand All @@ -26,6 +26,7 @@ impl ::std::default::Default for Node {

impl creusot_contracts::Default for Node {
#[predicate]
#[open]
fn is_default(self) -> bool {
pearlite! { self.next@ == usize::MAX@ && self.prev@ == usize::MAX@ && self.ts@ == 0 }
}
Expand Down Expand Up @@ -135,7 +136,7 @@ impl Decisions {
#[ensures((^self)[email protected]() == [email protected]())]
fn rescore(&mut self, _f: &Formula) {
let INVALID: usize = usize::MAX;
let old_self: Ghost<&mut Decisions> = ghost! { self };
let old_self: Snapshot<&mut Decisions> = snapshot! { self };
let mut curr_score = self.linked_list.len();
let mut i: usize = 0;
let mut curr = self.start;
Expand Down Expand Up @@ -203,7 +204,7 @@ impl Decisions {
#[maintains((mut self).invariant(f.num_vars@))]
pub fn increment_and_move(&mut self, f: &Formula, v: Vec<usize>) {
let mut counts_with_index: Vec<(usize, usize)> = vec![(0, 0); v.len()];
let old_self: Ghost<&mut Decisions> = ghost! { self };
let old_self: Snapshot<&mut Decisions> = snapshot! { self };
let mut i: usize = 0;
#[invariant(old_self.inner() == self)]
#[invariant([email protected]() == [email protected]())]
Expand Down
Loading
Loading