Skip to content

Commit b4fb863

Browse files
committed
More work on in-logic compilation
1 parent c5c0c98 commit b4fb863

File tree

63 files changed

+379
-647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+379
-647
lines changed

compiler/backend/ag32/proofs/ag32_configProofScript.sml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,63 @@ val ag32_compile_correct =
7979
|> DISCH_ALL
8080
|> curry save_thm"ag32_compile_correct";
8181

82+
Theorem get_shmem_info_LENGTH:
83+
∀xs c l1 l2.
84+
get_shmem_info xs c l1 l2 = (t1,t2) ∧ LENGTH l1 = LENGTH l2 ⇒
85+
LENGTH t1 = LENGTH t2
86+
Proof
87+
ho_match_mp_tac lab_to_targetTheory.get_shmem_info_ind \\ rw []
88+
\\ gvs [lab_to_targetTheory.get_shmem_info_def]
89+
\\ pairarg_tac \\ gvs []
90+
QED
91+
92+
Triviality IMP_EVERY_list_add_if_fresh:
93+
∀xs x p. p x ∧ EVERY p xs ⇒ EVERY p (list_add_if_fresh x xs)
94+
Proof
95+
Induct \\ gvs [lab_to_targetTheory.list_add_if_fresh_def] \\ rw []
96+
QED
97+
98+
Theorem find_ffi_names_ExtCall:
99+
∀xs. EVERY (λx. ∃i. ExtCall i = x) (find_ffi_names xs)
100+
Proof
101+
ho_match_mp_tac lab_to_targetTheory.find_ffi_names_ind
102+
\\ rpt strip_tac
103+
\\ asm_rewrite_tac [lab_to_targetTheory.find_ffi_names_def,EVERY_DEF]
104+
\\ Cases_on ‘x’ \\ gvs []
105+
\\ Cases_on ‘a’ \\ gvs []
106+
\\ irule IMP_EVERY_list_add_if_fresh \\ gvs []
107+
QED
108+
109+
Theorem MAP_ExtCall_ffinames:
110+
∀xs.
111+
EVERY (λx. ∃i. ExtCall i = x) xs ⇒
112+
xs = MAP ExtCall (ffinames_to_string_list xs)
113+
Proof
114+
Induct \\ gvs [backendTheory.ffinames_to_string_list_def]
115+
\\ Cases \\ gvs [backendTheory.ffinames_to_string_list_def]
116+
QED
117+
118+
Theorem compile_imp_ffi_names:
119+
backend$compile c p = SOME (b,d,c1) ∧
120+
c1.lab_conf.shmem_extra = [] ∧ f ≠ [] ∧
121+
c.lab_conf.ffi_names = NONE
122+
ffinames_to_string_list (the [] c1.lab_conf.ffi_names) = f ⇒
123+
c1.lab_conf.ffi_names = SOME (MAP ExtCall f)
124+
Proof
125+
Cases_on ‘c1.lab_conf.ffi_names’
126+
\\ gvs [libTheory.the_def,backendTheory.ffinames_to_string_list_def]
127+
\\ gvs [backendTheory.compile_def]
128+
\\ rpt (pairarg_tac \\ gvs [])
129+
\\ gvs [oneline backendTheory.attach_bitmaps_def, AllCaseEqs()]
130+
\\ strip_tac \\ gvs []
131+
\\ gvs [lab_to_targetTheory.compile_def]
132+
\\ gvs [lab_to_targetTheory.compile_lab_def]
133+
\\ rpt (pairarg_tac \\ gvs [])
134+
\\ gvs [AllCaseEqs()]
135+
\\ rpt (pairarg_tac \\ gvs [])
136+
\\ drule get_shmem_info_LENGTH \\ gvs [] \\ rw []
137+
\\ irule MAP_ExtCall_ffinames
138+
\\ gvs [find_ffi_names_ExtCall]
139+
QED
140+
82141
val _ = export_theory();

compiler/backend/cv_compute/backend_asmScript.sml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ Definition attach_bitmaps_def:
217217
let syms = MAP (λ(n,p,l). (lookup_any n names «NOTFOUND»,p,l))
218218
c'.inc_sec_pos_len
219219
in
220-
SOME (code_bytes,data,ffi_names,syms,encode_backend_config $ c with
220+
SOME (code_bytes, LENGTH code_bytes,
221+
data, LENGTH data,
222+
ffi_names, LENGTH c'.inc_shmem_extra,
223+
syms, encode_backend_config $ c with
221224
<| inc_lab_conf := c'; inc_symbols := syms |>)) ∧
222225
attach_bitmaps names c bm NONE = NONE
223226
End
@@ -308,12 +311,16 @@ End
308311
*----------------------------------------------------------------*)
309312

310313
Theorem from_lab_thm[local]:
311-
from_lab asm_conf c names p bm = SOME (bytes,bm1,ffi_names,syms,conf_str) ⇒
314+
from_lab asm_conf c names p bm =
315+
SOME (bytes,bytes_len,bm1,bm1_len,ffi_names,shmem_len,syms,conf_str) ⇒
312316
∃c1.
313317
backend$from_lab (inc_config_to_config asm_conf c) names p bm =
314318
SOME (bytes,bm1,c1) ∧
315319
ffi_names = ffinames_to_string_list (the [] c1.lab_conf.ffi_names) ∧
316320
syms = c1.symbols ∧
321+
LENGTH bytes = bytes_len ∧
322+
LENGTH bm1 = bm1_len ∧
323+
LENGTH c1.lab_conf.shmem_extra = shmem_len ∧
317324
conf_str = encode_backend_config (config_to_inc_config c1)
318325
Proof
319326
gvs [from_lab_def,backendTheory.from_lab_def]
@@ -333,11 +340,15 @@ Proof
333340
QED
334341

335342
Theorem from_stack_thm[local]:
336-
from_stack asm_conf c names p bm = SOME (bytes,bm1,ffi_names,syms,conf_str) ⇒
343+
from_stack asm_conf c names p bm =
344+
SOME (bytes,bytes_len,bm1,bm1_len,ffi_names,shmem_len,syms,conf_str) ⇒
337345
∃c1.
338346
backend$from_stack (inc_config_to_config asm_conf c) names p bm = SOME (bytes,bm1,c1) ∧
339347
ffi_names = ffinames_to_string_list (the [] c1.lab_conf.ffi_names) ∧
340348
syms = c1.symbols ∧
349+
LENGTH bytes = bytes_len ∧
350+
LENGTH bm1 = bm1_len ∧
351+
LENGTH c1.lab_conf.shmem_extra = shmem_len ∧
341352
conf_str = encode_backend_config (config_to_inc_config c1)
342353
Proof
343354
gvs [from_stack_def,backendTheory.from_stack_def] \\ rw []
@@ -367,11 +378,15 @@ Proof
367378
QED
368379

369380
Theorem from_word_0_thm[local]:
370-
from_word_0 asm_conf (c,p,names) = SOME (bytes,bm,ffi_names,syms,conf_str) ⇒
381+
from_word_0 asm_conf (c,p,names) =
382+
SOME (bytes,bytes_len,bm1,bm1_len,ffi_names,shmem_len,syms,conf_str) ⇒
371383
∃c1.
372-
backend$from_word_0 (inc_config_to_config asm_conf c) names p = SOME (bytes,bm,c1) ∧
384+
backend$from_word_0 (inc_config_to_config asm_conf c) names p = SOME (bytes,bm1,c1) ∧
373385
ffi_names = ffinames_to_string_list (the [] c1.lab_conf.ffi_names) ∧
374386
syms = c1.symbols ∧
387+
LENGTH bytes = bytes_len ∧
388+
LENGTH bm1 = bm1_len ∧
389+
LENGTH c1.lab_conf.shmem_extra = shmem_len ∧
375390
conf_str = encode_backend_config (config_to_inc_config c1)
376391
Proof
377392
gvs [from_word_0_def,from_word_def,AllCaseEqs()] \\ strip_tac \\ gvs []
@@ -474,11 +489,15 @@ QED
474489

475490
Theorem compile_cake_thm:
476491
∀asm_conf:'a asm_config.
477-
compile_cake asm_conf c p = SOME (bytes,bm,ffi_names,syms,conf_str) ⇒
492+
compile_cake asm_conf c p =
493+
SOME (bytes,bytes_len,bm,bm_len,ffi_names,shmem_len,syms,conf_str) ⇒
478494
∃c1.
479495
backend$compile (inc_config_to_config asm_conf c) p = SOME (bytes,bm,c1) ∧
480496
ffi_names = ffinames_to_string_list (the [] c1.lab_conf.ffi_names) ∧
481497
syms = c1.symbols ∧
498+
LENGTH bytes = bytes_len ∧
499+
LENGTH bm = bm_len ∧
500+
LENGTH c1.lab_conf.shmem_extra = shmem_len ∧
482501
conf_str = encode_backend_config (config_to_inc_config c1)
483502
Proof
484503
rw [compile_cake_def]

compiler/backend/proofs/backendProofScript.sml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2706,7 +2706,7 @@ Proof
27062706
\\ gs []
27072707
QED
27082708

2709-
Triviality compile_asm_config_eq:
2709+
Theorem compile_asm_config_eq:
27102710
compile (c : 'a config) prog = SOME (b,bm,c') ==>
27112711
c'.lab_conf.asm_conf = c.lab_conf.asm_conf
27122712
Proof

compiler/bootstrap/compilation/ag32/32/Holmakefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARCH = ag32
22
WORD_SIZE = 32
3-
INCLUDES = $(CAKEMLDIR)/semantics $(CAKEMLDIR)/basis ../../../..\
3+
INCLUDES = $(CAKEMLDIR)/semantics $(CAKEMLDIR)/basis $(CAKEMLDIR)/cv_translator ../../../..\
44
../../../../encoders/asm ../../../../encoders/$(ARCH)\
55
../../../../backend/$(ARCH) ../../../translation
66

@@ -18,3 +18,7 @@ cake-$(ARCH)-$(WORD_SIZE).tar.gz: cake.S basis_ffi.c Makefile
1818
tar -chzf $@ --transform='s|^|cake-$(ARCH)-$(WORD_SIZE)/|' cake.S basis_ffi.c Makefile
1919

2020
EXTRA_CLEANS = cake.S cake-$(ARCH)-$(WORD_SIZE).tar.gz
21+
22+
ifdef POLY
23+
HOLHEAP = $(CAKEMLDIR)/cv_translator/cake_compile_heap
24+
endif

compiler/bootstrap/compilation/ag32/32/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,3 @@ library, as a thin wrapper around the relevant system calls.
1313
[proofs](proofs):
1414
This directory contains the end-to-end correctness theorem for the
1515
32-bit version of the CakeML compiler.
16-
17-
[to_dataBootstrapScript.sml](to_dataBootstrapScript.sml):
18-
Evaluate the 32-bit version of the compiler down to a DataLang
19-
program.
20-
21-
[to_lab_ag32BootstrapScript.sml](to_lab_ag32BootstrapScript.sml):
22-
Evaluate the 32-bit version of the compiler down to a LabLang
23-
program (an assembly program).

compiler/bootstrap/compilation/ag32/32/ag32BootstrapScript.sml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
Evaluate the final part of the 32-bit version of the compiler
33
into machine code for ag32, i.e. the Silver ISA.
44
*)
5-
open preamble to_lab_ag32BootstrapTheory compilationLib
5+
open preamble compiler32ProgTheory eval_cake_compile_ag32Lib;
66

77
val _ = new_theory "ag32Bootstrap";
88

9-
val () = ml_translatorLib.reset_translation();
10-
11-
val bootstrap_thm =
12-
compilationLib.cbv_to_bytes_ag32
13-
stack_to_lab_thm lab_prog_def
14-
"code" "data" "config" "cake.S";
15-
16-
val cake_compiled = save_thm("cake_compiled", bootstrap_thm);
9+
Theorem compiler32_compiled =
10+
eval_cake_compile_ag32 "" compiler32_prog_def "cake.S";
1711

1812
val _ = export_theory();

compiler/bootstrap/compilation/ag32/32/proofs/ag32BootstrapProofScript.sml

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ open preamble
99

1010
val _ = new_theory"ag32BootstrapProof";
1111

12-
val with_clos_conf_simp = prove(
13-
``(mc_init_ok (ag32_backend_config with <| clos_conf := z ; bvl_conf updated_by
12+
Triviality with_clos_conf_simp:
13+
(mc_init_ok (ag32_backend_config with <| clos_conf := z ; bvl_conf updated_by
1414
(λc. c with <|inline_size_limit := t1; exp_cut := t2|>) |>) =
1515
mc_init_ok ag32_backend_config) /\
1616
(x.max_app <> 0 /\ (case x.known_conf of NONE => T | SOME k => k.val_approx_spt = LN) ==>
1717
(backend_config_ok (ag32_backend_config with clos_conf := x) =
18-
backend_config_ok ag32_backend_config))``,
18+
backend_config_ok ag32_backend_config))
19+
Proof
1920
fs [mc_init_ok_def,FUN_EQ_THM,backend_config_ok_def]
20-
\\ rw [] \\ eq_tac \\ rw [] \\ EVAL_TAC);
21+
\\ rw [] \\ eq_tac \\ rw [] \\ EVAL_TAC
22+
QED
2123

22-
Overload cake_config = “ag32Bootstrap$config”;
24+
Overload cake_config = “ag32Bootstrap$info”;
2325

2426
Definition compiler_instance_def:
2527
compiler_instance =
@@ -43,7 +45,10 @@ QED
4345
Theorem cake_config_lab_conf_asm_conf:
4446
cake_config.lab_conf.asm_conf = ag32_config
4547
Proof
46-
once_rewrite_tac [ag32BootstrapTheory.config_def] \\ EVAL_TAC
48+
assume_tac $ cj 1 compiler32_compiled
49+
\\ drule compile_asm_config_eq
50+
\\ gvs [backendTheory.set_oracle_def]
51+
\\ strip_tac \\ EVAL_TAC
4752
QED
4853

4954
val cake_io_events_def = new_specification("cake_io_events_def",["cake_io_events"],
@@ -58,30 +63,38 @@ val cake_io_events_def = new_specification("cake_io_events_def",["cake_io_events
5863
val (cake_sem,cake_output) = cake_io_events_def |> SPEC_ALL |> UNDISCH |> CONJ_PAIR
5964
val (cake_not_fail,cake_sem_sing) = MATCH_MP semantics_prog_Terminate_not_Fail cake_sem |> CONJ_PAIR
6065

61-
val ffi_names =
62-
``config.lab_conf.ffi_names``
63-
|> (REWRITE_CONV[ag32BootstrapTheory.config_def] THENC EVAL);
64-
65-
val LENGTH_code =
66-
``LENGTH code``
67-
|> (REWRITE_CONV[ag32BootstrapTheory.code_def] THENC listLib.LENGTH_CONV);
66+
Theorem extcalls_ffi_names:
67+
extcalls cake_config.lab_conf.ffi_names = ffis
68+
Proof
69+
rewrite_tac [compiler32_compiled]
70+
\\ qspec_tac (‘cake_config.lab_conf.ffi_names’,‘xs’) \\ Cases
71+
\\ gvs [extcalls_def,backendTheory.ffinames_to_string_list_def,
72+
libTheory.the_def]
73+
\\ Induct_on ‘x’ \\ gvs []
74+
\\ gvs [extcalls_def,backendTheory.ffinames_to_string_list_def,
75+
libTheory.the_def]
76+
\\ Cases
77+
\\ gvs [extcalls_def,backendTheory.ffinames_to_string_list_def,
78+
libTheory.the_def]
79+
QED
6880

69-
val LENGTH_data =
70-
``LENGTH data``
71-
|> (REWRITE_CONV[ag32BootstrapTheory.data_def] THENC listLib.LENGTH_CONV);
81+
val ffis = ffis_def |> CONV_RULE (RAND_CONV EVAL);
82+
val ffi_names = extcalls_ffi_names |> SRULE [ffis]
7283

73-
val shmem =
74-
``config.lab_conf.shmem_extra``
75-
|> (REWRITE_CONV[ag32BootstrapTheory.config_def] THENC EVAL);
84+
val LENGTH_code = “LENGTH code” |> SCONV [compiler32_compiled];
85+
val LENGTH_data = “LENGTH data” |> SCONV [compiler32_compiled];
86+
val shmem = “info.lab_conf.shmem_extra” |> SCONV [compiler32_compiled];
7687

7788
Overload cake_machine_config =
78-
``ag32_machine_config (extcalls config.lab_conf.ffi_names) (LENGTH code) (LENGTH data)``
89+
ag32_machine_config (extcalls info.lab_conf.ffi_names) (LENGTH code) (LENGTH data)
7990

8091
Theorem target_state_rel_cake_start_asm_state:
8192
SUM (MAP strlen cl) + LENGTH cl ≤ cline_size ∧
8293
LENGTH inp ≤ stdin_size ∧
83-
is_ag32_init_state (init_memory code data (extcalls config.lab_conf.ffi_names) (cl,inp)) ms ⇒
84-
∃n. target_state_rel ag32_target (init_asm_state code data (extcalls config.lab_conf.ffi_names) (cl,inp)) (FUNPOW Next n ms) ∧
94+
is_ag32_init_state (init_memory code data (extcalls info.lab_conf.ffi_names) (cl,inp)) ms ⇒
95+
∃n. target_state_rel ag32_target
96+
(init_asm_state code data (extcalls info.lab_conf.ffi_names) (cl,inp))
97+
(FUNPOW Next n ms) ∧
8598
((FUNPOW Next n ms).io_events = ms.io_events) ∧
8699
(∀x. x ∉ (ag32_startup_addresses) ⇒
87100
((FUNPOW Next n ms).MEM x = ms.MEM x))
@@ -90,7 +103,7 @@ Proof
90103
\\ drule (GEN_ALL init_asm_state_RTC_asm_step)
91104
\\ disch_then drule
92105
\\ simp_tac std_ss []
93-
\\ disch_then(qspecl_then[`code`,`data`,`extcalls config.lab_conf.ffi_names`]mp_tac)
106+
\\ disch_then(qspecl_then[`code`,`data`,`extcalls info.lab_conf.ffi_names`]mp_tac)
94107
\\ impl_tac >- ( EVAL_TAC>> fs[ffi_names,LENGTH_data,LENGTH_code,extcalls_def])
95108
\\ strip_tac
96109
\\ drule (GEN_ALL target_state_rel_ag32_init)
@@ -107,11 +120,12 @@ val cake_startup_clock_def =
107120
|> SIMP_RULE bool_ss [GSYM RIGHT_EXISTS_IMP_THM,SKOLEM_THM]);
108121

109122
val compile_correct_applied =
110-
MATCH_MP compile_correct_eval cake_compiled
111-
|> SIMP_RULE(srw_ss())[LET_THM,ml_progTheory.init_state_env_thm,GSYM AND_IMP_INTRO,
112-
with_clos_conf_simp]
123+
MATCH_MP compile_correct_eval (cj 1 compiler32_compiled)
124+
|> SIMP_RULE(srw_ss())[LET_THM,ml_progTheory.init_state_env_thm,
125+
GSYM AND_IMP_INTRO,with_clos_conf_simp]
113126
|> Q.INST [‘ev’|->‘SOME compiler_instance’]
114-
|> SIMP_RULE (srw_ss()) [add_eval_state_def,opt_eval_config_wf_def,compiler_instance_lemma]
127+
|> SIMP_RULE (srw_ss()) [add_eval_state_def,opt_eval_config_wf_def,
128+
compiler_instance_lemma]
115129
|> C MATCH_MP cake_not_fail
116130
|> C MATCH_MP ag32_backend_config_ok
117131
|> REWRITE_RULE[cake_sem_sing,AND_IMP_INTRO]
@@ -131,16 +145,25 @@ Theorem cake_compiled_thm =
131145
Theorem cake_installed:
132146
SUM (MAP strlen cl) + LENGTH cl ≤ cline_size ∧
133147
LENGTH inp ≤ stdin_size ∧
134-
is_ag32_init_state (init_memory code data (extcalls config.lab_conf.ffi_names) (cl,inp)) ms0 ⇒
135-
installed code 0 data 0 config.lab_conf.ffi_names
148+
is_ag32_init_state (init_memory code data
149+
(extcalls info.lab_conf.ffi_names) (cl,inp)) ms0 ⇒
150+
installed code 0 data 0 info.lab_conf.ffi_names
136151
(heap_regs ag32_backend_config.stack_conf.reg_names)
137-
(cake_machine_config) config.lab_conf.shmem_extra
152+
(cake_machine_config) info.lab_conf.shmem_extra
138153
(FUNPOW Next (cake_startup_clock ms0 inp cl) ms0)
139154
Proof
140155
rewrite_tac[ffi_names, extcalls_def, shmem]
141156
\\ strip_tac
142157
\\ qmatch_asmsub_abbrev_tac ‘init_memory _ _ ff’
143-
\\ ‘^(ffi_names |> concl |> rand |> rand) = MAP ExtCall ff’ by simp [Abbr‘ff’]
158+
\\ qmatch_goalsub_abbrev_tac ‘installed _ _ _ _ dd’
159+
\\ ‘dd = SOME (MAP ExtCall ff)’ by
160+
(unabbrev_all_tac
161+
\\ assume_tac (cj 1 compiler32_compiled)
162+
\\ drule ag32_configProofTheory.compile_imp_ffi_names
163+
\\ gvs [compiler32_compiled]
164+
\\ gvs [GSYM compiler32_compiled,ffis]
165+
\\ simp [backendTheory.set_oracle_def,
166+
ag32_configTheory.ag32_backend_config_def])
144167
\\ asm_rewrite_tac []
145168
\\ irule ag32_installed
146169
\\ unabbrev_all_tac
@@ -200,7 +223,8 @@ Proof
200223
QED
201224

202225
Theorem FST_ALOOKUP_fastForwardFD_infds:
203-
OPTION_MAP FST (ALOOKUP (fastForwardFD fs fd).infds fd') = OPTION_MAP FST (ALOOKUP fs.infds fd')
226+
OPTION_MAP FST (ALOOKUP (fastForwardFD fs fd).infds fd') =
227+
OPTION_MAP FST (ALOOKUP fs.infds fd')
204228
Proof
205229
rw[fsFFIPropsTheory.fastForwardFD_def]
206230
\\ Cases_on`ALOOKUP fs.infds fd` \\ simp[libTheory.the_def]
@@ -212,7 +236,8 @@ Proof
212236
QED
213237

214238
Theorem FST_ALOOKUP_add_stdo_infds:
215-
OPTION_MAP FST (ALOOKUP (add_stdo fd nm fs out).infds fd') = OPTION_MAP FST (ALOOKUP fs.infds fd')
239+
OPTION_MAP FST (ALOOKUP (add_stdo fd nm fs out).infds fd') =
240+
OPTION_MAP FST (ALOOKUP fs.infds fd')
216241
Proof
217242
mp_tac TextIOProofTheory.add_stdo_MAP_FST_infds
218243
\\ strip_tac
@@ -501,7 +526,7 @@ QED
501526
Theorem cake_ag32_next:
502527
SUM (MAP strlen cl) + LENGTH cl ≤ cline_size ∧ wfcl cl ∧
503528
LENGTH inp ≤ stdin_size ∧
504-
is_ag32_init_state (init_memory code data (extcalls config.lab_conf.ffi_names) (cl,inp)) ms0
529+
is_ag32_init_state (init_memory code data (extcalls info.lab_conf.ffi_names) (cl,inp)) ms0
505530
506531
∃k1. ∀k. k1 ≤ k ⇒
507532
let ms = FUNPOW Next k ms0 in

0 commit comments

Comments
 (0)