Skip to content

Commit ab6d5e9

Browse files
committed
Issue #196: excessive proof-checking times in .v files generated by clightgen
The check that "build_composite_env composites = OK (make_composite_env composites)" is taking time exponential on the number of struct/union definitions, at least on the example provided in #196. The solution implemented in this commit is to use computational reflection more efficiently, just to check that "build_composite_env composites" is of the form "OK _". From there, a new function Clightdefs.mkprogram produces the appropriate Clight.program without additional computation.
1 parent 0aa08f5 commit ab6d5e9

3 files changed

Lines changed: 34 additions & 13 deletions

File tree

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Usability:
2424
Bug fixing:
2525

2626
- Issue #179: clightgen produces wrong output for "switch" statements.
27+
- Issue #196: excessive proof times in .v files produced by clightgen.
2728
- Do not generate code for functions with "inline" specifier that are
2829
neither static nor extern, as per ISO C99.
2930
- Some line number information was missing for some goto labels and

exportclight/Clightdefs.v

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,27 @@ Definition talignas (n: N) (ty: type) :=
6565
Definition tvolatile_alignas (n: N) (ty: type) :=
6666
tattr {| attr_volatile := true; attr_alignas := Some n |} ty.
6767

68-
Definition make_composite_env (comps: list composite_definition): composite_env :=
69-
match build_composite_env comps with
70-
| OK e => e
71-
| Error _ => PTree.empty _
72-
end.
68+
Definition wf_composites (types: list composite_definition) : Prop :=
69+
match build_composite_env types with OK _ => True | Error _ => False end.
70+
71+
Definition build_composite_env' (types: list composite_definition)
72+
(WF: wf_composites types)
73+
: { ce | build_composite_env types = OK ce }.
74+
Proof.
75+
revert WF. unfold wf_composites. case (build_composite_env types); intros.
76+
- exists c; reflexivity.
77+
- contradiction.
78+
Defined.
79+
80+
Definition mkprogram (types: list composite_definition)
81+
(defs: list (ident * globdef fundef type))
82+
(public: list ident)
83+
(main: ident)
84+
(WF: wf_composites types) : Clight.program :=
85+
let (ce, EQ) := build_composite_env' types WF in
86+
{| prog_defs := defs;
87+
prog_public := public;
88+
prog_main := main;
89+
prog_types := types;
90+
prog_comp_env := ce;
91+
prog_comp_env_eq := EQ |}.

exportclight/ExportClight.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,14 @@ let print_program p prog =
550550
fprintf p "Definition composites : list composite_definition :=@ ";
551551
print_list print_composite_definition p prog.prog_types;
552552
fprintf p ".@ @ ";
553-
fprintf p "Definition prog : Clight.program := {|@ ";
554-
fprintf p "prog_defs :=@ %a;@ " (print_list print_ident_globdef) prog.Ctypes.prog_defs;
555-
fprintf p "prog_public :=@ %a;@ " (print_list ident) prog.Ctypes.prog_public;
556-
fprintf p "prog_main := %a;@ " ident prog.Ctypes.prog_main;
557-
fprintf p "prog_types := composites;@ ";
558-
fprintf p "prog_comp_env := make_composite_env composites;@ ";
559-
fprintf p "prog_comp_env_eq := refl_equal _@ ";
560-
fprintf p "|}.@ ";
553+
fprintf p "Definition global_definitions :=@ ";
554+
print_list print_ident_globdef p prog.Ctypes.prog_defs;
555+
fprintf p ".@ @ ";
556+
fprintf p "Definition public_idents :=@ ";
557+
print_list ident p prog.Ctypes.prog_public;
558+
fprintf p ".@ @ ";
559+
fprintf p "Definition prog : Clight.program := @ ";
560+
fprintf p " mkprogram composites global_definitions public_idents %a Logic.I.@ @ "
561+
ident prog.Ctypes.prog_main;
561562
print_assertions p;
562563
fprintf p "@]@."

0 commit comments

Comments
 (0)