Skip to content

Commit 3d69739

Browse files
Gustavo2622strub
andcommitted
Better printing of hint DBs
This commit introduces the following printing commands: - `print hint`: prints all hints in the current scope - `print hint simplify`: same but only for simplify hints - `print hint solve`: same but only for solve hints - `print hint rewrite`: same but only for rewrite hints Co-Authored-By: Gustavo Delerue <gxdelerue@proton.me> Co-Authored-By: Pierre-Yves Strub <pierre-yves@strub.nu>
1 parent 2317d82 commit 3d69739

File tree

4 files changed

+48
-61
lines changed

4 files changed

+48
-61
lines changed

src/ecCommands.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,20 @@ module HiPrinting = struct
284284
let hint_rewrite = EcEnv.BaseRw.all env in
285285

286286
let ppe = EcPrinting.PPEnv.ofenv env in
287-
let pp_path = EcPrinting.pp_long_short_path (fun q -> EcEnv.Ax.lookup_opt q env) in
287+
288+
let pp_path =
289+
EcPrinting.pp_shorten_path
290+
(fun (p : EcPath.path) (q : EcSymbols.qsymbol) ->
291+
Option.equal EcPath.p_equal
292+
(Some p)
293+
(Option.map fst (EcEnv.Ax.lookup_opt q env))) in
288294

289295
let pp_hint_rewrite _ppe fmt = (fun (p, sp) ->
290296
let elems = EcPath.Sp.ntr_elements sp in
291297
if List.is_empty elems then
292298
Format.fprintf fmt "%s (empty)@." (EcPath.basename p)
293299
else
294-
Format.fprintf fmt "@[<b 2>%s = @\n%a@]@." (EcPath.basename p)
300+
Format.fprintf fmt "@[<b 2>%s = @\n%a@]@\n" (EcPath.basename p)
295301
(EcPrinting.pp_list "@\n" (fun fmt p ->
296302
Format.fprintf fmt "%a" pp_path p))
297303
(EcPath.Sp.ntr_elements sp)
@@ -320,7 +326,7 @@ module HiPrinting = struct
320326
(EcPrinting.pp_list "@\n" (fun fmt rl ->
321327
begin match rl.rl_cond with
322328
| [] -> Format.fprintf fmt "Conditions: None@\n"
323-
| xs -> Format.fprintf fmt "Conditions: %a@\n" (EcPrinting.pp_list "," (EcPrinting.pp_form ppe)) xs
329+
| xs -> Format.fprintf fmt "Conditions: %a@\n" (EcPrinting.pp_list ",@ " (EcPrinting.pp_form ppe)) xs
324330
end;
325331
Format.fprintf fmt "Target: %a@\nPattern: %a@\n"
326332
(EcPrinting.pp_form ppe) rl.rl_tg

src/ecCorePrinting.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ module type PrinterAPI = sig
6161
val pp_tyvar : PPEnv.t -> ident pp
6262
val pp_tyunivar : PPEnv.t -> EcUid.uid pp
6363
val pp_path : path pp
64-
val pp_long_short_path : (qsymbol -> (EcPath.path * 'a) option) -> path pp
64+
65+
(* ------------------------------------------------------------------ *)
66+
val shorten_path : (path -> qsymbol -> bool) -> path -> qsymbol * qsymbol option
67+
68+
val pp_shorten_path : (path -> qsymbol -> bool) -> path pp
6569

6670
(* ------------------------------------------------------------------ *)
6771
val pp_codepos1 : PPEnv.t -> EcMatching.Position.codepos1 pp

src/ecPrinting.ml

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module PPEnv = struct
143143
(fun env x -> EcEnv.Mod.bind_param x mty env)
144144
ppe.ppe_env xs; }
145145

146-
let p_shorten cond p =
146+
let p_shorten cond (nm, x) =
147147
let rec shorten prefix (nm, x) =
148148
match cond (nm, x) with
149149
| true -> (nm, x)
@@ -154,36 +154,35 @@ module PPEnv = struct
154154
end
155155
in
156156

157-
let (nm, x) = P.toqsymbol p in
158157
shorten (List.rev nm) ([], x)
159158

160159
let ty_symb (ppe : t) p =
161160
let exists sm =
162161
try EcPath.p_equal (EcEnv.Ty.lookup_path ~unique:true sm ppe.ppe_env) p
163162
with EcEnv.LookupFailure _ -> false
164163
in
165-
p_shorten exists p
164+
p_shorten exists (P.toqsymbol p)
166165

167166
let tc_symb (ppe : t) p =
168167
let exists sm =
169168
try EcPath.p_equal (EcEnv.TypeClass.lookup_path sm ppe.ppe_env) p
170169
with EcEnv.LookupFailure _ -> false
171170
in
172-
p_shorten exists p
171+
p_shorten exists (P.toqsymbol p)
173172

174173
let rw_symb (ppe : t) p =
175174
let exists sm =
176175
try EcPath.p_equal (EcEnv.BaseRw.lookup_path sm ppe.ppe_env) p
177176
with EcEnv.LookupFailure _ -> false
178177
in
179-
p_shorten exists p
178+
p_shorten exists (P.toqsymbol p)
180179

181180
let ax_symb (ppe : t) p =
182181
let exists sm =
183182
try EcPath.p_equal (EcEnv.Ax.lookup_path sm ppe.ppe_env) p
184183
with EcEnv.LookupFailure _ -> false
185184
in
186-
p_shorten exists p
185+
p_shorten exists (P.toqsymbol p)
187186

188187
let op_symb (ppe : t) p info =
189188
let specs = [1, EcPath.pqoname (EcPath.prefix EcCoreLib.CI_Bool.p_eq) "<>"] in
@@ -221,21 +220,21 @@ module PPEnv = struct
221220
(* FIXME: for special operators, do check `info` *)
222221
if List.exists (fun (_, sp) -> EcPath.p_equal sp p) specs
223222
then ([], EcPath.basename p)
224-
else p_shorten exists p
223+
else p_shorten exists (P.toqsymbol p)
225224

226225
let ax_symb (ppe : t) p =
227226
let exists sm =
228227
try EcPath.p_equal (EcEnv.Ax.lookup_path sm ppe.ppe_env) p
229228
with EcEnv.LookupFailure _ -> false
230229
in
231-
p_shorten exists p
230+
p_shorten exists (P.toqsymbol p)
232231

233232
let th_symb (ppe : t) p =
234233
let exists sm =
235234
try EcPath.p_equal (EcEnv.Theory.lookup_path sm ppe.ppe_env) p
236235
with EcEnv.LookupFailure _ -> false
237236
in
238-
p_shorten exists p
237+
p_shorten exists (P.toqsymbol p)
239238

240239
let rec mod_symb (ppe : t) mp : EcSymbols.msymbol =
241240
let (nm, x, p2) =
@@ -361,6 +360,18 @@ module PPEnv = struct
361360
end
362361

363362
(* -------------------------------------------------------------------- *)
363+
let shorten_path (cond : P.path -> qsymbol -> bool) (p : P.path) : qsymbol * qsymbol option =
364+
let (nm, x) = EcPath.toqsymbol p in
365+
let nm =
366+
match nm with
367+
| top :: nm when top = EcCoreLib.i_top -> nm
368+
| _ -> nm in
369+
let nm', x' = PPEnv.p_shorten (cond p) (nm, x) in
370+
let plong, pshort = (nm, x), (nm', x') in
371+
372+
(plong, if plong = pshort then None else Some pshort)
373+
374+
(* -------------------------------------xz------------------------------- *)
364375
let pp_id pp fmt x = Format.fprintf fmt "%a" pp x
365376

366377
(* -------------------------------------------------------------------- *)
@@ -434,33 +445,16 @@ let pp_path fmt p =
434445
Format.fprintf fmt "%s" (P.tostring p)
435446

436447
(* -------------------------------------------------------------------- *)
437-
let pp_long_short_path (lk: qsymbol -> (EcPath.path * 'a) option) fmt p =
438-
let rec doit prefix (nm, x) =
439-
match lk (nm, x) with
440-
| Some (p', _) when EcPath.p_equal p p' ->
441-
(nm, x)
442-
| _ -> begin
443-
match prefix with
444-
| [] -> (nm, x)
445-
| n :: prefix -> doit prefix (n :: nm, x)
446-
end
447-
in
448+
let pp_shorten_path (cond : P.path -> qsymbol -> bool) (fmt : Format.formatter) (p : P.path) =
449+
let plong, pshort = shorten_path cond p in
448450

449-
let (nm, x) = EcPath.toqsymbol p in
450-
let nm =
451-
match nm with
452-
| top :: nm when top = EcCoreLib.i_top ->
453-
nm
454-
| _ -> nm in
455-
456-
let nm', x' = doit (List.rev nm) ([], x) in
457-
let plong, pshort = (nm, x), (nm', x') in
458-
match plong, pshort with
459-
| plong, pshort when plong = pshort -> Format.fprintf fmt "%a" EcSymbols.pp_qsymbol plong
460-
| plong, pshort ->
461-
Format.fprintf fmt "%a (shorten name: %a)"
462-
EcSymbols.pp_qsymbol plong
463-
EcSymbols.pp_qsymbol pshort
451+
match pshort with
452+
| None ->
453+
Format.fprintf fmt "%a" EcSymbols.pp_qsymbol plong
454+
| Some pshort ->
455+
Format.fprintf fmt "%a (shorten name: %a)"
456+
EcSymbols.pp_qsymbol plong
457+
EcSymbols.pp_qsymbol pshort
464458

465459
(* -------------------------------------------------------------------- *)
466460
let rec pp_msymbol (fmt : Format.formatter) (mx : msymbol) =

src/ecScope.ml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,28 +2364,11 @@ module Search = struct
23642364

23652365
let locate (scope : scope) ({ pl_desc = name } : pqsymbol) =
23662366
let shorten lk p =
2367-
let rec doit prefix (nm, x) =
2368-
match lk (nm, x) (env scope) with
2369-
| Some (p', _) when EcPath.p_equal p p' ->
2370-
(nm, x)
2371-
| _ -> begin
2372-
match prefix with
2373-
| [] -> (nm, x)
2374-
| n :: prefix -> doit prefix (n :: nm, x)
2375-
end
2376-
in
2377-
2378-
let (nm, x) = EcPath.toqsymbol p in
2379-
let nm =
2380-
match nm with
2381-
| top :: nm when top = EcCoreLib.i_top ->
2382-
nm
2383-
| _ -> nm in
2384-
2385-
let nm', x' = doit (List.rev nm) ([], x) in
2386-
let plong, pshort = (nm, x), (nm', x') in
2387-
2388-
(plong, if plong = pshort then None else Some pshort)
2367+
let lk (p : path) (qs : qsymbol) =
2368+
match lk qs (env scope) with
2369+
| Some (p', _) -> p_equal p p'
2370+
| _ -> false in
2371+
EcPrinting.shorten_path lk p
23892372
in
23902373

23912374
let buffer = Buffer.create 0 in

0 commit comments

Comments
 (0)