Skip to content

Commit 9068e5b

Browse files
authored
Merge pull request #1064 from MetaCoq/unsafe-and-ewcbvevalnamed
Unsafe and ewcbvevalnamed
2 parents 2cbbd67 + e8e5ede commit 9068e5b

File tree

4 files changed

+217
-83
lines changed

4 files changed

+217
-83
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ifeq '$(METACOQ_CONFIG)' 'local'
1212
export OCAMLPATH
1313
endif
1414

15-
.PHONY: printconf all utils template-coq pcuic erasure install uninstall html clean mrproper .merlin test-suite translations quotation
15+
.PHONY: printconf all utils template-coq pcuic erasure install uninstall html clean mrproper safechecker-plugin .merlin test-suite translations quotation
1616

1717
printconf:
1818
ifeq '$(METACOQ_CONFIG)' 'local'
@@ -26,7 +26,7 @@ else
2626
endif
2727
endif
2828

29-
install: all
29+
install: all
3030
$(MAKE) -C utils install
3131
$(MAKE) -C common install
3232
$(MAKE) -C template-coq install

erasure-plugin/src/g_metacoq_erasure.mlg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ let default_config =
5959

6060
let make_erasure_config config =
6161
let open Erasure0 in
62-
{ enable_unsafe = config.unsafe;
62+
{ enable_unsafe = if config.unsafe then all_unsafe_passes else no_unsafe_passes ;
6363
enable_typed_erasure = config.typed;
6464
enable_fast_remove_params = config.fast;
6565
dearging_config = default_dearging_config;
6666
inductives_mapping = [];
67-
inlining = Kernames.KernameSet.empty }
67+
inlined_constants = Kernames.KernameSet.empty }
6868

6969
let time_opt config str fn arg =
7070
if config.time then

erasure-plugin/theories/Erasure.v

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,65 @@ Import EWcbvEval.
3030

3131
Local Obligation Tactic := program_simpl.
3232

33+
Record unsafe_passes :=
34+
{ fix_to_lazy : bool;
35+
reorder_constructors : bool;
36+
inlining : bool;
37+
unboxing : bool;
38+
betared : bool }.
39+
3340
Record erasure_configuration := {
34-
enable_unsafe : bool;
41+
enable_unsafe : unsafe_passes;
3542
enable_typed_erasure : bool;
3643
enable_fast_remove_params : bool;
3744
dearging_config : dearging_config;
3845
inductives_mapping : EReorderCstrs.inductives_mapping;
39-
inlining : KernameSet.t
46+
inlined_constants : KernameSet.t
4047
}.
4148

4249
Definition default_dearging_config :=
4350
{| overridden_masks := fun _ => None;
4451
do_trim_const_masks := true;
4552
do_trim_ctor_masks := false |}.
4653

47-
(* This runs the cofix -> fix translation which is not entirely verified yet *)
54+
55+
Definition make_unsafe_passes b :=
56+
{| fix_to_lazy := b;
57+
reorder_constructors := b;
58+
inlining := b;
59+
unboxing := b;
60+
betared := b |}.
61+
62+
Definition no_unsafe_passes := make_unsafe_passes false.
63+
Definition all_unsafe_passes := make_unsafe_passes true.
64+
65+
(* This runs the cofix -> fix/lazy translation as well as inlining and
66+
beta-redex simplification, which are not verified. It does not change
67+
representation by reordering constructors or unboxing. *)
68+
69+
Definition default_unsafe_passes :=
70+
{| fix_to_lazy := true;
71+
reorder_constructors := false;
72+
inlining := true;
73+
unboxing := false;
74+
betared := true |}.
75+
4876
Definition default_erasure_config :=
49-
{| enable_unsafe := true;
77+
{| enable_unsafe := default_unsafe_passes;
5078
dearging_config := default_dearging_config;
5179
enable_typed_erasure := true;
5280
enable_fast_remove_params := true;
5381
inductives_mapping := [];
54-
inlining := KernameSet.empty |}.
82+
inlined_constants := KernameSet.empty |}.
5583

5684
(* This runs only the verified phases without the typed erasure and "fast" remove params *)
5785
Definition safe_erasure_config :=
58-
{| enable_unsafe := false;
86+
{| enable_unsafe := no_unsafe_passes;
5987
enable_typed_erasure := false;
6088
enable_fast_remove_params := false;
6189
dearging_config := default_dearging_config;
6290
inductives_mapping := [];
63-
inlining := KernameSet.empty |}.
91+
inlined_constants := KernameSet.empty |}.
6492

6593
Axiom assume_welltyped_template_program_expansion :
6694
forall p (wtp : ∥ wt_template_program_env p ∥),
@@ -96,22 +124,40 @@ Definition final_wcbv_flags := {|
96124
with_constructor_as_block := true |}.
97125

98126
Program Definition optional_unsafe_transforms econf :=
127+
let passes := econf.(enable_unsafe) in
99128
let efl := EConstructorsAsBlocks.switch_cstr_as_blocks
100129
(EInlineProjections.disable_projections_env_flag (ERemoveParams.switch_no_params EWellformed.all_env_flags)) in
101-
ETransform.optional_self_transform econf.(enable_unsafe)
130+
ETransform.optional_self_transform passes.(fix_to_lazy)
102131
((* Rebuild the efficient lookup table *)
103132
rebuild_wf_env_transform (efl := efl) false false ▷
104133
(* Coinductives & cofixpoints are translated to inductive types and thunked fixpoints *)
105134
coinductive_to_inductive_transformation efl
106-
(has_app := eq_refl) (has_box := eq_refl) (has_rel := eq_refl) (has_pars := eq_refl) (has_cstrblocks := eq_refl) ▷
107-
reorder_cstrs_transformation efl final_wcbv_flags econf.(inductives_mapping) ▷
108-
rebuild_wf_env_transform (efl := efl) false false ▷
109-
unbox_transformation efl final_wcbv_flags ▷
110-
inline_transformation efl final_wcbv_flags econf.(inlining) ▷
111-
forget_inlining_info_transformation efl final_wcbv_flags ▷
112-
(* Heuristically do it twice for more beta-normal terms *)
113-
betared_transformation efl final_wcbv_flags ▷
114-
betared_transformation efl final_wcbv_flags).
135+
(has_app := eq_refl) (has_box := eq_refl) (has_rel := eq_refl) (has_pars := eq_refl) (has_cstrblocks := eq_refl)) ▷
136+
ETransform.optional_self_transform passes.(reorder_constructors)
137+
(reorder_cstrs_transformation efl final_wcbv_flags econf.(inductives_mapping)) ▷
138+
ETransform.optional_self_transform passes.(unboxing)
139+
(rebuild_wf_env_transform (efl := efl) false false ▷
140+
unbox_transformation efl final_wcbv_flags) ▷
141+
ETransform.optional_self_transform passes.(inlining)
142+
(inline_transformation efl final_wcbv_flags econf.(inlined_constants) ▷
143+
forget_inlining_info_transformation efl final_wcbv_flags) ▷
144+
(* Heuristically do it twice for more beta-normal terms *)
145+
ETransform.optional_self_transform passes.(betared)
146+
(betared_transformation efl final_wcbv_flags ▷
147+
betared_transformation efl final_wcbv_flags).
148+
149+
Next Obligation.
150+
destruct (enable_unsafe econf) as [[] [] [] [] []]; cbn in * => //; intuition auto.
151+
Qed.
152+
Next Obligation.
153+
destruct (enable_unsafe econf) as [[] [] [] [] []]; cbn in * => //; intuition auto.
154+
Qed.
155+
Next Obligation.
156+
destruct (enable_unsafe econf) as [[] [] [] [] []]; cbn in * => //; intuition auto.
157+
Qed.
158+
Next Obligation.
159+
destruct (enable_unsafe econf) as [[] [] [] [] []]; cbn in * => //; intuition auto.
160+
Qed.
115161

116162
Program Definition verified_lambdabox_pipeline {guard : abstract_guard_impl}
117163
(efl := EWellformed.all_env_flags)
@@ -266,7 +312,7 @@ Qed.
266312

267313
Next Obligation.
268314
unfold optional_unsafe_transforms. cbn.
269-
destruct enable_unsafe => //.
315+
destruct enable_unsafe as [[] ? ? ? ?]=> //.
270316
Qed.
271317

272318
Local Obligation Tactic := intros; eauto.
@@ -365,7 +411,9 @@ Next Obligation.
365411
cbn in H. split; cbn; intuition eauto.
366412
Qed.
367413
Next Obligation.
368-
cbn in H. unfold optional_unsafe_transforms. destruct enable_unsafe => //.
414+
cbn in H. unfold optional_unsafe_transforms.
415+
cbn.
416+
destruct enable_unsafe as [[] ? ? ? ?]=> //.
369417
Qed.
370418
Next Obligation.
371419
cbn in H. split; cbn; intuition eauto.
@@ -409,8 +457,8 @@ Program Definition run_erase_program {guard : abstract_guard_impl} econf :=
409457
else run (erasure_pipeline ▷ (optional_unsafe_transforms econf)).
410458
Next Obligation.
411459
Proof.
412-
unfold optional_unsafe_transforms.
413-
destruct enable_unsafe => //.
460+
unfold optional_unsafe_transforms; cbn.
461+
destruct enable_unsafe as [[] ? ? ? ?]=> //.
414462
Qed.
415463

416464
Program Definition erase_and_print_template_program econf (p : Ast.Env.program) : string :=
@@ -425,23 +473,23 @@ Next Obligation.
425473
Qed.
426474

427475
Definition erasure_fast_config :=
428-
{| enable_unsafe := false;
476+
{| enable_unsafe := no_unsafe_passes;
429477
dearging_config := default_dearging_config;
430478
enable_typed_erasure := false;
431479
enable_fast_remove_params := true;
432480
inductives_mapping := [];
433-
inlining := KernameSet.empty |}.
481+
inlined_constants := KernameSet.empty |}.
434482

435483
Program Definition erase_fast_and_print_template_program (p : Ast.Env.program) : string :=
436484
erase_and_print_template_program erasure_fast_config p.
437485

438486
Definition typed_erasure_config :=
439-
{| enable_unsafe := false;
487+
{| enable_unsafe := no_unsafe_passes;
440488
dearging_config := default_dearging_config;
441489
enable_typed_erasure := true;
442490
enable_fast_remove_params := true;
443491
inductives_mapping := [];
444-
inlining := KernameSet.empty |}.
492+
inlined_constants := KernameSet.empty |}.
445493

446494
(* Parameterized by a configuration for dearging, allowing to, e.g., override masks. *)
447495
Program Definition typed_erase_and_print_template_program (p : Ast.Env.program)

0 commit comments

Comments
 (0)