Skip to content

Commit 2cbbd67

Browse files
authored
Implement a general Show typeclass in MetaCoq.Utils (#1063)
* Implement a general Show typeclass in MetaCoq.Utils * Fix dependencies of new template-coq plugin
1 parent 260ce0d commit 2cbbd67

File tree

11 files changed

+99
-40
lines changed

11 files changed

+99
-40
lines changed

common/theories/Primitive.v

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,3 @@ Variant prim_tag :=
99
| primFloat
1010
| primArray.
1111
Derive NoConfusion EqDec for prim_tag.
12-
13-
Definition string_of_prim_int (i:Uint63.int) : string :=
14-
(* Better? DecimalString.NilZero.string_of_uint (BinNat.N.to_uint (BinInt.Z.to_N (Int63.to_Z i))). ? *)
15-
string_of_Z (Uint63.to_Z i).
16-
17-
Definition string_of_float (f : PrimFloat.float) : string :=
18-
match Prim2SF f with
19-
| S754_zero sign => if sign then "-0" else "0"
20-
| S754_infinity sign => if sign then "-INFINITY" else "INFINITY"
21-
| S754_nan => "NAN"
22-
| S754_finite sign p z =>
23-
let abs := "0x" ++ bytestring.String.of_string (Numbers.HexadecimalString.NilZero.string_of_uint (Pos.to_hex_uint p)) ++ "p" ++
24-
bytestring.String.of_string (Numbers.DecimalString.NilZero.string_of_int (Z.to_int z))
25-
in if sign then "-" ++ abs else abs
26-
end.

erasure-plugin/theories/Erasure.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ Program Definition optional_unsafe_transforms econf :=
109109
unbox_transformation efl final_wcbv_flags ▷
110110
inline_transformation efl final_wcbv_flags econf.(inlining) ▷
111111
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 ▷
112114
betared_transformation efl final_wcbv_flags).
113115

114116
Program Definition verified_lambdabox_pipeline {guard : abstract_guard_impl}

erasure/theories/EBeta.v

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@ Definition map_subterms (f : term -> term) (t : term) : term :=
1919
| tLazy t => tLazy (f t)
2020
| tForce t => tForce (f t)
2121
| tConstruct ind n args => tConstruct ind n (map f args)
22-
| t => t
22+
| tRel n => tRel n
23+
| tVar na => tVar na
24+
| tConst kn => tConst kn
25+
| tBox => tBox
2326
end.
2427

2528
Section betared.
26-
Fixpoint decompose_lam (t : term) {struct t} : list name × term :=
27-
match t with
28-
| tLambda na B =>
29-
let (ns, B0) := decompose_lam B in
30-
(na :: ns, B0)
31-
| _ => ([], t)
32-
end.
3329

3430
Fixpoint beta_body (body : term) (args : list term) {struct args} : term :=
3531
match args with

erasure/theories/EPretty.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ Module PrintTermTree.
8686

8787
Definition print_prim (soft : EAst.term -> Tree.t) (p : @prim_val EAst.term) : Tree.t :=
8888
match p.π2 return Tree.t with
89-
| primIntModel f => "(int: " ^ Primitive.string_of_prim_int f ^ ")"
90-
| primFloatModel f => "(float: " ^ Primitive.string_of_float f ^ ")"
89+
| primIntModel f => "(int: " ^ show f ^ ")"
90+
| primFloatModel f => "(float: " ^ show f ^ ")"
9191
| primArrayModel a => "(array:" ^ soft a.(array_default) ^ " , " ^ string_of_list soft a.(array_value) ^ ")"
9292
end.
9393

pcuic/theories/utils/PCUICPretty.v

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ Module PrintTermTree.
119119

120120
Definition print_prim (soft : term -> Tree.t) (p : prim_val) : Tree.t :=
121121
match p.π2 return Tree.t with
122-
| primIntModel f => "(int: " ^ Primitive.string_of_prim_int f ^ ")"
123-
| primFloatModel f => "(float: " ^ Primitive.string_of_float f ^ ")"
122+
| primIntModel f => "(int: " ^ show f ^ ")"
123+
| primFloatModel f => "(float: " ^ show f ^ ")"
124124
| primArrayModel a => "(array:" ^ string_of_list soft a.(array_value) ^ ")"
125125
end.
126126

127127
Section Aux.
128128
Context (print_term : list ident -> bool -> bool -> term -> t).
129129

130130
Definition print_def {A} (f : A -> t) (g : A -> t) (def : def A) :=
131-
string_of_name (binder_name (dname def)) ^ " { struct " ^ string_of_nat (rarg def) ^ " }" ^
131+
string_of_name (binder_name (dname def)) ^ " { struct " ^ show (rarg def) ^ " }" ^
132132
" : " ^ f (dtype def) ^ " := " ^ nl ^ g (dbody def).
133133

134134
Definition print_defs Γ (defs : mfixpoint term) :=
@@ -344,5 +344,11 @@ Definition print_context Σ Γ Δ : string :=
344344
Definition print_env (short : bool) (prefix : nat) Σ :=
345345
Tree.to_string (PrintTermTree.print_env short prefix Σ).
346346

347+
#[export] Instance show_env : Show global_env :=
348+
fun Σ => print_env false (List.length Σ.(declarations)) Σ.
349+
347350
Definition print_program (short : bool) (prefix : nat) (p : program) : string :=
348-
Tree.to_string (PrintTermTree.print_program short prefix p).
351+
Tree.to_string (PrintTermTree.print_program short prefix p).
352+
353+
#[export] Instance show_program : Show program :=
354+
fun p => print_program false (List.length p.1.(declarations)) p.

template-coq/_PluginProject

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ gen-src/decidableType.ml
6868
gen-src/decidableType.mli
6969
gen-src/decimal.ml
7070
gen-src/decimal.mli
71-
gen-src/decimalString.ml
72-
gen-src/decimalString.mli
7371
gen-src/denoter.ml
7472
# gen-src/depElim.ml
7573
# gen-src/depElim.mli
@@ -103,8 +101,8 @@ gen-src/floatOps.ml
103101
gen-src/floatOps.mli
104102
gen-src/hexadecimal.ml
105103
gen-src/hexadecimal.mli
106-
gen-src/hexadecimalString.ml
107-
gen-src/hexadecimalString.mli
104+
# gen-src/hexadecimalString.ml
105+
# gen-src/hexadecimalString.mli
108106
gen-src/induction.ml
109107
gen-src/induction.mli
110108
# gen-src/init.ml
@@ -143,6 +141,10 @@ gen-src/mCRelations.ml
143141
gen-src/mCRelations.mli
144142
gen-src/mCString.ml
145143
gen-src/mCString.mli
144+
gen-src/sint63.mli
145+
gen-src/sint63.ml
146+
gen-src/show.mli
147+
gen-src/show.ml
146148
# gen-src/mCUint63.ml
147149
# gen-src/mCUint63.mli
148150
gen-src/mCUtils.ml

template-coq/_PluginProject.in

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ gen-src/decidableType.ml
6666
gen-src/decidableType.mli
6767
gen-src/decimal.ml
6868
gen-src/decimal.mli
69-
gen-src/decimalString.ml
70-
gen-src/decimalString.mli
7169
gen-src/denoter.ml
7270
# gen-src/depElim.ml
7371
# gen-src/depElim.mli
@@ -101,8 +99,8 @@ gen-src/floatOps.ml
10199
gen-src/floatOps.mli
102100
gen-src/hexadecimal.ml
103101
gen-src/hexadecimal.mli
104-
gen-src/hexadecimalString.ml
105-
gen-src/hexadecimalString.mli
102+
# gen-src/hexadecimalString.ml
103+
# gen-src/hexadecimalString.mli
106104
gen-src/induction.ml
107105
gen-src/induction.mli
108106
# gen-src/init.ml
@@ -141,6 +139,10 @@ gen-src/mCRelations.ml
141139
gen-src/mCRelations.mli
142140
gen-src/mCString.ml
143141
gen-src/mCString.mli
142+
gen-src/sint63.mli
143+
gen-src/sint63.ml
144+
gen-src/show.mli
145+
gen-src/show.ml
144146
# gen-src/mCUint63.ml
145147
# gen-src/mCUint63.mli
146148
gen-src/mCUtils.ml

template-coq/gen-src/metacoq_template_plugin.mlpack

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Caml_byte
2525
ByteCompare
2626
ByteCompareSpec
2727
String0
28-
HexadecimalString
2928
Orders
3029
OrdersAlt
3130
OrdersTac
@@ -74,8 +73,9 @@ Zpower
7473
SpecFloat
7574
PrimFloat
7675
FloatOps
77-
DecimalString
7876
MCString
77+
Sint63
78+
Show
7979
MCUtils
8080
Signature
8181
All_Forall

utils/_CoqProject

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ theories/MC_ExtrOCamlInt63.v
3131
theories/MC_ExtrOCamlZPosInt.v
3232
theories/ReflectEq.v
3333
theories/monad_utils.v
34+
theories/Show.v
3435
theories/utils.v
3536

3637
# extra tactics

utils/theories/MCUtils.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
From Coq Require Import Nat ZArith Bool.
22

3-
Require Export MCPrelude
3+
From MetaCoq.Utils Require Export MCPrelude
44
MCReflect
55
All_Forall
66
MCArith
@@ -23,6 +23,7 @@ Require Export MCPrelude
2323
MCTactics.UniquePose
2424
ReflectEq
2525
bytestring
26+
Show
2627
.
2728

2829
Tactic Notation "destruct" "?" :=

0 commit comments

Comments
 (0)