Ranvier.Heap.Ownership

Reading settings

Look

Mode

Definitions

Proofs

Imports

Arguments

References

References open

Saved in this browser.

ModulesGuarantees

Modules

Audit0Extract12

Base

Prelude9Syntax43

Reference

Semantics63Properties202

Pure

ObserverSet29SourceList104State16Edges12Marking117Engine103Check204Runs259Scheduler241Ownership49WholeGraph562Refinement465Witnesses244Optimised271Ledger6Collections302Concurrency141Extensions123Deltas68FastPaths435Combinators106MemoTable147MemoTableWitnesses62MemoTableFastPaths113

Heap

ObserverSet46SourceList89Ghost160Marking22Run286Scheduler7Ownership29Adequacy3Collections38Concurrency41Extensions17Deltas10MemoTable28

Conformance

Expected64Check119
On this page

On this page

Heap ownership: doubly-linked OwnerLink chains and whole-graph disposalDoubly-linked OwnerLink heap representationopt_loc_valprev_loc_ofhead_loc_ofowner_links_new_codeowner_links_append_codeowner_links_detach_codeowner_links_walk_prev_codeowner_links_unlink_codeis_link_nodeis_dchain_revis_owner_linksfields4_olfields5_lkowner_links_new_specowner_links_append_specowner_links_detach_specowner_links_walk_prev_specowner_links_stale_unlink_specWhole-graph ownership specifications and corollariesdispose_node_specdischarge_specretire_specdispose_scope_specteardown_specrun_cleanup_specrelease_specattach_specheap_ownership_guarantees
This definition

Ranvier.Heap.Ownership

Heap ownership: doubly-linked OwnerLink chains and whole-graph disposal

This module provides:

  1. The separation-logic representation and specifications for the doubly-linked OwnerLink list of Owner (Core.fs lines 955–1226) with unbounded integer generations (is_owner_links, owner_links_new_spec, owner_links_append_spec, owner_links_detach_spec, owner_links_walk_prev_spec, and owner_links_stale_unlink_spec).
  2. The whole-graph HeapLang specifications for dispose_node_code, discharge_code, retire_code, dispose_scope_code, teardown_code, run_cleanup_code, release_code, and attach_code, together with corollaries lifting Pure/Ownership.v's theorems (owners_in_order, cleanup_once_new_graph, disposed_no_edges_new_graph, disposed_effect_never_runs) to the heap tier.
7
From stdpp Require Import prelude gmap.
From Stdlib Require Import ZArith Sorted.
From Ranvier.Base Require Import Prelude Syntax.
From Ranvier.Pure Require Import ObserverSet SourceList State Edges Marking Engine Check Runs Scheduler Ownership.
From iris.heap_lang Require Import proofmode notation.
From Ranvier.Heap Require Import ObserverSet SourceList Ghost Marking Run Scheduler.
Open Scope nat_scope.
Definition opt_loc_val (ml : option loc) : val :=
  match ml with None => NONEV | Some l => SOMEV #l end.
References

Uses

  • None
  • Some
  • option
  • heap_lang.val
  • loc
  • NONEV
  • SOMEV
Definition prev_loc_of (rentries : list (loc * link)) : option loc :=
  match rentries with [] => None | (lk, _) :: _ => Some lk end.
References

Uses

  • link
  • None
  • Some
  • list
  • option
  • loc
Definition head_loc_of (rentries : list (loc * link)) : option loc :=
  fst <$> last rentries.
References

Uses

  • link
  • fst
  • list
  • option
  • loc
  • list.last
Section owner_links.
Context `{!heapGS Σ}.
References

Uses

  • heapGS
Fixpoint is_dchain_rev (next : option loc) (rentries : list (loc * link)) : iProp Σ :=
  match rentries with
  | [] => True
  | (lk, l) :: r' =>
      is_link_node lk (prev_loc_of r') next l ∗
      is_dchain_rev (Some lk) r'
  end.
References

Uses

1 more
  • loc
Local Lemma fields4_ol (l : loc) (v : val) :
  l ↦∗ replicate 4 v ⊣⊢
  l ↦ v ∗ (l +ₗ 1) ↦ v ∗ (l +ₗ 2) ↦ v ∗ (l +ₗ 3) ↦ v.
Qed
Proof.
  rewrite /= !array_cons array_nil !Loc.add_assoc /=.
  by rewrite right_id.
Qed.
References

Uses

  • array_cons
  • array_nil
  • heap_lang.val
  • Loc.add_assoc
  • loc
  • right_id
  • list.replicate
Local Lemma fields5_lk (l : loc) (v : val) :
  l ↦∗ replicate 5 v ⊣⊢
  l ↦ v ∗ (l +ₗ 1) ↦ v ∗ (l +ₗ 2) ↦ v ∗ (l +ₗ 3) ↦ v ∗ (l +ₗ 4) ↦ v.
Qed
Proof.
  rewrite /= !array_cons array_nil !Loc.add_assoc /=.
  by rewrite right_id.
Qed.
References

Uses

  • array_cons
  • array_nil
  • heap_lang.val
  • Loc.add_assoc
  • loc
  • right_id
  • list.replicate
End owner_links.

Whole-graph ownership specifications and corollaries

Section heap_ownership.
Context `{!heapGS Σ, !graphG Σ}.
References

Uses

✓ No axioms

dispose_node_code refines dispose_node (Memo.Dispose and Effect.Dispose) over is_graph.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the node id disposed.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Theorem dispose_node_spec γ g (n : node_id) (s : State.state) (fuel : nat) (s' : State.state) :
  dispose_node fuel n s = Some (s', tt) ->
  {{{ is_graph γ g s }}}
    dispose_node_code g #(Z.of_nat n)
  {{{ RET #(); is_graph γ g s' }}}.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the node id disposed.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Qed
Proof.
  intros H. iIntros (Φ) "Hg HΦ". wp_lam. wp_pures.
  by wp_apply (es_dispose_node _ fuel (engine_spec_all fuel) with "Hg").
Qed.
References
✓ No axioms

discharge_code refines discharge (Graph.Discharge) over is_graph.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id discharged.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Theorem discharge_spec γ g (o : owner_id) (s : State.state) (fuel : nat) (s' : State.state) :
  discharge fuel o s = Some (s', tt) ->
  {{{ is_graph γ g s }}}
    discharge_code g #(Z.of_nat o)
  {{{ RET #(); is_graph γ g s' }}}.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id discharged.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Qed
Proof.
  intros H. iIntros (Φ) "Hg HΦ". wp_lam. wp_pures.
  by wp_apply (es_discharge _ fuel (engine_spec_all fuel) with "Hg").
Qed.
References
✓ No axioms

retire_code refines retire (Graph.Retire and Owner.Dispose) over is_graph.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id retired.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Theorem retire_spec γ g (o : owner_id) (s : State.state) (fuel : nat) (s' : State.state) :
  retire fuel o s = Some (s', tt) ->
  {{{ is_graph γ g s }}}
    retire_code g #(Z.of_nat o)
  {{{ RET #(); is_graph γ g s' }}}.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id retired.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Qed
Proof.
  intros H. iIntros (Φ) "Hg HΦ". wp_lam. wp_pures.
  by wp_apply (es_retire _ fuel (engine_spec_all fuel) with "Hg").
Qed.
References
✓ No axioms

dispose_scope_code refines dispose_scope (Owner.DisposeScope) over is_graph.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id whose scope is torn down.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Theorem dispose_scope_spec γ g (o : owner_id) (s : State.state) (fuel : nat) (s' : State.state) :
  dispose_scope fuel o s = Some (s', tt) ->
  {{{ is_graph γ g s }}}
    dispose_scope_code g #(Z.of_nat o)
  {{{ RET #(); is_graph γ g s' }}}.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id whose scope is torn down.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Qed
Proof.
  intros H. iIntros (Φ) "Hg HΦ". wp_lam. wp_pures.
  by wp_apply (es_dispose_scope _ fuel (engine_spec_all fuel) with "Hg").
Qed.
References
✓ No axioms

teardown_code refines teardown (the reverse-acquisition merge loop of Owner.DisposeScope) over is_graph.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id being torn down.
ls : list link
the remaining child links in reverse acquisition order.
cs : list (cmd * env * nat)
the remaining cleanups in reverse acquisition order.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Theorem teardown_spec γ g (o : owner_id) (ls : list link) (cs : list (cmd * env * nat))
    (s : State.state) (fuel : nat) (s' : State.state) :
  teardown fuel o ls cs s = Some (s', tt) ->
  {{{ is_graph γ g s }}}
    teardown_code g #(Z.of_nat o) (links_val ls) (cleanups_val cs)
  {{{ RET #(); is_graph γ g s' }}}.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id being torn down.
ls : list link
the remaining child links in reverse acquisition order.
cs : list (cmd * env * nat)
the remaining cleanups in reverse acquisition order.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Qed
Proof.
  intros H. iIntros (Φ) "Hg HΦ". wp_lam. wp_pures.
  by wp_apply (es_teardown _ fuel (engine_spec_all fuel) with "Hg").
Qed.
References
✓ No axioms

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id whose cleanup runs.
b : cmd
the cleanup body command.
e : env
the cleanup environment.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Theorem run_cleanup_spec γ g (o : owner_id) (b : cmd) (e : env)
    (s : State.state) (fuel : nat) (s' : State.state) :
  run_cleanup fuel o b e s = Some (s', tt) ->
  {{{ is_graph γ g s }}}
    run_cleanup_code g #(Z.of_nat o) (compile_cmd b) (env_val e)
  {{{ RET #(); is_graph γ g s' }}}.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the owner id whose cleanup runs.
b : cmd
the cleanup body command.
e : env
the cleanup environment.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Qed
Proof.
  intros H. iIntros (Φ) "Hg HΦ". wp_lam. wp_pures.
  by wp_apply (es_run_cleanup _ fuel (engine_spec_all fuel) with "Hg").
Qed.
References
✓ No axioms

release_code refines release (IOwned.Release) over is_graph.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the released node id.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Theorem release_spec γ g (n : node_id) (s : State.state) (fuel : nat) (s' : State.state) :
  release fuel n s = Some (s', tt) ->
  {{{ is_graph γ g s }}}
    release_code g #(Z.of_nat n)
  {{{ RET #(); is_graph γ g s' }}}.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the released node id.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Qed
Proof.
  intros H. iIntros (Φ) "Hg HΦ". wp_lam. wp_pures.
  by wp_apply (es_release _ fuel (engine_spec_all fuel) with "Hg").
Qed.
References
✓ No axioms

attach_code refines attach (Owner.AttachLinked) over is_graph.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the child node id.
the owner id.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Theorem attach_spec γ g (n : node_id) (o : owner_id) (s : State.state) (fuel : nat) (s' : State.state) :
  attach fuel n o s = Some (s', tt) ->
  {{{ is_graph γ g s }}}
    attach_code g #(Z.of_nat n) #(Z.of_nat o)
  {{{ RET #(); is_graph γ g s' }}}.

Arguments

γ : iprop.gname
the ghost name.
g : lang.heap_lang.val
the graph value.
the child node id.
the owner id.
the initial pure state.
fuel : nat
the pure step budget.
the final pure state.
Qed
Proof.
  intros H. iIntros (Φ) "Hg HΦ". wp_lam. wp_pures.
  by wp_apply (es_attach _ fuel (engine_spec_all fuel) with "Hg").
Qed.
References
✓ No axioms

After any top-level heap program, every owner's children and cleanups are in acquisition order, each host's cleanup events are bounded by its registrations, and every non-running disposed node holds no source edges.

Combines run_top_spec with owners_in_order, cleanup_once_new_graph, and disposed_no_edges_new_graph from Pure/Ownership.v.

Arguments

c : cmd
the top-level command.
fuel : nat
the pure step budget.
the final pure state.
the returned outcome.
Corollary heap_ownership_guarantees (c : cmd) (fuel : nat) (s' : State.state) (r : outcome) :
  run_top fuel c (init current_flags) = Some (s', r) ->
  {{{ True }}}
    run_top_code (compile_cmd c)
  {{{ γ g, RET outcome_val r;
      is_graph γ g s' ∗
      ⌜(∀ o y, g_owners s' !! o = Some y -> acq_ok y) /\
       (∀ h, count_cleanups h (g_trace s') <= registered h s') /\
       (∀ n d, g_nodes s' !! n = Some d -> n_disposed d = true -> n ∉ g_running s' ->
          source_slots (sources_of (g_edges s') n) = [] /\
          (∀ src, ~ edge s' src n) /\
          (∀ src, n ∉ observer_view (observers_of (g_edges s') src)))⌝ }}}.

Arguments

c : cmd
the top-level command.
fuel : nat
the pure step budget.
the final pure state.
the returned outcome.
Qed
Proof.
  intros Hrun. iIntros (Φ) "_ HΦ".
  wp_apply (run_top_spec c fuel s' r Hrun); [done|]. iIntros (γ g) "Hg".
  iApply ("HΦ" $! γ g). iFrame "Hg". iPureIntro. split_and!.
  - intros o y Hy. exact (owners_in_order fuel current_flags c s' r o y Hrun Hy).
  - intros h. exact (proj1 (cleanup_once_new_graph fuel current_flags) c s' r h Hrun).
  - intros n d Hd Hdisp Hnr. exact (disposed_no_edges_new_graph fuel c s' r n d Hrun Hd Hdisp Hnr).
Qed.
References
End heap_ownership.