Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contextual refinement #20

Open
wants to merge 114 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
c051310
Add linking from cerise-stack-monotone
dlesbre Jan 9, 2023
eceaed3
Add make_link to linking
dlesbre Jan 9, 2023
a21b162
Add linking uniqueness lemmas
dlesbre Jan 9, 2023
2ddd4ba
Add resolve_imports_dom lemma
dlesbre Jan 9, 2023
c24c901
WIP on make_link_pre_wf
dlesbre Jan 9, 2023
4e83b41
Proof of make_link_pre_comp well formed
dlesbre Jan 9, 2023
d3db512
Add make_link_main_lib
dlesbre Jan 9, 2023
c843e37
Add link_is_context
dlesbre Jan 9, 2023
76b42e8
WIP on contextual refinement
dlesbre Jan 9, 2023
54352f6
Machine run ends in halted or error
dlesbre Jan 9, 2023
69801ad
More machine run facts
dlesbre Jan 9, 2023
1140abd
Better definition for contextual refinement
dlesbre Jan 9, 2023
503f509
Stopped reinventing wheel
dlesbre Jan 9, 2023
747dc11
Switch linking pre_comp to record
dlesbre Jan 9, 2023
235f99a
Generalize addr_restrictions
dlesbre Jan 9, 2023
87e8a0c
Restriction weakening
dlesbre Jan 9, 2023
d669da7
Implicit Arguments
dlesbre Jan 9, 2023
6f28685
Work on ctxt_ref def
dlesbre Jan 9, 2023
86a3005
Proof irrelevance lemmas
dlesbre Jan 9, 2023
c6540f8
Contextual refinement weakening
dlesbre Jan 9, 2023
196d515
Add to _CoqProject
dlesbre Jan 9, 2023
c0643d8
Machine run unique result
dlesbre Jan 9, 2023
1a18d87
Better implicits
dlesbre Jan 9, 2023
f54fbe9
WIP on split theorem
dlesbre Jan 9, 2023
a21084a
WIP on facts
dlesbre Jan 9, 2023
35837f7
Better imports type
dlesbre Jan 9, 2023
0b06082
resolve_imports twice
dlesbre Jan 9, 2023
74bb79d
link symmetric
dlesbre Jan 9, 2023
ba1ddfa
Refactor linking + WIP on assoc
dlesbre Jan 9, 2023
230209e
WAYYY too many case disjunctions
dlesbre Jan 9, 2023
5b11c79
Associativity
dlesbre Jan 9, 2023
1c4bc96
is_context assoc
dlesbre Jan 9, 2023
76f392c
Simplification and improvements
dlesbre Jan 9, 2023
c2105a1
Simplify ctxt_facts
dlesbre Jan 9, 2023
6257df4
Bowties are cool
dlesbre Jan 9, 2023
b75faa2
Halt context example
dlesbre Jan 9, 2023
208fb0a
Import inclusion
dlesbre Jan 9, 2023
bd82452
WIP on codom
dlesbre Jan 9, 2023
3f6347e
Rewrite using img
dlesbre Jan 9, 2023
7f2cb3d
Notation for contextual refinement
dlesbre Jan 11, 2023
8bb0d7e
WIP on link list
dlesbre Jan 11, 2023
b48940b
Can_link_list and properties
dlesbre Jan 11, 2023
49fd2ff
Link list with permutation
dlesbre Jan 11, 2023
11c61a9
Machine run complete
dlesbre Jan 13, 2023
cb699cc
Fix letter
dlesbre Jan 13, 2023
298d3ad
Machine run subseteq
dlesbre Jan 17, 2023
667dc00
is_context_pop
dlesbre Jan 17, 2023
92b7bab
solve_can_link tactic
dlesbre Jan 18, 2023
1eb02af
Typeclass rewrite + extra lemmas
dlesbre Jan 18, 2023
81b7f2b
ctxt_ref_grow_impl
dlesbre Jan 18, 2023
efbd37f
Progress on segment theorem
dlesbre Jan 18, 2023
3f513dc
Segment inclusion and consequences
dlesbre Jan 19, 2023
f05d927
Renaming and alt definition
dlesbre Jan 23, 2023
525539d
Remove addr restriction from linking
dlesbre Jan 26, 2023
39f2228
Big ugly proof
dlesbre Feb 1, 2023
b0a515c
Some extra results
dlesbre Feb 1, 2023
c780ecc
Cleanup and moving stuff around
dlesbre Feb 1, 2023
6f71b91
Rework proof to support seals
dlesbre Feb 2, 2023
17f7d7a
Add no seals+finish migrating to seals
dlesbre Feb 2, 2023
3a51ca5
Finish migrating to seals
dlesbre Feb 2, 2023
9af7017
Simplify some theorem statements
dlesbre Feb 2, 2023
add14f7
solve_can_link ints
dlesbre Feb 3, 2023
3687f59
Fix names
dlesbre Feb 6, 2023
d183c32
Define map restrict to make statements clearer
dlesbre Feb 6, 2023
856dfd9
img_insert_notin
dlesbre Feb 6, 2023
4bda9cf
Renamed lemmas
dlesbre Feb 6, 2023
9769b54
More lemmas and renames
dlesbre Feb 6, 2023
6d33aa9
Interp_link with smaller assumptions
dlesbre Feb 6, 2023
097a1b6
More general restrict
dlesbre Feb 6, 2023
0c3b7ee
Fix compilation
dlesbre Feb 6, 2023
d9fee43
More img lemmas
dlesbre Feb 7, 2023
a5088bb
Less wheel reinvention
dlesbre Feb 7, 2023
838e617
More facts
dlesbre Feb 7, 2023
2316f76
Fix infinite loop
dlesbre Feb 7, 2023
cb7eeec
More lemmas
dlesbre Feb 8, 2023
5d59d58
Yet more lemmas
dlesbre Feb 8, 2023
52aea76
More ltac trickery
dlesbre Feb 8, 2023
4172b98
Less wheel reinvention
dlesbre Feb 13, 2023
ac357c4
Reuse def
dlesbre Feb 13, 2023
f7a0898
Fix for new def
dlesbre Feb 13, 2023
a7e2b19
Minor changes
dlesbre Feb 15, 2023
a3f9d7e
Replace custom class with Proper
dlesbre Feb 17, 2023
5f1d296
Alternative formulation of Hrefines
dlesbre Feb 21, 2023
4d92dfc
Small results
dlesbre Feb 27, 2023
9d2c4e0
Small changes to formatting
dlesbre Feb 27, 2023
4b1b8d3
Simplify defs
dlesbre Feb 27, 2023
726a9ad
Rephrase resolve imports with map composition
dlesbre Feb 28, 2023
3e9252a
Add missing annotations
dlesbre Feb 28, 2023
07a0dee
Size and generic decomposition
dlesbre Mar 3, 2023
9d4375d
Linking altdef
dlesbre Mar 6, 2023
2794b5c
Fix MemNum staying transparent
dlesbre Mar 6, 2023
c10859c
Tiny changes
dlesbre Mar 6, 2023
7844c25
Exports domain inclusion
dlesbre Mar 7, 2023
5ac9cec
Remove exportless from spec
dlesbre Mar 10, 2023
8d791d9
Coqdoc
dlesbre Mar 10, 2023
f59ff24
Small changes
dlesbre Mar 20, 2023
7c05333
Switch to the version of map_img merged into stdpp
dlesbre Mar 20, 2023
78ee67e
Rename linking -> linking_old to merge with new linking
dlesbre Mar 27, 2023
3926664
Merge branch 'switch_to_new_link' into dorian/contextual-refinement
dlesbre Mar 27, 2023
76925ee
Rename is_word -> is_int
dlesbre Mar 27, 2023
7b4536a
Used newer linking defs for binary counter adequacy
dlesbre Mar 27, 2023
64b47e8
Move linking_old to attic
dlesbre Mar 27, 2023
c7cbe8d
WIP on generalization
dlesbre Mar 28, 2023
c5dc5a6
Working WP abstraction
dlesbre Mar 28, 2023
35932e3
Some rearranging
dlesbre Mar 28, 2023
4598b5c
Fix imports
dlesbre Mar 28, 2023
cb74adc
Remove stdpp_restrict
dlesbre Mar 28, 2023
5c033e2
Adequacy with link
dlesbre Mar 29, 2023
a67fd00
Use stdpp-ified version of stdpp_comp
dlesbre Mar 29, 2023
4c2dab4
Change program definition to require regs to be part of exports
dlesbre Mar 29, 2023
ddd81b8
Successful second abstraction
dlesbre Mar 29, 2023
bcd01c2
coq-doc formatting and some simplifications
dlesbre Mar 30, 2023
b617822
coq-doc and styling
dlesbre Mar 30, 2023
52c3ca8
coq_doc
dlesbre Mar 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion _CoqProject
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ machine_utils/theories/solve_pure.v
machine_utils/theories/tactics.v
theories/iris_extra.v
theories/stdpp_extra.v
theories/stdpp_img.v
theories/stdpp_comp.v
theories/map_simpl.v
theories/addr_reg.v
theories/linking.v
theories/solve_addr.v
theories/machine_base.v
theories/machine_parameters.v
Expand Down Expand Up @@ -95,7 +98,9 @@ theories/ftlr_binary/Store_binary.v
theories/ftlr_binary/Seal_binary.v
theories/ftlr_binary/UnSeal_binary.v
theories/fundamental_binary.v
theories/contextual_refinement_adequacy.v
theories/examples/addr_reg_sample.v
theories/contextual_refinement.v
theories/examples/malloc.v
theories/examples/salloc.v
theories/examples/assert.v
Expand Down Expand Up @@ -134,7 +139,6 @@ theories/examples/minimal_counter.v
theories/examples/ocpl_lowval_like.v
theories/examples/malloc_binary.v
theories/examples/macros_binary.v
theories/linking.v
theories/examples/counter_binary.v
theories/examples/counter_binary_preamble_def.v
theories/examples/counter_binary_preamble.v
Expand Down
4 changes: 4 additions & 0 deletions theories/addr_reg.v
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ Notation Addr := (finz MemNum).
Declare Scope Addr_scope.
Delimit Scope Addr_scope with a.

Global Instance addr_eq_dec: EqDecision Addr.
Proof. apply finz_eq_dec. Defined.


Notation "a1 <= a2 < a3" := (@finz.le_lt MemNum a1 a2 a3) : Addr_scope.
Notation "a1 <= a2" := (@finz.le MemNum a1 a2) : Addr_scope.
Notation "a1 <=? a2" := (@finz.leb MemNum a1 a2) : Addr_scope.
Expand Down
155 changes: 155 additions & 0 deletions theories/attic/linking.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
From iris Require Import base.
From iris.program_logic Require Import language ectx_language ectxi_language.
From stdpp Require Import gmap fin_maps fin_sets.
From cap_machine Require Import addr_reg.

Section Linking.

Variable Symbols: Type.
Variable Symbols_eq_dec: EqDecision Symbols.
Variable Symbols_countable: Countable Symbols.

Variable Word: Type.
Variable can_address_only: Word -> (gset Addr) -> Prop.
Variable is_main: Word -> Prop.

Definition imports: Type := gset (Symbols * Addr).
Definition exports: Type := gmap Symbols Word.
Definition segment: Type := gmap Addr Word.

Definition pre_component: Type := (segment * imports * exports).
Inductive component: Type :=
| Lib: pre_component -> component
| Main: pre_component -> Word -> component.

Inductive well_formed_pre_comp: pre_component -> Prop :=
| wf_pre_intro:
forall (ms : gmap Addr Word) imp (exp : gmap Symbols Word)
(Hdisj: forall s, is_Some (exp !! s) -> ~ exists a, (s, a) ∈ imp)
(Hexp: forall (s : Symbols) (w : Word), exp !! s = Some w -> can_address_only w (dom ms))
(Himp: forall s a, (s, a) ∈ imp -> is_Some (ms !! a))
(Himpdisj: forall s1 s2 a, (s1, a) ∈ imp -> (s2, a) ∈ imp -> s1 = s2)
(Hnpwl: forall (a : Addr) (w : Word), ms !! a = Some w -> can_address_only w (dom ms)),
well_formed_pre_comp (ms, imp, exp).

Inductive well_formed_comp: component -> Prop :=
| wf_lib:
forall comp
(Hwf_pre: well_formed_pre_comp comp),
well_formed_comp (Lib comp)
| wf_main:
forall comp w_main
(Hwf_pre: well_formed_pre_comp comp)
(Hw_main_addr: can_address_only w_main (dom (comp.1.1)))
(Hw_main: is_main w_main),
well_formed_comp (Main comp w_main).

Inductive is_program: component -> Prop :=
| is_program_intro:
forall ms imp exp w_main
(Hnoimports: imp = ∅)
(Hwfcomp: well_formed_comp (Main (ms, imp, exp) w_main)),
is_program (Main (ms,imp, exp) w_main).

Definition resolve_imports (imp: imports) (exp: exports) (ms: segment) :=
set_fold (fun '(s, a) m => match exp !! s with Some w => <[a:=w]> m | None => m end) ms imp.

Lemma resolve_imports_spec:
forall imp exp ms a
(Himpdisj: forall s1 s2 a, (s1, a) ∈ imp -> (s2, a) ∈ imp -> s1 = s2),
((~ exists s, (s, a) ∈ imp) ->
(resolve_imports imp exp ms) !! a = ms !! a) /\
(forall s, (s, a) ∈ imp ->
(exp !! s = None /\ (resolve_imports imp exp ms) !! a = ms !! a) \/ (exists wexp, exp !! s = Some wexp /\ (resolve_imports imp exp ms) !! a = Some wexp)).
Proof.
intros imp exp ms a. eapply (set_fold_ind_L (fun m imp => (forall s1 s2 a, (s1, a) ∈ imp -> (s2, a) ∈ imp -> s1 = s2) -> ((~ exists s, (s, a) ∈ imp) -> m !! a = ms !! a) /\ (forall s, (s, a) ∈ imp -> (exp !! s = None /\ m !! a = ms !! a) \/ (exists wexp, exp !! s = Some wexp /\ m !! a = Some wexp))) (fun '(s, a) m => match exp !! s with Some w => <[a:=w]> m | None => m end)); eauto.
{ intros. split; auto. intros.
eapply elem_of_empty in H0; elim H0; auto. }
intros. destruct x. split.
{ intros. destruct (exp !! s).
- rewrite lookup_insert_ne; auto.
+ apply H0.
* intros. eapply H1; eapply elem_of_union; right; eauto.
* intro Y. destruct Y as [sy Hiny].
eapply H2. exists sy. eapply elem_of_union. right; eauto.
+ intro; subst a. eapply H2. exists s.
eapply elem_of_union. left. eapply elem_of_singleton. reflexivity.
- apply H0.
+ intros. eapply H1; eapply elem_of_union; right; eauto.
+ intro Y. destruct Y as [sy Hiny].
eapply H2. exists sy. eapply elem_of_union. right; auto. }
{ intros; destruct (exp !! s) eqn:Hexp.
- destruct (decide (f = a)).
+ subst f; rewrite lookup_insert.
right. assert (s0 = s) as ->; eauto.
eapply elem_of_union in H2. destruct H2.
* generalize (proj1 (elem_of_singleton _ _) H2). inversion 1; subst; auto.
* eapply (H1 s0 s a); [eapply elem_of_union_r; auto|eapply elem_of_union_l; eapply elem_of_singleton; eauto].
+ rewrite lookup_insert_ne; auto.
eapply elem_of_union in H2; destruct H2.
* erewrite elem_of_singleton in H2. inversion H2; congruence.
* eapply H0; auto.
intros; eapply H1; eapply elem_of_union; right; eauto.
- eapply elem_of_union in H2. destruct H2.
+ erewrite elem_of_singleton in H2. inversion H2; subst; clear H2.
left; split; auto. eapply (proj1 (H0 ltac:(intros; eapply H1; eapply elem_of_union; right; eauto))).
intro Y. destruct Y as [sy Hsy].
eapply H. replace s with sy; auto.
eapply H1; [eapply elem_of_union_r; eauto| eapply elem_of_union_l; eapply elem_of_singleton; eauto].
+ eapply H0; auto.
intros; eapply H1; eapply elem_of_union_r; eauto. }
Qed.

Lemma resolve_imports_spec_in:
forall imp exp ms a s
(Himpdisj: forall s1 s2 a, (s1, a) ∈ imp -> (s2, a) ∈ imp -> s1 = s2),
(s, a) ∈ imp ->
(exp !! s = None /\ (resolve_imports imp exp ms) !! a = ms !! a) \/ (exists wexp, exp !! s = Some wexp /\ (resolve_imports imp exp ms) !! a = Some wexp).
Proof.
intros. eapply resolve_imports_spec; eauto.
Qed.

Lemma resolve_imports_spec_not_in:
forall imp exp ms a
(Himpdisj: forall s1 s2 a, (s1, a) ∈ imp -> (s2, a) ∈ imp -> s1 = s2),
((~ exists s, (s, a) ∈ imp) ->
(resolve_imports imp exp ms) !! a = ms !! a).
Proof.
intros. eapply resolve_imports_spec; eauto.
Qed.

Inductive link_pre_comp: pre_component -> pre_component -> pre_component -> Prop :=
| link_pre_comp_intro:
forall ms1 ms2 ms imp1 imp2 imp exp1 exp2 exp
(Hms_disj: forall a, is_Some (ms1 !! a) -> is_Some (ms2 !! a) -> False)
(Hexp: exp = merge (fun o1 o2 => match o1 with | Some _ => o1 | None => o2 end) exp1 exp2)
(Himp: forall s a, (s, a) ∈ imp <-> (((s, a) ∈ imp1 \/ (s, a) ∈ imp2) /\ exp !! s = None))
(Hms: ms = resolve_imports imp2 exp (resolve_imports imp1 exp (map_union ms1 ms2))),
link_pre_comp (ms1, imp1, exp1) (ms2, imp2, exp2) (ms, imp, exp).

Inductive link: component -> component -> component -> Prop :=
| link_lib_lib:
forall comp1 comp2 comp
(Hlink: link_pre_comp comp1 comp2 comp)
(Hwf_l: well_formed_comp (Lib comp1))
(Hwf_r: well_formed_comp (Lib comp2)),
link (Lib comp1) (Lib comp2) (Lib comp)
| link_lib_main:
forall comp1 comp2 comp w_main
(Hlink: link_pre_comp comp1 comp2 comp)
(Hwf_l: well_formed_comp (Lib comp1))
(Hwf_r: well_formed_comp (Main comp2 w_main)),
link (Lib comp1) (Main comp2 w_main) (Main comp w_main)
| link_main_lib:
forall comp1 comp2 comp w_main
(Hlink: link_pre_comp comp1 comp2 comp)
(Hwf_l: well_formed_comp (Main comp1 w_main))
(Hwf_r: well_formed_comp (Lib comp2)),
link (Main comp1 w_main) (Lib comp2) (Main comp w_main).

Inductive is_context (c comp p: component): Prop :=
| is_context_intro:
forall (His_program: link c comp p /\ is_program p),
is_context c comp p.

End Linking.
Loading