Ranvier.Heap.MemoTable
Layer 5 — Iris HeapLang Separation Logic & Closed Adequacy (`Heap/MemoTable.v`)
This module verifies the mutable pointer structures, bit-packed slot control blocks, GC-root payload
clearing, EdgeWorld + OwnerLink retirement, passive Dispose(), and closed heap_adequacy theorem
for MemoTable (T24–T28):
T24(lru_ring_ops_spec): Separation-logic Hoare triples forO(1)intrusive doubly-linked weighted-LRU pointer surgery (lru_push_front_code,lru_pop_back_code,lru_unlink_code) overis_lru_ringacross0-,1-,2-, andn-node aliasing configurations.T25(slot_get_and_refill_spec): Separation-logic Hoare triples forslot_pin_code,slot_unpin_code, andslot_get_code(hot resident hit, refill + weighted admission, Ruling R5 oversized bypass, cycle throw/recovery, andObjectDisposedExceptionpost-dispose guard).T26(slot_evict_and_retire_spec): Separation-logic Hoare triples for GC-root payload eviction (value_cell <- NONE, retaining or droppingstamp_cellper Ruling R2) and dormant slot retirement composingworld_direct_unlink_specandowner_links_active_mid_unlink_specfromHeap/Collections.v.T27(memotable_dispose_spec): Separation-logic Hoare triple for passive, idempotentmemotable_dispose_code(Ruling R3), detachingOwnerLinks viaowner_links_detach_code, clearing all slot cells and LRU pointers, and resettingtotal_weightto0.T28(heap_memotable_adequacy): ClosedProptheorem viaheap_adequacyoverranvierΣ(zeroiProp Σin its statement) proving HeapLangMemoTableprograms never get stuck, maintaintotal_weight <= max_weight, and match the pure specification.
8
From stdpp Require Import prelude gmap.
From Stdlib Require Import ZArith.
From Ranvier.Base Require Import Prelude Syntax.
From Ranvier.Pure Require Import ObserverSet SourceList State Edges Marking Engine Ownership Collections MemoTable MemoTableFastPaths.
From iris.heap_lang Require Import adequacy lang proofmode notation.
From iris.heap_lang.lib Require Import array.
From Ranvier.Heap Require Import ObserverSet SourceList Ghost Marking Run Scheduler Ownership Collections Adequacy.
Open Scope nat_scope.1. Heap layouts & HeapLang code for `TableSlot`, intrusive LRU ring, and `MemoTable`
Heap layout of an 8-cell `TableSlot` at location `sl : loc`:
sl +ₗ 0:key(#k)sl +ₗ 1:node_id(#(Z.of_nat nid))sl +ₗ 2:value_cell(NONEVwhen evicted / non-value so GC collects'V,SOMEV #vwhen resident)sl +ₗ 3:stamp_cell(NONEVorSOMEV #st)sl +ₗ 4:slot_flags(#(pack_slot_flags ...)— bits0..1tag,2has_stamp,3in_lru,4in_dorm,5refilling,6..29pins)sl +ₗ 5:weight(#(Z.of_nat w))sl +ₗ 6:lru_prev(NONEVorSOMEV #prev)sl +ₗ 7:lru_next(NONEVorSOMEV #next)
Heap layout of a 4-cell `MemoTable` header at location `tbl : loc`:
tbl +ₗ 0:disposed(#b)tbl +ₗ 1:max_weight(#(Z.of_nat max_w))tbl +ₗ 2:lru_hdr(#hdr— 3-cell intrusive LRU ring header[head; tail; total_weight])tbl +ₗ 3:owner_links(#ol— 4-cellOwnerdoubly-linked list header fromHeap/Ownership.v)
Record slot_heap_data := {
Record slot_heap_data := {
shd_key : Z;
shd_node : nat;
shd_payload : slot_payload;
shd_weight : nat;
shd_in_lru : bool;
shd_in_dorm : bool;
shd_refilling : bool;
shd_pins : nat
}.Definition payload_value_val (p : slot_payload) : val :=
Definition payload_value_val (p : slot_payload) : val :=
match p with
| SlotResident v _ => SOMEV #v
| _ => NONEV
end.References
Uses
- slot_payload
- SlotResident
- heap_lang.val
- NONEV
- SOMEV
Definition payload_stamp_val (p : slot_payload) : val :=
Definition payload_stamp_val (p : slot_payload) : val :=
match p with
| SlotResident _ (Some st) | SlotEvicted (Some st) => SOMEV #st
| _ => NONEV
end.References
Uses
- slot_payload
- SlotResident
- SlotEvicted
- Some
- heap_lang.val
- NONEV
- SOMEV
Definition slot_flags_of (d : slot_heap_data) : Z :=
Definition slot_flags_of (d : slot_heap_data) : Z :=
pack_slot_flags (slot_payload_tag (shd_payload d))
(slot_payload_has_stamp (shd_payload d))
(shd_in_lru d) (shd_in_dorm d) (shd_refilling d) (shd_pins d).Definition lru_ring_new_code : val :=
Definition lru_ring_new_code : val :=
λ: <>,
let: "hdr" := AllocN #3 #0 in
"hdr" <- NONE;;
("hdr" +ₗ #1) <- NONE;;
("hdr" +ₗ #2) <- #0;;
"hdr".Definition slot_alloc_code : val :=
Definition slot_alloc_code : val :=
λ: "k" "nid" "flags",
let: "sl" := AllocN #8 #0 in
"sl" <- "k";;
("sl" +ₗ #1) <- "nid";;
("sl" +ₗ #2) <- NONE;;
("sl" +ₗ #3) <- NONE;;
("sl" +ₗ #4) <- "flags";;
("sl" +ₗ #5) <- #0;;
("sl" +ₗ #6) <- NONE;;
("sl" +ₗ #7) <- NONE;;
"sl".`O(1)` intrusive push-front (MRU insertion) into `hdr = head; tail; total_weight`.
Definition lru_push_front_code : val :=
Definition lru_push_front_code : val :=
λ: "hdr" "sl" "w",
let: "old_hd" := !"hdr" in
("sl" +ₗ #5) <- "w";;
("sl" +ₗ #6) <- NONE;;
("sl" +ₗ #7) <- "old_hd";;
(match: "old_hd" with
NONE =>
"hdr" <- SOME "sl";;
("hdr" +ₗ #1) <- SOME "sl"
| SOME "h0" =>
("h0" +ₗ #6) <- SOME "sl";;
"hdr" <- SOME "sl"
end);;
("hdr" +ₗ #2) <- !("hdr" +ₗ #2) + "w".`O(1)` intrusive pop-back (LRU tail removal) from `hdr = head; tail; total_weight`.
Definition lru_pop_back_code : val :=
Definition lru_pop_back_code : val :=
λ: "hdr",
match: !("hdr" +ₗ #1) with
NONE => NONE
| SOME "tl" =>
let: "prv" := !("tl" +ₗ #6) in
let: "w" := !("tl" +ₗ #5) in
(match: "prv" with
NONE =>
"hdr" <- NONE;;
("hdr" +ₗ #1) <- NONE
| SOME "p" =>
("p" +ₗ #7) <- NONE;;
("hdr" +ₗ #1) <- SOME "p"
end);;
("tl" +ₗ #6) <- NONE;;
("tl" +ₗ #7) <- NONE;;
("hdr" +ₗ #2) <- !("hdr" +ₗ #2) - "w";;
SOME "tl"
end.References
Uses
- heap_lang.val
- NONE
- SOME
`O(1)` intrusive arbitrary-node splice (`unlink`) from `hdr = head; tail; total_weight`.
Definition lru_unlink_code : val :=
Definition lru_unlink_code : val :=
λ: "hdr" "sl",
let: "prv" := !("sl" +ₗ #6) in
let: "nxt" := !("sl" +ₗ #7) in
let: "w" := !("sl" +ₗ #5) in
(match: "prv" with
NONE => "hdr" <- "nxt"
| SOME "p" => ("p" +ₗ #7) <- "nxt"
end);;
(match: "nxt" with
NONE => ("hdr" +ₗ #1) <- "prv"
| SOME "n" => ("n" +ₗ #6) <- "prv"
end);;
("sl" +ₗ #6) <- NONE;;
("sl" +ₗ #7) <- NONE;;
("hdr" +ₗ #2) <- !("hdr" +ₗ #2) - "w".`1`-instruction pin/unpin via `+64` / `-64` on `slot_flags` (`T20`).
Definition slot_pin_code : val :=
Definition slot_pin_code : val :=
λ: "sl", ("sl" +ₗ #4) <- !("sl" +ₗ #4) + #64.Definition slot_unpin_code : val :=
Definition slot_unpin_code : val :=
λ: "sl", ("sl" +ₗ #4) <- !("sl" +ₗ #4) - #64.Evict payload from a popped tail slot `sl`: clears GC root `sl +ₗ 2 <- NONE`, clears `sl +ₗ 3 <- NONE` iff `keep_stamp = #false` (`CutoffComparer`, Ruling R2), zeroes `weight`, and updates `slot_flags`.
Definition slot_clear_payload_code : val :=
Definition slot_clear_payload_code : val :=
λ: "sl" "keep_stamp" "evicted_flags",
("sl" +ₗ #2) <- NONE;;
(if: "keep_stamp" then #() else ("sl" +ₗ #3) <- NONE);;
("sl" +ₗ #5) <- #0;;
("sl" +ₗ #4) <- "evicted_flags".References
Uses
- heap_lang.val
- NONE
Slot `Get` fast/refill/oversized-bypass (R5) / cycle (R1) / disposed (R3) execution on `(tbl, sl)`.
Definition slot_get_code : val :=
Definition slot_get_code : val :=
λ: "tbl" "sl" "is_active" "cycle_mode_recover" "cycle_val"
"compute_val" "stamp_opt" "item_weight" "res_flags" "ev_flags",
if: !"tbl" then InjL #disposed_table_failure
else if: "is_active" then
if: "cycle_mode_recover" then InjR "cycle_val"
else InjL #cycle_detected_failure
else
slot_pin_code "sl";;
let: "res" :=
match: !("sl" +ₗ #2) with
SOME "v_hit" => InjR "v_hit"
| NONE =>
let: "max_w" := !("tbl" +ₗ #1) in
let: "hdr" := !("tbl" +ₗ #2) in
("sl" +ₗ #3) <- "stamp_opt";;
if: "max_w" < "item_weight" then
(* Ruling R5: oversized single value bypasses LRU ring without evicting warm entries! *)
("sl" +ₗ #2) <- NONE;;
("sl" +ₗ #5) <- #0;;
("sl" +ₗ #4) <- ("ev_flags" + #64);;
InjR "compute_val"
else
("sl" +ₗ #2) <- SOME "compute_val";;
("sl" +ₗ #4) <- ("res_flags" + #64);;
lru_push_front_code "hdr" "sl" "item_weight";;
InjR "compute_val"
end in
slot_unpin_code "sl";;
"res".References
Uses
- cycle_detected_failure
- disposed_table_failure
- lru_push_front_code
- slot_pin_code
- slot_unpin_code
- heap_lang.InjL
- heap_lang.InjR
- heap_lang.val
2 more
- NONE
- SOME
Passive `MemoTable.Dispose()` (Ruling R3): idempotent, detaches `OwnerLink`s, clears LRU ring & slot cells.
Fixpoint clear_slot_list_code (sls : list loc) : expr :=
Fixpoint clear_slot_list_code (sls : list loc) : expr :=
match sls with
| [] => #()
| sl :: rest =>
(#sl +ₗ #2) <- NONE;;
(#sl +ₗ #3) <- NONE;;
(#sl +ₗ #5) <- #0;;
(#sl +ₗ #6) <- NONE;;
(#sl +ₗ #7) <- NONE;;
clear_slot_list_code rest
end.References
Uses
- list
- heap_lang.expr
- loc
- NONE
Definition memotable_dispose_header_code : val :=
Definition memotable_dispose_header_code : val :=
λ: "tbl",
if: !"tbl" then #()
else
"tbl" <- #true;;
let: "hdr" := !("tbl" +ₗ #2) in
let: "ol" := !("tbl" +ₗ #3) in
owner_links_detach_code "ol";;
"hdr" <- NONE;;
("hdr" +ₗ #1) <- NONE;;
("hdr" +ₗ #2) <- #0.References
Uses
- owner_links_detach_code
- true
- heap_lang.val
- NONE
2. Separation-logic predicates & Hoare triples (`T24`–`T27`)
Section heap_memotable.
References
Uses
- graphG
- Σ:18
- heapGS
Definition is_table_slot (sl : loc) (prv nxt : option loc) (d : slot_heap_data) : iProp Σ :=
Definition is_table_slot (sl : loc) (prv nxt : option loc) (d : slot_heap_data) : iProp Σ :=
sl ↦ #(shd_key d) ∗
(sl +ₗ 1) ↦ #(Z.of_nat (shd_node d)) ∗
(sl +ₗ 2) ↦ payload_value_val (shd_payload d) ∗
(sl +ₗ 3) ↦ payload_stamp_val (shd_payload d) ∗
(sl +ₗ 4) ↦ #(slot_flags_of d) ∗
(sl +ₗ 5) ↦ #(Z.of_nat (shd_weight d)) ∗
(sl +ₗ 6) ↦ opt_loc_val prv ∗
(sl +ₗ 7) ↦ opt_loc_val nxt.References
Uses
6 more
- slot_flags_of
- option
- heap_memotable.Σ
- Z.of_nat
- iProp_solution.iProp
- loc
Definition lru_head_loc (es : list (loc * slot_heap_data)) : option loc :=
Definition lru_head_loc (es : list (loc * slot_heap_data)) : option loc :=
match es with
| [] => None
| (l, _) :: _ => Some l
end. Fixpoint lru_tail_loc (es : list (loc * slot_heap_data)) : option loc :=
Fixpoint lru_tail_loc (es : list (loc * slot_heap_data)) : option loc :=
match es with
| [] => None
| [(l, _)] => Some l
| _ :: rest => lru_tail_loc rest
end. Fixpoint is_lru_chain (prv : option loc) (es : list (loc * slot_heap_data)) : iProp Σ :=
Fixpoint is_lru_chain (prv : option loc) (es : list (loc * slot_heap_data)) : iProp Σ :=
match es with
| [] => True
| (sl, d) :: rest =>
is_table_slot sl prv (lru_head_loc rest) d ∗
is_lru_chain (Some sl) rest
end.References
Uses
- slot_heap_data
- is_table_slot
- lru_head_loc
- Some
- list
- option
- heap_memotable.Σ
- iProp_solution.iProp
1 more
- loc
Definition is_lru_ring (hdr : loc) (es : list (loc * slot_heap_data)) (tot : nat) : iProp Σ :=
Definition is_lru_ring (hdr : loc) (es : list (loc * slot_heap_data)) (tot : nat) : iProp Σ :=
⌜tot = list_sum (shd_weight <$> es.*2)⌝ ∗
hdr ↦ opt_loc_val (lru_head_loc es) ∗
(hdr +ₗ 1) ↦ opt_loc_val (lru_tail_loc es) ∗
(hdr +ₗ 2) ↦ #(Z.of_nat tot) ∗
is_lru_chain None es.References
Uses
6 more
- nat
- heap_memotable.Σ
- list_sum
- Z.of_nat
- iProp_solution.iProp
- loc
Definition is_memotable_hdr (tbl hdr ol : loc) (disposed : bool) (max_w : nat) : iProp Σ :=
Definition is_memotable_hdr (tbl hdr ol : loc) (disposed : bool) (max_w : nat) : iProp Σ :=
tbl ↦ #disposed ∗
(tbl +ₗ 1) ↦ #(Z.of_nat max_w) ∗
(tbl +ₗ 2) ↦ #hdr ∗
(tbl +ₗ 3) ↦ #ol.References
Uses
- bool
- nat
- heap_memotable.Σ
- Z.of_nat
- iProp_solution.iProp
- loc
T24: Intrusive O(1) doubly-linked weighted-LRU pointer specifications (lru_ring_ops_spec)
covering:
lru_push_front_codeonto both empty (es = []) and non-empty (es = (h0, d0) :: rest) rings,lru_pop_back_codefrom empty ([]), singleton ([(tl, d)]), and 2-node ([(hd, dh); (tl, dt)]) rings,lru_unlink_codesplicing out a singleton ([(sl, d)]) or an interior node ([(lp, dp); (sl, d); (ln, dn)]).
Theorem lru_ring_ops_spec :
Theorem lru_ring_ops_spec :
(* 1. Push front onto any ring `es` *)
(forall (hdr sl : loc) (prv0 nxt0 : option loc) (d : slot_heap_data) (w : nat)
(es : list (loc * slot_heap_data)) (tot : nat),
let d' := {| shd_key := shd_key d; shd_node := shd_node d; shd_payload := shd_payload d;
shd_weight := w; shd_in_lru := shd_in_lru d; shd_in_dorm := shd_in_dorm d;
shd_refilling := shd_refilling d; shd_pins := shd_pins d |} in
{{{ is_lru_ring hdr es tot ∗ is_table_slot sl prv0 nxt0 d }}}
lru_push_front_code #hdr #sl #(Z.of_nat w)
{{{ RET #(); is_lru_ring hdr ((sl, d') :: es) (w + tot) }}}) /\
(* 2a. Pop back on empty ring *)
(forall (hdr : loc),
{{{ is_lru_ring hdr [] 0 }}}
lru_pop_back_code #hdr
{{{ RET NONEV; is_lru_ring hdr [] 0 }}}) /\
(* 2b. Pop back on singleton ring *)
(forall (hdr tl : loc) (d : slot_heap_data),
{{{ is_lru_ring hdr [(tl, d)] (shd_weight d) }}}
lru_pop_back_code #hdr
{{{ RET SOMEV #tl; is_lru_ring hdr [] 0 ∗ is_table_slot tl None None d }}}) /\
(* 2c. Pop back on 2-element ring (updating predecessor's `next` and `hdr.tail`) *)
(forall (hdr hd tl : loc) (dh dt : slot_heap_data),
{{{ is_lru_ring hdr [(hd, dh); (tl, dt)] (shd_weight dh + shd_weight dt) }}}
lru_pop_back_code #hdr
{{{ RET SOMEV #tl; is_lru_ring hdr [(hd, dh)] (shd_weight dh) ∗ is_table_slot tl None None dt }}}) /\
(* 3a. Unlink singleton node *)
(forall (hdr sl : loc) (d : slot_heap_data),
{{{ is_lru_ring hdr [(sl, d)] (shd_weight d) }}}
lru_unlink_code #hdr #sl
{{{ RET #(); is_lru_ring hdr [] 0 ∗ is_table_slot sl None None d }}}) /\
(* 3b. Unlink interior node between `lp` and `ln` *)
(forall (hdr lp sl ln : loc) (dp d dn : slot_heap_data),
{{{ is_lru_ring hdr [(lp, dp); (sl, d); (ln, dn)]
(shd_weight dp + (shd_weight d + shd_weight dn)) }}}
lru_unlink_code #hdr #sl
{{{ RET #();
is_lru_ring hdr [(lp, dp); (ln, dn)] (shd_weight dp + shd_weight dn) ∗
is_table_slot sl None None d }}}).
Qed
Proof.
split_and!.
- (* 1. lru_push_front_code *)
intros hdr sl prv0 nxt0 d w es tot d'.
iIntros (Φ) "[(%Htot & Hh0 & Hh1 & Hh2 & Hchain) (Hs0 & Hs1 & Hs2 & Hs3 & Hs4 & Hs5 & Hs6 & Hs7)] HΦ".
rewrite /lru_push_front_code.
destruct es as [|[h0 d0] rest]; simpl in *.
+ wp_lam. wp_pures. wp_load. wp_pures.
wp_store. wp_store. wp_store. wp_pures.
wp_store. wp_store. wp_load. wp_pures. wp_store.
iModIntro. iApply "HΦ".
rewrite /is_lru_ring /is_lru_chain /is_table_slot /= in Htot |- *.
replace #(Z.of_nat (w + tot)) with #(Z.of_nat tot + Z.of_nat w)%Z by (do 2 f_equal; lia).
iFrame. iPureIntro. unfold fmap in *; simpl in *; lia.
+ iDestruct "Hchain" as "[(Hc0 & Hc1 & Hc2 & Hc3 & Hc4 & Hc5 & Hc6 & Hc7) Hrest]".
wp_lam. wp_pures. wp_load. wp_pures.
wp_store. wp_store. wp_store. wp_pures.
wp_store. wp_store. wp_load. wp_pures. wp_store.
iModIntro. iApply "HΦ".
rewrite /is_lru_ring /is_lru_chain /is_table_slot /= in Htot |- *.
replace #(Z.of_nat (w + tot)) with #(Z.of_nat tot + Z.of_nat w)%Z by (do 2 f_equal; lia).
iFrame. iPureIntro. unfold fmap in *; simpl in *; lia.
- (* 2a. lru_pop_back_code empty *)
intros hdr. iIntros (Φ) "(%Htot & Hh0 & Hh1 & Hh2 & _) HΦ".
rewrite /lru_pop_back_code /=.
wp_lam. wp_pures. wp_load. wp_pures.
iModIntro. iApply "HΦ".
rewrite /is_lru_ring /list_sum /=. by iFrame.
- (* 2b. lru_pop_back_code singleton *)
intros hdr tl d.
iIntros (Φ) "(%Htot & Hh0 & Hh1 & Hh2 & (Ht0 & Ht1 & Ht2 & Ht3 & Ht4 & Ht5 & Ht6 & Ht7) & _) HΦ".
rewrite /lru_pop_back_code /=.
wp_lam. wp_pures. wp_load. wp_pures.
wp_load. wp_load. wp_pures.
wp_store. wp_store. wp_store. wp_store.
wp_load. wp_pures. wp_store. wp_pures.
iModIntro. iApply "HΦ".
rewrite /is_lru_ring /is_lru_chain /is_table_slot /list_sum /=.
replace #(Z.of_nat 0) with #(Z.of_nat (shd_weight d) - Z.of_nat (shd_weight d))%Z by (do 2 f_equal; lia).
by iFrame.
- (* 2c. lru_pop_back_code 2-element *)
intros hdr hd tl dh dt.
iIntros (Φ) "(%Htot & Hh0 & Hh1 & Hh2 & (Hp0 & Hp1 & Hp2 & Hp3 & Hp4 & Hp5 & Hp6 & Hp7) & (Ht0 & Ht1 & Ht2 & Ht3 & Ht4 & Ht5 & Ht6 & Ht7) & _) HΦ".
rewrite /lru_pop_back_code /=.
wp_lam. wp_pures. wp_load. wp_pures.
wp_load. wp_load. wp_pures.
wp_store. wp_store. wp_store. wp_store.
wp_load. wp_pures. wp_store. wp_pures.
iModIntro. iApply "HΦ".
rewrite /is_lru_ring /is_lru_chain /is_table_slot /list_sum /= in Htot |- *.
replace #(Z.of_nat (shd_weight dh))
with #(Z.of_nat (shd_weight dh + shd_weight dt) - Z.of_nat (shd_weight dt))%Z by (do 2 f_equal; lia).
iFrame. iPureIntro. unfold fmap in *; simpl in *; lia.
- (* 3a. lru_unlink_code singleton *)
intros hdr sl d.
iIntros (Φ) "(%Htot & Hh0 & Hh1 & Hh2 & (Hs0 & Hs1 & Hs2 & Hs3 & Hs4 & Hs5 & Hs6 & Hs7) & _) HΦ".
rewrite /lru_unlink_code /=.
wp_lam. wp_pures. wp_load. wp_load. wp_load. wp_pures.
wp_store. wp_store. wp_store. wp_store.
wp_load. wp_pures. wp_store.
iModIntro. iApply "HΦ".
rewrite /is_lru_ring /is_lru_chain /is_table_slot /list_sum /=.
replace #(Z.of_nat 0) with #(Z.of_nat (shd_weight d) - Z.of_nat (shd_weight d))%Z by (do 2 f_equal; lia).
by iFrame.
- (* 3b. lru_unlink_code interior *)
intros hdr lp sl ln dp d dn.
iIntros (Φ) "(%Htot & Hh0 & Hh1 & Hh2 & (Hp0 & Hp1 & Hp2 & Hp3 & Hp4 & Hp5 & Hp6 & Hp7) & (Hs0 & Hs1 & Hs2 & Hs3 & Hs4 & Hs5 & Hs6 & Hs7) & (Hn0 & Hn1 & Hn2 & Hn3 & Hn4 & Hn5 & Hn6 & Hn7) & _) HΦ".
rewrite /lru_unlink_code /=.
wp_lam. wp_pures. wp_load. wp_load. wp_load. wp_pures.
wp_store. wp_store. wp_store. wp_store.
wp_load. wp_pures. wp_store.
iModIntro. iApply "HΦ".
rewrite /is_lru_ring /is_lru_chain /is_table_slot /list_sum /= in Htot |- *.
replace #(Z.of_nat (shd_weight dp + shd_weight dn))
with #(Z.of_nat (shd_weight dp + (shd_weight d + shd_weight dn)) - Z.of_nat (shd_weight d))%Z by (do 2 f_equal; lia).
iFrame. iPureIntro. unfold fmap in *; simpl in *; lia.
Qed.References
Uses
17 more
- shd_pins
- lru_push_front_code
- lru_pop_back_code
- lru_unlink_code
- is_table_slot
- is_lru_chain
- is_lru_ring
- None
- list
- nat
- option
- list_sum
- Z.of_nat
- loc
- NONEV
- SOMEV
- fmap
T25: Separation-logic specifications for slot_get_code (slot_get_and_refill_spec)
covering:
- Post-dispose guard (
disposed = truereturnsInjLV #disposed_table_failure), - Cycle detection (
is_active = truereturnsInjLV #cycle_detected_failureorInjRV #cycle_val, Ruling R1), - Resident hot hit (
SlotResident v msreturnsInjRV #vand preserves pin count via+64/-64), - Oversized bypass (
max_w < item_wreturnsInjRV #v, transitions slot directly toSlotEvicted mswithvalue_cell = NONEV, and leaves warmis_lru_ringcompletely untouched, Ruling R5), - Within-budget miss/refill (
item_w <= max_wstoresSOMEV #v, pushesslto MRU head ofis_lru_ring, and restores pin count).
Theorem slot_get_and_refill_spec :
Theorem slot_get_and_refill_spec :
(* 1. Disposed table *)
(forall (tbl hdr ol sl : loc) (max_w : nat) (act cyc_rec : bool) (cv v w : Z) (st_v rf ef : val),
{{{ is_memotable_hdr tbl hdr ol true max_w }}}
slot_get_code #tbl #sl #act #cyc_rec #cv #v st_v #w rf ef
{{{ RET InjLV #disposed_table_failure; is_memotable_hdr tbl hdr ol true max_w }}}) /\
(* 2. Cycle throw & recover *)
(forall (tbl hdr ol sl : loc) (max_w : nat) (cyc_rec : bool) (cv v w : Z) (st_v rf ef : val),
{{{ is_memotable_hdr tbl hdr ol false max_w }}}
slot_get_code #tbl #sl #true #cyc_rec #cv #v st_v #w rf ef
{{{ RET (if cyc_rec then InjRV #cv else InjLV #cycle_detected_failure);
is_memotable_hdr tbl hdr ol false max_w }}}) /\
(* 3. Resident hit *)
(forall (tbl hdr ol sl : loc) (prv nxt : option loc) (max_w : nat) (d : slot_heap_data)
(v : Z) (ms : option Z) (cyc_rec : bool) (cv v_comp w : Z) (st_v rf ef : val),
shd_payload d = SlotResident v ms ->
{{{ is_memotable_hdr tbl hdr ol false max_w ∗ is_table_slot sl prv nxt d }}}
slot_get_code #tbl #sl #false #cyc_rec #cv #v_comp st_v #w rf ef
{{{ RET InjRV #v; is_memotable_hdr tbl hdr ol false max_w ∗ is_table_slot sl prv nxt d }}}) /\
(* 4. Ruling R5 oversized bypass: leaves warm LRU ring untouched and clears value_cell! *)
(forall (tbl hdr ol sl : loc) (max_w w_item tot : nat) (d : slot_heap_data)
(v_comp : Z) (ms : option Z) (es : list (loc * slot_heap_data)) (cyc_rec : bool) (cv : Z) (rf : val),
(forall v0 ms0, shd_payload d ≠ SlotResident v0 ms0) ->
max_w < w_item ->
let d_ev := {| shd_key := shd_key d; shd_node := shd_node d; shd_payload := SlotEvicted ms;
shd_weight := 0; shd_in_lru := false; shd_in_dorm := shd_in_dorm d;
shd_refilling := false; shd_pins := shd_pins d |} in
{{{ is_memotable_hdr tbl hdr ol false max_w ∗
is_lru_ring hdr es tot ∗
is_table_slot sl None None d }}}
slot_get_code #tbl #sl #false #cyc_rec #cv #v_comp
(payload_stamp_val (SlotEvicted ms)) #(Z.of_nat w_item) rf #(slot_flags_of d_ev)
{{{ RET InjRV #v_comp;
is_memotable_hdr tbl hdr ol false max_w ∗
is_lru_ring hdr es tot ∗
is_table_slot sl None None d_ev }}}) /\
(* 5. Normal refill + MRU push-front *)
(forall (tbl hdr ol sl : loc) (max_w w_item tot : nat) (d : slot_heap_data)
(v_comp : Z) (ms : option Z) (es : list (loc * slot_heap_data)) (cyc_rec : bool) (cv : Z) (ef : val),
(forall v0 ms0, shd_payload d ≠ SlotResident v0 ms0) ->
w_item <= max_w ->
let d_res := {| shd_key := shd_key d; shd_node := shd_node d; shd_payload := SlotResident v_comp ms;
shd_weight := w_item; shd_in_lru := true; shd_in_dorm := shd_in_dorm d;
shd_refilling := false; shd_pins := shd_pins d |} in
{{{ is_memotable_hdr tbl hdr ol false max_w ∗
is_lru_ring hdr es tot ∗
is_table_slot sl None None d }}}
slot_get_code #tbl #sl #false #cyc_rec #cv #v_comp
(payload_stamp_val (SlotResident v_comp ms)) #(Z.of_nat w_item) #(slot_flags_of d_res) ef
{{{ RET InjRV #v_comp;
is_memotable_hdr tbl hdr ol false max_w ∗
is_lru_ring hdr ((sl, d_res) :: es) (w_item + tot) }}}).
Qed
Proof.
split_and!.
- (* 1. Disposed *)
intros tbl hdr ol sl max_w act cyc_rec cv v w st_v rf ef.
iIntros (Φ) "(Ht0 & Ht1 & Ht2 & Ht3) HΦ".
rewrite /slot_get_code.
wp_lam. wp_pures. wp_load. wp_pures.
iModIntro. iApply "HΦ". iFrame.
- (* 2. Cycle *)
intros tbl hdr ol sl max_w cyc_rec cv v w st_v rf ef.
iIntros (Φ) "(Ht0 & Ht1 & Ht2 & Ht3) HΦ".
rewrite /slot_get_code.
wp_lam. wp_pures. wp_load. wp_pures.
destruct cyc_rec; wp_pures; iModIntro; iApply "HΦ"; iFrame.
- (* 3. Resident hit *)
intros tbl hdr ol sl prv nxt max_w d v ms cyc_rec cv v_comp w st_v rf ef Hres.
rewrite /is_memotable_hdr /is_table_slot Hres /=.
iIntros (Φ) "[(Ht0 & Ht1 & Ht2 & Ht3) (Hs0 & Hs1 & Hs2 & Hs3 & Hs4 & Hs5 & Hs6 & Hs7)] HΦ".
rewrite /slot_get_code /slot_pin_code /slot_unpin_code /=.
wp_lam. wp_pures. wp_load. wp_pures.
wp_load. wp_pures. wp_store. wp_pures.
wp_load. wp_pures.
wp_load. wp_pures. wp_store. try wp_pures.
iModIntro. iApply "HΦ".
replace #(slot_flags_of d) with #(slot_flags_of d + 64 - 64)%Z by (do 2 f_equal; lia).
iFrame.
- (* 4. Ruling R5 oversized bypass *)
intros tbl hdr ol sl max_w w_item tot d v_comp ms es cyc_rec cv rf Hnonres Hover d_ev.
assert (Hpv : payload_value_val (shd_payload d) = NONEV).
{ destruct (shd_payload d) as [|v0 ms0|ms0]; auto. exfalso. exact (Hnonres v0 ms0 eq_refl). }
rewrite {1}/is_memotable_hdr {1}/is_table_slot Hpv /=.
iIntros (Φ) "((Ht0 & Ht1 & Ht2 & Ht3) & Hring & (Hs0 & Hs1 & Hs2 & Hs3 & Hs4 & Hs5 & Hs6 & Hs7)) HΦ".
rewrite /slot_get_code /slot_pin_code /slot_unpin_code /=.
wp_lam. wp_pures. wp_load. wp_pures.
wp_load. wp_pures. wp_store. wp_pures.
wp_load. wp_pures.
wp_load. wp_load. wp_store. wp_pures.
rewrite bool_decide_eq_true_2; [|lia].
wp_pures. wp_store. wp_store. wp_store. wp_pures.
wp_load. wp_pures. wp_store. try wp_pures.
iModIntro. iApply "HΦ".
rewrite /is_memotable_hdr /is_table_slot /=.
replace #(slot_flags_of d_ev) with #(slot_flags_of d_ev + 64 - 64)%Z by (do 2 f_equal; lia).
iFrame.
- (* 5. Within-budget refill + MRU push-front *)
intros tbl hdr ol sl max_w w_item tot d v_comp ms es cyc_rec cv ef Hnonres Hfit d_res.
assert (Hpv : payload_value_val (shd_payload d) = NONEV).
{ destruct (shd_payload d) as [|v0 ms0|ms0]; auto. exfalso. exact (Hnonres v0 ms0 eq_refl). }
rewrite {1}/is_memotable_hdr {1}/is_table_slot Hpv /=.
iIntros (Φ) "((Ht0 & Ht1 & Ht2 & Ht3) & Hring & (Hs0 & Hs1 & Hs2 & Hs3 & Hs4 & Hs5 & Hs6 & Hs7)) HΦ".
rewrite /slot_get_code /slot_pin_code /slot_unpin_code /=.
wp_lam. wp_pures. wp_load. wp_pures.
wp_load. wp_pures. wp_store. wp_pures.
wp_load. wp_pures.
wp_load. wp_load. wp_store. wp_pures.
rewrite bool_decide_eq_false_2; [|lia].
wp_pures. wp_store. wp_store.
set (d_pinned := {| shd_key := shd_key d; shd_node := shd_node d; shd_payload := SlotResident v_comp ms;
shd_weight := shd_weight d; shd_in_lru := true; shd_in_dorm := shd_in_dorm d;
shd_refilling := false; shd_pins := S (shd_pins d) |}).
destruct lru_ring_ops_spec as (Hpush & _).
wp_bind (lru_push_front_code _ _ _).
wp_apply (Hpush hdr sl None None d_pinned w_item es tot with "[$Hring Hs0 Hs1 Hs2 Hs3 Hs4 Hs5 Hs6 Hs7]").
{ rewrite /is_table_slot /=.
replace #(slot_flags_of d_pinned) with #(slot_flags_of d_res + 64)%Z
by (do 2 f_equal; unfold slot_flags_of, d_res, d_pinned, pack_slot_flags; simpl; lia).
iFrame. }
iIntros "(%Htot' & Hh0 & Hh1 & Hh2 & [(Hs0 & Hs1 & Hs2 & Hs3 & Hs4 & Hs5 & Hs6 & Hs7) Hchain])".
wp_pures.
wp_load. wp_pures. wp_store. try wp_pures.
iModIntro. iApply "HΦ".
rewrite /is_memotable_hdr /is_lru_ring /is_lru_chain /is_table_slot /=.
replace #(slot_flags_of d_res) with #(slot_flags_of d_pinned - 64)%Z
by (do 2 f_equal; unfold slot_flags_of, d_res, d_pinned, pack_slot_flags; simpl; lia).
iFrame. iPureIntro. exact Htot'.
Qed.References
Uses
- cycle_detected_failure
- disposed_table_failure
- SlotResident
- SlotEvicted
- pack_slot_flags
- slot_heap_data
- shd_key
- shd_node
36 more
- shd_payload
- shd_weight
- shd_in_lru
- shd_in_dorm
- shd_refilling
- shd_pins
- payload_value_val
- payload_stamp_val
- slot_flags_of
- lru_push_front_code
- slot_pin_code
- slot_unpin_code
- slot_get_code
- is_table_slot
- is_lru_chain
- is_lru_ring
- is_memotable_hdr
- lru_ring_ops_spec
- None
- S
- bool
- false
- list
- nat
- option
- true
- eq_refl
- Z
- Z.of_nat
- heap_lang.InjLV
- heap_lang.InjRV
- heap_lang.val
- loc
- NONEV
- bool_decide_eq_false_2
- bool_decide_eq_true_2
T26: Payload eviction (slot_clear_payload_code) and dormant slot retirement (slot_evict_and_retire_spec)
composing:
- GC-root payload clearing (
value_cell <- NONE), keepingSOMEV #stwhenkeep_stamp = true(CutoffStamp,T9a) and droppingstamp_cell <- NONEwhenkeep_stamp = false(CutoffComparer,T9b), - Upstream
EdgeWorlddetachment viasources_clear_code(world_direct_unlink_specinHeap/Collections.v), - Active mid-list
OwnerLinkunlinking frommt_ownerviaowner_links_unlink_code(owner_links_active_mid_unlink_specinHeap/Collections.v).
Theorem slot_evict_and_retire_spec :
Theorem slot_evict_and_retire_spec :
(* 1. Payload eviction under CutoffStamp (retains stamp) and CutoffComparer (drops stamp) *)
(forall (sl : loc) (d : slot_heap_data) (v : Z) (ms : option Z) (keep_stamp : bool),
shd_payload d = SlotResident v ms ->
(keep_stamp = true -> is_Some ms) ->
let ms_after := if keep_stamp then ms else None in
let d_ev := {| shd_key := shd_key d; shd_node := shd_node d; shd_payload := SlotEvicted ms_after;
shd_weight := 0; shd_in_lru := false; shd_in_dorm := shd_in_dorm d;
shd_refilling := shd_refilling d; shd_pins := shd_pins d |} in
{{{ is_table_slot sl None None d }}}
slot_clear_payload_code #sl #keep_stamp #(slot_flags_of d_ev)
{{{ RET #(); is_table_slot sl None None d_ev }}}) /\
(* 2. Dormant slot retirement: upstream edge detachment + active mid-list OwnerLink unlinking *)
(forall (res : val) tbl_w (nid : node_id) (w w' : EdgeWorld)
(ol lk_prev lk lk_next : loc) (prev_p next_n : option loc)
(l_prev l l_next : link) (gen : nat),
world_well_formed w ->
nid ∈ dom tbl_w ->
sources_clear nid w = Some w' ->
l_child l = nid ->
l_generation l = Some gen ->
{{{ resolver tbl_w res ∗
is_world tbl_w w ∗
(ol +ₗ 2) ↦ #(Z.of_nat gen) ∗
is_link_node lk_prev prev_p (Some lk) l_prev ∗
is_link_node lk (Some lk_prev) (Some lk_next) l ∗
is_link_node lk_next (Some lk) next_n l_next }}}
sources_clear_code res #(Z.of_nat nid);;
owner_links_unlink_code #ol #lk
{{{ RET #();
⌜world_well_formed w' /\ source_slots (sources_of w' nid) = [] /\
(forall src, nid ∉ observer_view (observers_of w' src))⌝ ∗
is_world tbl_w w' ∗
(ol +ₗ 2) ↦ #(Z.of_nat gen) ∗
is_link_node lk_prev prev_p (Some lk_next) l_prev ∗
is_link_node lk_next (Some lk_prev) next_n l_next ∗
is_link_node lk None None (link_detached l) }}}).
Qed
Proof.
split.
- intros sl d v ms keep_stamp Hres Hks ms_after d_ev.
rewrite {1}/is_table_slot Hres /=.
iIntros (Φ) "(Hs0 & Hs1 & Hs2 & Hs3 & Hs4 & Hs5 & Hs6 & Hs7) HΦ".
rewrite /slot_clear_payload_code /=.
wp_lam. wp_pures. wp_store.
destruct keep_stamp.
+ destruct (Hks eq_refl) as [st ->].
wp_pures. wp_store. wp_store.
iModIntro. iApply "HΦ".
rewrite /is_table_slot /=. iFrame.
+ wp_pures. wp_store. wp_store. wp_store.
iModIntro. iApply "HΦ".
rewrite /is_table_slot /=. iFrame.
- intros res tbl_w nid w w' ol lk_prev lk lk_next prev_p next_n l_prev l l_next gen
Hwf Hdom Hclr Hchild Hgen.
iIntros (Φ) "(Hres & Hw & Hol2 & Hprev & Hlk & Hnext) HΦ".
wp_bind (sources_clear_code _ _).
wp_apply (world_direct_unlink_spec res tbl_w nid w w' Hwf Hdom Hclr with "[$Hres $Hw]").
iIntros "[%Hwpost Hw]". wp_pures.
wp_apply (owner_links_active_mid_unlink_spec ol lk_prev lk lk_next prev_p next_n l_prev l l_next gen Hgen
with "[$Hol2 $Hprev $Hlk $Hnext]").
iIntros "(Hol2 & Hprev & Hnext & Hlk)".
iApply "HΦ". iFrame. done.
Qed.References
Uses
39 more
- link
- l_child
- l_generation
- SlotResident
- SlotEvicted
- sources_clear_code
- resolver
- is_world
- owner_links_unlink_code
- is_link_node
- world_direct_unlink_spec
- link_detached
- owner_links_active_mid_unlink_spec
- slot_heap_data
- shd_key
- shd_node
- shd_payload
- shd_weight
- shd_in_lru
- shd_in_dorm
- shd_refilling
- shd_pins
- slot_flags_of
- slot_clear_payload_code
- is_table_slot
- None
- Some
- bool
- false
- nat
- option
- true
- eq_refl
- Z
- Z.of_nat
- heap_lang.val
- loc
- dom
- is_Some
T27: Passive, idempotent MemoTable.Dispose() specification (memotable_dispose_spec, Ruling R3):
- When already disposed (
disposed = true),memotable_dispose_header_codeis a pure no-op; - When live (
disposed = false),memotable_dispose_header_codesetsdisposed <- #true, detaches all childOwnerLinks frommt_owner(ol) inO(1)viaowner_links_detach_code(incrementingol's generation so stale unlinks become no-ops), resetshdr's head, tail, andtotal_weightto0, and leaves scheduler queues untouched.
Theorem memotable_dispose_spec :
Theorem memotable_dispose_spec :
(forall (tbl hdr ol : loc) (max_w : nat),
{{{ is_memotable_hdr tbl hdr ol true max_w }}}
memotable_dispose_header_code #tbl
{{{ RET #(); is_memotable_hdr tbl hdr ol true max_w }}}) /\
(forall (tbl hdr ol : loc) (o : owner_id) (entries : list (loc * link)) (gen acq max_w tot : nat)
(hd_opt tl_opt : option loc),
{{{ is_memotable_hdr tbl hdr ol false max_w ∗
is_owner_links ol o entries gen acq ∗
hdr ↦ opt_loc_val hd_opt ∗
(hdr +ₗ 1) ↦ opt_loc_val tl_opt ∗
(hdr +ₗ 2) ↦ #(Z.of_nat tot) }}}
memotable_dispose_header_code #tbl
{{{ RET #();
is_memotable_hdr tbl hdr ol true max_w ∗
is_owner_links ol o [] (S gen) 0 ∗
is_lru_ring hdr [] 0 }}}).
Qed
Proof.
split.
- intros tbl hdr ol max_w.
iIntros (Φ) "(Ht0 & Ht1 & Ht2 & Ht3) HΦ".
rewrite /memotable_dispose_header_code.
wp_lam. wp_pures. wp_load. wp_pures.
iModIntro. iApply "HΦ". iFrame.
- intros tbl hdr ol o entries gen acq max_w tot hd_opt tl_opt.
iIntros (Φ) "((Ht0 & Ht1 & Ht2 & Ht3) & Hol & Hh0 & Hh1 & Hh2) HΦ".
rewrite /memotable_dispose_header_code.
wp_lam. wp_pures. wp_load. wp_pures.
wp_store. wp_load. wp_load. wp_pures.
wp_bind (owner_links_detach_code _).
wp_apply (owner_links_detach_spec ol o entries gen acq with "Hol").
iIntros "[Hol _]". wp_pures.
wp_store. wp_store. wp_store.
iModIntro. iApply "HΦ".
rewrite /is_memotable_hdr /is_lru_ring /=.
by iFrame.
Qed.References
Uses
- owner_id
- link
- opt_loc_val
- owner_links_detach_code
- is_owner_links
- owner_links_detach_spec
- memotable_dispose_header_code
- is_lru_ring
9 more
- is_memotable_hdr
- S
- false
- list
- nat
- option
- true
- Z.of_nat
- loc
End heap_memotable.
3. Closed HeapLang Adequacy Theorem (`T28`)
Complete closed HeapLang program exercising: 1. Allocating `lru_ring`, `owner_links`, `MemoTable` header (`max_weight = max_w`), and two `TableSlot`s, 2. Admitting key `1` (`v1`, weight `w1 <= max_w`) and reading it back via the resident hot path, 3. Executing an oversized read on key `2` (`v2`, weight `w2 > max_w`, Ruling R5) and verifying warm key `1` remains resident in the LRU ring with `total_weight = w1 <= max_w`, 4. Popping and evicting key `1` (`total_weight = 0`), then passively disposing the table (Ruling R3) and verifying post-dispose `slot_get_code` returns `InjLV #disposed_table_failure`.
Definition heap_memotable_prog (max_w w1 w2 : nat) (v1 v2 : Z) : expr :=
Definition heap_memotable_prog (max_w w1 w2 : nat) (v1 v2 : Z) : expr :=
let: "hdr" := lru_ring_new_code #() in
let: "ol" := owner_links_new_code #false in
let: "tbl" := AllocN #4 #0 in
"tbl" <- #false;;
("tbl" +ₗ #1) <- #(Z.of_nat max_w);;
("tbl" +ₗ #2) <- "hdr";;
("tbl" +ₗ #3) <- "ol";;
let: "d0_fl" := #(pack_slot_flags 0 false false false false 0) in
let: "res1_fl" := #(pack_slot_flags 1 true true false false 0) in
let: "ev1_fl" := #(pack_slot_flags 2 true false false false 0) in
let: "ev2_fl" := #(pack_slot_flags 2 true false false false 0) in
let: "sl1" := slot_alloc_code #1 #10 "d0_fl" in
let: "sl2" := slot_alloc_code #2 #11 "d0_fl" in
let: "r_miss1" := slot_get_code "tbl" "sl1" #false #false #0 #v1 (SOME #v1) #(Z.of_nat w1) "res1_fl" "ev1_fl" in
let: "r_hit1" := slot_get_code "tbl" "sl1" #false #false #0 #999 (SOME #999) #(Z.of_nat w1) "res1_fl" "ev1_fl" in
let: "r_over2" := slot_get_code "tbl" "sl2" #false #false #0 #v2 (SOME #v2) #(Z.of_nat w2) "res1_fl" "ev2_fl" in
let: "warm_weight" := !("hdr" +ₗ #2) in
let: "_pop" := lru_pop_back_code "hdr" in
slot_clear_payload_code "sl1" #true "ev1_fl";;
memotable_dispose_header_code "tbl";;
let: "r_post_disp" := slot_get_code "tbl" "sl1" #false #false #0 #v1 (SOME #v1) #(Z.of_nat w1) "res1_fl" "ev1_fl" in
let: "final_weight" := !("hdr" +ₗ #2) in
("r_miss1", "r_hit1", "r_over2", "warm_weight", "r_post_disp", "final_weight").References
Uses
- pack_slot_flags
- owner_links_new_code
- lru_ring_new_code
- slot_alloc_code
- lru_pop_back_code
- slot_clear_payload_code
- slot_get_code
- memotable_dispose_header_code
8 more
- false
- nat
- true
- Z
- Z.of_nat
- heap_lang.AllocN
- heap_lang.expr
- SOME
Used by
T28: Closed HeapLang adequacy for MemoTable (heap_memotable_adequacy):
Closed Prop statement (zero iProp Σ) proved via heap_adequacy over ranvierΣ:
heap_memotable_progisadequate NotStuckfrominit_heap(memory-safe, never gets stuck), and- Every operational execution terminating in
(v_out, σ')yields the exact pure tuple(InjRV #v1, InjRV #v1, InjRV #v2, #(Z.of_nat w1), InjLV #disposed_table_failure, #0)withw1 <= max_w.
Theorem heap_memotable_adequacy (max_w w1 w2 : nat) (v1 v2 : Z) (σ' : heap_lang.state) (v_out : val) :
Theorem heap_memotable_adequacy (max_w w1 w2 : nat) (v1 v2 : Z) (σ' : heap_lang.state) (v_out : val) :
w1 <= max_w ->
max_w < w2 ->
adequate NotStuck (heap_memotable_prog max_w w1 w2 v1 v2) init_heap
(fun v _ =>
v = (InjRV #v1, InjRV #v1, InjRV #v2, #(Z.of_nat w1), InjLV #disposed_table_failure, #0)%V /\
w1 <= max_w) /\
(rtc erased_step ([heap_memotable_prog max_w w1 w2 v1 v2], init_heap) ([of_val v_out], σ') ->
v_out = (InjRV #v1, InjRV #v1, InjRV #v2, #(Z.of_nat w1), InjLV #disposed_table_failure, #0)%V /\
w1 <= max_w).
Qed
Proof.
intros Hfit Hover.
assert (Had : adequate NotStuck (heap_memotable_prog max_w w1 w2 v1 v2) init_heap
(fun v _ =>
v = (InjRV #v1, InjRV #v1, InjRV #v2, #(Z.of_nat w1), InjLV #disposed_table_failure, #0)%V /\
w1 <= max_w)).
{ apply (heap_adequacy ranvierΣ NotStuck (heap_memotable_prog max_w w1 w2 v1 v2) init_heap
(fun v =>
v = (InjRV #v1, InjRV #v1, InjRV #v2, #(Z.of_nat w1), InjLV #disposed_table_failure, #0)%V /\
w1 <= max_w)).
iIntros (Hinv) "_".
rewrite /heap_memotable_prog.
(* Allocate lru_ring *)
wp_bind (lru_ring_new_code #()).
rewrite /lru_ring_new_code. wp_lam. wp_alloc hdr as "Hhdr"; [lia|].
rewrite (_ : Z.to_nat 3 = 3%nat) // /= !array_cons array_nil !Loc.add_assoc /= right_id.
iDestruct "Hhdr" as "(Hh0 & Hh1 & Hh2)".
wp_pures. wp_store. wp_pures. wp_store. wp_pures. wp_store.
(* Allocate owner_links *)
wp_pures. wp_bind (owner_links_new_code #false).
wp_apply (owner_links_new_spec 1 false); [done|].
iIntros (ol) "Hol". wp_pures.
(* Allocate tbl *)
wp_alloc tbl as "Htbl"; [lia|].
rewrite (_ : Z.to_nat 4 = 4%nat) // /= !array_cons array_nil !Loc.add_assoc /= right_id.
iDestruct "Htbl" as "(Ht0 & Ht1 & Ht2 & Ht3)".
wp_pures. wp_store. wp_pures. wp_store. wp_pures. wp_store. wp_pures. wp_store. wp_pures.
(* Allocate sl1 *)
wp_bind (slot_alloc_code #1 #10 _).
rewrite {1}/slot_alloc_code. wp_lam. wp_pures. wp_alloc sl1 as "Hsl1"; [lia|].
rewrite (_ : Z.to_nat 8 = 8%nat) // /= !array_cons array_nil !Loc.add_assoc /= right_id.
iDestruct "Hsl1" as "(Hs10 & Hs11 & Hs12 & Hs13 & Hs14 & Hs15 & Hs16 & Hs17)".
do 8 (try wp_pures; wp_store). try wp_pures.
(* Allocate sl2 *)
wp_bind (slot_alloc_code #2 #11 _).
rewrite /slot_alloc_code. wp_lam. wp_pures. wp_alloc sl2 as "Hsl2"; [lia|].
rewrite (_ : Z.to_nat 8 = 8%nat) // /= !array_cons array_nil !Loc.add_assoc /= right_id.
iDestruct "Hsl2" as "(Hs20 & Hs21 & Hs22 & Hs23 & Hs24 & Hs25 & Hs26 & Hs27)".
do 8 (try wp_pures; wp_store). try wp_pures.
(* Package predicates *)
set (d1_init := {| shd_key := 1%Z; shd_node := 10; shd_payload := SlotNonValue;
shd_weight := 0; shd_in_lru := false; shd_in_dorm := false;
shd_refilling := false; shd_pins := 0 |}).
set (d2_init := {| shd_key := 2%Z; shd_node := 11; shd_payload := SlotNonValue;
shd_weight := 0; shd_in_lru := false; shd_in_dorm := false;
shd_refilling := false; shd_pins := 0 |}).
destruct slot_get_and_refill_spec as (Hget_disp & _ & Hget_hit & Hget_over & Hget_refill).
(* Step 1: Cold miss on sl1 *)
wp_bind (slot_get_code #tbl #sl1 _ _ _ _ _ _ _ _).
wp_apply (Hget_refill tbl hdr ol sl1 max_w w1 0 d1_init v1 (Some v1) [] false 0%Z
#(pack_slot_flags 2 true false false false 0)
ltac:(intros ? ?; discriminate) Hfit
with "[Ht0 Ht1 Ht2 Ht3 Hh0 Hh1 Hh2 Hs10 Hs11 Hs12 Hs13 Hs14 Hs15 Hs16 Hs17]").
{ rewrite /is_memotable_hdr /is_lru_ring /is_table_slot /=. iFrame. done. }
rewrite Nat.add_0_r. iIntros "[Htbl Hring]". wp_pures.
(* Step 2: Warm resident hit on sl1 *)
iDestruct "Hring" as "(%Htot1 & Hh0 & Hh1 & Hh2 & [Hsl1 _])".
set (d1_res := {| shd_key := 1%Z; shd_node := 10; shd_payload := SlotResident v1 (Some v1);
shd_weight := w1; shd_in_lru := true; shd_in_dorm := false;
shd_refilling := false; shd_pins := 0 |}).
wp_bind (slot_get_code #tbl #sl1 _ _ _ _ _ _ _ _).
wp_apply (Hget_hit tbl hdr ol sl1 None None max_w d1_res v1 (Some v1) false 0%Z 999%Z (Z.of_nat w1)
(SOMEV #999) #(pack_slot_flags 1 true true false false 0)
#(pack_slot_flags 2 true false false false 0) eq_refl
with "[$Htbl $Hsl1]").
iIntros "[Htbl Hsl1]". wp_pures.
(* Step 3: Ruling R5 oversized read on sl2 *)
wp_bind (slot_get_code #tbl #sl2 _ _ _ _ _ _ _ _).
wp_apply (Hget_over tbl hdr ol sl2 max_w w2 w1 d2_init v2 (Some v2) [(sl1, d1_res)] false 0%Z
#(pack_slot_flags 1 true true false false 0)
ltac:(intros ? ?; discriminate) Hover
with "[Htbl Hh0 Hh1 Hh2 Hsl1 Hs20 Hs21 Hs22 Hs23 Hs24 Hs25 Hs26 Hs27]").
{ rewrite /is_lru_ring /is_lru_chain /is_table_slot /=. iFrame. iPureIntro. unfold fmap in *; simpl in *; lia. }
iIntros "(Htbl & Hring & Hsl2)". wp_pures.
(* Read warm_weight *)
iDestruct "Hring" as "(%Htot_w & Hh0 & Hh1 & Hh2 & [Hsl1 _])".
wp_load. wp_pures.
(* Step 4: Pop sl1, clear payload, dispose table, post-dispose Get *)
destruct lru_ring_ops_spec as (_ & _ & Hpop1 & _).
wp_bind (lru_pop_back_code #hdr).
wp_apply (Hpop1 hdr sl1 d1_res with "[Hh0 Hh1 Hh2 Hsl1]").
{ rewrite /is_lru_ring /is_lru_chain /=. iFrame. iPureIntro. unfold fmap in *; simpl in *; lia. }
iIntros "[Hring0 Hsl1]". wp_pures.
destruct slot_evict_and_retire_spec as [Hevict _].
wp_bind (slot_clear_payload_code #sl1 _ _).
wp_apply (Hevict sl1 d1_res v1 (Some v1) true eq_refl ltac:(intros _; eauto) with "Hsl1").
iIntros "Hsl1". wp_pures.
destruct memotable_dispose_spec as [_ Hdisp].
iDestruct "Hring0" as "(_ & Hh0 & Hh1 & Hh2 & _)".
wp_bind (memotable_dispose_header_code #tbl).
wp_apply (Hdisp tbl hdr ol 1 [] 0 0 max_w 0 None None with "[$Htbl $Hol $Hh0 $Hh1 $Hh2]").
iIntros "(Htbl & Hol & Hring_end)". wp_pures.
wp_bind (slot_get_code #tbl #sl1 _ _ _ _ _ _ _ _).
wp_apply (Hget_disp tbl hdr ol sl1 max_w false false 0%Z v1 (Z.of_nat w1) (SOMEV #v1)
#(pack_slot_flags 1 true true false false 0)
#(pack_slot_flags 2 true false false false 0) with "Htbl").
iIntros "Htbl". wp_pures.
iDestruct "Hring_end" as "(_ & Hh0 & Hh1 & Hh2 & _)".
wp_load. try wp_pures.
iModIntro. iPureIntro. split; [reflexivity | exact Hfit]. }
split.
- exact Had.
- intros Hsteps. by eapply (adequate_result _ _ _ _ Had).
Qed.References
Uses
- disposed_table_failure
- SlotNonValue
- SlotResident
- pack_slot_flags
- init_heap
- owner_links_new_code
- owner_links_new_spec
- ranvierΣ
50 more
- shd_key
- shd_node
- shd_payload
- shd_weight
- shd_in_lru
- shd_in_dorm
- shd_refilling
- shd_pins
- lru_ring_new_code
- slot_alloc_code
- lru_pop_back_code
- slot_clear_payload_code
- slot_get_code
- memotable_dispose_header_code
- is_table_slot
- is_lru_chain
- is_lru_ring
- is_memotable_hdr
- lru_ring_ops_spec
- slot_get_and_refill_spec
- slot_evict_and_retire_spec
- memotable_dispose_spec
- heap_memotable_prog
- None
- Some
- false
- nat
- true
- eq_refl
- Z
- Nat.add_0_r
- Z.of_nat
- Z.to_nat
- NotStuck
- heap_adequacy
- array_cons
- array_nil
- heap_lang.InjLV
- heap_lang.InjRV
- heap_lang.of_val
- heap_lang.state
- heap_lang.val
- Loc.add_assoc
- SOMEV
- adequate
- adequate_result
- erased_step
- fmap
- right_id
- rtc
Used by