Ranvier.Pure.Marking
Marks
3
From stdpp Require Import prelude gmap.
From Ranvier.Base Require Import Prelude.
From Ranvier.Pure Require Import ObserverSet SourceList State.A copy of d with new values of n_freshness, n_unannounced and n_queued.
Definition node_marked (f : freshness) (u q : bool) (d : node) : node :=
Definition node_marked (f : freshness) (u q : bool) (d : node) : node :=
{| n_kind := n_kind d; n_value := n_value d; n_failure := n_failure d; n_status := n_status d;
n_freshness := f; n_unannounced := u; n_runs := n_runs d; n_published := n_published d;
n_disposed := n_disposed d; n_queued := q; n_in_cleanup := n_in_cleanup d;
n_scope := n_scope d; n_violated := n_violated d; n_body := n_body d; n_env := n_env d;
n_mode := n_mode d; n_comparer := n_comparer d; n_link := n_link d |}.References
Uses
Used by
- effect_marked
- mark_check
- mark_dirty
- mark_prim
- score_marked_le
- prim_measure
- measure_memo_clean
- measure_memo_announce
50 more
- set_node_takes
- mark_forwards_on_unannounced
- set_node_undirty
- mark_check_undirty
- memo_mark_dirty_keeps_others_short
- clean_memo_keeps_unannounced
- marked_step
- marked_effect
- prim_invariant
- set_marked_fixed
- told_marked
- told_marked_stale
- queued_marked
- set_marked_prim
- forward_told
- effect_mark_keeps
- prim_step
- rise_set
- ytouch_set
- qt_rise_others
- check_un
- qt_forward
- effect_marked_mq
- mq_dirty
- dirty_visit
- gd_marks
- marks_q
- mark_check_up
- mark_dirty_up
- link_marks
- walk_appends
- mark_dirty_saturated_id
- window_memo
- strip_effect_marked
- leaf_clean_memo_mark_dirty_eq
- notify_moved_single_check_memo_eq
- iter_mark_check_chain
- iterative_mark_check_chain_eq
- node_clean_unqueued_marked_dirty
- queue_rel_fused_signal
- fused_single_signal_effect_eq
- fused_single_memo_effect
- fused_single_memo_effect_flush_eq
- idle_first_run_effect_fusion_eq
- try_promote_top_effect_eq
- chain_direct_moved_step_eq
- node_marked_spec
- effect_marked_spec
- mark_check_spec
- mark_dirty_spec
Definition set_node (n : node_id) (d : node) (s : state) : state :=
Definition set_node (n : node_id) (d : node) (s : state) : state :=
{| g_flags := g_flags s; g_edges := g_edges s; g_nodes := <[n := d]> (g_nodes s);
g_owners := g_owners s; g_queue := g_queue s; g_queue_head := g_queue_head s;
g_flushing := g_flushing s; g_flush_owed := g_flush_owed s; g_batch_depth := g_batch_depth s; g_pull_depth := g_pull_depth s;
g_current := g_current s; g_untracked := g_untracked s; g_current_owner := g_current_owner s;
g_next_id := g_next_id s; g_trace := g_trace s; g_running := g_running s; g_checking := g_checking s; g_ghost := g_ghost s;
g_registered := g_registered s;
g_skip := g_skip s; g_epoch := g_epoch s; g_stamps := g_stamps s |}.References
Uses
Used by
- effect_marked
- mark_check
- mark_dirty
- mark_prim
- measure_memo_clean
- measure_memo_announce
- set_node_stale
- set_node_edges
185 more
- set_node_takes
- set_node_dirty
- set_node_undirty
- mark_check_undirty
- memo_mark_dirty_keeps_others_short
- clean_memo_keeps_unannounced
- modify_node
- add_node
- current_owner
- has_kind_set
- has_kind_set_back
- is_Some_set
- is_Some_set_back
- invariant_set_gen
- invariant_set
- frame_set
- frame_node
- prim_invariant
- invariant_new_node
- invariant_run_begin
- bind_modify_node
- invariant_cleared
- ok_recompute_full
- ok_run_memo_full
- ok_write_S
- resolve_walk_check_clears
- set_marked_fixed
- told_marked
- told_marked_stale
- queued_marked
- set_marked_prim
- forward_told
- effect_mark_keeps
- has_kind_put
- base_set
- told_others
- told_set
- ekept_set
- extras_neutral
- gsimp
- gsimp
- gsimp
- extras_run_begin
- extras_announce
- extras_resolved
- extras_cleared
- extras_dispose
- extras_new
- ok2_new_node
- set_node_twice
- ok2_recompute_S
- effect_tail
- ok2_execute_S
- ok2_body_S
- ok2_run_effect_S
- ok2_dispose_S
- ok2_write_S
- run_start
- run_same_set
- run_finish_shape
- data_set
- post_set
- step_node
- sok_new_node
- prim_step
- sok_current_owner
- body_start
- step_body_start
- execute_tail
- measure_set
- memo_failure_contained
- comparer_throw_contained
- disposed_effect_never_runs
- rise_set
- ytouch_set
- shapes_set
- resolve_step
- Aref_S
- run_memo_parts
- run_finish_parts
- Arun_S
- wframe_set
- ko_set
- ko_new_node
- whole_new
- wok_new_node
- wok_current_owner
- qt_rise_others
- check_un
- qt_forward
- effect_marked_mq
- mq_dirty
- dirty_visit
- write_step
- effect_tail_wk
- exe_core
- Wwrite_S
- Wdisp_S
- Wnew_effect
- set_node_shift
- mark_check_shift
- mark_dirty_shift
- set_ne
- set_eq
- stale_set_other
- gd_set
- tot_modify_node
- qbit_set
- marks_q
- mark_check_up
- mark_dirty_up
- tot_clean
- refresh_post
- setup_add
- setup_exec
- host_write
- host_dispose
- setup_ends
- ans_write
- ans_dispose
- walk_appends
- rs_at
- set_node_same
- strip_set_node
- old2_current_owner
- modify_at
- simM_modify_adv
- simM_add_node_adv
- simM_add_node
- strip_effect_marked
- write_signal_except_wakes_others
- publication_comparer_guarded_refines_cutoff
- b1_rel_set_node
- set_node_with_pull
- upd_pull_tac
- b2_add_node
- b2_pure_tac
- leaf_clean_memo_mark_dirty_eq
- notify_moved_single_check_memo_eq
- iter_mark_check_chain
- queue_rel_set_node
- qrel_upd_tac
- m_bind_modify_node
- reset_queue_set_node
- set_node_with_flushing
- set_node_with_flush_owed
- queue_rel_fused_signal
- queue_rel_fused_memo
- fused_single_signal_effect_eq
- fused_single_memo_effect_flush_eq
- custom_comparer_fused_flush_eq
- idle_first_run_effect_fusion_eq
- try_promote_top_effect_eq
- chain_direct_moved_step_eq
- marks_bd
- bd_state_eq
- b2_pure_modify_node
- b2_pure_current_owner
- b2_pure_track
- b2_pure_announce
- b2_pure_cmp_throws
- b2_upd_tac
- b2_pure_add_node
- mt_create_slot
- memotable_create_slot_pure_caller_ok
- current_owner_pure_memo
- memotable_body_pure_enforced
- mt_retire_key
- memotable_retire_key_preserves_coherent
- clear_slot_nodes
- clear_slot_nodes_preserves_empty
- clear_slot_nodes_ok
- mt_refill_clean
- refill_clean_preserves_graph_and_unannounced
- mt_recompute_dirty
- resolve_check_evicted_cutoff_no_refill
- nested_maint_step_preserves_pinned
- pre_track_fanout_coherence
- compute_throw_and_pending_recovery
- mt_retire_key_unpinned
- w7_check_state
- graph_set_node_spec
- graph_put_node_spec
- add_node_spec
- write_signal_except_spec
Graph.Schedule.
Definition enqueue (n : node_id) (s : state) : state :=
Definition enqueue (n : node_id) (s : state) : state :=
{| g_flags := g_flags s; g_edges := g_edges s; g_nodes := g_nodes s;
g_owners := g_owners s; g_queue := g_queue s ++ [n]; g_queue_head := g_queue_head s;
g_flushing := g_flushing s; g_flush_owed := g_flush_owed s; g_batch_depth := g_batch_depth s; g_pull_depth := g_pull_depth s;
g_current := g_current s; g_untracked := g_untracked s; g_current_owner := g_current_owner s;
g_next_id := g_next_id s; g_trace := g_trace s; g_running := g_running s; g_checking := g_checking s; g_ghost := g_ghost s;
g_registered := g_registered s;
g_skip := g_skip s; g_epoch := g_epoch s; g_stamps := g_stamps s |}.References
Uses
Used by
The backward walk of NotifyDirty, NotifyDirtyExcept and NotifyCheck. The natural is the
cursor plus one, and each step reads the observer set of the current state. A cursor at or past the
count descends one position at a time, which reaches the position i <- count - 1 selects.
Fixpoint walk_marks (mark : node_id -> state -> option state) (src : node_id) (n : nat) (s : state)
Fixpoint walk_marks (mark : node_id -> state -> option state) (src : node_id) (n : nat) (s : state)
: option state :=
match n with
| 0 => Some s
| S i =>
if decide (length (observer_items (observers_of (g_edges s) src)) <= i) then walk_marks mark src i s
else match observer_items (observers_of (g_edges s) src) !! i with
| Some (c, _) => mark c s ≫= walk_marks mark src i
| None => None
end
end.References
Used by
Marks the observers of src with mark, walking backward from the observer count of the starting state.
Arguments
Definition notify_with (mark : node_id -> state -> option state) (src : node_id) (s : state) : option state :=
Definition notify_with (mark : node_id -> state -> option state) (src : node_id) (s : state) : option state :=
walk_marks mark src (length (observer_items (observers_of (g_edges s) src))) s.References
Uses
Used by
- mark_check
- notify_check
- mark_dirty
- notify_dirty
- notify_dirty_except
- notify_with_rtc
- notify_with_list
- notify_with_rtc_check
32 more
- notify_with_reaches
- notify_with_stale
- forward_members
- memo_mark_dirty_keeps_others_short
- clean_memo_keeps_unannounced
- walk_marks_hoist_slot0_eq
- forward_told
- notify_keeps
- ytouch_forward
- notify_visit
- qt_forward
- dirty_visit
- fl_go
- mark_check_up
- mark_dirty_up
- notify_budget
- ans_write
- notify_queues_observers_reversed
- notify_old
- notify_dirty_mono
- notify_dirty_except_mono
- mark_check_with_pull
- mark_dirty_with_pull
- notify_dirty_with_pull
- notify_dirty_except_with_pull
- notify_with_nil
- notify_with_singleton
- qrel_mark_check
- qrel_mark_dirty
- qrel_notify_dirty
- qrel_notify_dirty_except
- notify_with_spec
The elif unannounced test.
Definition announce_due (s : state) (d : node) : bool :=
Definition announce_due (s : state) (d : node) : bool :=
f_unannounced (g_flags s) && n_unannounced d.References
Used by
- mark_check
- mark_dirty
- mark_check_rtc
- mark_dirty_rtc
- announce_due_unannounced
- mark_check_some
- mark_dirty_some
- mark_forwards_on_unannounced
37 more
- mark_dirty_ends_dirty
- mark_check_undirty
- memo_mark_dirty_keeps_others_short
- mark_check_keeps
- mark_dirty_keeps
- ytouch_check
- ytouch_dirty
- check_un
- mq_check
- mq_dirty
- dirty_visit
- mark_check_le
- mark_dirty_le
- mark_check_shift
- mark_dirty_shift
- mark_check_up
- mark_dirty_up
- memo_saturated
- prim_keeps_saturated
- mark_dirty_saturates_or_window
- simM_inert
- rel_map
- simM_track
- mark_check_old
- mark_dirty_old
- mark_check_mono
- mark_dirty_mono
- mark_check_with_pull
- mark_dirty_with_pull
- notify_moved_single_check_memo_eq
- iter_mark_check_chain
- iterative_mark_check_chain_eq
- qrel_mark_check
- qrel_mark_dirty
- announce_due_spec
- mark_check_spec
- mark_dirty_spec
Effect.MarkDirty and Effect.MarkCheck, writing freshness f.
Definition effect_marked (f : freshness) (n : node_id) (d : node) (s : state) : state :=
Definition effect_marked (f : freshness) (n : node_id) (d : node) (s : state) : state :=
if n_disposed d || n_in_cleanup d then s
else if n_queued d then set_node n (node_marked f (n_unannounced d) true d) s
else enqueue n (set_node n (node_marked f (n_unannounced d) true d) s).References
Uses
4 more
Used by
- mark_check
- mark_dirty
- effect_marked_rtc
- effect_marked_stale
- effect_marked_queues
- disposed_effect_ignores_marks
- in_cleanup_ignores_marks
- mark_dirty_ends_dirty
25 more
- mark_check_undirty
- effect_mark_keeps
- mark_dirty_other
- ytouch_effect
- effect_marked_mq
- dirty_visit
- mark_new_dirty
- Wnew_effect
- mark_check_shift
- mark_dirty_shift
- mark_check_up
- mark_dirty_up
- walk_appends
- mark_dirty_saturated_id
- mark_dirty_saturates_or_window
- strip_effect_marked
- mark_check_with_pull
- mark_dirty_with_pull
- iter_mark_check_chain
- queue_rel_effect_marked
- fused_single_signal_effect_eq
- fused_single_memo_effect_flush_eq
- idle_first_run_effect_fusion_eq
- try_promote_top_effect_eq
- effect_marked_spec
MarkCheck. A signal and an absent node take no mark: every F# observer is a computation.
None is exhausted fuel.
Fixpoint mark_check (fuel : nat) (n : node_id) (s : state) {struct fuel} : option state :=
Fixpoint mark_check (fuel : nat) (n : node_id) (s : state) {struct fuel} : option state :=
match fuel with
| 0 => None
| S f =>
match g_nodes s !! n with
| Some d =>
match n_kind d with
| KMemo =>
if decide (n_freshness d = Clean) then
notify_with (mark_check f) n (set_node n (node_marked Check (n_unannounced d) (n_queued d) d) s)
else if announce_due s d then
notify_with (mark_check f) n (set_node n (node_marked (n_freshness d) false (n_queued d) d) s)
else Some s
| KEffect =>
Some (effect_marked (if decide (n_freshness d = Clean) then Check else n_freshness d) n d s)
| KSignal => Some s
end
| None => Some s
end
end.References
Uses
16 more
- n_unannounced
- n_queued
- state
- g_nodes
- node_marked
- set_node
- notify_with
- announce_due
- effect_marked
- None
- S
- Some
- false
- nat
- option
- decide
Used by
- notify_check
- mark_dirty
- any_mark
- mark_check_rtc
- mark_check_some
- mark_terminates
- dirty_not_lost
- notify_walk_unmutated
66 more
- notify_with_rtc_check
- mark_check_stale
- forward_members
- mark_forwards_on_clean
- mark_forwards_on_unannounced
- effect_mark_queues
- disposed_effect_ignores_marks
- in_cleanup_ignores_marks
- mark_check_undirty
- mark_check_keeps_check
- memo_mark_dirty_keeps_others_short
- clean_memo_keeps_unannounced
- mark_reader
- ok_mark_reader
- forward_told
- mark_check_keeps
- ok2_track_mark
- later_mark_forwarded
- sok_mark_reader
- ytouch_forward
- ytouch_check
- A_tail
- ko_mark_reader
- wk_mark_from
- check_un
- qt_forward
- mq_check
- tkm_mark_reader
- Wnode_S
- mark_check_le
- le_mark_reader
- mark_check_shift
- cm_mark_reader
- mark_check_up
- mark_dirty_up
- in_cleanup_observer_stays_clean
- disposed_running_observer_stays_clean
- requeue_holds_two_entries
- keeps_mark_reader
- mark_check_old
- simM_mark_reader
- mark_check_mono
- m_step_mark_check_mono
- mark_reader_mono
- mark_reader_depths
- mark_check_with_pull
- b1_mono_tac
- eng_mono_tac
- b1_pure_mark_reader
- b1_pure_mark_reader_bwd
- b2_mark_reader
- iterative_mark_check_chain_eq
- qrel_mark_check
- qrel_mark_reader
- fused_single_memo_effect_flush_eq
- bd_prim
- b2_pure_mark_reader
- unannounced_clobbered_by_refill_statement
- w7_s_ok
- w7_s_bad
- unannounced_clobbered_by_refill_falsified
- mark_check_spec
- notify_check_spec
- mark_dirty_spec
- mark_reader_spec
- forwarding_edge_mark_spec
NotifyCheck: marks each observer of src with mark_check.
Arguments
Definition notify_check (fuel : nat) (src : node_id) (s : state) : option state :=
Definition notify_check (fuel : nat) (src : node_id) (s : state) : option state :=
notify_with (mark_check fuel) src s.Arguments
MarkDirty. A memo tells its observers Check, so the recursion runs through mark_check.
Definition mark_dirty (fuel : nat) (n : node_id) (s : state) : option state :=
Definition mark_dirty (fuel : nat) (n : node_id) (s : state) : option state :=
match fuel with
| 0 => None
| S f =>
match g_nodes s !! n with
| Some d =>
match n_kind d with
| KMemo =>
if decide (n_freshness d = Clean) then
notify_with (mark_check f) n (set_node n (node_marked Dirty (n_unannounced d) (n_queued d) d) s)
else if announce_due s d then
notify_with (mark_check f) n (set_node n (node_marked Dirty false (n_queued d) d) s)
else if decide (n_freshness d = Dirty) then Some s
else Some (set_node n (node_marked Dirty (n_unannounced d) (n_queued d) d) s)
| KEffect => Some (effect_marked Dirty n d s)
| KSignal => Some s
end
| None => Some s
end
end.References
Uses
17 more
- n_unannounced
- n_queued
- state
- g_nodes
- node_marked
- set_node
- notify_with
- announce_due
- effect_marked
- mark_check
- None
- S
- Some
- false
- nat
- option
- decide
Used by
- notify_dirty
- mark_except
- any_mark
- mark_dirty_rtc
- mark_dirty_some
- mark_terminates
- notify_walk_unmutated
- mark_dirty_stale
72 more
- mark_forwards_on_clean
- mark_forwards_on_unannounced
- effect_mark_queues
- disposed_effect_ignores_marks
- in_cleanup_ignores_marks
- mark_dirty_ends_dirty
- memo_mark_dirty_keeps_others_short
- clean_memo_keeps_unannounced
- exec
- ok_mark_dirty
- resolve_walk_step
- resolve_walk_no_stale_source
- mark_dirty_keeps
- ok2_mark_dirty
- later_mark_forwarded
- mark_dirty_other
- sok_mark_dirty
- ytouch_dirty
- wok_mark_new
- mq_dirty
- dirty_visit
- mark_new_dirty
- Wnew_effect
- mark_dirty_le
- fl_go
- mark_dirty_shift
- cm_go
- mark_dirty_up
- walk_step_eq
- setup_ends
- walk_appends
- oexec
- mark_dirty_saturated_id
- mark_dirty_saturates_or_window
- walk_saturated_id
- window_mark
- mark_dirty_saturates_falsified
- mark_dirty_old
- simM_mark_dirty
- sgo1
- mark_dirty_mono
- m_step_mark_dirty_mono
- engine_mono_all
- engine_depths_kept
- b1_exec
- b1_mono_all
- b1_depths_kept
- mark_dirty_with_pull
- b1_mono_tac
- eng_mono_tac
- b1_pure_mark_dirty
- b1_pure_mark_dirty_bwd
- b1_fwd_all
- b1_bwd_all
- b2_inv_all
- leaf_clean_memo_mark_dirty_eq
- refresh_after_src
- resolve_walk_0_step
- qrel_mark_dirty
- b1_qrel_all
- fused_single_signal_effect_eq
- fused_single_memo_effect
- fused_single_memo_effect_tail_mono
- fused_single_memo_effect_flush_eq
- idle_first_run_effect_fusion_eq
- try_promote_top_effect_eq
- bd_prim
- b2_pure_mark_dirty
- b2_mono_tac
- mark_dirty_spec
- notify_dirty_spec
- forwarding_edge_mark_spec
NotifyDirty: marks each observer of src with mark_dirty.
Arguments
Definition notify_dirty (fuel : nat) (src : node_id) (s : state) : option state :=
Definition notify_dirty (fuel : nat) (src : node_id) (s : state) : option state :=
notify_with (mark_dirty fuel) src s.Arguments
References
Uses
- node_id
- state
- notify_with
- mark_dirty
- nat
- option
Used by
- any_mark
- notify_terminates
- notify_walk_unmutated
- notify_stales
- notify_dirty_ends_dirty
- exec
- sok_notify_dirty
- write_step
38 more
- fl_go
- cm_go
- ans_write
- notify_queues_observers_reversed
- notify_after_swap
- skip_removed_fires
- notify_write
- eqM_notify_write
- notify_dirty_stamped_id
- window_facts
- unchecked_record_unsound
- notify_dirty_old
- walk_record_sound
- simM_notify_write
- sgo1
- notify_removed
- notify_removed_wakes_observers
- notify_dirty_mono
- m_step_notify_dirty_mono
- engine_depths_kept
- b1_exec
- b1_depths_kept
- notify_dirty_with_pull
- b1_mono_tac
- eng_mono_tac
- b1_pure_notify_dirty
- b1_pure_notify_dirty_bwd
- b2_inv_all
- qrel_notify_dirty
- b1_qrel_all
- fused_single_signal_effect_eq
- fused_single_memo_effect_flush_eq
- write_signal_cmp
- bd_prim
- b2_pure_notify_dirty
- b2_mono_tac
- notify_dirty_spec
- notify_removed_spec
The visit of NotifyDirtyExcept. r is CurrentComputation, and None is null.
Definition mark_except (fuel : nat) (src : node_id) (r : option node_id) (c : node_id) (s : state) : option state :=
Definition mark_except (fuel : nat) (src : node_id) (r : option node_id) (c : node_id) (s : state) : option state :=
if decide (r = Some c /\ src ∉ read_prefix (g_edges s) c) then Some s else mark_dirty fuel c s.References
Used by
NotifyDirtyExcept: marks each observer of src with mark_dirty, skipping the computation r unless r has already read src in its current run.
Arguments
Definition notify_dirty_except (fuel : nat) (src : node_id) (r : option node_id) (s : state) : option state :=
Definition notify_dirty_except (fuel : nat) (src : node_id) (r : option node_id) (s : state) : option state :=
notify_with (mark_except fuel src r) src s.References
Uses
- node_id
- state
- notify_with
- mark_except
- nat
- option
Used by
- any_mark
- notify_terminates
- notify_walk_unmutated
- notify_stales
- notify_dirty_ends_dirty
- exec
- run_finish
- run_finish_shape
42 more
- notify_except_fixed
- notice_skips_current
- sok_notify_except
- ytouch_notify_except
- run_finish_parts
- fl_go
- cm_go
- notify_budget
- run_memo_tot
- skip_removed_fires
- oexec
- notify_except_old
- simM_notify_except
- sgo1
- write_signal_except
- write_signal_except_wakes_others
- publication_comparer_guarded_refines_cutoff
- notify_dirty_except_mono
- m_step_notify_dirty_except_mono
- engine_depths_kept
- b1_exec
- b1_depths_kept
- notify_dirty_except_with_pull
- b1_mono_tac
- eng_mono_tac
- b1_pure_notify_dirty_except
- b1_pure_notify_dirty_except_bwd
- b2_inv_all
- notify_moved_single_check_memo_eq
- qrel_notify_dirty_except
- b1_qrel_all
- ref_ready_cutoff_step
- leaf_memo_no_cutoff_eq
- try_promote_top_effect_eq
- chain_moved_ref_step
- bd_prim
- b2_pure_notify_dirty_except
- b2_mono_tac
- mt_refill_clean
- mt_recompute_dirty
- notify_dirty_except_spec
- write_signal_except_spec
Any of the five marking operations, from s to s'.
Definition any_mark (fuel : nat) (n : node_id) (r : option node_id) (s s' : state) : Prop :=
Definition any_mark (fuel : nat) (n : node_id) (r : option node_id) (s s' : state) : Prop :=
mark_check fuel n s = Some s' \/ mark_dirty fuel n s = Some s' \/
notify_check fuel n s = Some s' \/ notify_dirty fuel n s = Some s' \/
notify_dirty_except fuel n r s = Some s'.References
A node's contribution to mark_measure: its clean transition and its pending announcement. Only a
memo forwards a mark.
Definition mark_score (d : node) : nat :=
Definition mark_score (d : node) : nat :=
match n_kind d with
| KMemo => (if decide (n_freshness d = Clean) then 1 else 0) + (if n_unannounced d then 1 else 0)
| _ => 0
end.Definition nodes_score (m : gmap node_id node) : nat :=
Definition nodes_score (m : gmap node_id node) : nat :=
sum_list (mark_score ∘ snd <$> map_to_list m).References
Uses
- node_id
- node
- mark_score
- nat
- snd
- map_to_list
- gmap
- list.sum_list
Bound on the walks started by later marks: one per memo in Clean, one per memo holding an
announcement.
Definition mark_measure (s : state) : nat := nodes_score (g_nodes s).References
Uses
The primitive steps
One change to a node's freshness mark: a memo takes a freshness at or above its own and keeps or clears its unannounced flag, a queued effect takes a freshness at or above its own, or an unqueued effect does so and is enqueued.
Inductive mark_prim : state -> state -> Prop :=
Inductive mark_prim : state -> state -> Prop :=
| prim_memo s n d f u :
g_nodes s !! n = Some d ->
n_kind d = KMemo ->
freshness_le (n_freshness d) f ->
(u = n_unannounced d \/ u = false) ->
mark_prim s (set_node n (node_marked f u (n_queued d) d) s)
| prim_effect s n d f :
g_nodes s !! n = Some d ->
n_kind d = KEffect ->
n_queued d = true ->
freshness_le (n_freshness d) f ->
mark_prim s (set_node n (node_marked f (n_unannounced d) true d) s)
| prim_enqueue s n d f :
g_nodes s !! n = Some d ->
n_kind d = KEffect ->
n_queued d = false ->
freshness_le (n_freshness d) f ->
mark_prim s (enqueue n (set_node n (node_marked f (n_unannounced d) true d) s)).References
Uses
7 more
- g_nodes
- node_marked
- set_node
- enqueue
- Some
- false
- true
Used by
54 more
- marks_holds
- ok_mark
- prim_dom
- marks_dom
- invariant_told
- prim_fixed
- marks_fixed
- forward_told
- covered_rises
- later_mark_forwarded
- prim_step
- marks_step
- sok_mark
- run_finish_some
- prim_rise
- rtc_rise
- prim_next
- marks_next
- ko_mark
- notify_visit
- write_step
- marks_own
- marks_queue
- tk_of_marks
- tkm_mark
- marks_flushing
- marks_shapes
- gd_marks
- marks_q
- walk_up
- mark_check_up
- mark_dirty_up
- marks_kept
- notify_budget
- setup_marks
- host_write
- link_marks
- ans_write
- prim_skip
- marks_skip
- prim_keeps_saturated
- rtc_keeps_saturated
- rtc_frame
- simM_mark_step
- walk_record_sound
- marks_same_depths
- mark_prim_b2_inv
- marks_b2_inv
- marks_bd
- mark_check_rtc
- mark_dirty_rtc
- set_node_takes
- set_marked_prim
- effect_marked_rtc
Local Notation marks := (rtc mark_prim).Lemma freshness_le_refl f : freshness_le f f.
Qed
Proof. unfold freshness_le. lia. Qed.Lemma freshness_le_trans f g h : freshness_le f g -> freshness_le g h -> freshness_le f h.
Qed
Proof. unfold freshness_le. lia. Qed.Lemma freshness_le_clean f : freshness_le Clean f.
Qed
Proof. unfold freshness_le. simpl. lia. Qed.Lemma freshness_le_dirty f : freshness_le f Dirty.
Qed
Proof. destruct f; unfold freshness_le; simpl; lia. Qed.Lemma walk_marks_rtc (mark : node_id -> state -> option state) src n s s' :
Lemma walk_marks_rtc (mark : node_id -> state -> option state) src n s s' :
(forall c s0 s1, mark c s0 = Some s1 -> marks s0 s1) ->
walk_marks mark src n s = Some s' ->
marks s s'.
Qed
Proof.
intros Hm. revert s. induction n as [|i IH]; intros s Hw; simpl in Hw.
- simplify_eq. apply rtc_refl.
- destruct (decide _) as [_|_]; [by apply IH|].
destruct (observer_items (observers_of (g_edges s) src) !! i) as [[c ?]|]; [|done].
destruct (mark c s) as [s1|] eqn:Ec; simpl in Hw; [|done].
eapply marks_trans; [by eapply Hm|by apply IH].
Qed.References
Uses
4 more
- Some
- option
- decide
- rtc_refl
Used by
Lemma notify_with_rtc mark src s s' :
Lemma notify_with_rtc mark src s s' :
(forall c s0 s1, mark c s0 = Some s1 -> marks s0 s1) ->
notify_with mark src s = Some s' ->
marks s s'.
Qed
Proof. intros Hm. by apply walk_marks_rtc. Qed.Lemma effect_marked_rtc f n d s :
Lemma effect_marked_rtc f n d s :
g_nodes s !! n = Some d ->
n_kind d = KEffect ->
freshness_le (n_freshness d) f ->
marks s (effect_marked f n d s).
Qed
Proof.
intros Hd Hk Hf. unfold effect_marked.
destruct (_ || _); [apply rtc_refl|].
destruct (n_queued d) eqn:Hq; apply rtc_once; [eapply prim_effect|eapply prim_enqueue]; done.
Qed.Lemma mark_check_rtc f n s s' : mark_check f n s = Some s' -> marks s s'.
Qed
Proof.
revert n s s'. induction f as [|f IH]; intros n s s' Hm; simpl in Hm; [done|].
destruct (g_nodes s !! n) as [d|] eqn:Hd; [|simplify_eq; apply rtc_refl].
destruct (n_kind d) eqn:Hk.
- simplify_eq. apply rtc_refl.
- destruct (decide (n_freshness d = Clean)) as [Hc|Hc].
+ eapply rtc_l.
* eapply prim_memo; [done|done| |by left]. rewrite Hc. apply freshness_le_clean.
* eapply notify_with_rtc; [|done]. intros ???. apply IH.
+ destruct (announce_due s d).
* eapply rtc_l.
-- eapply prim_memo; [done|done|apply freshness_le_refl|by right].
-- eapply notify_with_rtc; [|done]. intros ???. apply IH.
* simplify_eq. apply rtc_refl.
- simplify_eq. apply effect_marked_rtc; [done|done|].
destruct (decide (n_freshness d = Clean)) as [->|_]; [apply freshness_le_clean|apply freshness_le_refl].
Qed.References
Uses
8 more
- freshness_le_refl
- freshness_le_clean
- notify_with_rtc
- effect_marked_rtc
- Some
- decide
- rtc_l
- rtc_refl
Used by
Lemma mark_dirty_rtc f n s s' : mark_dirty f n s = Some s' -> marks s s'.
Qed
Proof.
destruct f as [|f]; intros Hm; simpl in Hm; [done|].
destruct (g_nodes s !! n) as [d|] eqn:Hd; [|simplify_eq; apply rtc_refl].
destruct (n_kind d) eqn:Hk.
- simplify_eq. apply rtc_refl.
- destruct (decide (n_freshness d = Clean)) as [Hc|Hc].
+ eapply rtc_l.
* eapply prim_memo; [done|done|apply freshness_le_dirty|by left].
* eapply notify_with_rtc; [|done]. intros ???. apply mark_check_rtc.
+ destruct (announce_due s d).
* eapply rtc_l.
-- eapply prim_memo; [done|done|apply freshness_le_dirty|by right].
-- eapply notify_with_rtc; [|done]. intros ???. apply mark_check_rtc.
* destruct (decide (n_freshness d = Dirty)); simplify_eq; [apply rtc_refl|].
apply rtc_once. eapply prim_memo; [done|done|apply freshness_le_dirty|by left].
- simplify_eq. apply effect_marked_rtc; [done|done|apply freshness_le_dirty].
Qed.References
Uses
10 more
- marks
- freshness_le_dirty
- notify_with_rtc
- effect_marked_rtc
- mark_check_rtc
- Some
- decide
- rtc_l
- rtc_once
- rtc_refl
Used by
Lemma mark_except_rtc f src r c s s' : mark_except f src r c s = Some s' -> marks s s'.
Qed
Proof.
unfold mark_except. destruct (decide _); [intros; simplify_eq; apply rtc_refl|apply mark_dirty_rtc].
Qed.References
Uses
- mark_except
- marks
- mark_dirty_rtc
- Some
- decide
- rtc_refl
Lemma any_mark_rtc f n r s s' : any_mark f n r s s' -> marks s s'.
Qed
Proof.
intros [H|[H|[H|[H|H]]]].
- by eapply mark_check_rtc.
- by eapply mark_dirty_rtc.
- eapply notify_with_rtc; [|done]. intros ???. apply mark_check_rtc.
- eapply notify_with_rtc; [|done]. intros ???. apply mark_dirty_rtc.
- eapply notify_with_rtc; [|done]. intros ???. apply mark_except_rtc.
Qed.References
Used by
- mark_monotone
- mark_preserves_edges
- mark_keeps_queue_once
- ok_run_memo_full
- ok_write_S
- base_marks
- ok2_mark
- ok2_track_mark
32 more
- ok2_run_memo_S
- ok2_write_S
- notify_except_fixed
- sok_notify_dirty
- sok_notify_except
- run_finish_some
- any_mark_rise
- kgo1
- T_ok_S
- Wwrite_S
- cm_go
- notify_budget
- host_write
- ans_write
- any_mark_skip
- marks_keep_saturated
- simM_notify_except
- walk_record_sound
- engine_depths_kept
- b1_depths_kept
- b1_pure_mark_reader
- b1_pure_mark_reader_bwd
- b1_pure_mark_dirty
- b1_pure_mark_dirty_bwd
- b1_pure_notify_dirty
- b1_pure_notify_dirty_bwd
- b1_pure_notify_dirty_except
- b1_pure_notify_dirty_except_bwd
- b2_inv_any_mark
- bd_prim
- b2_pure_notify_dirty
- b2_pure_notify_dirty_except
What a mark holds fixed
Lemma marks_edges s s' : marks s s' -> g_edges s' = g_edges s.
Qed
Proof.
induction 1 as [|s1 s2 s3 Hp _ IH]; [done|]. rewrite IH. by apply prim_edges.
Qed.d' is a later copy of d under marks.
Definition node_rises (d d' : node) : Prop :=
Definition node_rises (d d' : node) : Prop :=
n_kind d' = n_kind d /\ n_disposed d' = n_disposed d /\ n_in_cleanup d' = n_in_cleanup d /\
freshness_le (n_freshness d) (n_freshness d') /\ (n_unannounced d = false -> n_unannounced d' = false).Lemma node_rises_refl d : node_rises d d.
Qed
Proof. split_and!; try done. apply freshness_le_refl. Qed.Lemma node_rises_trans d1 d2 d3 : node_rises d1 d2 -> node_rises d2 d3 -> node_rises d1 d3.
Qed
Proof.
intros (H1 & H2 & H3 & H4 & H5) (H1' & H2' & H3' & H4' & H5').
split_and!; try congruence; [|auto]. by eapply freshness_le_trans.
Qed.Lemma prim_rises s s' m d :
Lemma prim_rises s s' m d :
mark_prim s s' -> g_nodes s !! m = Some d ->
exists d', g_nodes s' !! m = Some d' /\ node_rises d d'.
Qed
Proof.
intros Hp Hm. destruct Hp as [s n d0 f u Hd Hk Hf Hu|s n d0 f Hd Hk Hq Hf|s n d0 f Hd Hk Hq Hf]; simpl.
all: destruct (decide (m = n)) as [->|Hne].
all: try (rewrite lookup_insert_ne by done; exists d; split; [done|apply node_rises_refl]).
all: rewrite lookup_insert_eq; eexists; split; [reflexivity|]; simplify_eq.
all: split_and!; simpl; try done.
destruct Hu as [-> | ->]; auto.
Qed.References
Uses
- g_nodes
- mark_prim
- node_rises
- node_rises_refl
- Some
- decide
- lookup_insert_eq
- lookup_insert_ne
Used by
Lemma marks_rises s s' m d :
Lemma marks_rises s s' m d :
marks s s' -> g_nodes s !! m = Some d ->
exists d', g_nodes s' !! m = Some d' /\ node_rises d d'.
Qed
Proof.
intros Hr. revert d. induction Hr as [s|s1 s2 s3 Hp _ IH]; intros d Hm.
- exists d. split; [done|apply node_rises_refl].
- destruct (prim_rises _ _ _ _ Hp Hm) as (d2 & Hd2 & Hr2).
destruct (IH _ Hd2) as (d3 & Hd3 & Hr3). exists d3. split; [done|by eapply node_rises_trans].
Qed.The measure
Lemma sum_list_perm (l1 l2 : list nat) : l1 ≡ₚ l2 -> sum_list l1 = sum_list l2.
Qed
Proof. induction 1; simpl; lia. Qed.Lemma nodes_score_delete m n d :
Lemma nodes_score_delete m n d :
m !! n = Some d -> nodes_score m = mark_score d + nodes_score (delete n m).
Qed
Proof.
intros Hd. unfold nodes_score.
rewrite <- (sum_list_perm _ _ (fmap_Permutation _ _ _ (map_to_list_delete m n d Hd))).
reflexivity.
Qed.References
Uses
- mark_score
- nodes_score
- sum_list_perm
- Some
- delete
- map_to_list_delete
- list.fmap_Permutation
Used by
Lemma nodes_score_insert m n d d' :
Lemma nodes_score_insert m n d d' :
m !! n = Some d ->
nodes_score (<[n := d']> m) + mark_score d = nodes_score m + mark_score d'.
Qed
Proof.
intros Hd. rewrite (nodes_score_delete m n d Hd).
rewrite (nodes_score_delete (<[n := d']> m) n d') by apply lookup_insert_eq.
rewrite delete_insert_eq. lia.
Qed.References
Uses
- mark_score
- nodes_score
- nodes_score_delete
- Some
- delete_insert_eq
- lookup_insert_eq
Lemma score_marked_le d f u q :
Lemma score_marked_le d f u q :
freshness_le (n_freshness d) f -> (u = n_unannounced d \/ u = false) ->
mark_score (node_marked f u q d) <= mark_score d.
Qed
Proof.
intros Hf Hu. unfold mark_score. simpl. destruct (n_kind d); [lia| |lia].
destruct (decide (n_freshness d = Clean)) as [Hc|Hc]; destruct (decide (f = Clean)) as [->|Hf'].
- destruct Hu as [-> | ->]; [lia|destruct (n_unannounced d); lia].
- destruct Hu as [-> | ->]; [lia|destruct (n_unannounced d); lia].
- destruct (n_freshness d); [done|unfold freshness_le in Hf; simpl in Hf; lia..].
- destruct Hu as [-> | ->]; [lia|destruct (n_unannounced d); lia].
Qed.References
Used by
Lemma score_effect d : n_kind d = KEffect -> mark_score d = 0.
Qed
Proof. intros Hk. unfold mark_score. by rewrite Hk. Qed.Lemma prim_measure s s' : mark_prim s s' -> mark_measure s' <= mark_measure s.
Qed
Proof.
intros Hp. destruct Hp as [s n d f u Hd Hk Hf Hu|s n d f Hd Hk Hq Hf|s n d f Hd Hk Hq Hf];
unfold mark_measure; simpl.
- pose proof (nodes_score_insert (g_nodes s) n d (node_marked f u (n_queued d) d) Hd).
pose proof (score_marked_le d f u (n_queued d) Hf Hu). lia.
- pose proof (nodes_score_insert (g_nodes s) n d (node_marked f (n_unannounced d) true d) Hd).
rewrite (score_effect (node_marked f (n_unannounced d) true d)), (score_effect d) in * by done. lia.
- pose proof (nodes_score_insert (g_nodes s) n d (node_marked f (n_unannounced d) true d) Hd).
rewrite (score_effect (node_marked f (n_unannounced d) true d)), (score_effect d) in * by done. lia.
Qed.Lemma marks_measure s s' : marks s s' -> mark_measure s' <= mark_measure s.
Qed
Proof.
induction 1 as [|s1 s2 s3 Hp _ IH]; [done|]. pose proof (prim_measure _ _ Hp). lia.
Qed.A walk's start uses up a clean transition or an announcement.
Lemma measure_memo_clean s n d f q :
Lemma measure_memo_clean s n d f q :
g_nodes s !! n = Some d -> n_kind d = KMemo -> n_freshness d = Clean -> f <> Clean ->
S (mark_measure (set_node n (node_marked f (n_unannounced d) q d) s)) <= mark_measure s.
Qed
Proof.
intros Hd Hk Hc Hf. unfold mark_measure. simpl.
pose proof (nodes_score_insert (g_nodes s) n d (node_marked f (n_unannounced d) q d) Hd) as Hi.
unfold mark_score in Hi. simpl in Hi. rewrite Hk, Hc in Hi.
rewrite decide_True in Hi by done. rewrite decide_False in Hi by done. lia.
Qed.References
Uses
7 more
- mark_score
- mark_measure
- nodes_score_insert
- S
- Some
- decide_False
- decide_True
Lemma measure_memo_announce s n d f q :
Lemma measure_memo_announce s n d f q :
g_nodes s !! n = Some d -> n_kind d = KMemo -> n_freshness d <> Clean -> f <> Clean -> n_unannounced d = true ->
S (mark_measure (set_node n (node_marked f false q d) s)) <= mark_measure s.
Qed
Proof.
intros Hd Hk Hc Hf Hu. unfold mark_measure. simpl.
pose proof (nodes_score_insert (g_nodes s) n d (node_marked f false q d) Hd) as Hi.
unfold mark_score in Hi. simpl in Hi. rewrite Hk, Hu in Hi.
rewrite !decide_False in Hi by done. lia.
Qed.References
Uses
8 more
- mark_score
- mark_measure
- nodes_score_insert
- S
- Some
- false
- true
- decide_False
Lemma announce_due_unannounced s d : announce_due s d = true -> n_unannounced d = true.
Qed
Proof. unfold announce_due. destruct (f_unannounced _), (n_unannounced d); done. Qed.Marking finishes
Lemma walk_marks_some (mark : node_id -> state -> option state) src n s bound :
Lemma walk_marks_some (mark : node_id -> state -> option state) src n s bound :
(forall c s0, mark_measure s0 < bound -> is_Some (mark c s0)) ->
(forall c s0 s1, mark c s0 = Some s1 -> marks s0 s1) ->
mark_measure s < bound ->
is_Some (walk_marks mark src n s).
Qed
Proof.
intros Hs Hr. revert s. induction n as [|i IH]; intros s Hb; simpl; [by eexists|].
destruct (decide _) as [_|Hlt]; [by apply IH|].
destruct (lookup_lt_is_Some_2 (observer_items (observers_of (g_edges s) src)) i) as [[c slot] Hc]; [lia|].
rewrite Hc. destruct (Hs c s Hb) as [s1 Hs1]. rewrite Hs1. simpl.
apply IH. pose proof (marks_measure _ _ (Hr _ _ _ Hs1)). lia.
Qed.References
Uses
6 more
- marks_measure
- Some
- option
- decide
- is_Some
- list.lookup_lt_is_Some_2
Lemma mark_check_some f n s : mark_measure s < f -> is_Some (mark_check f n s).
Qed
Proof.
revert n s. induction f as [|f IH]; intros n s Hb; [lia|]. simpl.
destruct (g_nodes s !! n) as [d|] eqn:Hd; [|by eexists].
destruct (n_kind d) eqn:Hk; [by eexists| |by eexists].
destruct (decide (n_freshness d = Clean)) as [Hc|Hc].
- apply (walk_marks_some _ _ _ _ f); [intros; by apply IH|intros ???; apply mark_check_rtc|].
pose proof (measure_memo_clean s n d Check (n_queued d) Hd Hk Hc ltac:(done)). lia.
- destruct (announce_due s d) eqn:Hu; [|by eexists].
apply (walk_marks_some _ _ _ _ f); [intros; by apply IH|intros ???; apply mark_check_rtc|].
pose proof (measure_memo_announce s n d (n_freshness d) (n_queued d) Hd Hk Hc Hc
(announce_due_unannounced _ _ Hu)). lia.
Qed.Lemma mark_dirty_some f n s : mark_measure s < f -> is_Some (mark_dirty f n s).
Qed
Proof.
destruct f as [|f]; intros Hb; [lia|]. simpl.
destruct (g_nodes s !! n) as [d|] eqn:Hd; [|by eexists].
destruct (n_kind d) eqn:Hk; [by eexists| |by eexists].
destruct (decide (n_freshness d = Clean)) as [Hc|Hc].
- apply (walk_marks_some _ _ _ _ f);
[intros; by apply mark_check_some|intros ???; apply mark_check_rtc|].
pose proof (measure_memo_clean s n d Dirty (n_queued d) Hd Hk Hc ltac:(done)). lia.
- destruct (announce_due s d) eqn:Hu.
+ apply (walk_marks_some _ _ _ _ f);
[intros; by apply mark_check_some|intros ???; apply mark_check_rtc|].
pose proof (measure_memo_announce s n d Dirty (n_queued d) Hd Hk Hc ltac:(done)
(announce_due_unannounced _ _ Hu)). lia.
+ destruct (decide (n_freshness d = Dirty)); by eexists.
Qed.Marking a node finishes on any graph, cycles included.
With fuel above mark_measure, mark_check and mark_dirty return a state.
Arguments
mark_measure s.Theorem mark_terminates fuel n s :
Theorem mark_terminates fuel n s :
mark_measure s < fuel ->
is_Some (mark_check fuel n s) /\ is_Some (mark_dirty fuel n s).
Arguments
mark_measure s.Qed
Proof. intros Hb. split; [by apply mark_check_some|by apply mark_dirty_some]. Qed.References
Used by
Marking a node's observers finishes on any graph, cycles included.
With fuel above mark_measure, notify_check, notify_dirty and notify_dirty_except return a state.
Arguments
mark_measure s.notify_dirty_except, or None.Theorem notify_terminates fuel n r s :
Theorem notify_terminates fuel n r s :
mark_measure s < fuel ->
is_Some (notify_check fuel n s) /\ is_Some (notify_dirty fuel n s) /\
is_Some (notify_dirty_except fuel n r s).
Arguments
mark_measure s.notify_dirty_except, or None.Qed
Proof.
intros Hb. split_and!.
- apply (walk_marks_some _ _ _ _ fuel);
[intros; by apply mark_check_some|intros ???; apply mark_check_rtc|done].
- apply (walk_marks_some _ _ _ _ fuel);
[intros; by apply mark_dirty_some|intros ???; apply mark_dirty_rtc|done].
- apply (walk_marks_some _ _ _ _ fuel); [|intros ???; apply mark_except_rtc|done].
intros c s0 Hb0. unfold mark_except. destruct (decide _); [by eexists|by apply mark_dirty_some].
Qed.Marks raise freshness and leave edges alone
Marks only raise freshness.
After any of the five marking operations, each existing node still exists, and its freshness has stayed or risen in the order Clean, Check, Dirty.
Arguments
notify_dirty_except, or None.s.m in s.Theorem mark_monotone fuel n r s s' m d :
Theorem mark_monotone fuel n r s s' m d :
any_mark fuel n r s s' ->
g_nodes s !! m = Some d ->
exists d', g_nodes s' !! m = Some d' /\ freshness_le (n_freshness d) (n_freshness d').
Arguments
notify_dirty_except, or None.s.m in s.Qed
Proof.
intros Ha Hm. destruct (marks_rises _ _ _ _ (any_mark_rtc _ _ _ _ _ Ha) Hm) as (d' & Hd' & _ & _ & _ & Hf & _).
eauto.
Qed.A Check mark leaves a Dirty node Dirty.
Covers mark_check only. mark_monotone gives the same for every marking operation.
Arguments
Theorem dirty_not_lost fuel n s s' m d :
Theorem dirty_not_lost fuel n s s' m d :
mark_check fuel n s = Some s' ->
g_nodes s !! m = Some d ->
n_freshness d = Dirty ->
exists d', g_nodes s' !! m = Some d' /\ n_freshness d' = Dirty.
Arguments
Qed
Proof.
intros Hc Hm Hf. destruct (marks_rises _ _ _ _ (mark_check_rtc _ _ _ _ Hc) Hm)
as (d' & Hd' & _ & _ & _ & Hle & _).
exists d'. split; [done|]. rewrite Hf in Hle. destruct (n_freshness d'); [| |done];
unfold freshness_le in Hle; simpl in Hle; lia.
Qed.References
Used by
Marks leave the edges alone.
Each of the five marking operations leaves both ends of every edge unchanged.
Arguments
notify_dirty_except, or None.Arguments
notify_dirty_except, or None.Qed
Proof. intros Ha. by eapply marks_edges, any_mark_rtc. Qed.A marking walk visits a fixed list
Marks the observers vis in order with mark, stopping at the first None.
References
Lemma length_view o : length (observer_view o) = length (observer_items o).
Qed
Proof. unfold observer_view. by rewrite length_fmap. Qed.References
Uses
- observer_items
- observer_view
- length
- list.length_fmap
Lemma walk_clamp i o muts vis o' :
Lemma walk_clamp i o muts vis o' :
length (observer_items o) <= i -> walk i o muts vis o' -> walk (S i) o muts vis o'.
Qed
Proof.
intros Hle Hw. inversion Hw as [|n' j o2 c slot ms o1 rest vis2 o3 Hmin Hj Ha Hr]; subst.
- apply walk_end. lia.
- eapply walk_visit with (i := j); [lia|done|done|done].
Qed.Lemma walk_static n o :
Lemma walk_static n o :
walk n o ((fun _ => []) <$> rev (take n (observer_view o))) (rev (take n (observer_view o))) o.
Qed
Proof.
induction n as [|i IH].
- rewrite take_0. simpl. apply walk_end. lia.
- destruct (decide (length (observer_items o) <= i)) as [Hle|Hlt].
+ rewrite !take_ge in * by (rewrite length_view; lia). by apply walk_clamp.
+ destruct (lookup_lt_is_Some_2 (observer_items o) i) as [[c slot] Hc]; [lia|].
assert (Hv : observer_view o !! i = Some c) by (apply view_lookup; eauto).
rewrite (take_S_r _ _ _ Hv), rev_app_distr. simpl.
eapply walk_visit with (i := i); [lia|done|reflexivity|done].
Qed.References
Uses
10 more
- Some
- length
- rev
- rev_app_distr
- decide
- list.lookup_lt_is_Some_2
- list.take
- list.take_0
- list.take_S_r
- list.take_ge
Used by
Lemma walk_marks_list (mark : node_id -> state -> option state) src n s :
Lemma walk_marks_list (mark : node_id -> state -> option state) src n s :
(forall c s0 s1, mark c s0 = Some s1 -> marks s0 s1) ->
walk_marks mark src n s = mark_list mark (rev (take n (observer_view (observers_of (g_edges s) src)))) s.
Qed
Proof.
intros Hm. revert s. induction n as [|i IH]; intros s; simpl.
- done.
- destruct (decide _) as [Hle|Hlt].
+ rewrite IH. rewrite !take_ge by (rewrite length_view; lia). done.
+ destruct (lookup_lt_is_Some_2 (observer_items (observers_of (g_edges s) src)) i) as [[c slot] Hc]; [lia|].
assert (Hv : observer_view (observers_of (g_edges s) src) !! i = Some c) by (apply view_lookup; eauto).
rewrite Hc, (take_S_r _ _ _ Hv), rev_app_distr. simpl.
destruct (mark c s) as [s1|] eqn:E; simpl; [|done].
rewrite IH. rewrite (marks_edges _ _ (Hm _ _ _ E)). done.
Qed.References
Uses
13 more
- marks
- marks_edges
- mark_list
- length_view
- Some
- option
- rev
- rev_app_distr
- decide
- list.lookup_lt_is_Some_2
- list.take
- list.take_S_r
- list.take_ge
Used by
Lemma notify_with_list (mark : node_id -> state -> option state) src s :
Lemma notify_with_list (mark : node_id -> state -> option state) src s :
(forall c s0 s1, mark c s0 = Some s1 -> marks s0 s1) ->
notify_with mark src s = mark_list mark (rev (observer_view (observers_of (g_edges s) src))) s.
Qed
Proof.
intros Hm. unfold notify_with. rewrite walk_marks_list by done.
rewrite take_ge by (rewrite length_view; lia). done.
Qed.References
Uses
6 more
- length_view
- walk_marks_list
- Some
- option
- rev
- list.take_ge
A marking walk visits the observers present at its start, last position first.
Each notify operation folds its mark over that one list, and the walk is a walk with empty mutations at every visit. A walk with a mutation behaves differently: see walk_visits_added_observer.
Arguments
notify_dirty_except, or None.Theorem notify_walk_unmutated fuel src r s (o := observers_of (g_edges s) src) (vis := rev (observer_view o)) :
Theorem notify_walk_unmutated fuel src r s (o := observers_of (g_edges s) src) (vis := rev (observer_view o)) :
walk (length (observer_items o)) o ((fun _ => []) <$> vis) vis o /\
notify_check fuel src s = mark_list (mark_check fuel) vis s /\
notify_dirty fuel src s = mark_list (mark_dirty fuel) vis s /\
notify_dirty_except fuel src r s = mark_list (mark_except fuel src r) vis s.
Arguments
notify_dirty_except, or None.Qed
Proof.
split_and!.
- pose proof (walk_static (length (observer_items o)) o) as Hw.
rewrite take_ge in Hw by (rewrite length_view; lia). exact Hw.
- apply notify_with_list. intros ???. apply mark_check_rtc.
- apply notify_with_list. intros ???. apply mark_dirty_rtc.
- apply notify_with_list. intros ???. apply mark_except_rtc.
Qed.Lemma mark_list_visit (mark : node_id -> state -> option state) vis s s' c :
Lemma mark_list_visit (mark : node_id -> state -> option state) vis s s' c :
(forall c s0 s1, mark c s0 = Some s1 -> marks s0 s1) ->
mark_list mark vis s = Some s' ->
c ∈ vis ->
exists s1 s2, marks s s1 /\ mark c s1 = Some s2 /\ marks s2 s'.
Qed
Proof.
intros Hm. revert s. induction vis as [|c0 r IH]; intros s Hl Hc; [set_solver|].
simpl in Hl. destruct (mark c0 s) as [s1|] eqn:E; simpl in Hl; [|done].
assert (Hmarks : marks s1 s').
{ clear -Hm Hl. revert s1 Hl. induction r as [|c1 r' IHr]; intros s1 Hl; simpl in Hl.
- simplify_eq. apply rtc_refl.
- destruct (mark c1 s1) as [s2|] eqn:E; simpl in Hl; [|done].
eapply marks_trans; [by eapply Hm|by apply IHr]. }
apply elem_of_cons in Hc as [->|Hc].
- exists s, s1. split_and!; [apply rtc_refl|done|done].
- destruct (IH _ Hl Hc) as (s2 & s3 & H1 & H2 & H3). exists s2, s3. split_and!; [|done|done].
eapply marks_trans; [by eapply Hm|done].
Qed.References
Lemma elem_rev (c : node_id) l : c ∈ l -> c ∈ rev l.
Qed
Proof. rewrite !list_elem_of_In. apply in_rev. Qed.Marks reach observers
The computations affected by a mark: a memo, or an effect outside its disposal and its cleanups.
in_cleanup_observer_stays_clean and disposed_running_observer_stays_clean show observers
outside this set.
Definition takes_marks (s : state) (m : node_id) : Prop :=
Definition takes_marks (s : state) (m : node_id) : Prop :=
exists d, g_nodes s !! m = Some d /\
(n_kind d = KMemo \/ (n_kind d = KEffect /\ n_disposed d = false /\ n_in_cleanup d = false)).References
Used by
- marks_takes
- mark_check_stale
- mark_dirty_stale
- notify_with_reaches
- notify_with_stale
- notify_stales
- set_node_takes
- forward_members
16 more
- mark_forwards_on_clean
- mark_forwards_on_unannounced
- mark_dirty_ends_dirty
- notify_dirty_ends_dirty
- pair_takes
- forward_told
- ok2_track_mark
- later_mark_forwarded
- moved_marks_except_running
- Arun_S
- write_signal_except_wakes_others
- notify_removed_wakes_observers
- key_direct_row_retire_wakes_without_item_signal
- publication_comparer_guarded_refines_cutoff
- write_signal_except_spec
- notify_removed_spec
Definition ends_stale (s : state) (m : node_id) : Prop :=
Definition ends_stale (s : state) (m : node_id) : Prop :=
exists d, g_nodes s !! m = Some d /\ stale (n_freshness d) = true.References
Uses
Lemma stale_rises f g : freshness_le f g -> stale f = true -> stale g = true.
Qed
Proof. destruct f, g; unfold freshness_le; simpl; try done; lia. Qed.Lemma marks_stale s s' m : marks s s' -> ends_stale s m -> ends_stale s' m.
Qed
Proof.
intros Hr (d & Hd & Hst). destruct (marks_rises _ _ _ _ Hr Hd) as (d' & Hd' & _ & _ & _ & Hf & _).
exists d'. split; [done|]. by eapply stale_rises.
Qed.Lemma marks_takes s s' m : marks s s' -> takes_marks s m -> takes_marks s' m.
Qed
Proof.
intros Hr (d & Hd & Hk). destruct (marks_rises _ _ _ _ Hr Hd) as (d' & Hd' & H1 & H2 & H3 & _ & _).
exists d'. split; [done|]. rewrite H1, H2, H3. done.
Qed.Lemma set_node_stale s n d : stale (n_freshness d) = true -> ends_stale (set_node n d s) n.
Qed
Proof. intros Hst. exists d. split; [apply lookup_insert_eq|done]. Qed.References
Uses
- stale
- n_freshness
- set_node
- ends_stale
- true
- lookup_insert_eq
Lemma effect_marked_stale f n d s :
Lemma effect_marked_stale f n d s :
stale f = true -> n_disposed d = false -> n_in_cleanup d = false ->
ends_stale (effect_marked f n d s) n.
Qed
Proof.
intros Hf Hd Hc. unfold effect_marked. rewrite Hd, Hc. simpl.
destruct (n_queued d); by apply set_node_stale.
Qed.References
Lemma notify_with_rtc_check f n s s' :
Lemma notify_with_rtc_check f n s s' :
notify_with (mark_check f) n s = Some s' -> marks s s'.
Qed
Proof. apply notify_with_rtc. intros ???. apply mark_check_rtc. Qed.Lemma mark_check_stale f m s s' :
Lemma mark_check_stale f m s s' :
takes_marks s m -> mark_check f m s = Some s' -> ends_stale s' m.
Qed
Proof.
intros Ht Hc. destruct Ht as (d & Hd & Hk).
destruct (decide (n_freshness d = Clean)) as [Hf|Hf]; last first.
{ eapply marks_stale; [by eapply mark_check_rtc|]. exists d. split; [done|].
by apply stale_of_not_clean. }
destruct f as [|f]; simpl in Hc; [done|]. rewrite Hd in Hc.
destruct Hk as [Hk|(Hk & Hdi & Hcl)]; rewrite Hk in Hc.
- rewrite decide_True in Hc by done. eapply marks_stale; [by eapply notify_with_rtc_check|].
by apply set_node_stale.
- rewrite decide_True in Hc by done. simplify_eq. by apply effect_marked_stale.
Qed.References
Uses
6 more
- effect_marked_stale
- stale_of_not_clean
- notify_with_rtc_check
- Some
- decide
- decide_True
Used by
Lemma mark_dirty_stale f m s s' :
Lemma mark_dirty_stale f m s s' :
takes_marks s m -> mark_dirty f m s = Some s' -> ends_stale s' m.
Qed
Proof.
intros Ht Hc. destruct Ht as (d & Hd & Hk).
destruct (decide (n_freshness d = Clean)) as [Hf|Hf]; last first.
{ eapply marks_stale; [by eapply mark_dirty_rtc|]. exists d. split; [done|].
by apply stale_of_not_clean. }
destruct f as [|f]; simpl in Hc; [done|]. rewrite Hd in Hc.
destruct Hk as [Hk|(Hk & Hdi & Hcl)]; rewrite Hk in Hc.
- rewrite decide_True in Hc by done. eapply marks_stale; [by eapply notify_with_rtc_check|].
by apply set_node_stale.
- simplify_eq. by apply effect_marked_stale.
Qed.References
Uses
6 more
- effect_marked_stale
- stale_of_not_clean
- notify_with_rtc_check
- Some
- decide
- decide_True
Used by
Lemma notify_with_reaches (P : state -> Prop) (mark : node_id -> state -> option state) src s s' m :
Lemma notify_with_reaches (P : state -> Prop) (mark : node_id -> state -> option state) src s s' m :
(forall s0 s1, marks s0 s1 -> P s0 -> P s1) ->
(forall c s0 s1, mark c s0 = Some s1 -> marks s0 s1) ->
(forall s0 s1, g_edges s0 = g_edges s -> takes_marks s0 m -> mark m s0 = Some s1 -> P s1) ->
notify_with mark src s = Some s' ->
m ∈ observer_view (observers_of (g_edges s) src) ->
takes_marks s m ->
P s'.
Qed
Proof.
intros Hp Hr Hst Hn Hin Ht. rewrite notify_with_list in Hn by done.
destruct (mark_list_visit _ _ _ _ m Hr Hn (elem_rev _ _ Hin))
as (s1 & s2 & H1 & H2 & H3).
eapply Hp; [done|]. eapply Hst; [by apply marks_edges|by eapply marks_takes|done].
Qed.Lemma notify_with_stale (mark : node_id -> state -> option state) src s s' m :
Lemma notify_with_stale (mark : node_id -> state -> option state) src s s' m :
(forall c s0 s1, mark c s0 = Some s1 -> marks s0 s1) ->
(forall s0 s1, g_edges s0 = g_edges s -> takes_marks s0 m -> mark m s0 = Some s1 -> ends_stale s1 m) ->
notify_with mark src s = Some s' ->
m ∈ observer_view (observers_of (g_edges s) src) ->
takes_marks s m ->
ends_stale s' m.
Qed
Proof.
apply (notify_with_reaches (fun s0 => ends_stale s0 m)). intros ???. by eapply marks_stale.
Qed.A marking walk leaves each observer stale.
Each observer of the source that takes marks ends Check or Dirty. notify_dirty_except skips the running computation unless it has already read the source in its current run, so the guarantee covers observers other than that one and running observers that have already read the source. An observer takes marks when it is a memo, or an effect outside its disposal and its cleanups.
Arguments
notify_dirty_except, or None.src that takes marks.Theorem notify_stales fuel src r s s' m :
Theorem notify_stales fuel src r s s' m :
m ∈ observer_view (observers_of (g_edges s) src) ->
takes_marks s m ->
(notify_check fuel src s = Some s' \/ notify_dirty fuel src s = Some s' \/
(notify_dirty_except fuel src r s = Some s' /\ (r <> Some m \/ src ∈ read_prefix (g_edges s) m))) ->
ends_stale s' m.
Arguments
notify_dirty_except, or None.src that takes marks.Qed
Proof.
intros Hin Ht [Hn|[Hn|[Hn Hne]]].
- eapply notify_with_stale; [|intros ?? _; apply mark_check_stale|done|done|done].
intros ???. apply mark_check_rtc.
- eapply notify_with_stale; [|intros ?? _; apply mark_dirty_stale|done|done|done].
intros ???. apply mark_dirty_rtc.
- eapply notify_with_stale; [intros ???; apply mark_except_rtc| |done|done|done].
intros s0 s1 He Ht0. unfold mark_except. rewrite He. rewrite decide_False by tauto. by apply mark_dirty_stale.
Qed.Lemma set_node_takes s n f u d m :
Lemma set_node_takes s n f u d m :
g_nodes s !! n = Some d -> n_kind d = KMemo ->
(u = n_unannounced d \/ u = false) -> freshness_le (n_freshness d) f ->
takes_marks s m -> takes_marks (set_node n (node_marked f u (n_queued d) d) s) m.
Qed
Proof.
intros Hd Hk Hu Hf. apply marks_takes. apply rtc_once. by eapply prim_memo.
Qed.References
Uses
7 more
- set_node
- prim_memo
- takes_marks
- marks_takes
- Some
- false
- rtc_once
The walk a memo's transition starts, from the state after its write.
Lemma forward_members f n s1 s' m :
Lemma forward_members f n s1 s' m :
notify_with (mark_check f) n s1 = Some s' ->
m ∈ observer_view (observers_of (g_edges s1) n) ->
takes_marks s1 m ->
ends_stale s' m.
Qed
Proof. intros Hn Hin Ht. eapply (notify_stales f n None s1 s' m); [done|done|by left]. Qed.A clean memo goes stale and passes the mark to its observers.
After mark_check or mark_dirty of a Clean memo, the memo is stale, and so is each of its observers that takes marks. An effect in its cleanups stays clean: see in_cleanup_observer_stays_clean.
Arguments
Theorem mark_forwards_on_clean fuel n d os s s' :
Theorem mark_forwards_on_clean fuel n d os s s' :
g_nodes s !! n = Some d ->
n_kind d = KMemo ->
n_freshness d = Clean ->
observer_view (observers_of (g_edges s) n) = os ->
(mark_check fuel n s = Some s' \/ mark_dirty fuel n s = Some s') ->
ends_stale s' n /\ forall m, m ∈ os -> takes_marks s m -> ends_stale s' m.
Arguments
Qed
Proof.
intros Hd Hk Hc <- Hm.
destruct fuel as [|f]; [by destruct Hm|].
destruct Hm as [Hm|Hm]; simpl in Hm; rewrite Hd, Hk in Hm; rewrite decide_True in Hm by done.
all: split; [eapply marks_stale; [by eapply notify_with_rtc_check|by apply set_node_stale]|].
all: intros m Hin Ht; eapply forward_members; [done|by rewrite set_node_edges|].
all: eapply set_node_takes; [done|done|by left| |done]; rewrite Hc; apply freshness_le_clean.
Qed.A stale memo holding an announcement passes the mark on and spends the announcement.
After mark_check or mark_dirty, the memo is still stale with n_unannounced cleared, and each of its observers that takes marks is stale.
Premises: the f_unannounced flag is on, and the memo is stale with n_unannounced set.
Arguments
Theorem mark_forwards_on_unannounced fuel n d os s s' :
Theorem mark_forwards_on_unannounced fuel n d os s s' :
f_unannounced (g_flags s) = true ->
g_nodes s !! n = Some d ->
n_kind d = KMemo ->
stale (n_freshness d) = true ->
n_unannounced d = true ->
observer_view (observers_of (g_edges s) n) = os ->
(mark_check fuel n s = Some s' \/ mark_dirty fuel n s = Some s') ->
(exists d', g_nodes s' !! n = Some d' /\ stale (n_freshness d') = true /\ n_unannounced d' = false) /\
forall m, m ∈ os -> takes_marks s m -> ends_stale s' m.
Arguments
Qed
Proof.
intros Hflag Hd Hk Hst Hu <- Hm.
assert (Hc : n_freshness d <> Clean) by (intros Hc; rewrite Hc in Hst; done).
assert (Hdue : announce_due s d = true) by (unfold announce_due; by rewrite Hflag, Hu).
destruct fuel as [|f]; [by destruct Hm|].
destruct Hm as [Hm|Hm]; simpl in Hm; rewrite Hd, Hk in Hm; rewrite decide_False in Hm by done;
rewrite Hdue in Hm.
- split.
+ destruct (marks_rises _ _ n (node_marked (n_freshness d) false (n_queued d) d)
(notify_with_rtc_check _ _ _ _ Hm) ltac:(apply lookup_insert_eq))
as (d' & Hd' & _ & _ & _ & Hf & Hfalse).
exists d'. split_and!; [done| |by apply Hfalse]. by eapply stale_rises.
+ intros m Hin Ht. eapply forward_members; [done|by rewrite set_node_edges|].
eapply set_node_takes; [done|done|by right|apply freshness_le_refl|done].
- split.
+ destruct (marks_rises _ _ n (node_marked Dirty false (n_queued d) d)
(notify_with_rtc_check _ _ _ _ Hm) ltac:(apply lookup_insert_eq))
as (d' & Hd' & _ & _ & _ & Hf & Hfalse).
exists d'. split_and!; [done| |by apply Hfalse]. by eapply stale_rises.
+ intros m Hin Ht. eapply forward_members; [done|by rewrite set_node_edges|].
eapply set_node_takes; [done|done|by right|apply freshness_le_dirty|done].
Qed.References
Uses
Effects queue once
[queuequeueHead..queueCount-1]. F# releases a slot as it is consumed.
Definition pending (s : state) : list node_id := drop (g_queue_head s) (g_queue s).References
Uses
- node_id
- state
- g_queue
- g_queue_head
- list
- list.drop
Used by
- queue_once
- pending_enqueue
- effect_marked_queues
- effect_mark_queues
- sched_data
- data_of_same
- step_emit
- data_set
52 more
- sok_new_node
- prim_step
- step_put
- step_owner_fresh
- data_pop
- step_reset
- step_ghost
- step_register
- step_body_start
- sok_dispose_scope_S
- sok_cleanup_S
- sok_drain_S
- step_cleanup_start
- queue_agrees
- flush_returns_clean
- drain_no_escape
- quiescent
- host_flush
- host_step
- sim_inv
- sim_converged
- requeue_holds_two_entries
- left_behind
- read_move_leaves_effect_queued
- nested_self_run_ends_clean_and_wrong
- passed_over
- walk_passed_stays_deaf
- effect_resolves_over_moved_source
- failed_batch_leaves_queue
- cmp_never_passes_source
- queue_rel
- queue_rel_live_queue
- queue_rel_head_lookup
- queue_rel_pop
- queue_rel_enqueue
- queue_rel_set_node
- qrel_upd_tac
- qrel_current_owner
- qrel_next_id
- qrel_note_host_read
- qrel_log_label
- qrel_track
- qrel_edges_opt
- queue_rel_fused_signal
- queue_rel_fused_memo
- fused_single_signal_effect_eq
- fused_single_memo_effect_flush_eq
- custom_comparer_fused_flush_eq
- idle_first_run_effect_fusion_eq
- heap_flush_returns_clean
- check_disposed_window
- view_of
References
Uses
- node_id
- length
- list
- nat
- filter
The queue's agreement with queued for n: at most one pending entry, and none while unset. The
flag can be set with no entry, between a dequeue and queued <- false in Execute.
Lemma entries_absent n l : n ∉ l -> entries_of n l = 0.
Qed
Proof.
induction l as [|x l IH]; intros Hn; [done|].
assert (Hx : x <> n) by (intros ->; apply Hn; left).
assert (Hl : n ∉ l) by (intros Hin; apply Hn; by right).
unfold entries_of in *. rewrite filter_cons_False by done. by apply IH.
Qed.Lemma pending_enqueue n s :
Lemma pending_enqueue n s :
pending (enqueue n s) = drop (g_queue_head s) (g_queue s ++ [n]).
Qed
Proof. done. Qed.Lemma entries_after_enqueue n h q :
Lemma entries_after_enqueue n h q :
n ∉ drop h q -> entries_of n (drop h (q ++ [n])) <= 1.
Qed
Proof.
intros Hn. destruct (decide (h <= length q)) as [Hle|Hgt].
- rewrite drop_app_le by done. unfold entries_of. rewrite filter_app, length_app.
pose proof (entries_absent _ _ Hn) as H0. unfold entries_of in H0. rewrite H0.
rewrite filter_cons_True by done. simpl. lia.
- rewrite drop_ge by (rewrite length_app; simpl; lia). simpl. unfold entries_of. simpl. lia.
Qed.References
Uses
- entries_of
- entries_absent
- length
- length_app
- decide
- list.drop
- list.drop_app_le
- list.drop_ge
2 more
- list.filter_app
- list.filter_cons_True
Lemma elem_of_enqueued (x n : node_id) h (q : list node_id) :
Lemma elem_of_enqueued (x n : node_id) h (q : list node_id) :
x ∈ drop h (q ++ [n]) -> x ∈ drop h q \/ x = n.
Qed
Proof.
destruct (decide (h <= length q)) as [Hle|Hgt].
- rewrite drop_app_le by done. set_solver.
- rewrite drop_ge by (rewrite length_app; simpl; lia). set_solver.
Qed.Lemma entries_other (m n : node_id) h (q : list node_id) :
Lemma entries_other (m n : node_id) h (q : list node_id) :
m <> n -> entries_of m (drop h (q ++ [n])) = entries_of m (drop h q).
Qed
Proof.
intros Hne. destruct (decide (h <= length q)) as [Hle|Hgt].
- rewrite drop_app_le by done. unfold entries_of. rewrite filter_app, length_app.
rewrite filter_cons_False by done. simpl. lia.
- rewrite !drop_ge by (try rewrite length_app; simpl; lia). done.
Qed.References
Uses
- node_id
- entries_of
- length
- list
- length_app
- decide
- list.drop
- list.drop_app_le
3 more
- list.drop_ge
- list.filter_app
- list.filter_cons_False
Used by
Lemma prim_queue_once s s' m : mark_prim s s' -> queue_once s m -> queue_once s' m.
Qed
Proof.
intros Hp Hq d0 Hd0.
destruct Hp as [s n d f u Hd Hk Hf Hu|s n d f Hd Hk Hqd Hf|s n d f Hd Hk Hqd Hf]; simpl in Hd0.
all: destruct (decide (m = n)) as [->|Hne]; [rewrite lookup_insert_eq in Hd0|rewrite lookup_insert_ne in Hd0 by done].
- simplify_eq. apply (Hq d Hd).
- apply (Hq d0 Hd0).
- simplify_eq. split; [apply (Hq d Hd)|done].
- apply (Hq d0 Hd0).
- simplify_eq. destruct (Hq d Hd) as [_ Hun]. split; [|done].
rewrite pending_enqueue. apply entries_after_enqueue. by apply Hun.
- destruct (Hq d0 Hd0) as [Hle Hun]. rewrite pending_enqueue. split.
+ rewrite entries_other by done. done.
+ intros Hu Hin. apply elem_of_enqueued in Hin as [Hin | ->]; [by apply Hun|done].
Qed.References
Uses
- mark_prim
- queue_once
- pending_enqueue
- entries_after_enqueue
- elem_of_enqueued
- entries_other
- decide
- lookup_insert_eq
1 more
- lookup_insert_ne
Used by
Lemma effect_marked_queues f n d s :
Lemma effect_marked_queues f n d s :
g_nodes s !! n = Some d ->
n_disposed d = false ->
n_in_cleanup d = false ->
queue_once s n ->
let s' := effect_marked f n d s in
(exists d', g_nodes s' !! n = Some d' /\ n_queued d' = true) /\ queue_once s' n /\
(g_queue_head s <= length (g_queue s) -> n_queued d = false -> n ∈ pending s').
Qed
Proof.
intros Hd Hdi Hcl Hq s'. subst s'. unfold effect_marked. rewrite Hdi, Hcl. simpl.
destruct (Hq d Hd) as [Hle Hun].
destruct (n_queued d) eqn:Hqd.
- split_and!.
+ eexists. split; [apply lookup_insert_eq|done].
+ intros d0 Hd0. simpl in Hd0. rewrite lookup_insert_eq in Hd0. simplify_eq. split; [done|done].
+ intros _ ?. done.
- split_and!.
+ eexists. split; [apply lookup_insert_eq|done].
+ intros d0 Hd0. simpl in Hd0. rewrite lookup_insert_eq in Hd0. simplify_eq. split; [|done].
rewrite pending_enqueue. apply entries_after_enqueue. by apply Hun.
+ intros Hh _. rewrite pending_enqueue. by apply elem_after_enqueue.
Qed.References
Uses
9 more
- queue_once
- pending_enqueue
- entries_after_enqueue
- elem_after_enqueue
- Some
- false
- length
- true
- lookup_insert_eq
Used by
Marks keep each effect's queue entries in step with its queued flag.
Each marking operation preserves queue_once: at most one pending entry for the node, and none while its flag is unset. An effect marked along several paths has at most one pending entry.
Premise: queue_once holds beforehand.
Arguments
notify_dirty_except, or None.s.Theorem mark_keeps_queue_once fuel n r s s' m :
Theorem mark_keeps_queue_once fuel n r s s' m :
any_mark fuel n r s s' -> queue_once s m -> queue_once s' m.
Arguments
notify_dirty_except, or None.s.Qed
Proof.
intros Ha. apply any_mark_rtc in Ha. induction Ha as [|s1 s2 s3 Hp _ IH]; [done|].
intros Hq. apply IH. by eapply prim_queue_once.
Qed.A marked effect ends queued.
After mark_check or mark_dirty, the effect's n_queued is set and queue_once still holds. An effect that was not queued has a pending entry, provided the queue head lies within the queue.
Premises: the effect is outside its disposal and its cleanups, and queue_once holds beforehand.
Arguments
n in s.Theorem effect_mark_queues fuel n d s s' :
Theorem effect_mark_queues fuel n d s s' :
g_nodes s !! n = Some d ->
n_kind d = KEffect ->
n_disposed d = false ->
n_in_cleanup d = false ->
queue_once s n ->
(mark_check fuel n s = Some s' \/ mark_dirty fuel n s = Some s') ->
(exists d', g_nodes s' !! n = Some d' /\ n_queued d' = true) /\ queue_once s' n /\
(g_queue_head s <= length (g_queue s) -> n_queued d = false -> n ∈ pending s').
Arguments
n in s.Qed
Proof.
intros Hd Hk Hdi Hcl Hq Hm.
destruct fuel as [|f]; [by destruct Hm|].
destruct Hm as [Hm|Hm]; simpl in Hm; rewrite Hd, Hk in Hm; simplify_eq; by apply effect_marked_queues.
Qed.References
Uses
9 more
- mark_check
- mark_dirty
- pending
- queue_once
- effect_marked_queues
- Some
- false
- length
- true
Used by
A disposed effect ignores marks.
mark_check and mark_dirty return the state unchanged, given any positive fuel.
Arguments
S fuel.n in s.Theorem disposed_effect_ignores_marks fuel n d s :
Theorem disposed_effect_ignores_marks fuel n d s :
g_nodes s !! n = Some d ->
n_kind d = KEffect ->
n_disposed d = true ->
mark_check (S fuel) n s = Some s /\ mark_dirty (S fuel) n s = Some s.
Arguments
S fuel.n in s.Qed
Proof.
intros Hd Hk Hdi. simpl. rewrite Hd, Hk. unfold effect_marked. rewrite Hdi. done.
Qed.References
Used by
An effect running its cleanups ignores marks.
mark_check and mark_dirty return the state unchanged, given any positive fuel.
Arguments
S fuel.n in s.Theorem in_cleanup_ignores_marks fuel n d s :
Theorem in_cleanup_ignores_marks fuel n d s :
g_nodes s !! n = Some d ->
n_kind d = KEffect ->
n_in_cleanup d = true ->
mark_check (S fuel) n s = Some s /\ mark_dirty (S fuel) n s = Some s.
Arguments
S fuel.n in s.Qed
Proof.
intros Hd Hk Hcl. simpl. rewrite Hd, Hk. unfold effect_marked. rewrite Hcl, orb_true_r. done.
Qed.References
Used by
How Dirty and Check marks differ
Definition ends_dirty (s : state) (m : node_id) : Prop :=
Definition ends_dirty (s : state) (m : node_id) : Prop :=
exists d, g_nodes s !! m = Some d /\ n_freshness d = Dirty.References
Used by
Lemma marks_dirty s s' m : marks s s' -> ends_dirty s m -> ends_dirty s' m.
Qed
Proof.
intros Hr (d & Hd & Hf). destruct (marks_rises _ _ _ _ Hr Hd) as (d' & Hd' & _ & _ & _ & Hle & _).
exists d'. split; [done|]. rewrite Hf in Hle. destruct (n_freshness d'); [| |done];
unfold freshness_le in Hle; simpl in Hle; lia.
Qed.Lemma set_node_dirty s n d : n_freshness d = Dirty -> ends_dirty (set_node n d s) n.
Qed
Proof. intros Hf. exists d. split; [apply lookup_insert_eq|done]. Qed.A Dirty mark makes its target Dirty.
A memo, or an effect outside its disposal and its cleanups, ends Dirty. That includes an effect already queued on Check.
Arguments
Theorem mark_dirty_ends_dirty fuel n s s' :
Theorem mark_dirty_ends_dirty fuel n s s' :
takes_marks s n -> mark_dirty fuel n s = Some s' -> ends_dirty s' n.
Arguments
Qed
Proof.
intros (d & Hd & Hk) Hc.
destruct fuel as [|f]; simpl in Hc; [done|]. rewrite Hd in Hc.
destruct Hk as [Hk|(Hk & Hdi & Hcl)]; rewrite Hk in Hc.
- destruct (decide (n_freshness d = Clean)).
{ eapply marks_dirty; [by eapply notify_with_rtc_check|]. by apply set_node_dirty. }
destruct (announce_due s d).
{ eapply marks_dirty; [by eapply notify_with_rtc_check|]. by apply set_node_dirty. }
destruct (decide (n_freshness d = Dirty)); simplify_eq; [by exists d|]. by apply set_node_dirty.
- simplify_eq. unfold effect_marked. rewrite Hdi, Hcl. simpl.
destruct (n_queued d); by apply set_node_dirty.
Qed.A dirty walk leaves each observer Dirty.
Each observer of the source that takes marks ends Dirty. notify_dirty_except skips the running computation, so the guarantee covers observers other than that one.
Arguments
notify_dirty_except, or None.src that takes marks.Theorem notify_dirty_ends_dirty fuel src r s s' m :
Theorem notify_dirty_ends_dirty fuel src r s s' m :
m ∈ observer_view (observers_of (g_edges s) src) ->
takes_marks s m ->
(notify_dirty fuel src s = Some s' \/
(notify_dirty_except fuel src r s = Some s' /\ (r <> Some m \/ src ∈ read_prefix (g_edges s) m))) ->
ends_dirty s' m.
Arguments
notify_dirty_except, or None.src that takes marks.Qed
Proof.
intros Hin Ht [Hn|[Hn Hne]].
- eapply (notify_with_reaches (fun s0 => ends_dirty s0 m));
[intros ???; by eapply marks_dirty|intros ???; apply mark_dirty_rtc|
intros ?? _; apply mark_dirty_ends_dirty|done|done|done].
- eapply (notify_with_reaches (fun s0 => ends_dirty s0 m));
[intros ???; by eapply marks_dirty|intros ???; apply mark_except_rtc| |done|done|done].
intros s0 s1 He Ht0. unfold mark_except. rewrite He. rewrite decide_False by tauto. by apply mark_dirty_ends_dirty.
Qed.References
Uses
8 more
Definition keeps_undirty (s s' : state) : Prop :=
Definition keeps_undirty (s s' : state) : Prop :=
forall m d, g_nodes s !! m = Some d ->
exists d', g_nodes s' !! m = Some d' /\ (n_freshness d' = Dirty -> n_freshness d = Dirty).Lemma keeps_undirty_refl s : keeps_undirty s s.
Qed
Proof. intros m d Hd. eauto. Qed.Lemma keeps_undirty_trans s1 s2 s3 :
Lemma keeps_undirty_trans s1 s2 s3 :
keeps_undirty s1 s2 -> keeps_undirty s2 s3 -> keeps_undirty s1 s3.
Qed
Proof.
intros H1 H2 m d Hd. destruct (H1 _ _ Hd) as (d2 & Hd2 & Hf2).
destruct (H2 _ _ Hd2) as (d3 & Hd3 & Hf3). eauto.
Qed.Lemma set_node_undirty s n d f u q :
Lemma set_node_undirty s n d f u q :
g_nodes s !! n = Some d -> (f = Dirty -> n_freshness d = Dirty) ->
keeps_undirty s (set_node n (node_marked f u q d) s).
Qed
Proof.
intros Hd Hf m d0 Hm. simpl. destruct (decide (m = n)) as [->|Hne].
- rewrite lookup_insert_eq. rewrite Hd in Hm. simplify_eq. eauto.
- rewrite lookup_insert_ne by done. eauto.
Qed.References
Uses
2 more
- lookup_insert_eq
- lookup_insert_ne
Used by
Lemma walk_undirty (mark : node_id -> state -> option state) src n s s' :
Lemma walk_undirty (mark : node_id -> state -> option state) src n s s' :
(forall c s0 s1, mark c s0 = Some s1 -> keeps_undirty s0 s1) ->
walk_marks mark src n s = Some s' ->
keeps_undirty s s'.
Qed
Proof.
intros Hm. revert s. induction n as [|i IH]; intros s Hw; simpl in Hw.
- simplify_eq. apply keeps_undirty_refl.
- destruct (decide _) as [_|_]; [by apply IH|].
destruct (observer_items (observers_of (g_edges s) src) !! i) as [[c ?]|]; [|done].
destruct (mark c s) as [s1|] eqn:Ec; simpl in Hw; [|done].
eapply keeps_undirty_trans; [by eapply Hm|by apply IH].
Qed.References
Uses
4 more
- keeps_undirty_trans
- Some
- option
- decide
Lemma mark_check_undirty f n s s' : mark_check f n s = Some s' -> keeps_undirty s s'.
Qed
Proof.
revert n s s'. induction f as [|f IH]; intros n s s' Hm; simpl in Hm; [done|].
destruct (g_nodes s !! n) as [d|] eqn:Hd; [|simplify_eq; apply keeps_undirty_refl].
destruct (n_kind d).
- simplify_eq. apply keeps_undirty_refl.
- destruct (decide (n_freshness d = Clean)).
{ eapply keeps_undirty_trans;
[|eapply (walk_undirty (mark_check f)); [intros ???; apply IH|exact Hm]].
apply set_node_undirty; [done|by intros]. }
destruct (announce_due s d); [|simplify_eq; apply keeps_undirty_refl].
eapply keeps_undirty_trans;
[|eapply (walk_undirty (mark_check f)); [intros ???; apply IH|exact Hm]].
apply set_node_undirty; [done|by intros].
- simplify_eq. unfold effect_marked.
assert (Hup : keeps_undirty s (set_node n (node_marked
(if decide (n_freshness d = Clean) then Check else n_freshness d) (n_unannounced d) true d) s)).
{ apply set_node_undirty; [done|]. destruct (decide _); by intros. }
destruct (_ || _); [apply keeps_undirty_refl|].
destruct (n_queued d); exact Hup.
Qed.A Check mark makes no node Dirty.
mark_check and notify_check leave each node short of Dirty still short of it.
Arguments
Theorem mark_check_keeps_check fuel n s s' m d :
Theorem mark_check_keeps_check fuel n s s' m d :
(mark_check fuel n s = Some s' \/ notify_check fuel n s = Some s') ->
g_nodes s !! m = Some d ->
n_freshness d <> Dirty ->
exists d', g_nodes s' !! m = Some d' /\ n_freshness d' <> Dirty.
Arguments
Qed
Proof.
intros Hc Hm Hf.
assert (Hk : keeps_undirty s s').
{ destruct Hc as [Hc|Hc]; [by eapply mark_check_undirty|].
eapply (walk_undirty (mark_check fuel)); [intros ???; apply mark_check_undirty|exact Hc]. }
destruct (Hk _ _ Hm) as (d' & Hd' & Hd). exists d'. split; [done|]. intros Hx. by apply Hf, Hd.
Qed.A Dirty mark on a memo makes no other node Dirty.
mark_dirty of a memo leaves every other node that was short of Dirty still short of it.
Arguments
Theorem memo_mark_dirty_keeps_others_short fuel n d s s' m d0 :
Theorem memo_mark_dirty_keeps_others_short fuel n d s s' m d0 :
g_nodes s !! n = Some d ->
n_kind d = KMemo ->
mark_dirty fuel n s = Some s' ->
m <> n ->
g_nodes s !! m = Some d0 ->
n_freshness d0 <> Dirty ->
exists d', g_nodes s' !! m = Some d' /\ n_freshness d' <> Dirty.
Arguments
Qed
Proof.
intros Hd Hk Hc Hne Hm Hf.
assert (Hset : forall f u q, g_nodes (set_node n (node_marked f u q d) s) !! m = Some d0).
{ intros. simpl. by rewrite lookup_insert_ne. }
assert (Hwalk : forall f g u,
notify_with (mark_check f) n (set_node n (node_marked g u (n_queued d) d) s) = Some s' ->
exists d', g_nodes s' !! m = Some d' /\ n_freshness d' <> Dirty).
{ intros f g u Hn. eapply (mark_check_keeps_check f n); [right; exact Hn|apply Hset|done]. }
destruct fuel as [|f]; simpl in Hc; [done|]. rewrite Hd, Hk in Hc.
destruct (decide (n_freshness d = Clean)); [by eapply Hwalk|].
destruct (announce_due s d); [by eapply Hwalk|].
destruct (decide (n_freshness d = Dirty)); simplify_eq; [by exists d0|].
exists d0. split; [apply Hset|done].
Qed.References
Uses
9 more
- set_node
- notify_with
- announce_due
- mark_check
- mark_dirty
- mark_check_keeps_check
- Some
- decide
- lookup_insert_ne
Marking a clean memo leaves its announcement flag as it was.
mark_check sets the memo to Check and mark_dirty sets it to Dirty, each with n_unannounced unchanged, and then each walks the observers with mark_check. Given any positive fuel.
Arguments
Theorem clean_memo_keeps_unannounced fuel n d s :
Theorem clean_memo_keeps_unannounced fuel n d s :
g_nodes s !! n = Some d ->
n_kind d = KMemo ->
n_freshness d = Clean ->
mark_check (S fuel) n s =
notify_with (mark_check fuel) n (set_node n (node_marked Check (n_unannounced d) (n_queued d) d) s) /\
mark_dirty (S fuel) n s =
notify_with (mark_check fuel) n (set_node n (node_marked Dirty (n_unannounced d) (n_queued d) d) s).
Arguments
Qed
Proof.
intros Hd Hk Hc. split.
- simpl. rewrite Hd, Hk, decide_True by done. reflexivity.
- unfold mark_dirty. simpl. rewrite Hd, Hk, decide_True by done. reflexivity.
Qed.References
Uses
9 more
- g_nodes
- node_marked
- set_node
- notify_with
- mark_check
- mark_dirty
- S
- Some
- decide_True
Used by
The backward observer walk restricted to indices strictly above slot 0.
Fixpoint walk_marks_above0 (mark : node_id -> state -> option state) (src : node_id) (n : nat) (s : state)
Fixpoint walk_marks_above0 (mark : node_id -> state -> option state) (src : node_id) (n : nat) (s : state)
: option state :=
match n with
| 0 | 1 => Some s
| S i =>
if decide (length (observer_items (observers_of (g_edges s) src)) <= i) then walk_marks_above0 mark src i s
else match observer_items (observers_of (g_edges s) src) !! i with
| Some (c, _) => mark c s ≫= walk_marks_above0 mark src i
| None => None
end
end.References
notify_with with slot 0 hoisted out of the i > 0 loop.
Definition notify_with_hoisted0 (mark : node_id -> state -> option state) (src : node_id) (s : state)
Definition notify_with_hoisted0 (mark : node_id -> state -> option state) (src : node_id) (s : state)
: option state :=
match length (observer_items (observers_of (g_edges s) src)) with
| 0 => Some s
| n =>
walk_marks_above0 mark src n s ≫= fun s1 =>
match observer_items (observers_of (g_edges s1) src) !! 0 with
| Some (c0, _) => mark c0 s1
| None => Some s1
end
end.References
Used by
Lemma walk_marks_split_0 mark src n s :
Lemma walk_marks_split_0 mark src n s :
(1 <= n)%nat ->
walk_marks mark src n s =
walk_marks_above0 mark src n s ≫= fun s1 =>
match observer_items (observers_of (g_edges s1) src) !! 0 with
| Some (c0, _) => mark c0 s1
| None => Some s1
end.
Qed
Proof.
revert s. induction n as [|k IH]; intros s Hn; [lia|].
destruct k as [|m].
- cbn [walk_marks walk_marks_above0]. simpl.
destruct (decide (length (observer_items (observers_of (g_edges s) src)) <= 0)) as [Hle|Hgt].
+ assert (Hnil : observer_items (observers_of (g_edges s) src) = []).
{ apply nil_length_inv. lia. }
rewrite Hnil. reflexivity.
+ destruct (observer_items (observers_of (g_edges s) src) !! 0) as [p0|] eqn:E.
* destruct p0 as [c0 sl0]. destruct (mark c0 s); reflexivity.
* exfalso. apply lookup_ge_None in E. lia.
- change (walk_marks mark src (S (S m)) s) with
(if decide (length (observer_items (observers_of (g_edges s) src)) <= S m) then walk_marks mark src (S m) s
else match observer_items (observers_of (g_edges s) src) !! S m with
| Some (c, _) => mark c s ≫= walk_marks mark src (S m)
| None => None
end).
change (walk_marks_above0 mark src (S (S m)) s) with
(if decide (length (observer_items (observers_of (g_edges s) src)) <= S m) then walk_marks_above0 mark src (S m) s
else match observer_items (observers_of (g_edges s) src) !! S m with
| Some (c, _) => mark c s ≫= walk_marks_above0 mark src (S m)
| None => None
end).
destruct (decide (length (observer_items (observers_of (g_edges s) src)) <= S m)); [apply IH; lia|].
destruct (observer_items (observers_of (g_edges s) src) !! S m) as [p|]; [|reflexivity].
destruct p as [c sl].
destruct (mark c s) as [s1|] eqn:Em; [apply IH; lia | reflexivity].
Qed.References
Uses
4 more
- length
- decide
- list.lookup_ge_None
- list.nil_length_inv
Used by
Hoisting slot 0 out of the while i > 0 notification loop preserves notify_with across all dynamic observer-set mutations.
Matches ObserverSet.NotifyDirty, NotifyDirtyExcept, NotifyDirtyOther, and NotifyCheck (Core.fs):
walking overflow observers down to index 1 (while i > 0) and handling slot 0 (first) afterward
executes the identical sequence of observer marks and handles dynamic removal of slot 0 identically.
Arguments
Theorem walk_marks_hoist_slot0_eq (mark : node_id -> state -> option state) (src : node_id) (s : state) :
Theorem walk_marks_hoist_slot0_eq (mark : node_id -> state -> option state) (src : node_id) (s : state) :
notify_with_hoisted0 mark src s = notify_with mark src s.
Arguments
Qed
Proof.
unfold notify_with_hoisted0, notify_with.
destruct (length (observer_items (observers_of (g_edges s) src))) as [|n] eqn:El.
- reflexivity.
- symmetry. apply walk_marks_split_0. lia.
Qed.References
Uses
2 more
- length
- option
Used by