Skip to content

Commit 9911eca

Browse files
committed
Another work bug?
1 parent f36c2bf commit 9911eca

1 file changed

Lines changed: 60 additions & 14 deletions

File tree

rocq-brick-libstdcpp/proof/mutex/demo_cpp_proof.v

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Definition CR
3232
structR "C" q **
3333
_field "C::mut" |-> recursive_mutex.R γ.(recursive_mutex.lock_gname) q **
3434
as_Rep (fun this : ptr =>
35-
recursive_mutex.inv_rmutex γ (∃ a_b : tele_arg _, tele_app (P this) a_b)).
35+
recursive_mutex.inv_rmutex γ (∃ a b, this |-> CR' a b)).
3636

3737
#[only(cfractional,ascfractional,type_ptr)] derive CR.
3838
#[only(lazy_unfold)] derive CR.
@@ -50,32 +50,78 @@ Section with_cpp.
5050
\arg{x} "x" (Vint x)
5151
\prepost{γ q} this |-> CR γ q
5252
\prepost{q'} recursive_mutex.token γ.(recursive_mutex.lock_gname) q'
53-
\pre{args th} recursive_mutex.acquireable γ th args (TT:=TT) (P this)
54-
\post recursive_mutex.acquireable γ th (TT:=TT) (recursive_mutex.update (TT:=TT) (fun (a b : Z) => mk (trim 64 (a+x)) b) args) (P this)).
53+
\pre{args th} recursive_mutex.acquireable γ th args (TT:=TT) (fun a b => this |-> CR' a b)
54+
\post recursive_mutex.acquireable γ th (TT:=TT) (recursive_mutex.update (TT:=TT) (fun (a b : Z) => mk (trim 64 (a+x)) b) args) (fun a b => this |-> CR' a b)).
5555

5656
cpp.spec "C::update_b(long)" as C_update_b from demo_cpp.source with
5757
(\this this
5858
\arg{x} "x" (Vint x)
5959
\prepost{γ q} this |-> CR γ q
6060
\prepost{q'} recursive_mutex.token γ.(recursive_mutex.lock_gname) q'
61-
\pre{args th} recursive_mutex.acquireable γ th args (TT:=TT) (P this)
62-
\post recursive_mutex.acquireable γ th (TT:=TT) (recursive_mutex.update (TT:=TT) (fun (a b : Z) => mk a (trim 64 (b + x))) args) (P this)).
61+
\pre{args th} recursive_mutex.acquireable γ th args (TT:=TT) (fun a b => this |-> CR' a b)
62+
\post recursive_mutex.acquireable γ th (TT:=TT) (recursive_mutex.update (TT:=TT) (fun (a b : Z) => mk a (trim 64 (b + x))) args) (fun a b => this |-> CR' a b)).
6363

6464
#[global] Instance CR_learn : Cbn (Learn (learn_eq ==> any ==> learn_hints.fin) CR).
6565
Proof. solve_learnable. Qed.
6666

67+
Import recursive_mutex.
68+
69+
#[global] Instance: `{Proper (equiv ==> equiv) (inv_rmutex γ)}.
70+
Proof. rewrite inv_rmutex.unlock. solve_proper. Qed.
71+
72+
#[program]
73+
Definition inv_rmutex_iff_C γ :=
74+
\cancelx
75+
\preserving{P1} inv_rmutex γ P1
76+
\proving{P2} inv_rmutex γ P2
77+
\through [| P1 ⊣⊢@{mpredI} P2 |]
78+
\end.
79+
Next Obligation. work. by setoid_subst. Qed.
80+
#[local] Hint Resolve inv_rmutex_iff_C : br_hints.
81+
82+
#[program]
83+
Definition inv_rmutex_wand_C γ :=
84+
\cancelx
85+
\preserving{P1} inv_rmutex γ P1
86+
\proving{P2} inv_rmutex γ P2
87+
\through □ (P1 ∗-∗ P2)
88+
\end.
89+
Next Obligation.
90+
rewrite inv_rmutex.unlock.
91+
iIntros "%% A %P2 #[? ?]".
92+
iApply (inv_iff with "A").
93+
iIntros "!> !>"; iSplit; ework with br_erefl; case_match; work.
94+
Qed.
95+
(* #[local] Hint Resolve inv_rmutex_wand_C : br_hints. *)
96+
97+
Lemma CR'_tele_equiv (this : ptr) :
98+
(∃ a b : Z, this |-> CR' a b) ⊣⊢
99+
∃ xs : TT, tele_app (TT := TT) (λ a b : Z, this |-> CR' a b) xs.
100+
Proof.
101+
iSplit.
102+
{ iDestruct 1 as (a b) "?"; iExists (mk a b); work. }
103+
iDestruct 1 as ([a [b []]]) "?"; iExists a, b; work.
104+
Qed.
105+
#[local] Hint Resolve CR'_tele_equiv : br_hints.
106+
107+
Lemma CR'_self_eq (this : ptr) :
108+
(∃ a b : Z, this |-> CR' a b) ⊣⊢
109+
(∃ a b : Z, this |-> CR' a b).
110+
Proof. done. Qed.
111+
#[local] Hint Resolve CR'_self_eq : br_hints.
112+
67113
Lemma update_a_ok : verify[source] "C::update_a(long)".
68114
Proof.
69115
verify_spec; go.
70116
iExists TT.
71117
go.
72-
73-
rewrite P.unlock /=.
74118
destruct args as [a [b []]]; simpl; go.
75-
iExists TT, _, _, (mk (trim 64 (a + x)) b).
119+
iExists TT, (P this), _, (mk (trim 64 (a + x)) b).
120+
go.
121+
rewrite P.unlock.
76122
go.
77123
erewrite recursive_mutex.update_eq; last done; cbn.
78-
rewrite P.unlock; work.
124+
work.
79125
Qed.
80126

81127
Lemma update_b_ok : verify[source] "C::update_b(long)".
@@ -84,31 +130,31 @@ Section with_cpp.
84130
iExists TT.
85131
go.
86132

87-
rewrite P.unlock /=.
88133
destruct args as [a [b []]]; simpl; go.
89134
iExists TT, _, _, (mk a (trim 64 (b + x))).
90135
go.
91136
erewrite recursive_mutex.update_eq; last done; cbn.
92-
rewrite P.unlock; work.
137+
work.
93138
Qed.
94139

95140
cpp.spec "C::transfer(int)" as C_transfer_int from demo_cpp.source with
96141
(\this this
97142
\arg{x} "x" (Vint x)
98143
\prepost{γ q} this |-> CR γ q
99144
\prepost{q'} recursive_mutex.token γ.(recursive_mutex.lock_gname) q'
100-
\pre{args th} recursive_mutex.acquireable γ th args (TT:=TT) (P this)
101-
\post recursive_mutex.acquireable γ th (TT:=TT) (recursive_mutex.update (TT:=TT) (fun (a b : Z) => mk (trim 64 (a+x)) (trim 64 (b-x))) args) (P this)).
145+
\pre{args th} recursive_mutex.acquireable γ th args (TT:=TT) (fun a b => this |-> CR' a b)
146+
\post recursive_mutex.acquireable γ th (TT:=TT) (recursive_mutex.update (TT:=TT) (fun (a b : Z) => mk (trim 64 (a+x)) (trim 64 (b-x))) args) (fun a b => this |-> CR' a b)).
102147

103148
Lemma transfer_ok : verify[source] "C::transfer(int)".
104149
Proof.
105150
verify_spec; go.
106151
iExists TT.
107152
go.
153+
destruct args as [a[b []]]; simpl.
154+
go.
108155
iExists TT.
109156
go.
110157
erewrite recursive_mutex.update_eq; last done; cbn.
111-
destruct args as [a[b []]]; simpl.
112158
work.
113159
Qed.
114160

0 commit comments

Comments
 (0)