Skip to content

Commit a2afd43

Browse files
committed
fixes for atomics and ghost state; resolves #769, resolves #770
1 parent 21d46b5 commit a2afd43

16 files changed

+450
-293
lines changed

atomics/SC_atomics.v

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ Context `{!VSTGS OK_ty Σ}.
1515

1616
Class atomic_int_impl (atomic_int : type) := { atomic_int_at : share -> val -> val -> mpred;
1717
atomic_int_at__ : forall sh v p, atomic_int_at sh v p ⊢ atomic_int_at sh Vundef p;
18-
atomic_int_conflict : forall sh v v' p, sepalg.nonidentity sh -> atomic_int_at sh v p ∗ atomic_int_at sh v' p ⊢ False }.
18+
atomic_int_conflict : forall sh v v' p, sepalg.nonidentity sh -> atomic_int_at sh v p ∗ atomic_int_at sh v' p ⊢ False;
19+
atomic_int_isptr : forall sh v p, atomic_int_at sh v p ⊢ ⌜isptr p⌝;
20+
atomic_int_timeless sh v p :: Timeless (atomic_int_at sh v p)
21+
}.
1922

2023
Class atomic_ptr_impl := { atomic_ptr : type; atomic_ptr_at : share -> val -> val -> mpred;
21-
atomic_ptr_conflict : forall sh v v' p, sepalg.nonidentity sh -> atomic_ptr_at sh v p ∗ atomic_ptr_at sh v' p ⊢ False }.
24+
atomic_ptr_conflict : forall sh v v' p, sepalg.nonidentity sh -> atomic_ptr_at sh v p ∗ atomic_ptr_at sh v' p ⊢ False;
25+
atomic_ptr_isptr : forall sh v p, atomic_ptr_at sh v p ⊢ ⌜isptr p⌝;
26+
atomic_ptr_timeless sh v p :: Timeless (atomic_ptr_at sh v p)
27+
}.
2228

2329
Context {CS : compspecs} `{AI : atomic_int_impl} {AP : atomic_ptr_impl}.
2430

atomics/general_atomics.v

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ Ltac start_function1 ::=
855855
|- _ => idtac
856856
| s:=?spec':_ |- _ => check_canonical_funspec spec'
857857
end; change (semax_body V G F s); subst s)
858-
end; unfold NDmk_funspec;
858+
end;
859859
(let gv := fresh "gv" in
860860
match goal with
861861
| |- semax_body _ _ _ (_, mk_funspec _ _ _ _ ?Pre _) =>
@@ -871,8 +871,15 @@ Ltac start_function1 ::=
871871
| (a, b) => _
872872
end => intros Espec [a b]
873873
| λne i, _ => intros Espec i
874-
end; simpl fn_body; simpl fn_params; simpl fn_return
875-
end;
874+
end
875+
| |- semax_body _ _ _ (pair _ (NDmk_funspec _ _ _ ?Pre _)) =>
876+
split3; [check_parameter_types' | check_return_type | ];
877+
match Pre with
878+
| (convertPre _ _ (fun i => _)) => intros Espec (*DependedTypeList*) i
879+
| (fun x => match _ with (a,b) => _ end) => intros Espec (*DependedTypeList*) [a b]
880+
| (fun i => _) => intros Espec (*DependedTypeList*) i (* this seems to be named "a" no matter what *)
881+
end
882+
end; simpl fn_body; simpl fn_params; simpl fn_return;
876883
cbv[dtfr dependent_type_functor_rec constOF idOF prodOF discrete_funOF ofe_morOF
877884
sigTOF listOF oFunctor_car ofe_car] in *; cbv[ofe_mor_car];
878885
rewrite_old_main_pre; rewrite ?argsassert_of_at ?assert_of_at;

atomics/verif_lock.v

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ Section mpred.
99

1010
Context `{!VSTGS OK_ty Σ, !cinvG Σ, atom_impl : !atomic_int_impl (Tstruct _atom_int noattr)}.
1111

12-
(* add these to atomic_int_impl? *)
13-
Axiom atomic_int_isptr : forall sh v p, atomic_int_at sh v p ⊢ ⌜isptr p⌝.
14-
#[local] Hint Resolve atomic_int_isptr : saturate_local.
15-
Axiom atomic_int_timeless : forall sh v p, Timeless (atomic_int_at sh v p).
16-
#[export] Existing Instance atomic_int_timeless.
17-
1812
#[global] Opaque atomic_int_at.
1913

2014
Section PROOFS.

atomics/verif_lock_atomic.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Section PROOFS.
9191
Proof.
9292
start_function.
9393
Intros v.
94-
assert_PROP (is_pointer_or_null a) by entailer.
94+
assert_PROP (is_pointer_or_null p) by entailer.
9595
forward_call.
9696
- Exists v. cancel.
9797
- entailer!.

lib/proof/spec_SC_atomics.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Notation vint z := (Vint (Int.repr z)).
1717
atomic_int_at__ : forall sh v p, atomic_int_at sh v p ⊢ atomic_int_at sh Vundef p;
1818
atomic_int_conflict : forall sh v v' p, sepalg.nonidentity sh -> atomic_int_at sh v p ∗ atomic_int_at sh v' p ⊢ False%I;
1919
atomic_int_isptr : forall sh v p, atomic_int_at sh v p ⊢ ⌜isptr p⌝;
20-
atomic_int_timeless : forall sh v p, Timeless (atomic_int_at sh v p);
21-
atomic_ptr : type := Tstruct _atom_ptr noattr;
20+
atomic_int_timeless sh v p :: Timeless (atomic_int_at sh v p);
21+
atomic_ptr : type := Tstruct _atom_ptr noattr;
2222
atomic_ptr_at : share -> val -> val -> mpred;
2323
atomic_ptr_conflict : forall sh v v' p, sepalg.nonidentity sh -> atomic_ptr_at sh v p ∗ atomic_ptr_at sh v' p ⊢ False%I
2424
}.

lib/proof/verif_locks.v

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Definition Vprog : varspecs. mk_varspecs prog. Defined.
1717

1818
Section mpred.
1919

20-
Context `{!VSTGS OK_ty Σ, !cinvG Σ, atom_impl : !atomic_int_impl (Tstruct _atom_int noattr)}.
20+
Context `{!VSTGS OK_ty Σ, !cinvG Σ(*, atom_impl : !atomic_int_impl (Tstruct _atom_int noattr)*)}.
2121

2222

2323
#[export] Program Instance M : lockAPD := {
@@ -98,8 +98,6 @@ Definition Gprog := lockImports ++ LockASI.
9898
{ eapply semax_pre, semax_ff; go_lower; done. }
9999
Qed.
100100

101-
Opaque inv_for_lock.
102-
103101
Lemma body_release: semax_body Vprog Gprog f_release release_spec.
104102
Proof.
105103
(* the following line should not be necessary;
@@ -112,7 +110,6 @@ Opaque inv_for_lock.
112110
- destruct h as ((p, i), g); simpl; Intros.
113111
subst Frame; instantiate (1 := []); simpl; cancel.
114112
iIntros "(HR & #I & ? & P & HQ)".
115-
(* the next line fails for some reason
116113
iInv i as "((% & >p & ?) & Hown)" "Hclose".
117114
destruct b.
118115
+ iExists Ews; rewrite (bi.pure_True (writable_share _)) //.
@@ -127,7 +124,6 @@ Opaque inv_for_lock.
127124
rewrite bi.affinely_elim; iNext; iApply ("HR" with "[$]").
128125
- entailer!.
129126
Qed.
130-
*) Admitted.
131127

132128
Lemma body_acquire: semax_body Vprog Gprog f_acquire acquire_spec.
133129
Proof.
@@ -151,7 +147,7 @@ Opaque inv_for_lock.
151147
- unfold lock_inv; destruct h as ((p, i), g); Intros.
152148
subst Frame; instantiate (1 := []); simpl fold_right_sepcon; cancel.
153149
iIntros "(#I & ?)".
154-
(* the next line fails for some reason
150+
rewrite {1}/inv_for_lock /=.
155151
iInv "I" as "((% & >? & ?) & ?)" "Hclose".
156152
iExists Ews, (Val.of_bool b); rewrite (bi.pure_True (writable_share _)) //.
157153
iFrame.
@@ -165,8 +161,9 @@ Opaque inv_for_lock.
165161
- Intros r. if_tac; forward_if; try discriminate; try contradiction.
166162
+ forward. simpl lock_inv; entailer!.
167163
+ forward. simpl lock_inv; entailer!.
168-
Qed. *)
169-
Admitted.
164+
Qed.
165+
166+
Opaque inv_for_lock.
170167

171168
#[global] Opaque M.
172169

lib/test/verif_incr.v

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Require Import VST.floyd.VSU.
33
Require Import VST.concurrency.conclib.
44
From VSTlib Require Import spec_locks spec_threads spec_malloc.
55
Require VSTlib.verif_locks.
6+
Require Import iris_ora.algebra.ext_order.
67
Require Import iris_ora.logic.cancelable_invariants.
8+
Require Import iris.algebra.lib.excl_auth.
79
Require Import VSTlibtest.incr.
810

911
#[export] Instance CompSpecs : compspecs. make_compspecs prog. Defined.
@@ -12,11 +14,12 @@ Definition Vprog : varspecs. mk_varspecs prog. Defined.
1214
#[export] Existing Instance verif_locks.M.
1315
#[export] Existing Instance verif_malloc.M.
1416

17+
Canonical Structure excl_authR A := inclR (excl_authR A).
1518

1619
Section mpred.
17-
Context `{VSTGS1: !VSTGS unit Σ,
18-
cinvG1: !cinvG Σ,
19-
inG1: !inG Σ (excl_authR natO),
20+
Context `{VSTGS1: !VSTGS unit Σ,
21+
cinvG1: !cinvG Σ,
22+
inG1: !inG Σ (excl_authR natO),
2023
aii1: !atomic_int_impl (Tstruct _atom_int noattr)}.
2124

2225
Definition spawn_spec := DECLARE _spawn spawn_spec.
@@ -216,7 +219,6 @@ Proof.
216219
ghost_alloc (fun g => own g (●E O ⋅ ◯E O : excl_authR natO)).
217220
{ apply excl_auth_valid. }
218221
Intro g2.
219-
sep_apply (library.create_mem_mgr gv).
220222
forward_call (gv, fun _ : lock_handle => cptr_lock_inv g1 g2 ctr).
221223
Intros lock.
222224
forward.
@@ -253,11 +255,13 @@ Proof.
253255
{ lock_props.
254256
rewrite -{2}Qp.half_half -frac_op -lock_inv_share_join.
255257
subst ctr; cancel. }
256-
forward.
258+
forward.
257259
unfold_data_at (data_at_ _ _ _). simpl.
258260
cancel.
259-
admit.
260-
Admitted.
261+
unfold cptr_lock_inv; Intros z x y; cancel.
262+
rewrite -(field_at_share_join _ _ Ews); [|eauto]; cancel.
263+
by iIntros "(_ & _ & _ & _)".
264+
Qed.
261265

262266
(*
263267

lib/test/verif_incr_main.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Definition AB_VSU :=
2323
Require VSTlib.verif_locks.
2424
Definition ABC_VSU:=
2525
ltac:(linkVSUs AB_VSU
26-
(verif_locks.LockVSU (atom_impl := aii1))).
26+
(verif_locks.LockVSU)).
2727

2828
Ltac SC_tac ::=
2929
match goal with |- SC_test ?ids _ _ =>
@@ -42,13 +42,13 @@ Ltac SC_tac ::=
4242
end.
4343

4444
Definition core_VSU :=
45-
ltac:(linkVSUs (IncrVSU (aii1:=aii1)) ABC_VSU).
45+
ltac:(linkVSUs IncrVSU ABC_VSU).
4646

4747
#[export] Instance CompSpecs : compspecs. make_compspecs prog. Defined.
4848
Definition main_QPprog := ltac:(QPprog prog).
4949
Definition whole_prog := ltac:(QPlink_progs main_QPprog (VSU_prog core_VSU)).
5050
Definition Vprog: varspecs := QPvarspecs whole_prog.
51-
Definition Main_imports := filter (matchImportExport main_QPprog) (VSU_Exports core_VSU).
51+
Definition Main_imports := filter (matchImportExport main_QPprog) (VSU_Exports core_VSU).
5252

5353
Definition main_spec :=
5454
DECLARE _main

progs/incr.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "../concurrency/threads.h"
22
//#include <stdio.h>
33

4-
typedef struct counter { unsigned ctr; lock_t *lock; } counter;
4+
typedef struct counter { unsigned ctr; lock_t lock; } counter;
55
counter c;
66

77
void incr() {
@@ -21,16 +21,16 @@ int thread_func(void *thread_lock) {
2121
//Increment the counter
2222
incr();
2323
//Yield: 'ready to join'.
24-
release((lock_t *)thread_lock);
24+
release((lock_t)thread_lock);
2525
return 0;
2626
}
2727

28-
int main(void)
28+
int compute2(void)
2929
{
3030
c.ctr = 0;
3131
c.lock = makelock();
3232
release(c.lock);
33-
lock_t *thread_lock = makelock();
33+
lock_t thread_lock = makelock();
3434
/* Spawn */
3535
spawn((void *)&thread_func, (void *)thread_lock);
3636

@@ -49,3 +49,7 @@ int main(void)
4949

5050
return t;
5151
}
52+
53+
int main(void) {
54+
return compute2();
55+
}

0 commit comments

Comments
 (0)