Skip to content

Commit 2c34214

Browse files
committed
Merge pull request #4 from uwplse/immediate-output
Immediate output
2 parents d83c754 + df93bf0 commit 2c34214

File tree

3 files changed

+123
-42
lines changed

3 files changed

+123
-42
lines changed

Net.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Section StepAsync.
269269
input_handlers h inp (nwState net h) = (out, d, l) ->
270270
net' = mkNetwork (send_packets h l ++ nwPackets net)
271271
(update (nwState net) h d) ->
272-
step_m net net' [(h, inl inp)]. (* note: we throw away the immediate output!*)
272+
step_m net net' [(h, inl inp); (h, inr out)].
273273

274274
Definition step_m_star := refl_trans_1n_trace step_m.
275275
End StepAsync.
@@ -309,7 +309,7 @@ Section StepDup.
309309
input_handlers h inp (nwState net h) = (out, d, l) ->
310310
net' = mkNetwork (send_packets h l ++ nwPackets net)
311311
(update (nwState net) h d) ->
312-
step_d net net' [(h, inl inp)] (* note: we throw away the immediate output!*)
312+
step_d net net' [(h, inl inp); (h, inr out)]
313313
| SD_dup : forall net net' p xs ys,
314314
nwPackets net = xs ++ p :: ys ->
315315
net' = mkNetwork (p :: xs ++ p :: ys)

PrimaryBackup.v

Lines changed: 107 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Section PrimaryBackup.
9797
PB_input_handler h i d = (os, d', ms) ->
9898
(h = Primary /\
9999
state d' = state d /\
100+
os = [] /\
100101
exists r,
101102
i = Request r /\
102103
queue d' = queue d ++ [r] /\
@@ -425,6 +426,13 @@ Section PrimaryBackup.
425426
intros. destruct h; auto.
426427
Qed.
427428

429+
Lemma inputs_m_inl_read :
430+
forall h l,
431+
inputs_m ((h, inl Read) :: l) = inputs_m l.
432+
Proof.
433+
intros. destruct h; auto.
434+
Qed.
435+
428436
Lemma list_destruct_last :
429437
forall A (l : list A),
430438
l = [] \/ exists l' x, l = l' ++ [x].
@@ -496,6 +504,13 @@ Section PrimaryBackup.
496504
auto.
497505
Qed.
498506

507+
Lemma inputs_m_backup :
508+
forall i l,
509+
inputs_m ((Backup, inl i) :: l) = inputs_m l.
510+
Proof.
511+
auto.
512+
Qed.
513+
499514
Lemma step_1_star_no_trace_no_step :
500515
forall st st' tr,
501516
step_1_star st st' tr ->
@@ -643,6 +658,15 @@ Section PrimaryBackup.
643658
+ subst. constructor. auto.
644659
Qed.
645660

661+
Lemma outputs_m_read_response_singleton :
662+
forall h o,
663+
outputs_m [(h, inr [ReadResponse o])] = [].
664+
Proof.
665+
intros.
666+
simpl in *.
667+
break_match; auto.
668+
Qed.
669+
646670
Lemma correspond_reachable :
647671
forall net tr_m,
648672
step_m_star step_m_init net tr_m ->
@@ -680,23 +704,29 @@ Section PrimaryBackup.
680704
outputs_m_inr_nil_singleton.
681705
+ find_apply_lem_hyp PB_input_handler_defn.
682706
intuition; subst;
683-
try rewrite inputs_m_app in *.
707+
repeat rewrite snoc_assoc in *;
708+
repeat rewrite inputs_m_app in *.
684709
* break_exists. break_and. subst.
710+
rewrite inputs_m_inr_singleton in *. rewrite app_nil_r in *.
685711
rewrite inputs_m_primary_inl_request_singleton in *.
686712
find_apply_lem_hyp inputs_1_invert_app. break_exists. break_and.
687713
subst. simpl in *. find_inversion. destruct x1.
688714
find_apply_lem_hyp step_1_snoc_inv. break_exists. break_and.
689-
{ eapply correspond_preserved_snoc; eauto.
715+
{ eapply correspond_preserved_primary_same_no_outputs; eauto.
716+
eapply correspond_preserved_snoc; eauto.
690717
- eauto using step_1_singleton_inversion.
691718
- rewrite update_eq by auto. auto.
692719
- rewrite update_eq by auto. auto.
693720
}
694-
* rewrite inputs_m_inl_read_singleton in *. rewrite app_nil_r in *.
721+
* rewrite inputs_m_inr_singleton in *. rewrite app_nil_r in *.
722+
rewrite inputs_m_inl_read_singleton in *. rewrite app_nil_r in *.
695723
eauto using
696724
correspond_preserved_primary_same_no_outputs,
697725
update_nop,
698-
outputs_m_inl_read_singleton.
699-
* rewrite inputs_m_backup_singleton in *. rewrite app_nil_r in *.
726+
outputs_m_inl_read_singleton,
727+
outputs_m_read_response_singleton.
728+
* rewrite inputs_m_inr_singleton in *.
729+
rewrite inputs_m_backup_singleton in *. repeat rewrite app_nil_r in *.
700730
eauto using correspond_preserved_primary_same_no_outputs, update_diff.
701731
Qed.
702732

@@ -716,12 +746,18 @@ Section PrimaryBackup.
716746
rewrite inputs_m_inr_singleton in H
717747
| [ H : context [ inputs_m [(Primary, inl (Request _))] ] |- _ ] =>
718748
rewrite inputs_m_primary_inl_request_singleton in H
749+
| [ H : context [ inputs_m ((Primary, inl (Request _)) :: _) ] |- _ ] =>
750+
rewrite inputs_m_primary_inl in H
719751
| [ H : context [ inputs_m [(_, inl Read)] ] |- _ ] =>
720752
rewrite inputs_m_inl_read_singleton in H
753+
| [ H : context [ inputs_m ((_, inl Read) :: _) ] |- _ ] =>
754+
rewrite inputs_m_inl_read in H
721755
| [ H : context [ inputs_1 _ = [] ] |- _ ] =>
722756
apply inputs_1_nil_is_nil in H; subst
723757
| [ H : context [ inputs_m [_] ] |- _ ] =>
724758
rewrite inputs_m_backup_singleton in H
759+
| [ H : context [ inputs_m (_ :: _) ] |- _ ] =>
760+
rewrite inputs_m_backup in H
725761
| [ H : step_1_star _ _ [] |- _ ] =>
726762
apply step_1_star_no_trace_no_step in H; [|solve [auto]]; subst
727763
| [ H : step_1_star _ _ [_] |- _ ] =>
@@ -742,17 +778,20 @@ Section PrimaryBackup.
742778
| [ H : exists _, _ |- _ ] => break_exists
743779
| [ H : _ \/ _ |- _ ] => break_or_hyp
744780
| _ => repeat break_let; repeat find_rewrite; repeat tuple_inversion; subst; auto
745-
end;
781+
end; repeat rewrite snoc_assoc;
746782
eauto using
747783
correspond_preserved_primary_same_no_outputs,
748784
update_nop,
749785
update_diff,
750786
outputs_m_inr_nil_singleton,
751-
outputs_m_inl_read_singleton.
787+
outputs_m_inl_read_singleton,
788+
outputs_m_read_response_singleton.
752789
- eapply correspond_preserved_primary_apply_entry; eauto using update_eq.
753790
- eapply correspond_preserved_primary_apply_entry; eauto using update_eq.
754-
- eapply correspond_preserved_snoc; eauto; rewrite update_eq by auto; repeat find_rewrite; auto.
755-
- eapply correspond_preserved_snoc; eauto; rewrite update_eq by auto; repeat find_rewrite; auto.
791+
- eapply correspond_preserved_primary_same_no_outputs; eauto.
792+
eapply correspond_preserved_snoc; eauto; rewrite update_eq by auto; repeat find_rewrite; auto.
793+
- eapply correspond_preserved_primary_same_no_outputs; eauto.
794+
eapply correspond_preserved_snoc; eauto; rewrite update_eq by auto; repeat find_rewrite; auto.
756795
Qed.
757796

758797
Lemma step_m_outputs_m :
@@ -784,10 +823,10 @@ Section PrimaryBackup.
784823
rewrite update_diff by auto. auto.
785824
- rewrite inputs_m_inr_singleton.
786825
rewrite update_diff by auto. auto.
787-
- break_exists. intuition; subst; rewrite inputs_m_primary_inl_request_singleton; eauto.
788-
- rewrite inputs_m_inl_read_singleton. rewrite update_eq by auto. auto.
789-
- rewrite inputs_m_inl_read_singleton. rewrite update_diff by auto. auto.
790-
- rewrite inputs_m_backup_singleton.
826+
- break_exists. intuition; subst; rewrite inputs_m_primary_inl; eauto.
827+
- rewrite inputs_m_inl_read. rewrite update_eq by auto. auto.
828+
- rewrite inputs_m_inl_read. rewrite update_diff by auto. auto.
829+
- rewrite inputs_m_backup.
791830
rewrite update_diff by auto. auto.
792831
Qed.
793832

@@ -958,22 +997,31 @@ Section PrimaryBackup.
958997
repeat break_match; repeat find_inversion; auto; try discriminate.
959998
Qed.
960999

961-
Definition no_output_at_backup {A B} x := forall y, snd x = @inr A (list B) y -> fst x = Primary \/ y = [].
1000+
Definition no_output_at_backup {A} x := forall y, snd x = @inr A _ y ->
1001+
fst x = Primary \/
1002+
match y with
1003+
| [] => True
1004+
| [ReadResponse _] => True
1005+
| _ => False
1006+
end.
9621007

963-
Definition no_output_at_backup_trace {A B} tr := (forall x, In x tr -> @no_output_at_backup A B x).
1008+
Definition no_output_at_backup_trace {A} tr := (forall x, In x tr -> @no_output_at_backup A x).
9641009

9651010
Lemma NOABT_tail :
966-
forall A B x y,
967-
@no_output_at_backup_trace A B (x :: y) ->
1011+
forall A x y,
1012+
@no_output_at_backup_trace A (x :: y) ->
9681013
no_output_at_backup_trace y.
9691014
Proof.
9701015
unfold no_output_at_backup_trace.
9711016
intros. simpl in *. eauto.
9721017
Qed.
9731018

9741019
Lemma NOABT_contra :
975-
forall A B l tr,
976-
@no_output_at_backup_trace A B ((Backup, inr l) :: tr) -> l = [].
1020+
forall A l tr,
1021+
@no_output_at_backup_trace A ((Backup, inr l) :: tr) ->
1022+
l = [] \/
1023+
exists d,
1024+
l = [ReadResponse d].
9771025
Proof.
9781026
unfold no_output_at_backup_trace, no_output_at_backup.
9791027
intros. simpl in *.
@@ -983,6 +1031,7 @@ Section PrimaryBackup.
9831031
simpl in *.
9841032
econcludes.
9851033
intuition.
1034+
repeat break_match; intuition eauto.
9861035
Qed.
9871036

9881037
Lemma outputs_m_revert_trace :
@@ -1001,40 +1050,40 @@ Section PrimaryBackup.
10011050
repeat break_match; auto.
10021051
+ rewrite IHtr by eauto using NOABT_tail. auto.
10031052
+ find_copy_apply_lem_hyp NOABT_tail.
1004-
find_apply_lem_hyp NOABT_contra.
1005-
subst. simpl. auto.
1053+
find_apply_lem_hyp NOABT_contra. intuition; break_exists;
1054+
subst; simpl; auto.
10061055
Qed.
10071056

10081057
Lemma NOABT_nil :
1009-
forall A B,
1010-
@no_output_at_backup_trace A B [].
1058+
forall A,
1059+
@no_output_at_backup_trace A [].
10111060
Proof.
10121061
unfold no_output_at_backup_trace.
10131062
simpl. intuition.
10141063
Qed.
10151064

10161065
Lemma NOABT_cons :
1017-
forall A B x y,
1066+
forall A x y,
10181067
no_output_at_backup x ->
1019-
@no_output_at_backup_trace A B y ->
1068+
@no_output_at_backup_trace A y ->
10201069
no_output_at_backup_trace (x :: y).
10211070
Proof.
10221071
unfold no_output_at_backup_trace, no_output_at_backup.
10231072
simpl. intros. intuition; subst; eauto.
10241073
Qed.
10251074

10261075
Lemma NOABT_head :
1027-
forall A B x y,
1028-
@no_output_at_backup_trace A B (x :: y) ->
1076+
forall A x y,
1077+
@no_output_at_backup_trace A (x :: y) ->
10291078
no_output_at_backup x.
10301079
Proof.
10311080
unfold no_output_at_backup_trace, no_output_at_backup.
10321081
simpl. intuition.
10331082
Qed.
10341083

10351084
Lemma NOABT_app :
1036-
forall A B xs ys,
1037-
@no_output_at_backup_trace A B xs ->
1085+
forall A xs ys,
1086+
@no_output_at_backup_trace A xs ->
10381087
no_output_at_backup_trace ys ->
10391088
no_output_at_backup_trace (xs ++ ys).
10401089
Proof.
@@ -1045,25 +1094,33 @@ Section PrimaryBackup.
10451094
Qed.
10461095

10471096
Lemma NOABT_singleton_inr_nil :
1048-
forall A B h,
1049-
@no_output_at_backup_trace A B [(h, inr [])].
1097+
forall A h,
1098+
@no_output_at_backup_trace A [(h, inr [])].
1099+
Proof.
1100+
unfold no_output_at_backup_trace, no_output_at_backup.
1101+
simpl. intros. intuition. subst. simpl in *. find_inversion. auto.
1102+
Qed.
1103+
1104+
Lemma NOABT_singleton_inr_read_response :
1105+
forall A h d,
1106+
@no_output_at_backup_trace A [(h, inr [ReadResponse d])].
10501107
Proof.
10511108
unfold no_output_at_backup_trace, no_output_at_backup.
10521109
simpl. intros. intuition. subst. simpl in *. find_inversion. auto.
10531110
Qed.
10541111

10551112
Lemma NOABT_singleton_primary :
1056-
forall A B out,
1057-
no_output_at_backup_trace [(Primary, @inr A (list B) out)].
1113+
forall A out,
1114+
no_output_at_backup_trace [(Primary, @inr A _ out)].
10581115
Proof.
10591116
unfold no_output_at_backup_trace, no_output_at_backup.
10601117
simpl.
10611118
intuition. subst. simpl in *. find_inversion. auto.
10621119
Qed.
10631120

10641121
Lemma NOABT_singleton_inl :
1065-
forall A B h r,
1066-
@no_output_at_backup_trace A B [(h, inl r)].
1122+
forall A h r,
1123+
@no_output_at_backup_trace A [(h, inl r)].
10671124
Proof.
10681125
unfold no_output_at_backup_trace, no_output_at_backup.
10691126
simpl. intuition. subst. simpl in *. discriminate.
@@ -1085,7 +1142,11 @@ Section PrimaryBackup.
10851142
+ find_apply_lem_hyp PB_net_defn'.
10861143
intuition; subst; repeat find_rewrite;
10871144
auto using NOABT_singleton_inr_nil, NOABT_singleton_primary.
1088-
+ auto using NOABT_singleton_inl.
1145+
+ rewrite cons_cons_app. apply NOABT_app.
1146+
* auto using NOABT_singleton_inl.
1147+
* find_apply_lem_hyp PB_input_handler_defn.
1148+
intuition; break_exists; intuition; subst;
1149+
auto using NOABT_singleton_inr_nil, NOABT_singleton_inr_read_response.
10891150
Qed.
10901151

10911152
Definition zero_or_one_outputs_per_step {A B C} t :=
@@ -1195,7 +1256,11 @@ Section PrimaryBackup.
11951256
intuition; subst; auto using ZOOOPST_singleton_nil.
11961257
break_exists. break_and. break_match.
11971258
intuition; subst; auto using ZOOOPST_singleton_singleton.
1198-
+ auto using ZOOOPST_singleton_inl.
1259+
+ rewrite cons_cons_app.
1260+
apply ZOOOPST_app.
1261+
* auto using ZOOOPST_singleton_inl.
1262+
* find_apply_lem_hyp PB_input_handler_defn; intuition; subst;
1263+
auto using ZOOOPST_singleton_nil, ZOOOPST_singleton_singleton.
11991264
Qed.
12001265

12011266
Lemma inputs_1_m_revert :
@@ -1232,10 +1297,12 @@ Section PrimaryBackup.
12321297
intuition; subst; simpl in *.
12331298
* break_exists.
12341299
intuition; subst;
1235-
rewrite (inputs_m_primary_inl_request_singleton); rewrite update_eq; auto.
1236-
* rewrite (inputs_m_inl_read_singleton).
1300+
rewrite (inputs_m_primary_inl); rewrite update_eq; auto.
1301+
* rewrite (inputs_m_inl_read).
1302+
rewrite inputs_m_inr_singleton.
12371303
rewrite app_nil_r. rewrite update_nop. auto.
1238-
* rewrite (inputs_m_backup_singleton).
1304+
* rewrite (inputs_m_backup).
1305+
rewrite inputs_m_inr_singleton.
12391306
rewrite app_nil_r. rewrite update_nop. auto.
12401307
Qed.
12411308
End PrimaryBackup.

Util.v

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,3 +1107,17 @@ Section assoc.
11071107
Qed.
11081108
End assoc.
11091109

1110+
Lemma snoc_assoc :
1111+
forall A (l : list A) x y,
1112+
l ++ [x; y] = (l ++ [x]) ++ [y].
1113+
Proof.
1114+
induction l; intros; simpl; intuition.
1115+
auto using f_equal.
1116+
Qed.
1117+
1118+
Lemma cons_cons_app :
1119+
forall A (x y : A),
1120+
[x; y] = [x] ++ [y].
1121+
Proof.
1122+
auto.
1123+
Qed.

0 commit comments

Comments
 (0)