Skip to content

Commit 6b22d5b

Browse files
committed
more explanation about init_ctor spec
1 parent fffa0b2 commit 6b22d5b

File tree

1 file changed

+8
-3
lines changed
  • rocq-brick-libcpp/proof/shared_ptr

1 file changed

+8
-3
lines changed

rocq-brick-libcpp/proof/shared_ptr/specs.v

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,21 @@ Section specs.
107107
specify {| info_name := (Nscoped ("std::shared_ptr".<<Atype ty>>) (Nctor [Tptr ty])).<<Atype ty, Atype "void">>
108108
; info_type := tCtor ("std::shared_ptr".<<Atype ty>>) [Tptr ty] |} (fun (this:ptr) =>
109109
\arg{p:ptr} "ownedPtr" (Vptr p)
110+
\pre{Rpiece: nat -> Rep} [∗ list] ctid ∈ allButFirstPieceId, p |-> Rpiece ctid
111+
(* ^ morally, the caller gives up all the pieces and gets back the 0th piece. The remaining pieces get stored in the invariant.
112+
Should this object be destructed immediately, the destructor will need all the pieces to call delete.
113+
We frame away the 0th piece in this spec. A derived spec can be proven where that framing away is not done *)
110114
\pre{p} dynAllocatedR ty p
111-
\pre{Rpiece: nat -> Rep} [∗ list] ctid ∈ allButFirstPieceId,
112-
p |-> Rpiece ctid
115+
(* ^ gets stored in the invariant. only gets taken out when the count becomes 0, to call delete. at that time the ownership of all other pieces are also taken out from the invariant *)
113116
\pre [|([∗ list] ctid ∈ allPieceIds, Rpiece ctid)
114117
|-- anyR ty 1 |]
115118
(* ^^ if anyR is not meaningful for non-scalar types,
116119
replace this with wp of default destructor *)
117120
\post Exists (ctrlBlockId: CtrlBlockId),
118121
this |-> SharedPtrR ctrlBlockId Rpiece p
119-
** ([∗ list] ctid ∈ allButFirstPieceId, pieceRight ctrlBlockId ctid)).
122+
** ([∗ list] ctid ∈ allButFirstPieceId, pieceRight ctrlBlockId ctid)
123+
(* ^ the right to create [maxContention-1] more shared_ptr objects on this payload and claim the correponsing Rpiece ownerships at copy construction *)
124+
).
120125

121126
Definition SpecFor_init_ctor := RegisterSpec init_ctor.
122127
#[global] Existing Instance SpecFor_init_ctor.

0 commit comments

Comments
 (0)