Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/declare_translation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let error = CErrors.user_err
let ongoing_translation = Summary.ref false ~name:"parametricity ongoing translation"
let ongoing_translation_opacity = Summary.ref false ~name:"parametricity ongoing translation opacity"
let check_nothing_ongoing () =
let open Summary.Ref in
if !ongoing_translation then
error (Pp.str "Some terms are being translated, please prove pending obligations before starting a new one. End them with the command 'Parametricity Done'.")

Expand All @@ -37,12 +38,14 @@ let obligation_message () =
let default_continuation = ignore

let parametricity_close_proof ~lemma ~pm =
let open Summary.Ref in
let opaque = if !ongoing_translation_opacity then Vernacexpr.Opaque else Transparent in
ongoing_translation := false;
let pm, _ = Declare.Proof.save ~pm ~proof:lemma ~opaque ~idopt:None in
pm

let add_definition ~opaque ~hook ~poly ~scope ~kind ~tactic name env evd term typ =
let open Summary.Ref in
debug Debug.all "add_definition, term = " env evd (snd (term ( evd)));
debug Debug.all "add_definition, typ = " env evd typ;
debug_evar_map Debug.all "add_definition, evd = " env evd;
Expand Down Expand Up @@ -96,7 +99,7 @@ let declare_abstraction ~opaque_access ?(opaque = false) ?(continuation = defaul
(try ignore (Relations.get_constant arity (UVars.out_punivs cte)); false with Not_found -> true)
->
Declare.Hook.(make (fun { dref ; _ } ->
if !ongoing_translation then error (Pp.str "Please use the 'Debug.Done' command to end proof obligations generated by the parametricity tactic.");
if Summary.Ref.(!ongoing_translation) then error (Pp.str "Please use the 'Debug.Done' command to end proof obligations generated by the parametricity tactic.");
Pp.(Flags.if_verbose msg_info (str (Printf.sprintf "'%s' is now a registered translation." (Names.Id.to_string name))));
let cte = (fst cte, EInstance.kind !evdr (snd cte)) in
Relations.declare_relation arity (Names.GlobRef.ConstRef (UVars.out_punivs cte)) dref;
Expand Down Expand Up @@ -138,7 +141,7 @@ let declare_constant ~opaque_access ?(continuation = default_continuation) ~scop
else
let cte = (cst, u) in
Declare.Hook.(make (fun { dref ; _ } ->
if !ongoing_translation then error (Pp.str "Please use the 'Debug.Done' command to end proof obligations generated by the parametricity tactic.");
if Summary.Ref.(!ongoing_translation) then error (Pp.str "Please use the 'Debug.Done' command to end proof obligations generated by the parametricity tactic.");
Pp.(Flags.if_verbose msg_info (str (Printf.sprintf "'%s' is now a registered translation." (Names.Id.to_string name))));
let cte = (fst cte, EInstance.kind !evdr (snd cte)) in
Relations.declare_relation arity (Names.GlobRef.ConstRef (UVars.out_punivs cte)) dref;
Expand Down Expand Up @@ -468,7 +471,7 @@ let command_reference_recursive ~opaque_access ?(continuation = default_continua
command_reference ~opaque_access ~continuation ~fullname arity gref None) dep_refs ()

let translate_command ~opaque_access arity c name =
if !ongoing_translation then error (Pp.str "On going translation.");
if Summary.Ref.(!ongoing_translation) then error (Pp.str "On going translation.");
(* Same comment as above *)
let env = Global.env () in
let evd = Evd.from_env env in
Expand Down
8 changes: 7 additions & 1 deletion src/relations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ let initial_relations = IntMap.empty
let relations = Summary.ref initial_relations ~name:"parametricity"

let print_relations () =
let open Summary.Ref in
IntMap.iter (fun n translations ->
GMap.iter (fun gref c -> Feedback.(msg_info (Printer.pr_global gref))) translations
) !relations

let add (n : int) f =
let open Summary.Ref in
let translations =
try IntMap.find n !relations with Not_found -> initial_translations
in
Expand Down Expand Up @@ -65,19 +67,23 @@ let declare_inductive_relation (n : int) (i : inductive) (i_R : inductive) =
let declare_variable_relation (n : int) (v : variable) (v_R : Constant.t) =
declare_relation n (GlobRef.VarRef v) (GlobRef.ConstRef v_R)

let get_constant n c =
let get_constant n c =
let open Summary.Ref in
let map = IntMap.find n !relations in
GMap.find (GlobRef.ConstRef c) map

let get_inductive n i =
let open Summary.Ref in
let map = IntMap.find n !relations in
GMap.find (GlobRef.IndRef i) map

let get_variable n v =
let open Summary.Ref in
let map = IntMap.find n !relations in
destConstRef (GMap.find (GlobRef.VarRef v) map)

let is_referenced n ref =
let open Summary.Ref in
try
let map = IntMap.find n !relations in
GMap.mem ref map
Expand Down
Loading