Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
3152f71
fixing the compilation of Asm.v
gmalecha Feb 12, 2019
a45bb23
a compiler from Imp2Asm.
gmalecha Feb 12, 2019
5aa7423
Work over the compiler. Bit of simplification in Imp to line up more …
YaZko Feb 13, 2019
36b8dce
Naive scheme to handle locals
YaZko Feb 13, 2019
3a26b8f
Changed representation of Asm programs and formulated theorems that a…
YaZko Feb 13, 2019
bab4a05
Work in progress on the compiler. Committing messy state to work on i…
YaZko Feb 15, 2019
89e039d
WIP
YaZko Feb 15, 2019
5153c1d
some more sketching of the proof + heterogenous eutt
gmalecha Feb 15, 2019
2de7fe9
some missing edits.
gmalecha Feb 15, 2019
122ebc6
Make eutt a heterogeneous relation
Lysxia Feb 16, 2019
b0d7459
Making global instances that got pushed inside of a section
YaZko Feb 16, 2019
f6c4599
Make eq_itree a heterogeneous relation
Lysxia Feb 17, 2019
7178597
Fix example with new heterogeneous eutt
Lysxia Feb 17, 2019
7a5e209
Merge remote-tracking branch 'origin/master' into imp2asm
Lysxia Feb 17, 2019
eb67983
Simplify some Eq proofs
Lysxia Feb 17, 2019
e078b5c
Heterogeneous version of eq_itree_bind
Lysxia Feb 17, 2019
936a083
Prove eutt_map
Lysxia Feb 17, 2019
cb88698
Add some automation for unalltaus_notau
Lysxia Feb 17, 2019
b0ac565
Progress in the proof of the compiler
YaZko Feb 18, 2019
04262b7
Some clean up and starting to fill up the admits, though admittedly t…
YaZko Feb 18, 2019
7da6e67
Minor progress
YaZko Feb 18, 2019
3d692d2
we learned a lot, but we aren't done.
gmalecha Feb 19, 2019
d6b181d
Proving a few lemmas that should go to ExtLib and that we need. Provi…
YaZko Feb 19, 2019
7d81476
Fixing a couple of easy lemmas about eutt
YaZko Feb 19, 2019
b98342a
Moving from In to alist_In in the simulation relation and fixing the …
YaZko Feb 19, 2019
02b8f15
Move lemmas from Imp2Asm example to UpToTaus
Lysxia Feb 19, 2019
ac6731e
Fixing a typo in untaus' description
YaZko Feb 19, 2019
e543b03
Finished fixing lemmas related to alist, Renv and sim_rel
YaZko Feb 19, 2019
cdde3ab
trying to build a theory of linking.
gmalecha Feb 19, 2019
50b6489
some work on defining the category of handlers
Zdancewic Feb 20, 2019
4d69708
Reorganize MorphismsFacts a bit
Lysxia Feb 19, 2019
95d1be4
Move around some eutt lemmas
Lysxia Feb 19, 2019
03a55be
interp_interp
Lysxia Feb 20, 2019
129d03f
Add loop and some convenience functions for rec
Lysxia Feb 20, 2019
4044328
Fix type of Sum1.bimap
Lysxia Feb 20, 2019
4f6043c
Move rec_unfold to library, add loop_unfold, interp_liftE, interp_tra…
Lysxia Feb 20, 2019
6974c7b
some more work
Zdancewic Feb 20, 2019
1053cd9
State bind_loop
Lysxia Feb 20, 2019
0a8043f
Sketch denotational semantics of asm using loop
Lysxia Feb 20, 2019
7b0efcf
some work on itree morphisms
Zdancewic Feb 20, 2019
f1933de
fix compile problem
Zdancewic Feb 20, 2019
5ef7deb
More diagramatic reasoning
Lysxia Feb 20, 2019
16ba87a
remove eh_swap and adding a few more sum1 morphisms
Zdancewic Feb 20, 2019
823b7be
finish proof of seq_correct
Lysxia Feb 20, 2019
e8bf2cc
Reorganize Imp2AsmBis
Lysxia Feb 20, 2019
007ce5a
Implementing Asm to fit with ImpToAsmBis
YaZko Feb 20, 2019
8870dd6
Rename loop to aloop, add new loop
Lysxia Feb 21, 2019
5108ddb
Proving a few lemmas
YaZko Feb 21, 2019
58d05da
Cleaning up some lemmas I accidentally duplicated
YaZko Feb 21, 2019
d813330
Refactoring
Lysxia Feb 21, 2019
42a2dc4
Fix stlc example
Lysxia Feb 21, 2019
3e5fe0f
interp_interp
Zdancewic Feb 22, 2019
06c6b5d
some more morphism facts
Zdancewic Feb 22, 2019
2451db5
Simplify definition of loop
Lysxia Feb 21, 2019
9425a50
Move sum to theories/Basics_Functions.v
Lysxia Feb 22, 2019
bb8dbc8
State loop equations for traced monoidal category
Lysxia Feb 22, 2019
3496b7b
Prove a few of the loop lemmas
Lysxia Feb 22, 2019
fc836fb
Prove all the loop lemmas
Lysxia Feb 22, 2019
170c7ef
Extracting the traced monoidal category of den outside, in progress t…
YaZko Feb 22, 2019
7832ecf
Trailing corrupted import
YaZko Feb 22, 2019
8bdd795
Make ~> parse-only (overlaps with other notations)
Lysxia Feb 22, 2019
82e54db
Almost prove eutt_loop
Lysxia Feb 22, 2019
8291776
easy lemma eutt_tau
Zdancewic Feb 23, 2019
96eede5
Finish eutt_loop proof
Lysxia Feb 23, 2019
5757ee1
ci: Manual travis script
Lysxia Feb 23, 2019
1344e4e
Makefile: Update test scripts
Lysxia Feb 23, 2019
d3b3352
Progress in den theory, abstract sequential linking
YaZko Feb 23, 2019
60dcc77
Renaming Imp2AsmBis
YaZko Feb 23, 2019
4b8eb4b
reformulation of translate to not use interp
Zdancewic Feb 23, 2019
b3c85a7
Rewriting the compiler
YaZko Feb 24, 2019
6bbc016
Prove eutt_interp1 and state eutt_interp_state
Lysxia Feb 23, 2019
22a1070
Shallow itree equivalence
Lysxia Feb 23, 2019
a86d3e1
Add SimUpToTaus (eutt preorder)
Lysxia Feb 24, 2019
8d70246
Refactor eutt_loop with sutt
Lysxia Feb 24, 2019
c1431d4
Add SimUpToTaus to _CoqConfig
Lysxia Feb 24, 2019
13978f2
factor out Translate (step 1)
Zdancewic Feb 24, 2019
823f2a2
fix up for changes to library?
Zdancewic Feb 24, 2019
9964030
finish relating the (new) translate and interp
Zdancewic Feb 24, 2019
7e834e5
Resolve admits in SimUpToTaus
Lysxia Feb 24, 2019
d1aed6b
eutt: generalize symmetry and transitivity to heterogeneous relations
Lysxia Feb 24, 2019
e73f931
Prove eutt_eq_under_rr
Lysxia Feb 24, 2019
a83a5e6
Prove eutt_bind_gen
Lysxia Feb 24, 2019
99312b2
Words about sutt
Lysxia Feb 24, 2019
1c623f0
Export SimUpToTaus by default
Lysxia Feb 24, 2019
2c25877
Makefile: refactor build system for examples
Lysxia Feb 24, 2019
b07ccc9
added eh_swap
Zdancewic Feb 25, 2019
aa19ea3
Fix imp2asm compiler
Lysxia Feb 25, 2019
25216fb
quick fix to the makefile (closes #67)
gmalecha Feb 25, 2019
dd5226f
Typechecking correctness theorem.
YaZko Feb 25, 2019
4465246
Merge pull request #68 from DeepSpec/imp2asm-makefile
gmalecha Feb 25, 2019
483c5da
Split compiler and compiler correctness
Lysxia Feb 25, 2019
a54c6ed
Sketch correctness proof for individual Imp constructs
Lysxia Feb 25, 2019
bb9b940
Add doc on asm syntax
Lysxia Feb 25, 2019
4af2ff3
Factor out AsmCombinators
Lysxia Feb 25, 2019
d395299
Correctness proof sketc
Lysxia Feb 25, 2019
581bc10
Fill in some more in toplevel theorem
Lysxia Feb 25, 2019
0602206
Couple of proofs in AsmCombinators
YaZko Feb 25, 2019
e53f124
Merge branch 'imp2asm' of github.com:DeepSpec/InteractionTrees into i…
YaZko Feb 25, 2019
741a45c
Work in progress to prove app_asm_correct
YaZko Feb 25, 2019
e14223d
Add unfold_mrec
Lysxia Feb 26, 2019
4a18824
an example of proving factorial correct
Zdancewic Feb 26, 2019
b9e780c
Proving a few lemmas.
YaZko Feb 26, 2019
7976b96
Make done an effect
Lysxia Feb 26, 2019
4782591
app_asm_correct
Lysxia Feb 26, 2019
2ffb17f
move Require out of sections.
gmalecha Feb 26, 2019
b99739b
cleanup ret_bind by using ret_bind_
Zdancewic Feb 26, 2019
a7fc195
Merge branch 'imp2asm' of https://github.com/DeepSpec/InteractionTree…
Zdancewic Feb 26, 2019
9f8acbd
generalizing Rhom.
gmalecha Feb 26, 2019
24b8eab
converting some (eq ==> ..) to `pointwise_relation _ ..`
gmalecha Feb 26, 2019
4c2684a
unifying Rhom and eh_eq (adding eh_eutt)
gmalecha Feb 26, 2019
adb0a8f
a bit of cleanup in Imp2AsmCorrectness
gmalecha Feb 26, 2019
fcf50ca
emptyE handler and some facts about it
Zdancewic Feb 26, 2019
8161b97
renamed eh_compose to eh_cmp
Zdancewic Feb 26, 2019
321e726
clean up eh proofs by properly lifting them from event morphisms, pro…
Zdancewic Feb 26, 2019
87e34e1
Proved equivalence of (sutt eq) and trace_incl
Feb 26, 2019
1970d2b
Proving loop_den related lemmas
YaZko Feb 26, 2019
431fba5
Proved remaining admit
YaZko Feb 26, 2019
a699aac
Merge pull request #69 from Grain/trace-sutt
Lysxia Feb 26, 2019
f1e9135
reduce eutt_interp to sutt_interp
gmalecha Feb 26, 2019
c8fd4e8
The meaning of zero in conditional must be reversed between imp's if …
YaZko Feb 26, 2019
7287670
If case in the proof of the compiler
YaZko Feb 27, 2019
84a42de
Minor changes in the compiler's proof
YaZko Feb 27, 2019
28ec29f
Define eq_locals
Lysxia Feb 27, 2019
e92c49e
Close toplevel proof. Auxiliary lemmas remain.
Lysxia Feb 27, 2019
8725e7b
Move to_itree to a safe place
Lysxia Feb 27, 2019
16f0ec8
Remove invalid assumptions
Lysxia Feb 27, 2019
ce8384e
Prove while_is_loop
Lysxia Feb 27, 2019
78697c4
Prove interp_locals_bind
Lysxia Feb 27, 2019
a22f0ed
Prove eutt_interp_locals
Lysxia Feb 27, 2019
42bf65b
Reduce proof of eq_locals_loop
Lysxia Feb 27, 2019
6bbd067
Rephrased while using loop
YaZko Feb 27, 2019
7e33e12
Make default the more corecursive version of `eutt`.
gilhur Feb 28, 2019
eebc50a
Change of notation for eqden
YaZko Feb 28, 2019
bc2fa96
Regeneralize interp1 proofs
Lysxia Feb 28, 2019
189cab8
Fix eutt_bind_gen
Lysxia Feb 28, 2019
309640b
Rename eutt_Ret -> eutt_ret in examples/Imp2AsmCorrectness
Lysxia Feb 28, 2019
ea98a6a
Merge branch 'imp2asm' into asmasm
Lysxia Feb 28, 2019
0793ceb
Merge pull request #70 from gilhur/imp2asm
Lysxia Feb 28, 2019
161a967
Removed obsolete file
YaZko Feb 28, 2019
f1f4cd5
Nits
YaZko Feb 28, 2019
d1ee490
Unary representation of nats to remove the admit
YaZko Feb 28, 2019
fc26ed7
Bit of claenup
YaZko Feb 28, 2019
66c891d
Removed obsolete import
YaZko Feb 28, 2019
39ea863
Move Den to ITree.KTree
Lysxia Feb 28, 2019
99149c1
Removed trailing Set Implicit Argument
YaZko Mar 1, 2019
cf1dadf
Move eq_notauF to Untaus
Lysxia Mar 1, 2019
a118dd7
Bit of cleaning in the files
YaZko Mar 2, 2019
a61e3bf
Change the def of "eutt" so that it provides very strong reasoning
gilhur Mar 2, 2019
f665f9b
fix implicit arguments on inl1 and inr1
gmalecha Mar 2, 2019
9562660
8.8 hotfix
Lysxia Mar 2, 2019
4cbd366
Clean up stash
Lysxia Mar 2, 2019
f9afa69
Merge pull request #71 from gilhur/imp2asm
Lysxia Mar 2, 2019
2cb37fb
Merge branch 'master' into imp2asm
Lysxia Mar 2, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ tests/extraction/*.ml
tests/extraction/*.mli
examples/io.ml
examples/io.mli
examples/extracted/

*.native
36 changes: 7 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.PHONY: clean all coq test tests examples install uninstall depgraph \
example-imp example-lc example-io example-nimp
.PHONY: clean all coq test tests examples install uninstall depgraph

COQPATHFILE=$(wildcard _CoqPath)

Expand All @@ -17,41 +16,20 @@ uninstall: Makefile.coq
test: examples tests

tests:
make -C tests
$(MAKE) -C tests

examples: example-imp example-lc example-io example-nimp example-threads

example-imp: examples/Imp.v
coqc -Q theories/ ITree examples/Imp.v

example-lc: examples/stlc.v
coqc -Q theories/ ITree examples/stlc.v

example-lc: examples/stlc.v
coqc -Q theories/ ITree examples/Nimp.v

example-io: examples/IO.v
cd examples && \
coqc -Q ../theories/ ITree IO.v && \
ocamlbuild io.native && ./io.native

THREADSV=examples/MultiThreadedPrinting.v examples/ExtractThreadsExample.v
THREADSML=examples/runthread.ml
example-threads: $(THREADSV) $(THREADSML)
coqc -Q theories/ ITree -Q examples/ Examples $(THREADSV) && \
cd examples && \
ocamlbuild -I extracted runthread.native && \
./runthread.native
examples:
$(MAKE) -C examples

Makefile.coq: _CoqProject
coq_makefile -f $< -o $@

clean: Makefile.coq
$(MAKE) -f Makefile.coq clean
$(RM) {*,*/*}/*.{vo,glob} {*,*/*}/.*.aux
$(MAKE) -C tests clean
$(MAKE) -C examples clean
$(RM) theories/{*,*/*}/*.{vo,glob} theories/{*,*/*}/.*.aux
$(RM) _CoqProject Makefile.coq*
$(RM) examples/extracted/*.*
cd examples && ocamlbuild -clean

_CoqProject: $(COQPATHFILE) _CoqConfig Makefile
@ echo "# Generating _CoqProject"
Expand Down
9 changes: 9 additions & 0 deletions _CoqConfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
-Q theories ITree

theories/Basics.v
theories/Basics_Functions.v
theories/Core.v

theories/Eq/Shallow.v
theories/Eq/Eq.v
theories/Eq/UpToTaus.v
theories/Eq/UpToTausExplicit.v
theories/Eq/Untaus.v
theories/Eq/SimUpToTaus.v

theories/Effect/Sum.v
theories/Effect/Std.v
Expand All @@ -16,9 +21,13 @@ theories/OpenSum.v
theories/Fix.v
theories/FixFacts.v

theories/Translate.v
theories/TranslateFacts.v
theories/Morphisms.v
theories/MorphismsFacts.v

theories/KTree.v

theories/UpTo.v
theories/Trace.v
theories/MFixITree.v
Expand Down
255 changes: 137 additions & 118 deletions examples/Asm.v
Original file line number Diff line number Diff line change
@@ -1,129 +1,158 @@
Require Import Coq.Strings.String.
From Coq Require Import
Strings.String
Program.Basics
ZArith.ZArith.
From ITree Require Import Basics_Functions.
From ExtLib Require Structures.Monad.
Require Import Imp.

Typeclasses eauto := 5.

Section Syntax.

Definition var : Set := string.
Definition value : Set := nat.

(** ** Syntax *)

Variant operand : Set :=
| Oimm (_ : value)
| Ovar (_ : var).

Variant instr : Set :=
| Imov (dest : var) (src : operand)
| Iadd (dest : var) (src : var) (o : operand)
| Iload (dest : var) (addr : operand)
| Istore (addr : var) (val : operand).

Variant branch {label : Type} : Type :=
| Bjmp (_ : label) (* jump to label *)
| Bbrz (_ : var) (yes no : label) (* conditional jump *)
| Bhalt
.
Global Arguments branch _ : clear implicits.

(** A block is a sequence of straightline instructions followed
by a branch. *)
Inductive block {label : Type} : Type :=
| bbi (_ : instr) (_ : block)
| bbb (_ : branch label).
Global Arguments block _ : clear implicits.

(** Collection of blocks labeled by [A], with branches in [B]. *)
Definition bks A B := A -> block B.

(** Blocks with visible unlinked labels [A] and [B] and internal
linked labels, allowing blocks to explicitly jump to each other.
- [A]: entry points
- [B]: exit points
- [internal]: linked and hidden labels
*)
Record asm A B : Type :=
{
internal : Type;
code : bks (internal + A) (internal + B)
}.

Global Arguments internal {A B}.
Global Arguments code {A B}.

End Syntax.

Arguments internal {A B}.
Arguments code {A B}.

Definition var : Set := string.
Definition value : Set := nat. (* this should change *)

(* start with the syntax *)

Variant operand : Set :=
| Oimm (_ : value)
| Ovar (_ : var).
From ITree Require Import
ITree OpenSum KTree.

Variant instr : Set :=
| Imov (dest : var) (src : operand)
| Iadd (dest : var) (src : var) (o : operand)
| Iload (dest : var) (addr : operand)
| Istore (addr : var) (val : operand).
Section Semantics.

Variant branch {label : Type} : Type :=
| Bjmp (_ : label) (* jump to label *)
| Bbrz (_ : var) (yes no : label) (* conditional jump *)
| Bhalt
.
Arguments branch _ : clear implicits.
(* Denotation in terms of itrees *)

Inductive block {label : Type} : Type :=
| bbi (_ : instr) (_ : block)
| bbb (_ : branch label).
Arguments block _ : clear implicits.
Import ExtLib.Structures.Monad.
Import MonadNotation.
Local Open Scope monad_scope.

Record program : Type :=
{ label : Type
; blocks : label -> block label
; main : label
}.
Import Imp.

Inductive Memory : Type -> Type :=
| Load (addr : value) : Memory value
| Store (addr val : value) : Memory unit.

(* now define a semantics *)
Inductive Exit : Type -> Type :=
| Done : Exit Empty_set.

From ITree Require Import
ITree OpenSum Fix.

Require Import ExtLib.Structures.Monad.
Import MonadNotation.
Local Open Scope monad_scope.

(* the "effect" to track local variables *)
Inductive Locals : Type -> Type :=
| GetVar (x : var) : Locals value
| SetVar (x : var) (v : value) : Locals unit.

Inductive Memory : Type -> Type :=
| Load (addr : value) : Memory value
| Store (addr val : value) : Memory unit.

Section with_effect.
Variable e : Type -> Type.
Context {HasLocals : Locals -< e}.
Context {HasMemory : Memory -< e}.

Definition denote_operand (o : operand) : itree e value :=
match o with
| Oimm v => Ret v
| Ovar v => lift (GetVar v)
end.
Definition done {E A} `{Exit -< E} : itree E A :=
Vis (subeffect _ Done) (fun v => match v : Empty_set with end).

Definition denote_instr (i : instr) : itree e unit :=
match i with
| Imov d s =>
v <- denote_operand s ;;
lift (SetVar d v)
| Iadd d l r =>
lv <- lift (GetVar l) ;;
rv <- denote_operand r ;;
lift (SetVar d (lv + rv))
| Iload d a =>
addr <- denote_operand a ;;
val <- lift (Load addr) ;;
lift (SetVar d val)
| Istore a v =>
addr <- lift (GetVar a) ;;
val <- denote_operand v ;;
lift (Store addr val)
end.
(* Denotation of blocks *)
Section with_effect.
Context {E : Type -> Type}.
Context {HasLocals : Locals -< E}.
Context {HasMemory : Memory -< E}.
Context {HasExit : Exit -< E}.

Section with_labels.
Context {label : Type}.

Definition denote_branch (b : branch label)
: itree e (option label) :=
match b with
| Bjmp l => ret (Some l)
| Bbrz v y n =>
val <- lift (GetVar v) ;;
if val : value then ret (Some y) else ret (Some n)
| Bhalt => ret None
Definition denote_operand (o : operand) : itree E value :=
match o with
| Oimm v => Ret v
| Ovar v => lift (GetVar v)
end.

Fixpoint denote_block (b : block label)
: itree e (option label) :=
match b with
| bbi i b =>
denote_instr i ;;
denote_block b
| bbb b =>
denote_branch b
Definition denote_instr (i : instr) : itree E unit :=
match i with
| Imov d s =>
v <- denote_operand s ;;
lift (SetVar d v)
| Iadd d l r =>
lv <- lift (GetVar l) ;;
rv <- denote_operand r ;;
lift (SetVar d (lv + rv))
| Iload d a =>
addr <- denote_operand a ;;
val <- lift (Load addr) ;;
lift (SetVar d val)
| Istore a v =>
addr <- lift (GetVar a) ;;
val <- denote_operand v ;;
lift (Store addr val)
end.
End with_labels.
End with_effect.

Definition denote_program {e} `{Locals -< e} `{Memory -< e}
(p : program) : itree e unit :=
rec (fun lbl : p.(label) =>
next <- denote_block (_ +' e) (p.(blocks) lbl) ;;
match next with
| None => ret tt
| Some next => lift (Call next)
end)
p.(main).
Section with_labels.
Context {A B : Type}.

(* SAZ: Everything from here down can probably be polished.
Definition denote_branch (b : branch B) : itree E B :=
match b with
| Bjmp l => ret l
| Bbrz v y n =>
val <- lift (GetVar v) ;;
if val : value then ret y else ret n
| Bhalt => done
end.

In particular, I'm still not completely happy with how all the different parts
fit together in run.
Fixpoint denote_block (b : block B) : itree E B :=
match b with
| bbi i b =>
denote_instr i ;; denote_block b
| bbb b =>
denote_branch b
end.

*)
Definition denote_b : bks A B -> ktree E A B :=
fun bs a => denote_block (bs a).

End with_labels.

(* A denotation of an asm program can be viewed as a circuit/diagram
where wires correspond to jumps/program links.

It is therefore denoted as a [den] term *)

(* Denotation of [asm] *)
Definition denote_asm {A B} : asm A B -> ktree E A B :=
fun s => loop (denote_b (code s)).

End with_effect.
End Semantics.

(* Interpretation ----------------------------------------------------------- *)

Expand Down Expand Up @@ -163,13 +192,3 @@ Instance RelDec_string : RelDec (@eq string) :=

Instance RelDec_value : RelDec (@eq value) := { rel_dec := Nat.eqb }.

(* SAZ: Is this the nicest way to present this? *)
Definition run (p: program) : itree emptyE _ :=
let p1 := interp1 interpret_Memory _ (denote_program p) in
let p2 := interp1 interpret_Locals _ p1 in
let p3 := run_env _ p2 empty in
let p4 := run_env _ p3 empty in
p4.

(* SAZ: Note: we should be able to prove that run produces trees that are equivalent
to run' where run' interprets memory and locals in a different order *)
Loading