Skip to content

Commit 394e769

Browse files
Merge pull request #101 from SkyLabsAI/gmalecha/vector-repfor
[RepFor] instance for [vector<T>] & misc types
2 parents fc7b5bb + 045bde3 commit 394e769

5 files changed

Lines changed: 48 additions & 1 deletion

File tree

rocq-brick-libstdcpp/proof/mutex/spec/defer_lock_t.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Section with_cpp.
88
Parameter R : forall {σ : genv}, cQp.t -> Rep.
99
#[only(cfracsplittable, type_ptr="std::defer_lock_t")] derive R.
1010

11+
Section with_RepFor.
12+
Import rep.RepFor.
13+
Import RepScheme.
14+
15+
#[global] Instance repfor `{Σ : cpp_logic} {σ : genv} :
16+
rep.RepFor.C "std::defer_lock_t" [ArgType.CFrac] R := {}.
17+
End with_RepFor.
18+
1119
cpp.spec "std::defer_lock_t::defer_lock_t(const std::defer_lock_t&)" as defer_lock_copy_ctor_spec from source with (
1220
\this this
1321
\arg{other} "other" (Vptr other)

rocq-brick-libstdcpp/proof/mutex/spec/lock_guard.v

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ Module lock_guard.
2626
#[only(type_ptr)] derive R.
2727
#[only(lazy_unfold)] derive R.
2828

29+
Section with_RepFor.
30+
Import rep.RepFor.
31+
Import RepScheme.
32+
33+
#[global] Instance repfor `{Σ : cpp_logic, !HasStdThreads Σ} {σ : genv} :
34+
rep.RepFor.C "std::lock_guard<std::mutex>"
35+
[ArgType.Constant _; ArgType.CFrac; ArgType.Constant _]
36+
R := {}.
37+
End with_RepFor.
38+
2939
(**
3040
These automated proofs fail, so we prove it by hand.
3141
[R_cfrac] does not seem too useful (why ever split a lock guard?), but let's

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ Section with_cpp.
3535
Parameter token : forall {HAS_THREADS : HasStdThreads Σ} {σ : genv}, gname -> Qp -> mpred.
3636
#[only(fractional,fracvalid,asfractional,timeless)] derive token.
3737

38+
Section with_RepFor.
39+
Import rep.RepFor.
40+
Import RepScheme.
41+
42+
#[global] Instance repfor `{!HasStdThreads Σ} {σ : genv} :
43+
rep.RepFor.C "std::mutex" [ArgType.Constant _; ArgType.CFrac; ArgType.Constant _]
44+
(funI γ q P => R γ q P ∗ pureR (token γ q)) := {}.
45+
End with_RepFor.
46+
47+
3848
(** A resource enforcing that the thread calling unlock must be the same thread
3949
that owns the lock
4050

rocq-brick-libstdcpp/proof/mutex/spec/unique_lock.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ NES.Begin unique_lock.
4848
pureR (m.(mutex_ptr) |-> mutexR (cQp.scale m.(mutex_q) q) m.(mutex_m))
4949
end.
5050

51+
Section with_RepFor.
52+
Import rep.RepFor.
53+
Import RepScheme.
54+
55+
#[global] Instance repfor `{Σ : cpp_logic} {σ : genv} ty {T} mutexR `{!BasicLockable ty (T:=T) mutexR} :
56+
rep.RepFor.C (Tnamed $ "std::unique_lock" .<< Atype ty >>) [ArgType.CFrac; ArgType.Constant _]
57+
(R ty mutexR) := {}.
58+
End with_RepFor.
59+
5160
Module R_unfold.
5261
#[only(lazy_unfold(export))] derive R.
5362
End R_unfold.

rocq-brick-libstdcpp/proof/vector/spec.v

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ NES.Begin std.
148148
(** Question(Simon): Should we take a predicate as a parameter instead of using [objR]? That would allow varying the
149149
representation of the contents of the vector of the course of a single proof. That's also enabled by manipulating
150150
[spineR] and [array_sliceR] separately. *)
151-
#[global] Notation R_alloc_cap ty alloc_ty q size st xs :=
151+
#[global] Abbreviation R_alloc_cap ty alloc_ty q size st xs :=
152152
( spineR ty alloc_ty q size st **
153153
pureR (base_pointer st |-> array_sliceR ty 0 size (objR ty q) xs) )%I
154154
(q in scope cQp_scope, basep in scope bi_scope, size, cap in scope Z_scope ).
@@ -163,6 +163,16 @@ NES.Begin std.
163163
#[global] Abbreviation R ty q xs :=
164164
(R_alloc ty (std.allocator.T ty) q xs).
165165

166+
Section with_RepFor.
167+
Import rep.RepFor.
168+
Import RepScheme.
169+
170+
#[global] Instance repfor `{Σ : cpp_logic} {σ : genv} ty aty `(_ : BundledRep ty M) :
171+
rep.RepFor.C (T ty aty)
172+
[ArgType.CFrac; ArgType.Model _]
173+
(λ q xs, R ty q xs) := {}.
174+
End with_RepFor.
175+
166176
(** [R_alloc_resized ty alloc_ty q size st xs] is a vector whose payloads can be proven (on
167177
demand) to be stored in memory specified by [st] if that memory can accommodate [size] elements.
168178
Otherwise, the memory location of the payloads is unspecified.

0 commit comments

Comments
 (0)