Skip to content

Commit c71bac4

Browse files
authored
Merge pull request rocq-community#3 from erikmd/make-fullname-optional
Add a "qualified" version for commands Parametricity & Parametricity Recursive.
2 parents 14234dd + dee1939 commit c71bac4

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

src/abstraction.ml4

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ VERNAC COMMAND EXTEND AbstractionReference CLASSIFIED AS SIDEFF
5757
[
5858
command_reference default_arity (Constrintern.intern_reference c) (Some name)
5959
]
60+
| [ "Parametricity" reference(c) "qualified" ] ->
61+
[
62+
command_reference ~fullname:true default_arity (Constrintern.intern_reference c) None
63+
]
6064
| [ "Parametricity" reference(c) "arity" int(arity) ] ->
6165
[
6266
command_reference arity (Constrintern.intern_reference c) None
@@ -65,6 +69,10 @@ VERNAC COMMAND EXTEND AbstractionReference CLASSIFIED AS SIDEFF
6569
[
6670
command_reference arity (Constrintern.intern_reference c) (Some name)
6771
]
72+
| [ "Parametricity" reference(c) "arity" int(arity) "qualified" ] ->
73+
[
74+
command_reference ~fullname:true arity (Constrintern.intern_reference c) None
75+
]
6876
| [ "Parametricity" reference(c) "as" ident(name) "arity" integer(arity) ] ->
6977
[
7078
command_reference arity (Constrintern.intern_reference c) (Some name)
@@ -80,6 +88,14 @@ VERNAC COMMAND EXTEND AbstractionRecursive CLASSIFIED AS SIDEFF
8088
[
8189
command_reference_recursive arity (Constrintern.intern_reference c)
8290
]
91+
| [ "Parametricity" "Recursive" reference(c) "qualified" ] ->
92+
[
93+
command_reference_recursive ~fullname:true default_arity (Constrintern.intern_reference c)
94+
]
95+
| [ "Parametricity" "Recursive" reference(c) "arity" integer(arity) "qualified" ] ->
96+
[
97+
command_reference_recursive ~fullname:true arity (Constrintern.intern_reference c)
98+
]
8399
END
84100

85101
VERNAC COMMAND EXTEND Abstraction CLASSIFIED AS SIDEFF

src/declare_translation.ml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -309,22 +309,22 @@ and declare_module ?(continuation = ignore) ?name arity mb =
309309
let command_variable ?(continuation = default_continuation) arity variable names =
310310
error (Pp.str "Cannot translate an axiom nor a variable. Please use the 'Parametricity Realizer' command.")
311311

312-
let translateFullName arity (constant : Names.constant) : string =
312+
let translateFullName ~fullname arity (kername : Names.KerName.t) : string =
313313
let nstr =
314314
(translate_string arity
315315
@@ Names.Label.to_string
316-
@@ Names.Constant.label
317-
@@ constant)in
316+
@@ Names.KerName.label
317+
@@ kername) in
318318
let pstr =
319319
(Names.ModPath.to_string
320320
@@ Names.modpath
321-
@@ Names.canonical_con
322-
@@ constant) in
321+
@@ kername) in
323322
let plstr = Str.split (Str.regexp ("\.")) pstr in
324-
(String.concat "_o_" (plstr@[nstr]))
323+
if fullname then
324+
(String.concat "_o_" (plstr@[nstr]))
325+
else nstr
325326

326-
327-
let command_constant ?(continuation = default_continuation) arity constant names =
327+
let command_constant ?(continuation = default_continuation) ~fullname arity constant names =
328328
let poly, opaque =
329329
let cb = Global.lookup_constant constant in
330330
let open Declarations in
@@ -335,7 +335,10 @@ let command_constant ?(continuation = default_continuation) arity constant names
335335
(match cb.const_body with Def _ -> false | _ -> true)
336336
in
337337
let name = match names with
338-
| None -> Names.id_of_string (translateFullName arity constant)
338+
| None -> Names.id_of_string
339+
@@ translateFullName ~fullname arity
340+
@@ Names.Constant.canonical
341+
@@ constant
339342
| Some name -> name
340343
in
341344
let kind = Decl_kinds.(Global, poly, DefinitionBody Definition) in
@@ -346,45 +349,43 @@ let command_constant ?(continuation = default_continuation) arity constant names
346349
let constr = mkConstU (fst pconst, EInstance.make @@ snd pconst) in
347350
declare_abstraction ~continuation ~opaque ~kind arity (ref evd) env constr name
348351

349-
let command_inductive ?(continuation = default_continuation) arity inductive names =
352+
let command_inductive ?(continuation = default_continuation) ~fullname arity inductive names =
350353
let (evd, env) = Lemmas.get_current_context () in
351354
let evd, pind =
352355
Evd.(with_context_set univ_rigid evd (Universes.fresh_inductive_instance env inductive))
353356
in
354357
let name = match names with
355358
| None ->
356359
Names.id_of_string
357-
@@ translate_string arity
358-
@@ Names.Label.to_string
359-
@@ Names.MutInd.label
360+
@@ translateFullName ~fullname arity
361+
@@ Names.MutInd.canonical
360362
@@ fst
361363
@@ fst
362364
@@ pind
363365
| Some name -> name
364366
in
365367
declare_inductive name ~continuation arity (ref evd) env pind
366368

367-
368369
let command_constructor ?(continuation = default_continuation) arity gref names =
369370
let open Pp in
370371
error ((str "'")
371372
++ (Printer.pr_global gref)
372373
++ (str "' is a constructor. To generate its parametric translation, please translate its inductive first."))
373374

374-
let command_reference ?(continuation = default_continuation) arity gref names =
375+
let command_reference ?(continuation = default_continuation) ?(fullname = false) arity gref names =
375376
check_nothing_ongoing ();
376377
let open Globnames in
377378
match gref with
378379
| VarRef variable ->
379380
command_variable ~continuation arity variable names
380381
| ConstRef constant ->
381-
command_constant ~continuation arity constant names
382+
command_constant ~continuation ~fullname arity constant names
382383
| IndRef inductive ->
383-
command_inductive ~continuation arity inductive names
384+
command_inductive ~continuation ~fullname arity inductive names
384385
| ConstructRef constructor ->
385386
command_constructor ~continuation arity gref names
386387

387-
let command_reference_recursive ?(continuation = default_continuation) arity gref =
388+
let command_reference_recursive ?(continuation = default_continuation) ?(fullname = false) arity gref =
388389
let open Globnames in
389390
let gref= Globnames.canonical_gr gref in
390391
let label = Names.Label.of_id (Nametab.basename_of_global gref) in
@@ -414,7 +415,7 @@ let command_reference_recursive ?(continuation = default_continuation) arity gre
414415
(* DEBUG: *)
415416
let open Pp in msg_info (str "DepRefs:");
416417
List.iter (fun x -> let open Pp in msg_info (Printer.pr_global x)) dep_refs;
417-
list_continuation continuation (fun continuation gref -> command_reference ~continuation arity gref None) dep_refs ()
418+
list_continuation continuation (fun continuation gref -> command_reference ~continuation ~fullname arity gref None) dep_refs ()
418419

419420
let translate_command arity c name =
420421
if !ongoing_translation then error (Pp.str "On going translation.");

0 commit comments

Comments
 (0)