Skip to content

Commit 66556dd

Browse files
committed
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 e8dcbde commit 66556dd

File tree

11 files changed

+111
-52
lines changed

11 files changed

+111
-52
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
@@ -111,6 +111,8 @@ Program Definition optional_unsafe_transforms econf :=
111111
unbox_transformation efl final_wcbv_flags ▷
112112
inline_transformation efl final_wcbv_flags econf.(inlining) ▷
113113
forget_inlining_info_transformation efl final_wcbv_flags ▷
114+
(* Heuristically do it twice for more beta-normal terms *)
115+
betared_transformation efl final_wcbv_flags ▷
114116
betared_transformation efl final_wcbv_flags).
115117

116118
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: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ gen-src/decidableType.ml
7070
gen-src/decidableType.mli
7171
gen-src/decimal.ml
7272
gen-src/decimal.mli
73-
gen-src/decimalString.ml
74-
gen-src/decimalString.mli
7573
gen-src/denoter.ml
7674
gen-src/depElim.ml
7775
gen-src/depElim.mli
@@ -105,12 +103,12 @@ gen-src/floatOps.ml
105103
gen-src/floatOps.mli
106104
gen-src/hexadecimal.ml
107105
gen-src/hexadecimal.mli
108-
gen-src/hexadecimalString.ml
109-
gen-src/hexadecimalString.mli
110-
gen-src/induction0.ml
111-
gen-src/induction0.mli
112-
gen-src/init.ml
113-
gen-src/init.mli
106+
# gen-src/hexadecimalString.ml
107+
# gen-src/hexadecimalString.mli
108+
gen-src/induction.ml
109+
gen-src/induction.mli
110+
# gen-src/init.ml
111+
# gen-src/init.mli
114112
gen-src/int0.ml
115113
gen-src/int0.mli
116114
gen-src/kernames.ml
@@ -145,8 +143,12 @@ gen-src/mCRelations.ml
145143
gen-src/mCRelations.mli
146144
gen-src/mCString.ml
147145
gen-src/mCString.mli
148-
gen-src/mCUint63.ml
149-
gen-src/mCUint63.mli
146+
gen-src/sint63.mli
147+
gen-src/sint63.ml
148+
gen-src/show.mli
149+
gen-src/show.ml
150+
# gen-src/mCUint63.ml
151+
# gen-src/mCUint63.mli
150152
gen-src/mCUtils.ml
151153
gen-src/mCUtils.mli
152154
gen-src/mSetAVL.ml

template-coq/_PluginProject.in

Lines changed: 12 additions & 10 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,12 +101,12 @@ 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
108-
gen-src/induction0.ml
109-
gen-src/induction0.mli
110-
gen-src/init.ml
111-
gen-src/init.mli
104+
# gen-src/hexadecimalString.ml
105+
# gen-src/hexadecimalString.mli
106+
gen-src/induction.ml
107+
gen-src/induction.mli
108+
# gen-src/init.ml
109+
# gen-src/init.mli
112110
gen-src/int0.ml
113111
gen-src/int0.mli
114112
gen-src/kernames.ml
@@ -143,8 +141,12 @@ gen-src/mCRelations.ml
143141
gen-src/mCRelations.mli
144142
gen-src/mCString.ml
145143
gen-src/mCString.mli
146-
gen-src/mCUint63.ml
147-
gen-src/mCUint63.mli
144+
gen-src/sint63.mli
145+
gen-src/sint63.ml
146+
gen-src/show.mli
147+
gen-src/show.ml
148+
# gen-src/mCUint63.ml
149+
# gen-src/mCUint63.mli
148150
gen-src/mCUtils.ml
149151
gen-src/mCUtils.mli
150152
gen-src/mSetAVL.ml

template-coq/gen-src/metacoq_template_plugin.mlpack

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Caml_byte
2626
ByteCompare
2727
ByteCompareSpec
2828
String0
29-
HexadecimalString
3029
Orders
3130
OrdersAlt
3231
OrdersTac
@@ -75,8 +74,9 @@ Zpower
7574
SpecFloat
7675
PrimFloat
7776
FloatOps
78-
DecimalString
7977
MCString
78+
Sint63
79+
Show
8080
MCUtils
8181
Signature
8282
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)