| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
open Pp |
| 14 |
open CErrors |
| 15 |
open CAst |
| 16 |
open Util |
| 17 |
open Names |
| 18 |
open Printer |
| 19 |
open Goptions |
| 20 |
open Libnames |
| 21 |
open Vernacexpr |
| 22 |
open Locality |
| 23 |
open Attributes |
| 24 |
open Synterp |
| 25 |
|
| 26 |
module NamedDecl = Context.Named.Declaration |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
let get_current_or_global_context ~pstate = |
| 33 |
match pstate with |
| 34 |
| None -> let env = Global.env () in Evd.(from_env env, env) |
| 35 |
| Some p -> Declare.Proof.get_current_context p |
| 36 |
|
| 37 |
let get_goal_or_global_context ~pstate glnum = |
| 38 |
match pstate with |
| 39 |
| None -> let env = Global.env () in Evd.(from_env env, env) |
| 40 |
| Some p -> Declare.Proof.get_goal_context p glnum |
| 41 |
|
| 42 |
let cl_of_qualid = function |
| 43 |
| FunClass -> Coercionops.CL_FUN |
| 44 |
| SortClass -> Coercionops.CL_SORT |
| 45 |
| RefClass r -> ComCoercion.class_of_global (Smartlocate.smart_global ~head:true r) |
| 46 |
|
| 47 |
let scope_class_of_qualid qid = |
| 48 |
Notation.scope_class_of_class (cl_of_qualid qid) |
| 49 |
|
| 50 |
|
| 51 |
module DefAttributes = struct |
| 52 |
type t = { |
| 53 |
hooks : Declare.Hook.t list ; |
| 54 |
scope : definition_scope; |
| 55 |
locality : bool option; |
| 56 |
poly : PolyFlags.t; |
| 57 |
program : bool; |
| 58 |
user_warns : Globnames.extended_global_reference UserWarn.with_qf option; |
| 59 |
canonical_instance : bool; |
| 60 |
typing_flags : Declarations.typing_flags option; |
| 61 |
using : Vernacexpr.section_subset_expr option; |
| 62 |
reversible : bool; |
| 63 |
clearbody: bool option; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
module Observer = Summary.MakeObservable (struct |
| 78 |
type value = Declare.Hook.t list attribute |
| 79 |
let local = false |
| 80 |
let stage = Summary.Stage.Interp |
| 81 |
let name = "Definition attribute" |
| 82 |
end) |
| 83 |
|
| 84 |
let active_hooks () : Declare.Hook.t list attribute = |
| 85 |
let module AttList = Monad.Make(Attributes.Notations) in |
| 86 |
let active = Observer.all_active () in |
| 87 |
let open Attributes.Notations in |
| 88 |
AttList.List.map snd active >>= fun res -> |
| 89 |
return (List.concat res) |
| 90 |
|
| 91 |
let importability_of_bool = function |
| 92 |
| true -> ImportNeedQualified |
| 93 |
| false -> ImportDefaultBehavior |
| 94 |
|
| 95 |
let warn_declaration_outside_section = |
| 96 |
CWarnings.create ~name:"declaration-outside-section" |
| 97 |
~category:CWarnings.CoreCategories.vernacular |
| 98 |
~default:CWarnings.AsError |
| 99 |
Pp.(fun (unexpected_thing, replacement) -> |
| 100 |
strbrk "Use of " ++ str unexpected_thing |
| 101 |
++ strbrk " outside sections behaves as " ++ str replacement ++ str ".") |
| 102 |
|
| 103 |
let scope_of_locality locality_flag discharge deprecated_thing replacement : definition_scope = |
| 104 |
let open Vernacexpr in |
| 105 |
match locality_flag, discharge with |
| 106 |
| Some b, NoDischarge -> Global (importability_of_bool b) |
| 107 |
| None, NoDischarge -> Global ImportDefaultBehavior |
| 108 |
| None, DoDischarge when not (Lib.sections_are_opened ()) -> |
| 109 |
|
| 110 |
warn_declaration_outside_section (deprecated_thing, replacement); |
| 111 |
Global ImportNeedQualified |
| 112 |
| None, DoDischarge -> Discharge |
| 113 |
| Some true, DoDischarge -> CErrors.user_err Pp.(str "Local not allowed in this case") |
| 114 |
| Some false, DoDischarge -> CErrors.user_err Pp.(str "Global not allowed in this case") |
| 115 |
|
| 116 |
open Attributes |
| 117 |
open Attributes.Notations |
| 118 |
|
| 119 |
let clearbody = bool_attribute ~name:"clearbody" |
| 120 |
|
| 121 |
|
| 122 |
let def_attributes_gen ?(coercion=false) ?(discharge=NoDischarge,"","") () = |
| 123 |
let discharge, deprecated_thing, replacement = discharge in |
| 124 |
let clearbody = match discharge with DoDischarge -> clearbody | NoDischarge -> return None in |
| 125 |
|
| 126 |
return () >>= fun () -> |
| 127 |
(locality ++ user_warns_with_use_globref_instead ++ poly PolyFlags.Definition ++ program ++ |
| 128 |
canonical_instance ++ typing_flags ++ using ++ |
| 129 |
reversible ++ clearbody ++ active_hooks ()) >>= |
| 130 |
fun (((((((((locality, user_warns), poly), program), |
| 131 |
canonical_instance), typing_flags), using), |
| 132 |
reversible), clearbody), hooks) -> |
| 133 |
let using = Option.map Proof_using.using_from_string using in |
| 134 |
let reversible = Option.default false reversible in |
| 135 |
let () = if Option.has_some clearbody && not (Lib.sections_are_opened()) |
| 136 |
then CErrors.user_err Pp.(str "Cannot use attribute clearbody outside sections.") |
| 137 |
in |
| 138 |
let scope = scope_of_locality locality discharge deprecated_thing replacement in |
| 139 |
return { hooks; scope; locality; poly; program; user_warns; canonical_instance; typing_flags; using; reversible; clearbody } |
| 140 |
|
| 141 |
let parse ?coercion ?discharge f = |
| 142 |
Attributes.parse (def_attributes_gen ?coercion ?discharge ()) f |
| 143 |
|
| 144 |
let def_attributes = def_attributes_gen () |
| 145 |
|
| 146 |
end |
| 147 |
|
| 148 |
let with_def_attributes ?coercion ?discharge ~atts f = |
| 149 |
let atts = DefAttributes.parse ?coercion ?discharge atts in |
| 150 |
if atts.DefAttributes.program then Declare.Obls.check_program_libraries (); |
| 151 |
f ~atts |
| 152 |
|
| 153 |
let with_section_locality ~atts f = |
| 154 |
let local = Attributes.(parse locality atts) in |
| 155 |
let section_local = make_section_locality local in |
| 156 |
f ~section_local |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
let show_proof ~pstate = |
| 162 |
|
| 163 |
try |
| 164 |
let pstate = match pstate with None -> raise Exit | Some s -> s in |
| 165 |
let p = Declare.Proof.get pstate in |
| 166 |
let sigma, _ = Declare.Proof.get_current_context pstate in |
| 167 |
let pprf = Proof.partial_proof p in |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
let env = Global.env() in |
| 174 |
Pp.prlist_with_sep Pp.fnl (Printer.pr_econstr_env env sigma) pprf |
| 175 |
|
| 176 |
with |
| 177 |
| Proof.NoSuchGoal _ | Exit -> |
| 178 |
user_err (str "No goals to show.") |
| 179 |
|
| 180 |
let show_top_evars ~proof = |
| 181 |
|
| 182 |
let Proof.{goals; sigma} = Proof.data proof in |
| 183 |
let shelf = Evd.shelf sigma in |
| 184 |
let given_up = Evar.Set.elements @@ Evd.given_up sigma in |
| 185 |
pr_evars_int sigma ~shelf ~given_up 1 (Evd.undefined_map sigma) |
| 186 |
|
| 187 |
let show_universes ~proof = |
| 188 |
let Proof.{goals;sigma} = Proof.data proof in |
| 189 |
let ctx = Evd.sort_context_set (Evd.minimize_universes sigma) in |
| 190 |
UState.pr (Evd.ustate sigma) ++ fnl () ++ |
| 191 |
v 1 (str "Normalized constraints:" ++ cut() ++ |
| 192 |
UnivGen.pr_sort_context (Termops.pr_evd_qvar sigma) (Termops.pr_evd_level sigma) ctx) |
| 193 |
|
| 194 |
|
| 195 |
let show_intro ~proof all = |
| 196 |
let open EConstr in |
| 197 |
let Proof.{goals;sigma} = Proof.data proof in |
| 198 |
if not (List.is_empty goals) then begin |
| 199 |
let evi = Evd.find_undefined sigma (List.hd goals) in |
| 200 |
let env = Evd.evar_filtered_env (Global.env ()) evi in |
| 201 |
let l,_= decompose_prod_decls sigma (Termops.strip_outer_cast sigma (Evd.evar_concl evi)) in |
| 202 |
if all then |
| 203 |
let lid = Tactics.find_intro_names env sigma l in |
| 204 |
hov 0 (prlist_with_sep spc Id.print lid) |
| 205 |
else if not (List.is_empty l) then |
| 206 |
let n = List.last l in |
| 207 |
Id.print (List.hd (Tactics.find_intro_names env sigma [n])) |
| 208 |
else mt () |
| 209 |
end else mt () |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
let show_match id = |
| 214 |
let patterns = |
| 215 |
try ComInductive.make_cases (Nametab.global_inductive id) |
| 216 |
with Not_found -> user_err Pp.(str "Unknown inductive type.") |
| 217 |
in |
| 218 |
let pr_branch l = |
| 219 |
str "| " ++ hov 1 (prlist_with_sep spc str l) ++ str " =>" |
| 220 |
in |
| 221 |
v 1 (str "match # with" ++ fnl () ++ |
| 222 |
prlist_with_sep fnl pr_branch patterns ++ fnl () ++ str "end" ++ fnl ()) |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
let print_loadpath dir = |
| 227 |
let l = Loadpath.get_load_paths () in |
| 228 |
let l = match dir with |
| 229 |
| None -> l |
| 230 |
| Some dir -> |
| 231 |
let filter p = is_dirpath_prefix_of dir (Loadpath.logical p) in |
| 232 |
List.filter filter l |
| 233 |
in |
| 234 |
str "Installed / Logical Path / Physical path:" ++ fnl () ++ |
| 235 |
prlist_with_sep fnl Loadpath.pp l |
| 236 |
|
| 237 |
let print_libraries () = |
| 238 |
let loaded = Library.loaded_libraries () in |
| 239 |
str"Loaded library files: " ++ |
| 240 |
pr_vertical_list DirPath.print loaded |
| 241 |
|
| 242 |
|
| 243 |
let print_module qid = |
| 244 |
match Nametab.locate_module qid with |
| 245 |
| mp -> Printmod.print_module ~with_body:true mp |
| 246 |
| exception Not_found -> user_err (str"Unknown Module " ++ pr_qualid qid ++ str".") |
| 247 |
|
| 248 |
let print_modtype qid = |
| 249 |
try |
| 250 |
let kn = Nametab.locate_modtype qid in |
| 251 |
Printmod.print_modtype kn |
| 252 |
with Not_found -> |
| 253 |
|
| 254 |
try |
| 255 |
let mp = Nametab.locate_module qid in |
| 256 |
Printmod.print_module ~with_body:false mp |
| 257 |
with Not_found -> |
| 258 |
user_err (str"Unknown Module Type or Module " ++ pr_qualid qid ++ str".") |
| 259 |
|
| 260 |
let print_namespace ~pstate ns = |
| 261 |
let ns = List.rev (Names.DirPath.repr ns) in |
| 262 |
|
| 263 |
|
| 264 |
let rec match_dirpath ns = function |
| 265 |
| [] -> Some ns |
| 266 |
| id::dir -> |
| 267 |
begin match match_dirpath ns dir with |
| 268 |
| Some [] as y -> y |
| 269 |
| Some (a::ns') -> |
| 270 |
if Names.Id.equal a id then Some ns' |
| 271 |
else None |
| 272 |
| None -> None |
| 273 |
end |
| 274 |
in |
| 275 |
let rec match_modulepath ns = function |
| 276 |
| MPbound _ -> None |
| 277 |
| MPfile dir -> match_dirpath ns (Names.DirPath.repr dir) |
| 278 |
| MPdot (mp,id) -> |
| 279 |
begin match match_modulepath ns mp with |
| 280 |
| Some [] as y -> y |
| 281 |
| Some (a::ns') -> |
| 282 |
if Names.Id.equal a id then Some ns' |
| 283 |
else None |
| 284 |
| None -> None |
| 285 |
end |
| 286 |
in |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
let qualified_minus n mp = |
| 294 |
let rec list_of_modulepath = function |
| 295 |
| MPbound _ -> assert false |
| 296 |
| MPfile dir -> Names.DirPath.repr dir |
| 297 |
| MPdot (mp,lbl) -> lbl::(list_of_modulepath mp) |
| 298 |
in |
| 299 |
snd (Util.List.chop n (List.rev (list_of_modulepath mp))) |
| 300 |
in |
| 301 |
let print_list pr l = prlist_with_sep (fun () -> str".") pr l in |
| 302 |
let print_kn kn = |
| 303 |
let (mp,lbl) = Names.KerName.repr kn in |
| 304 |
let qn = (qualified_minus (List.length ns) mp)@[lbl] in |
| 305 |
print_list Id.print qn |
| 306 |
in |
| 307 |
let print_constant ~pstate k body = |
| 308 |
|
| 309 |
let t = body.Declarations.const_type in |
| 310 |
let sigma, env = get_current_or_global_context ~pstate in |
| 311 |
print_kn k ++ str":" ++ spc() ++ Printer.pr_type_env env sigma t |
| 312 |
in |
| 313 |
let matches mp = match match_modulepath ns mp with |
| 314 |
| Some [] -> true |
| 315 |
| _ -> false in |
| 316 |
let constants_in_namespace = |
| 317 |
Environ.fold_constants (fun c body acc -> |
| 318 |
let kn = Constant.user c in |
| 319 |
if matches (KerName.modpath kn) |
| 320 |
then acc++fnl()++hov 2 (print_constant ~pstate kn body) |
| 321 |
else acc) |
| 322 |
(Global.env ()) (str"") |
| 323 |
in |
| 324 |
(print_list Id.print ns)++str":"++fnl()++constants_in_namespace |
| 325 |
|
| 326 |
let print_strategy r = |
| 327 |
let open Conv_oracle in |
| 328 |
let pr_level = function |
| 329 |
| Expand -> str "expand" |
| 330 |
| Level 0 -> str "transparent" |
| 331 |
| Level n -> str "level" ++ spc() ++ int n |
| 332 |
| Opaque -> str "opaque" |
| 333 |
in |
| 334 |
let pr_strategy (ref, lvl) = pr_global ref ++ str " : " ++ pr_level lvl in |
| 335 |
let oracle = Environ.oracle (Global.env ()) in |
| 336 |
match r with |
| 337 |
| None -> |
| 338 |
let fold key lvl (vacc, cacc, pacc) = match key with |
| 339 |
| Conv_oracle.EvalVarRef id -> ((GlobRef.VarRef id, lvl) :: vacc, cacc, pacc) |
| 340 |
| Conv_oracle.EvalConstRef cst -> (vacc, (GlobRef.ConstRef cst, lvl) :: cacc, pacc) |
| 341 |
| Conv_oracle.EvalProjectionRef p -> (vacc, cacc, (GlobRef.ConstRef (Projection.Repr.constant p), lvl) :: pacc) |
| 342 |
in |
| 343 |
let var_lvl, cst_lvl, prj_lvl = fold_strategy fold oracle ([], [], []) in |
| 344 |
let var_msg = |
| 345 |
if List.is_empty var_lvl then mt () |
| 346 |
else str "Variable strategies" ++ fnl () ++ |
| 347 |
hov 0 (prlist_with_sep fnl pr_strategy var_lvl) ++ fnl () |
| 348 |
in |
| 349 |
let cst_msg = |
| 350 |
if List.is_empty cst_lvl then mt () |
| 351 |
else str "Constant strategies" ++ fnl () ++ |
| 352 |
hov 0 (prlist_with_sep fnl pr_strategy cst_lvl) |
| 353 |
in |
| 354 |
let prj_msg = |
| 355 |
if List.is_empty prj_lvl then mt () |
| 356 |
else str "Projection strategies" ++ fnl () ++ |
| 357 |
hov 0 (prlist_with_sep fnl pr_strategy prj_lvl) |
| 358 |
in |
| 359 |
var_msg ++ cst_msg ++ prj_msg |
| 360 |
| Some r -> |
| 361 |
let r = Smartlocate.smart_global r in |
| 362 |
let key = let open GlobRef in match r with |
| 363 |
| VarRef id -> Evaluable.EvalVarRef id |
| 364 |
| ConstRef cst -> Evaluable.EvalConstRef cst |
| 365 |
| IndRef _ | ConstructRef _ -> user_err Pp.(str "The reference is not unfoldable.") |
| 366 |
in |
| 367 |
let lvl = get_strategy oracle (Evaluable.to_kevaluable key) in |
| 368 |
pr_strategy (r, lvl) |
| 369 |
|
| 370 |
let print_registered () = |
| 371 |
let pr_lib_ref (s,r) = |
| 372 |
pr_global r ++ str " registered as " ++ str s |
| 373 |
in |
| 374 |
hov 0 (prlist_with_sep fnl pr_lib_ref @@ Rocqlib.get_lib_refs ()) |
| 375 |
|
| 376 |
let print_registered_schemes () = |
| 377 |
let schemes = DeclareScheme.all_schemes() in |
| 378 |
let pr_one_scheme ind (kind, c) = |
| 379 |
pr_global c ++ str " registered as " ++ str kind ++ str " for " ++ pr_global (IndRef ind) |
| 380 |
in |
| 381 |
let pr_schemes_of_ind (ind, schemes) = |
| 382 |
prlist_with_sep fnl (pr_one_scheme ind) (CString.Map.bindings schemes) |
| 383 |
in |
| 384 |
hov 0 (prlist_with_sep fnl pr_schemes_of_ind (Indmap_env.bindings schemes)) |
| 385 |
|
| 386 |
let dump_universes output g = |
| 387 |
let open Univ in |
| 388 |
let dump_arc u = function |
| 389 |
| UGraph.Node ltle -> |
| 390 |
Univ.Level.Map.iter (fun v strict -> |
| 391 |
let typ = if strict then UnivConstraint.Lt else UnivConstraint.Le in |
| 392 |
output typ u v) ltle; |
| 393 |
| UGraph.Alias v -> |
| 394 |
output UnivConstraint.Eq u v |
| 395 |
in |
| 396 |
Univ.Level.Map.iter dump_arc g |
| 397 |
|
| 398 |
let dump_universes_gen prl g s = |
| 399 |
let fulls = System.get_output_path s in |
| 400 |
System.mkdir (Filename.dirname fulls); |
| 401 |
let output = open_out fulls in |
| 402 |
let output_constraint, close = |
| 403 |
if Filename.check_suffix s ".dot" || Filename.check_suffix s ".gv" then begin |
| 404 |
|
| 405 |
let init = lazy (Printf.fprintf output "digraph universes {\n") in |
| 406 |
begin fun kind left right -> |
| 407 |
let () = Lazy.force init in |
| 408 |
match kind with |
| 409 |
| Univ.UnivConstraint.Lt -> |
| 410 |
Printf.fprintf output " \"%s\" -> \"%s\" [style=bold];\n" right left |
| 411 |
| Univ.UnivConstraint.Le -> |
| 412 |
Printf.fprintf output " \"%s\" -> \"%s\" [style=solid];\n" right left |
| 413 |
| Univ.UnivConstraint.Eq -> |
| 414 |
Printf.fprintf output " \"%s\" -> \"%s\" [style=dashed];\n" left right |
| 415 |
end, begin fun () -> |
| 416 |
if Lazy.is_val init then Printf.fprintf output "}\n"; |
| 417 |
close_out output |
| 418 |
end |
| 419 |
end else begin |
| 420 |
begin fun kind left right -> |
| 421 |
let kind = match kind with |
| 422 |
| Univ.UnivConstraint.Lt -> "<" |
| 423 |
| Univ.UnivConstraint.Le -> "<=" |
| 424 |
| Univ.UnivConstraint.Eq -> "=" |
| 425 |
in |
| 426 |
Printf.fprintf output "%s %s %s ;\n" left kind right |
| 427 |
end, (fun () -> close_out output) |
| 428 |
end |
| 429 |
in |
| 430 |
let output_constraint k l r = output_constraint k (prl l) (prl r) in |
| 431 |
try |
| 432 |
dump_universes output_constraint g; |
| 433 |
close (); |
| 434 |
str "Universes written to file \"" ++ str s ++ str "\"." |
| 435 |
with reraise -> |
| 436 |
let reraise = Exninfo.capture reraise in |
| 437 |
close (); |
| 438 |
Exninfo.iraise reraise |
| 439 |
|
| 440 |
let universe_subgraph kept univ = |
| 441 |
let open Univ in |
| 442 |
let parse = function |
| 443 |
| NamedUniv q -> |
| 444 |
begin try Level.make (Nametab.locate_universe q) |
| 445 |
with Not_found -> |
| 446 |
CErrors.user_err ?loc:q.loc Pp.(str "Undeclared universe " ++ pr_qualid q ++ str".") |
| 447 |
end |
| 448 |
| RawUniv { CAst.v = s; loc } -> |
| 449 |
let parts = String.split_on_char '.' s in |
| 450 |
let () = if CList.is_empty parts then CErrors.user_err ?loc Pp.(str "Invalid raw universe.") in |
| 451 |
let i, dp = List.sep_last parts in |
| 452 |
let dp = Libnames.dirpath_of_string (String.concat "." dp) in |
| 453 |
let i = match int_of_string_opt i with |
| 454 |
| Some i -> i |
| 455 |
| None -> CErrors.user_err ?loc Pp.(str "Invalid raw universe.") |
| 456 |
in |
| 457 |
let u = UGlobal.make dp "" i in |
| 458 |
let u = Level.make u in |
| 459 |
begin match UGraph.check_declared_universes univ (Level.Set.singleton u) with |
| 460 |
| Ok () -> u |
| 461 |
| Error _ -> CErrors.user_err ?loc Pp.(str "Undeclared universe " ++ Level.raw_pr u ++ str".") |
| 462 |
end |
| 463 |
in |
| 464 |
let kept = List.fold_left (fun kept q -> Level.Set.add (parse q) kept) Level.Set.empty kept in |
| 465 |
let csts = UGraph.constraints_for ~kept univ in |
| 466 |
let add u newgraph = |
| 467 |
let strict = UGraph.check_constraint univ (Level.set,Lt,u) in |
| 468 |
UGraph.add_universe u ~strict newgraph |
| 469 |
in |
| 470 |
let univ = Level.Set.fold add kept UGraph.initial_universes in |
| 471 |
UGraph.merge_constraints csts univ |
| 472 |
|
| 473 |
let sort_universes g = |
| 474 |
let open Univ in |
| 475 |
let rec normalize u = match Level.Map.find u g with |
| 476 |
| UGraph.Alias u -> normalize u |
| 477 |
| UGraph.Node _ -> u |
| 478 |
in |
| 479 |
let get_next u = match Level.Map.find u g with |
| 480 |
| UGraph.Alias u -> assert false |
| 481 |
| UGraph.Node ltle -> ltle |
| 482 |
in |
| 483 |
|
| 484 |
let rec traverse accu todo = match todo with |
| 485 |
| [] -> accu |
| 486 |
| (u, n) :: todo -> |
| 487 |
let () = assert (Level.equal (normalize u) u) in |
| 488 |
let n = match Level.Map.find u accu with |
| 489 |
| m -> if m < n then Some n else None |
| 490 |
| exception Not_found -> Some n |
| 491 |
in |
| 492 |
match n with |
| 493 |
| None -> traverse accu todo |
| 494 |
| Some n -> |
| 495 |
let accu = Level.Map.add u n accu in |
| 496 |
let next = get_next u in |
| 497 |
let fold v lt todo = |
| 498 |
let v = normalize v in |
| 499 |
if lt then (v, n + 1) :: todo else (v, n) :: todo |
| 500 |
in |
| 501 |
let todo = Level.Map.fold fold next todo in |
| 502 |
traverse accu todo |
| 503 |
in |
| 504 |
|
| 505 |
let levels = traverse Level.Map.empty [normalize Level.set, 0] in |
| 506 |
let max_level = Level.Map.fold (fun _ n accu -> max n accu) levels 0 in |
| 507 |
let dummy_mp = Names.DirPath.make [Names.Id.of_string "Type"] in |
| 508 |
let ulevels = Array.init max_level (fun i -> Level.(make (UGlobal.make dummy_mp "" i))) in |
| 509 |
|
| 510 |
let fold (cur, ans) u = |
| 511 |
let ans = Level.Map.add cur (UGraph.Node (Level.Map.singleton u true)) ans in |
| 512 |
(u, ans) |
| 513 |
in |
| 514 |
let _, ans = Array.fold_left fold (Level.set, Level.Map.empty) ulevels in |
| 515 |
let ulevels = Array.cons Level.set ulevels in |
| 516 |
|
| 517 |
let fold u _ ans = |
| 518 |
if Level.is_set u then ans |
| 519 |
else |
| 520 |
let n = Level.Map.find (normalize u) levels in |
| 521 |
Level.Map.add u (UGraph.Alias ulevels.(n)) ans |
| 522 |
in |
| 523 |
Level.Map.fold fold g ans |
| 524 |
|
| 525 |
type constraint_source = GlobRef of GlobRef.t | Library of DirPath.t |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
type constraint_sources = { |
| 536 |
edges : (constraint_source * Univ.UnivConstraint.kind) Univ.Level.Map.t Univ.Level.Map.t; |
| 537 |
} |
| 538 |
|
| 539 |
let empty_sources = { edges = Univ.Level.Map.empty } |
| 540 |
|
| 541 |
let mk_sources () = |
| 542 |
let open Univ in |
| 543 |
let open UnivConstraint in |
| 544 |
let srcs = DeclareUniv.constraint_sources () in |
| 545 |
let pick_stricter_constraint (_,k as v) (_,k' as v') = |
| 546 |
match k, k' with |
| 547 |
| Le, Lt | Le, Eq -> v' |
| 548 |
| Lt, Le | Eq, Le -> v |
| 549 |
| Le, Le | Lt, Lt | Eq, Eq -> |
| 550 |
|
| 551 |
|
| 552 |
v |
| 553 |
| Lt, Eq | Eq, Lt -> |
| 554 |
|
| 555 |
assert false |
| 556 |
in |
| 557 |
let add_edge_unidirectional (u,k,v) ref edges = |
| 558 |
Level.Map.update u (fun uedges -> |
| 559 |
let uedges = Option.default Level.Map.empty uedges in |
| 560 |
Some (Level.Map.update v (function |
| 561 |
| None -> Some (ref, k) |
| 562 |
| Some v' -> Some (pick_stricter_constraint (ref, k) v')) |
| 563 |
uedges)) |
| 564 |
edges |
| 565 |
in |
| 566 |
let add_edge (u,k,v as cst) ref edges = |
| 567 |
let edges = add_edge_unidirectional cst ref edges in |
| 568 |
if k = Eq then add_edge_unidirectional (v,k,u) ref edges else edges |
| 569 |
in |
| 570 |
let edges = Level.Map.empty in |
| 571 |
let edges = |
| 572 |
let libs = Library.loaded_libraries () in |
| 573 |
List.fold_left (fun edges dp -> |
| 574 |
let _, (_, univ_csts) = |
| 575 |
Safe_typing.univs_of_library @@ Library.library_compiled dp in |
| 576 |
UnivConstraints.fold (fun cst edges -> add_edge cst (Library dp) edges) |
| 577 |
univ_csts edges) |
| 578 |
edges libs |
| 579 |
in |
| 580 |
let edges = |
| 581 |
List.fold_left (fun edges (ref, csts) -> |
| 582 |
UnivConstraints.fold (fun cst edges -> add_edge cst (GlobRef ref) edges) |
| 583 |
csts edges) |
| 584 |
edges srcs |
| 585 |
in |
| 586 |
{ |
| 587 |
edges; |
| 588 |
} |
| 589 |
|
| 590 |
exception Found of (Univ.UnivConstraint.kind * Univ.Level.t * constraint_source) list |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
let search src ~target k ~source = |
| 600 |
let module UMap = Univ.Level.Map in |
| 601 |
let rec loop visited todo next_todo = |
| 602 |
match todo, next_todo with |
| 603 |
| [], [] -> () |
| 604 |
| _, _ :: _ -> loop visited next_todo [] |
| 605 |
| (source,k,revpath)::todo, _ -> |
| 606 |
let is_visited = match UMap.find_opt source visited with |
| 607 |
| None -> false |
| 608 |
| Some has_enough_lt -> |
| 609 |
if has_enough_lt then true |
| 610 |
else |
| 611 |
k = Univ.UnivConstraint.Lt |
| 612 |
in |
| 613 |
if is_visited then loop visited todo next_todo |
| 614 |
else |
| 615 |
let visited = UMap.add source (k <> Univ.UnivConstraint.Lt) visited in |
| 616 |
let visited, next_todo = |
| 617 |
UMap.fold (fun u (ref,k') (visited,next_todo) -> |
| 618 |
if k = Univ.UnivConstraint.Eq && k' = Univ.UnivConstraint.Lt then |
| 619 |
|
| 620 |
(UMap.add u true visited, next_todo) |
| 621 |
else |
| 622 |
let next_k = if k = Univ.UnivConstraint.Lt && k' = Univ.UnivConstraint.Lt |
| 623 |
then Univ.UnivConstraint.Le |
| 624 |
else k |
| 625 |
in |
| 626 |
let revpath = (k',u,ref) :: revpath in |
| 627 |
if Univ.Level.equal u target && next_k <> Univ.UnivConstraint.Lt |
| 628 |
then raise (Found revpath) |
| 629 |
else (visited, (u, next_k, revpath) :: next_todo)) |
| 630 |
(Option.default UMap.empty (UMap.find_opt source src.edges)) |
| 631 |
(visited,next_todo) |
| 632 |
in |
| 633 |
loop visited todo next_todo |
| 634 |
in |
| 635 |
try loop UMap.empty [source,k,[]] []; None |
| 636 |
with Found l -> Some (List.rev l) |
| 637 |
|
| 638 |
let search src (u,k,v) = |
| 639 |
let path = search src ~source:u k ~target:v in |
| 640 |
match path with |
| 641 |
| None -> None |
| 642 |
| Some path -> |
| 643 |
if k = Univ.UnivConstraint.Eq && not (List.for_all (fun (k',_,_) -> k' = Univ.UnivConstraint.Eq) path) then |
| 644 |
let path' = search src ~source:v k ~target:u in |
| 645 |
begin match path' with |
| 646 |
| None -> None |
| 647 |
| Some path' -> Some (path @ path') |
| 648 |
end |
| 649 |
else Some path |
| 650 |
|
| 651 |
let find_source (u,k,v as cst) src = |
| 652 |
if Univ.Level.is_set u && k = Univ.UnivConstraint.Lt then [] |
| 653 |
else Option.default [] (search src cst) |
| 654 |
|
| 655 |
let pr_constraint_source = function |
| 656 |
| GlobRef ref -> begin try pr_global ref |
| 657 |
with Not_found -> |
| 658 |
|
| 659 |
GlobRef.print ref |
| 660 |
end |
| 661 |
| Library dp -> str "library " ++ pr_qualid (Nametab.shortest_qualid_of_module (MPfile dp)) |
| 662 |
|
| 663 |
let pr_source_path prl u src = |
| 664 |
if CList.is_empty src then mt() |
| 665 |
else |
| 666 |
let open Univ in |
| 667 |
let pr_rel = function |
| 668 |
| UnivConstraint.Eq -> str"=" | UnivConstraint.Lt -> str"<" | UnivConstraint.Le -> str"<=" |
| 669 |
in |
| 670 |
let pr_one (k,v,ref) = |
| 671 |
spc() ++ |
| 672 |
h (pr_rel k ++ surround (str "from " ++ pr_constraint_source ref) ++ |
| 673 |
spc() ++ prl v) |
| 674 |
in |
| 675 |
spc() ++ surround (str"because" ++ spc() ++ prl u ++ prlist_with_sep mt pr_one src) |
| 676 |
|
| 677 |
let pr_pmap sep pr map = |
| 678 |
let cmp (u,_) (v,_) = Univ.Level.compare u v in |
| 679 |
Pp.prlist_with_sep sep pr (List.sort cmp (Univ.Level.Map.bindings map)) |
| 680 |
|
| 681 |
let pr_arc srcs prl = let open Pp in |
| 682 |
function |
| 683 |
| u, UGraph.Node ltle -> |
| 684 |
if Univ.Level.Map.is_empty ltle then mt () |
| 685 |
else |
| 686 |
prl u ++ str " " ++ |
| 687 |
v 0 |
| 688 |
(pr_pmap spc (fun (v, strict) -> |
| 689 |
let k = if strict then Univ.UnivConstraint.Lt else Univ.UnivConstraint.Le in |
| 690 |
let src = find_source (u,k,v) srcs in |
| 691 |
hov 2 ((if strict then str "< " else str "<= ") ++ prl v ++ pr_source_path prl u src)) |
| 692 |
ltle) ++ |
| 693 |
fnl () |
| 694 |
| u, UGraph.Alias v -> |
| 695 |
let src = find_source (u,Eq,v) srcs in |
| 696 |
prl u ++ str " = " ++ prl v ++ pr_source_path prl u src ++ fnl () |
| 697 |
|
| 698 |
let pr_universes srcs prl g = pr_pmap Pp.mt (pr_arc srcs prl) g |
| 699 |
|
| 700 |
let print_universes { sort; subgraph; with_sources; file; } = |
| 701 |
let univ = Global.universes () in |
| 702 |
let univ = match subgraph with |
| 703 |
| None -> univ |
| 704 |
| Some g -> universe_subgraph g univ |
| 705 |
in |
| 706 |
let univ = UGraph.repr univ in |
| 707 |
let univ = if sort then sort_universes univ else univ in |
| 708 |
let pr_remaining = |
| 709 |
if Global.is_joined_environment () then mt () |
| 710 |
else str"There may remain asynchronous universe constraints" |
| 711 |
in |
| 712 |
let prl = UnivNames.pr_level_with_global_universes in |
| 713 |
begin match file with |
| 714 |
| None -> |
| 715 |
let with_sources = match with_sources, subgraph with |
| 716 |
| Some b, _ -> b |
| 717 |
| _, None -> false |
| 718 |
| _, Some _ -> true |
| 719 |
in |
| 720 |
let srcs = if with_sources then mk_sources () else empty_sources in |
| 721 |
pr_universes srcs prl univ ++ pr_remaining |
| 722 |
| Some s -> dump_universes_gen (fun u -> Pp.string_of_ppcmds (prl u)) univ s |
| 723 |
end |
| 724 |
|
| 725 |
let print_sorts () = |
| 726 |
let qualities = Sorts.QVar.Set.elements (Global.qualities ()) in |
| 727 |
let prq = UnivNames.pr_quality_with_global_universes in |
| 728 |
Pp.prlist_with_sep Pp.spc prq qualities |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
let locate_file f = |
| 734 |
let file = Flags.silently Loadpath.locate_file f in |
| 735 |
str file |
| 736 |
|
| 737 |
let msg_found_library (fulldir, file) = |
| 738 |
if Library.library_is_loaded fulldir then |
| 739 |
hov 0 (DirPath.print fulldir ++ strbrk " has been loaded from file " ++ str file) |
| 740 |
else |
| 741 |
hov 0 (DirPath.print fulldir ++ strbrk " is bound to file " ++ str file) |
| 742 |
|
| 743 |
let print_located_library qid = |
| 744 |
let open Loadpath in |
| 745 |
match locate_qualified_library qid with |
| 746 |
| Ok lib -> msg_found_library lib |
| 747 |
| Error LibUnmappedDir -> raise (UnmappedLibrary (None, qid)) |
| 748 |
| Error LibNotFound -> raise (NotFoundLibrary (None, qid)) |
| 749 |
|
| 750 |
let smart_global r = |
| 751 |
let gr = Smartlocate.smart_global r in |
| 752 |
Dumpglob.add_glob ?loc:r.loc gr; |
| 753 |
gr |
| 754 |
|
| 755 |
let qualid_global id = smart_global (make ?loc:id.loc @@ Constrexpr.AN id) |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
let vernac_declare_scope ~module_local sc = |
| 761 |
Metasyntax.declare_scope module_local sc |
| 762 |
|
| 763 |
let vernac_delimiters ~module_local sc action = |
| 764 |
match action with |
| 765 |
| Some lr -> Metasyntax.add_delimiters module_local sc lr |
| 766 |
| None -> Metasyntax.remove_delimiters module_local sc |
| 767 |
|
| 768 |
let vernac_bind_scope ~atts sc cll = |
| 769 |
let module_local, where = Attributes.(parse Notations.(module_locality ++ bind_scope_where) atts) in |
| 770 |
Metasyntax.add_class_scope module_local sc where (List.map scope_class_of_qualid cll) |
| 771 |
|
| 772 |
let vernac_open_close_scope ~section_local (to_open,s) = |
| 773 |
Metasyntax.open_close_scope section_local ~to_open s |
| 774 |
|
| 775 |
let interp_enable_notation_rule on ntn interp flags scope = |
| 776 |
let open Notation in |
| 777 |
let rule = Option.map (function |
| 778 |
| Inl ntn -> Inl (interpret_notation_string ntn) |
| 779 |
| Inr (vars,qid) -> Inr qid) ntn in |
| 780 |
let rec parse_notation_enable_flags all query = function |
| 781 |
| [] -> all, query |
| 782 |
| EnableNotationEntry entry :: flags -> |
| 783 |
let entry = Metasyntax.intern_notation_entry entry in |
| 784 |
parse_notation_enable_flags all { query with notation_entry_pattern = entry :: query.notation_entry_pattern } flags |
| 785 |
| EnableNotationOnly use :: flags -> |
| 786 |
parse_notation_enable_flags all { query with use_pattern = use } flags |
| 787 |
| EnableNotationAll :: flags -> parse_notation_enable_flags true query flags in |
| 788 |
let interp = Option.map (fun c -> |
| 789 |
let vars, recvars = |
| 790 |
match ntn with |
| 791 |
| None -> |
| 792 |
|
| 793 |
|
| 794 |
([], []) |
| 795 |
| Some (Inl ntn) -> let {recvars; mainvars} = decompose_raw_notation ntn in (mainvars, recvars) |
| 796 |
| Some (Inr (vars,qid)) -> (vars, []) |
| 797 |
in |
| 798 |
let ninterp_var_type = Id.Map.of_list (List.map (fun x -> (x, Notation_term.NtnInternTypeAny None)) vars) in |
| 799 |
let ninterp_rec_vars = Id.Map.of_list recvars in |
| 800 |
let nenv = Notation_term.{ ninterp_var_type; ninterp_rec_vars } in |
| 801 |
let (_acvars, ac, _reversibility) = Constrintern.interp_notation_constr (Global.env ()) nenv c in |
| 802 |
([], ac)) interp in |
| 803 |
let default_notation_enable_pattern = { |
| 804 |
notation_entry_pattern = []; |
| 805 |
interp_rule_key_pattern = rule; |
| 806 |
use_pattern = ParsingAndPrinting; |
| 807 |
scope_pattern = scope; |
| 808 |
interpretation_pattern = interp; |
| 809 |
} |
| 810 |
in |
| 811 |
let all, notation_pattern = |
| 812 |
parse_notation_enable_flags false default_notation_enable_pattern flags in |
| 813 |
on, all, notation_pattern |
| 814 |
|
| 815 |
let vernac_enable_notation ~module_local on rule interp flags scope = |
| 816 |
let () = match rule, interp, scope with |
| 817 |
| None, None, None -> user_err (str "No notation provided.") | _ -> () in |
| 818 |
let on, all, notation_pattern = interp_enable_notation_rule on rule interp flags scope in |
| 819 |
Metasyntax.declare_notation_toggle module_local ~on ~all notation_pattern |
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
let check_name_freshness locality {CAst.loc;v=id} : unit = |
| 825 |
|
| 826 |
if Termops.is_section_variable (Global.env ()) id || |
| 827 |
locality <> Discharge && Nametab.exists_cci (Lib.make_path id) || |
| 828 |
locality <> Discharge && Nametab.exists_cci (Lib.make_path_except_section id) |
| 829 |
then |
| 830 |
user_err ?loc (Id.print id ++ str " already exists.") |
| 831 |
|
| 832 |
let vernac_definition_hook ~atts ~canonical_instance ~local ~poly ~reversible kind = |
| 833 |
let hooks = atts.DefAttributes.hooks in |
| 834 |
let hooks = |
| 835 |
let open Decls in |
| 836 |
let open Declare.Hook in |
| 837 |
match kind with |
| 838 |
| Coercion -> |
| 839 |
(ComCoercion.coercion_hook ~reversible) :: hooks |
| 840 |
| CanonicalStructure -> |
| 841 |
make (fun { S.dref } -> Canonical.declare_canonical_structure ?local dref) :: hooks |
| 842 |
| SubClass -> |
| 843 |
(ComCoercion.subclass_hook ~poly ~reversible) :: hooks |
| 844 |
| Definition when canonical_instance -> |
| 845 |
make (fun { S.dref } -> Canonical.declare_canonical_structure ?local dref) :: hooks |
| 846 |
| Let when canonical_instance -> |
| 847 |
make (fun { S.dref } -> Canonical.declare_canonical_structure dref) :: hooks |
| 848 |
| _ -> hooks |
| 849 |
in |
| 850 |
match hooks with |
| 851 |
| [] -> None |
| 852 |
| _ -> Some (Declare.Hook.make (fun st -> List.iter (fun hook -> Declare.Hook.call ~hook st) hooks)) |
| 853 |
|
| 854 |
let default_thm_id = Id.of_string "Unnamed_thm" |
| 855 |
|
| 856 |
let fresh_name_for_anonymous_theorem () = |
| 857 |
Namegen.next_global_ident_away (Global.safe_env ()) default_thm_id Id.Set.empty |
| 858 |
|
| 859 |
let vernac_definition_name lid local = |
| 860 |
let lid = |
| 861 |
match lid with |
| 862 |
| { v = Name.Anonymous; loc } -> |
| 863 |
CAst.make ?loc (fresh_name_for_anonymous_theorem ()) |
| 864 |
| { v = Name.Name n; loc } -> CAst.make ?loc n in |
| 865 |
check_name_freshness local lid; |
| 866 |
let () = |
| 867 |
if Dumpglob.dump () then |
| 868 |
match local with |
| 869 |
| Discharge -> Dumpglob.dump_definition lid true "var" |
| 870 |
| Global _ -> Dumpglob.dump_definition lid false "def" |
| 871 |
in |
| 872 |
lid.v |
| 873 |
|
| 874 |
let vernac_definition_interactive ~atts (discharge, kind) (lid, udecl) bl t = |
| 875 |
let open DefAttributes in |
| 876 |
let scope, local, poly, program_mode, user_warns, typing_flags, using, clearbody = |
| 877 |
atts.scope, atts.locality, atts.poly, atts.program, atts.user_warns, atts.typing_flags, atts.using, atts.clearbody in |
| 878 |
let hook = |
| 879 |
let canonical_instance, reversible = atts.canonical_instance, atts.reversible in |
| 880 |
vernac_definition_hook ~atts ~canonical_instance ~local ~poly ~reversible kind |
| 881 |
in |
| 882 |
let name = vernac_definition_name lid scope in |
| 883 |
ComDefinition.do_definition_interactive ?loc:lid.loc ~typing_flags ~program_mode ~name ~poly ~scope ?clearbody:atts.clearbody |
| 884 |
~kind:(Decls.IsDefinition kind) ?user_warns ?using:atts.using ?hook udecl bl t |
| 885 |
|
| 886 |
let vernac_definition_refine ~atts (discharge, kind) (lid, udecl) bl red_option c typ_opt = |
| 887 |
if Option.has_some red_option then |
| 888 |
CErrors.user_err ?loc:c.loc Pp.(str "Cannot use Eval with #[refine]."); |
| 889 |
let open DefAttributes in |
| 890 |
let scope, local, poly, program_mode, user_warns, typing_flags, using, clearbody = |
| 891 |
atts.scope, atts.locality, atts.poly, atts.program, atts.user_warns, atts.typing_flags, atts.using, atts.clearbody in |
| 892 |
let hook = |
| 893 |
let canonical_instance, reversible = atts.canonical_instance, atts.reversible in |
| 894 |
vernac_definition_hook ~atts ~canonical_instance ~local ~poly kind ~reversible |
| 895 |
in |
| 896 |
let name = vernac_definition_name lid scope in |
| 897 |
ComDefinition.do_definition_refine ~name ?loc:lid.loc |
| 898 |
?clearbody ~poly ~typing_flags ~scope ~kind:(Decls.IsDefinition kind) |
| 899 |
?user_warns ?using udecl bl c typ_opt ?hook |
| 900 |
|
| 901 |
let vernac_definition ~atts ~pm (discharge, kind) (lid, udecl) bl red_option c typ_opt = |
| 902 |
let open DefAttributes in |
| 903 |
let scope, local, poly, program_mode, user_warns, typing_flags, using, clearbody = |
| 904 |
atts.scope, atts.locality, atts.poly, atts.program, atts.user_warns, atts.typing_flags, atts.using, atts.clearbody in |
| 905 |
let hook = |
| 906 |
let canonical_instance, reversible = atts.canonical_instance, atts.reversible in |
| 907 |
vernac_definition_hook ~atts ~canonical_instance ~local ~poly kind ~reversible |
| 908 |
in |
| 909 |
let name = vernac_definition_name lid scope in |
| 910 |
let red_option = match red_option with |
| 911 |
| None -> None |
| 912 |
| Some r -> |
| 913 |
let env = Global.env () in |
| 914 |
let sigma = Evd.from_env env in |
| 915 |
Some (snd (Redexpr.interp_redexp_no_ltac env sigma r)) in |
| 916 |
if program_mode then |
| 917 |
let kind = Decls.IsDefinition kind in |
| 918 |
ComDefinition.do_definition_program ?loc:lid.loc ~pm ~name |
| 919 |
?clearbody ~poly ?typing_flags ~scope ~kind |
| 920 |
?user_warns ?using udecl bl red_option c typ_opt ?hook |
| 921 |
else |
| 922 |
let () = |
| 923 |
ComDefinition.do_definition ~name ?loc:lid.loc |
| 924 |
?clearbody ~poly ?typing_flags ~scope ~kind |
| 925 |
?user_warns ?using udecl bl red_option c typ_opt ?hook in |
| 926 |
pm |
| 927 |
|
| 928 |
|
| 929 |
let vernac_start_proof ~atts kind l = |
| 930 |
let open DefAttributes in |
| 931 |
if Dumpglob.dump () then |
| 932 |
List.iter (fun ((id, _), _) -> Dumpglob.dump_definition id false "prf") l; |
| 933 |
let scope, local, poly, program_mode, user_warns, typing_flags, using, clearbody = |
| 934 |
atts.scope, atts.locality, atts.poly, |
| 935 |
atts.program, atts.user_warns, atts.typing_flags, atts.using, atts.clearbody in |
| 936 |
List.iter (fun ((id, _), _) -> check_name_freshness scope id) l; |
| 937 |
match l with |
| 938 |
| [] -> assert false |
| 939 |
| [({v=name; loc},udecl),(bl,typ)] -> |
| 940 |
ComDefinition.do_definition_interactive ?loc |
| 941 |
~typing_flags ~program_mode ~name ~poly ?clearbody ~scope |
| 942 |
~kind:(Decls.IsProof kind) ?user_warns ?using udecl bl typ |
| 943 |
| ((lid,_),_) :: _ -> |
| 944 |
let fix = List.map (fun ((fname, univs), (binders, rtype)) -> |
| 945 |
{ fname; binders; rtype; body_def = None; univs; notations = []}) l in |
| 946 |
let pm, proof = |
| 947 |
ComFixpoint.do_mutually_recursive ~refine:false ~program_mode ~use_inference_hook:program_mode |
| 948 |
~scope ?clearbody ~kind:(Decls.IsProof kind) ~poly ?typing_flags |
| 949 |
?user_warns ?using (CUnknownRecOrder, fix) in |
| 950 |
assert (Option.is_empty pm); |
| 951 |
Option.get proof |
| 952 |
|
| 953 |
let vernac_end_proof ~lemma ~pm = let open Vernacexpr in function |
| 954 |
| Admitted -> |
| 955 |
Declare.Proof.save_admitted ~pm ~proof:lemma |
| 956 |
| Proved (opaque,idopt) -> |
| 957 |
let pm, _ = Declare.Proof.save ~pm ~proof:lemma ~opaque ~idopt |
| 958 |
in pm |
| 959 |
|
| 960 |
let vernac_abort ~lemma:_ ~pm = pm |
| 961 |
|
| 962 |
let deprecated_exact_proof = CWarnings.create ~name:"deprecated-exact-proof" ~category:Deprecation.Version.v9_2 |
| 963 |
Pp.(fun () -> str "\"Proof term.\" is deprecated. Use \"Proof. exact term. Qed.\" instead.") |
| 964 |
|
| 965 |
let vernac_exact_proof ~lemma ~pm c = |
| 966 |
deprecated_exact_proof (); |
| 967 |
|
| 968 |
|
| 969 |
let lemma, status = Declare.Proof.by (Global.env ()) (Tactics.exact_proof c) lemma in |
| 970 |
let pm, _ = Declare.Proof.save ~pm ~proof:lemma ~opaque:Opaque ~idopt:None in |
| 971 |
if not status then Feedback.feedback Feedback.AddedAxiom; |
| 972 |
pm |
| 973 |
|
| 974 |
let vernac_assumption ~atts kind l inline = |
| 975 |
let open DefAttributes in |
| 976 |
let scope, poly, program_mode, using, user_warns = |
| 977 |
atts.scope, atts.poly, atts.program, atts.using, atts.user_warns in |
| 978 |
if Option.has_some using then |
| 979 |
Attributes.unsupported_attributes [CAst.make ("using",VernacFlagEmpty)]; |
| 980 |
ComAssumption.do_assumptions ~poly ~program_mode ~scope ~kind ?user_warns ~inline l |
| 981 |
|
| 982 |
let { Goptions.get = get_uniform_inductive_parameters } = |
| 983 |
Goptions.declare_bool_option_and_ref |
| 984 |
~key:["Uniform"; "Inductive"; "Parameters"] |
| 985 |
~value:false |
| 986 |
() |
| 987 |
|
| 988 |
let should_treat_as_uniform () = |
| 989 |
if get_uniform_inductive_parameters () |
| 990 |
then ComInductive.UniformParameters |
| 991 |
else ComInductive.NonUniformParameters |
| 992 |
|
| 993 |
|
| 994 |
let vernac_record records = |
| 995 |
let map ((is_coercion, name), binders, sort, nameopt, cfs, ido) = |
| 996 |
let idbuild = match nameopt with |
| 997 |
| None -> CAst.map (Nameops.add_prefix "Build_") name |
| 998 |
| Some lid -> lid |
| 999 |
in |
| 1000 |
let default_inhabitant_id = Option.map (fun CAst.{v=id} -> id) ido in |
| 1001 |
Record.Ast.{ name; is_coercion; binders; cfs; idbuild; sort; default_inhabitant_id } |
| 1002 |
in |
| 1003 |
let records = List.map map records in |
| 1004 |
records |
| 1005 |
|
| 1006 |
let extract_inductive_udecl (indl:(inductive_expr * notation_declaration list) list) = |
| 1007 |
match indl with |
| 1008 |
| [] -> assert false |
| 1009 |
| (((coe,(id,udecl)),b,c,d),e) :: rest -> |
| 1010 |
let rest = List.map (fun (((coe,(id,udecl)),b,c,d),e) -> |
| 1011 |
if Option.has_some udecl |
| 1012 |
then user_err Pp.(strbrk "Universe binders must be on the first inductive of the block.") |
| 1013 |
else (((coe,id),b,c,d),e)) |
| 1014 |
rest |
| 1015 |
in |
| 1016 |
udecl, (((coe,id),b,c,d),e) :: rest |
| 1017 |
|
| 1018 |
let finite_of_kind = let open Declarations in function |
| 1019 |
| Inductive_kw -> Finite |
| 1020 |
| CoInductive -> CoFinite |
| 1021 |
| Variant | Record | Structure | Class _ -> BiFinite |
| 1022 |
|
| 1023 |
let private_ind = |
| 1024 |
let open Attributes in |
| 1025 |
let open Notations in |
| 1026 |
attribute_of_list |
| 1027 |
[ "matching" |
| 1028 |
, single_key_parser ~name:"Private (matching) inductive type" ~key:"matching" () |
| 1029 |
] |
| 1030 |
|> qualify_attribute "private" |
| 1031 |
>>= function |
| 1032 |
| Some () -> return true |
| 1033 |
| None -> return false |
| 1034 |
|
| 1035 |
|
| 1036 |
let { Goptions.get = primitive_flag } = |
| 1037 |
Goptions.declare_bool_option_and_ref |
| 1038 |
~key:["Primitive";"Projections"] |
| 1039 |
~value:false |
| 1040 |
() |
| 1041 |
|
| 1042 |
let primitive_proj = |
| 1043 |
let open Attributes in |
| 1044 |
let open Notations in |
| 1045 |
qualify_attribute "projections" (bool_attribute ~name:"primitive") |
| 1046 |
>>= function |
| 1047 |
| Some t -> return t |
| 1048 |
| None -> return (primitive_flag ()) |
| 1049 |
|
| 1050 |
let mode_attr = |
| 1051 |
let open Attributes in |
| 1052 |
let open Notations in |
| 1053 |
payload_attribute ?cat:None ~name:"mode" >>= function |
| 1054 |
| None -> return None |
| 1055 |
| Some mode -> return (Some (Hints.parse_modes mode)) |
| 1056 |
|
| 1057 |
module Preprocessed_Mind_decl = struct |
| 1058 |
type flags = ComInductive.flags |
| 1059 |
type record = { |
| 1060 |
flags : flags; |
| 1061 |
udecl : Constrexpr.cumul_univ_decl_expr option; |
| 1062 |
primitive_proj : bool; |
| 1063 |
kind : Vernacexpr.inductive_kind; |
| 1064 |
records : Record.Ast.t list; |
| 1065 |
} |
| 1066 |
type inductive = { |
| 1067 |
flags : flags; |
| 1068 |
udecl : Constrexpr.cumul_univ_decl_expr option; |
| 1069 |
typing_flags : Declarations.typing_flags option; |
| 1070 |
private_ind : bool; |
| 1071 |
uniform : ComInductive.uniform_inductive_flag; |
| 1072 |
inductives : (Vernacexpr.one_inductive_expr * Vernacexpr.notation_declaration list) list; |
| 1073 |
} |
| 1074 |
type t = |
| 1075 |
| Record of record |
| 1076 |
| Inductive of inductive |
| 1077 |
end |
| 1078 |
|
| 1079 |
|
| 1080 |
type record_field_attr = { |
| 1081 |
rf_coercion: coercion_flag; |
| 1082 |
rf_reversible: bool option; |
| 1083 |
rf_instance: instance_flag; |
| 1084 |
rf_priority: int option; |
| 1085 |
rf_locality: Goptions.option_locality; |
| 1086 |
rf_canonical: bool; |
| 1087 |
} |
| 1088 |
|
| 1089 |
let check_proj_flags rf = |
| 1090 |
let open Vernacexpr in |
| 1091 |
let open Record.Data in |
| 1092 |
let () = match rf.rf_coercion, rf.rf_instance with |
| 1093 |
| NoCoercion, NoInstance -> |
| 1094 |
if rf.rf_locality <> Goptions.OptDefault then |
| 1095 |
Attributes.(unsupported_attributes |
| 1096 |
[CAst.make ("locality (without :> or ::)",VernacFlagEmpty)]) |
| 1097 |
| AddCoercion, NoInstance -> |
| 1098 |
if rf.rf_locality = Goptions.OptExport then |
| 1099 |
Attributes.(unsupported_attributes |
| 1100 |
[CAst.make ("export (without ::)",VernacFlagEmpty)]) |
| 1101 |
| _ -> () |
| 1102 |
in |
| 1103 |
let pf_coercion = |
| 1104 |
match rf.rf_coercion with |
| 1105 |
| AddCoercion -> |
| 1106 |
Some { |
| 1107 |
coe_local = rf.rf_locality = OptLocal; |
| 1108 |
coe_reversible = Option.default true rf.rf_reversible; |
| 1109 |
} |
| 1110 |
| NoCoercion -> |
| 1111 |
if rf.rf_reversible <> None then |
| 1112 |
Attributes.(unsupported_attributes |
| 1113 |
[CAst.make ("reversible (without :>)",VernacFlagEmpty)]); |
| 1114 |
None |
| 1115 |
in |
| 1116 |
let pf_instance = |
| 1117 |
match rf.rf_instance with |
| 1118 |
| NoInstance -> |
| 1119 |
let () = if Option.has_some rf.rf_priority then |
| 1120 |
CErrors.user_err Pp.(str "Priority not allowed without \"::\".") |
| 1121 |
in |
| 1122 |
None |
| 1123 |
| BackInstance -> |
| 1124 |
let local = |
| 1125 |
match rf.rf_locality with |
| 1126 |
| Goptions.OptLocal -> Hints.Local |
| 1127 |
| Goptions.(OptDefault | OptExport) -> Hints.Export |
| 1128 |
| Goptions.OptGlobal -> Hints.SuperGlobal |
| 1129 |
in |
| 1130 |
Some { |
| 1131 |
inst_locality = local; |
| 1132 |
inst_priority = rf.rf_priority; |
| 1133 |
} |
| 1134 |
in |
| 1135 |
{ pf_coercion; pf_instance; pf_canonical = rf.rf_canonical } |
| 1136 |
|
| 1137 |
let preprocess_defclass ~atts udecl (id, bl, c, l) = |
| 1138 |
let poly, mode = |
| 1139 |
Attributes.(parse Notations.(poly PolyFlags.Definition ++ mode_attr) atts) |
| 1140 |
in |
| 1141 |
let flags = { |
| 1142 |
|
| 1143 |
ComInductive.template=None; finite=BiFinite; schemes=None; |
| 1144 |
|
| 1145 |
poly; mode; |
| 1146 |
} |
| 1147 |
in |
| 1148 |
let bl = match bl with |
| 1149 |
| bl, None -> bl |
| 1150 |
| _ -> CErrors.user_err Pp.(str "Definitional classes do not support the \"|\" syntax.") |
| 1151 |
in |
| 1152 |
if fst id = AddCoercion then |
| 1153 |
user_err Pp.(str "Definitional classes do not support the \">\" syntax."); |
| 1154 |
let ((attr, rf_coercion, rf_instance), (lid, ce)) = l in |
| 1155 |
let rf_locality = match rf_coercion, rf_instance with |
| 1156 |
| AddCoercion, _ | _, BackInstance -> parse option_locality attr |
| 1157 |
| _ -> let () = unsupported_attributes attr in Goptions.OptDefault |
| 1158 |
in |
| 1159 |
let f = AssumExpr ((make ?loc:lid.loc @@ Name lid.v), [], ce), |
| 1160 |
check_proj_flags |
| 1161 |
{ rf_coercion ; rf_reversible = None ; rf_instance ; rf_priority = None ; |
| 1162 |
rf_locality ; rf_canonical = true }, |
| 1163 |
[] |
| 1164 |
in |
| 1165 |
let recordl = [id, bl, c, None, [f], None] in |
| 1166 |
let kind = Class true in |
| 1167 |
let records = vernac_record recordl in |
| 1168 |
Preprocessed_Mind_decl.(Record { flags; udecl; primitive_proj=false; kind; records }) |
| 1169 |
|
| 1170 |
let preprocess_record ~atts udecl kind indl = |
| 1171 |
let () = match kind with |
| 1172 |
| Variant -> |
| 1173 |
user_err (str "The Variant keyword does not support syntax { ... }.") |
| 1174 |
| Record | Structure | Class _ | Inductive_kw | CoInductive -> () |
| 1175 |
in |
| 1176 |
let check_where ((_, _, _, _), wh) = match wh with |
| 1177 |
| [] -> () |
| 1178 |
| _ :: _ -> |
| 1179 |
user_err (str "\"where\" clause not supported for records.") |
| 1180 |
in |
| 1181 |
let () = List.iter check_where indl in |
| 1182 |
let hint_mode_attr : Hints.hint_mode list option Attributes.attribute = |
| 1183 |
match kind with |
| 1184 |
| Class _ -> mode_attr |
| 1185 |
| _ -> Notations.return None |
| 1186 |
in |
| 1187 |
let (((template, poly), primitive_proj), mode), schemes = |
| 1188 |
Attributes.( |
| 1189 |
parse Notations.( |
| 1190 |
template |
| 1191 |
++ poly PolyFlags.Inductive |
| 1192 |
++ primitive_proj |
| 1193 |
++ hint_mode_attr |
| 1194 |
++ DeclareInd.schemes_attr) |
| 1195 |
atts) |
| 1196 |
in |
| 1197 |
let finite = finite_of_kind kind in |
| 1198 |
let flags = { ComInductive.template; poly; finite; mode; schemes } in |
| 1199 |
let parse_record_field_attr (x, f) = |
| 1200 |
let attr = |
| 1201 |
let rev = match f.rfu_coercion with |
| 1202 |
| AddCoercion -> reversible |
| 1203 |
| NoCoercion -> Notations.return None in |
| 1204 |
let loc = match f.rfu_coercion, f.rfu_instance with |
| 1205 |
| AddCoercion, _ | _, BackInstance -> option_locality |
| 1206 |
| _ -> Notations.return Goptions.OptDefault in |
| 1207 |
Notations.(rev ++ loc ++ canonical_field) in |
| 1208 |
let (rf_reversible, rf_locality), rf_canonical = parse attr f.rfu_attrs in |
| 1209 |
let flags = check_proj_flags { |
| 1210 |
rf_coercion = f.rfu_coercion; |
| 1211 |
rf_reversible; |
| 1212 |
rf_instance = f.rfu_instance; |
| 1213 |
rf_priority = f.rfu_priority; |
| 1214 |
rf_locality; |
| 1215 |
rf_canonical; |
| 1216 |
} |
| 1217 |
in |
| 1218 |
x, flags, f.rfu_notation |
| 1219 |
in |
| 1220 |
let unpack ((id, bl, c, decl), _) = match decl with |
| 1221 |
| RecordDecl (oc, fs, ido) -> |
| 1222 |
let bl = match bl with |
| 1223 |
| bl, None -> bl |
| 1224 |
| _ -> CErrors.user_err Pp.(str "Records do not support the \"|\" syntax.") |
| 1225 |
in |
| 1226 |
(id, bl, c, oc, List.map parse_record_field_attr fs, ido) |
| 1227 |
| Constructors _ -> assert false |
| 1228 |
in |
| 1229 |
let kind = match kind with Class _ -> Class false | _ -> kind in |
| 1230 |
let recordl = List.map unpack indl in |
| 1231 |
let records = vernac_record recordl in |
| 1232 |
Preprocessed_Mind_decl.(Record { flags; udecl; primitive_proj; kind; records }) |
| 1233 |
|
| 1234 |
let preprocess_inductive ~atts udecl kind indl = |
| 1235 |
let () = match kind with |
| 1236 |
| (Record | Structure) -> |
| 1237 |
user_err (str "The Record keyword is for types defined using the syntax { ... }.") |
| 1238 |
| Class _ -> |
| 1239 |
user_err (str "Inductive classes not supported.") |
| 1240 |
| Variant | Inductive_kw | CoInductive -> () |
| 1241 |
in |
| 1242 |
let check_name ((na, _, _, _), _) = match na with |
| 1243 |
| (AddCoercion, _) -> |
| 1244 |
user_err (str "Variant types do not handle the \"> Name\" \ |
| 1245 |
syntax, which is reserved for records. Use the \":>\" \ |
| 1246 |
syntax on constructors instead.") |
| 1247 |
| _ -> () |
| 1248 |
in |
| 1249 |
let () = List.iter check_name indl in |
| 1250 |
let hint_mode_attr : Hints.hint_mode list option Attributes.attribute = |
| 1251 |
match kind with |
| 1252 |
| Class _ -> mode_attr |
| 1253 |
| _ -> Notations.return None |
| 1254 |
in |
| 1255 |
let ((((template, poly), private_ind), typing_flags), mode), schemes = |
| 1256 |
Attributes.( |
| 1257 |
parse Notations.( |
| 1258 |
template |
| 1259 |
++ poly PolyFlags.Inductive |
| 1260 |
++ private_ind |
| 1261 |
++ typing_flags |
| 1262 |
++ hint_mode_attr |
| 1263 |
++ DeclareInd.schemes_attr) |
| 1264 |
atts) |
| 1265 |
in |
| 1266 |
let finite = finite_of_kind kind in |
| 1267 |
let flags = { ComInductive.template; poly; finite; mode; schemes } in |
| 1268 |
let unpack (((_, id) , bl, c, decl), ntn) = match decl with |
| 1269 |
| Constructors l -> (id, bl, c, l), ntn |
| 1270 |
| RecordDecl _ -> assert false |
| 1271 |
in |
| 1272 |
let inductives = List.map unpack indl in |
| 1273 |
let uniform = should_treat_as_uniform () in |
| 1274 |
Preprocessed_Mind_decl.(Inductive { flags; udecl; typing_flags; private_ind; uniform; inductives }) |
| 1275 |
|
| 1276 |
let preprocess_inductive_decl ~atts kind indl = |
| 1277 |
let udecl, indl = extract_inductive_udecl indl in |
| 1278 |
let v = match kind, indl with |
| 1279 |
| Class _, [ ( id , bl , c , Constructors [l]), [] ] -> |
| 1280 |
preprocess_defclass ~atts udecl (id,bl,c,l) |
| 1281 |
| _ -> |
| 1282 |
if List.for_all (function |
| 1283 |
| ((_ , _ , _ , RecordDecl _), _) -> true |
| 1284 |
| _ -> false) indl |
| 1285 |
then preprocess_record ~atts udecl kind indl |
| 1286 |
else if List.for_all (function |
| 1287 |
| ((_ , _ , _ , Constructors _), _) -> true |
| 1288 |
| _ -> false) indl |
| 1289 |
then preprocess_inductive ~atts udecl kind indl |
| 1290 |
else user_err (str "Mixed record-inductive definitions are not allowed.") |
| 1291 |
in |
| 1292 |
indl, v |
| 1293 |
|
| 1294 |
let dump_inductive indl_for_glob decl = |
| 1295 |
let open Preprocessed_Mind_decl in |
| 1296 |
if Dumpglob.dump () then begin |
| 1297 |
List.iter (fun (((coe,lid), _, _, cstrs), _) -> |
| 1298 |
match cstrs with |
| 1299 |
| Constructors cstrs -> |
| 1300 |
Dumpglob.dump_definition lid false "ind"; |
| 1301 |
List.iter (fun (_, (lid, _)) -> |
| 1302 |
Dumpglob.dump_definition lid false "constr") cstrs |
| 1303 |
| _ -> ()) |
| 1304 |
indl_for_glob; |
| 1305 |
match decl with |
| 1306 |
| Record { records } -> |
| 1307 |
let dump_glob_proj (x, _, _) = match x with |
| 1308 |
| Vernacexpr.(AssumExpr ({loc;v=Name id}, _, _) | DefExpr ({loc;v=Name id}, _, _, _)) -> |
| 1309 |
Dumpglob.dump_definition (make ?loc id) false "proj" |
| 1310 |
| _ -> () in |
| 1311 |
records |> List.iter (fun { Record.Ast.cfs; name } -> |
| 1312 |
let () = Dumpglob.dump_definition name false "rec" in |
| 1313 |
List.iter dump_glob_proj cfs) |
| 1314 |
| Inductive _ -> () |
| 1315 |
end |
| 1316 |
|
| 1317 |
let vernac_inductive ~atts kind indl = |
| 1318 |
let open Preprocessed_Mind_decl in |
| 1319 |
let indl_for_glob, decl = preprocess_inductive_decl ~atts kind indl in |
| 1320 |
dump_inductive indl_for_glob decl; |
| 1321 |
match decl with |
| 1322 |
| Record { flags; kind; udecl; primitive_proj; records } -> |
| 1323 |
let _ : _ list = |
| 1324 |
Record.definition_structure ~flags udecl kind ~primitive_proj records in |
| 1325 |
() |
| 1326 |
| Inductive { flags; udecl; typing_flags; private_ind; uniform; inductives } -> |
| 1327 |
ComInductive.do_mutual_inductive ~flags udecl inductives ?typing_flags ~private_ind ~uniform |
| 1328 |
|
| 1329 |
let preprocess_inductive_decl ~atts kind indl = |
| 1330 |
snd @@ preprocess_inductive_decl ~atts kind indl |
| 1331 |
|
| 1332 |
let vernac_fixpoint_common ~atts l = |
| 1333 |
if Dumpglob.dump () then |
| 1334 |
List.iter (fun { fname } -> Dumpglob.dump_definition fname false "def") l; |
| 1335 |
let scope = atts.DefAttributes.scope in |
| 1336 |
List.iter (fun { fname } -> check_name_freshness scope fname) l; |
| 1337 |
scope |
| 1338 |
|
| 1339 |
let with_obligations program_mode f pm = |
| 1340 |
if program_mode then |
| 1341 |
f pm ~program_mode:true |
| 1342 |
else |
| 1343 |
let pm', proof = f None ~program_mode:false in |
| 1344 |
assert (Option.is_empty pm'); |
| 1345 |
pm, proof |
| 1346 |
|
| 1347 |
let vernac_fixpoint ~atts ~refine ~pm (rec_order,fixl) = |
| 1348 |
let open DefAttributes in |
| 1349 |
let scope = vernac_fixpoint_common ~atts fixl in |
| 1350 |
let poly, typing_flags, program_mode, clearbody, using, user_warns = |
| 1351 |
atts.poly, atts.typing_flags, atts.program, atts.clearbody, atts.using, atts.user_warns in |
| 1352 |
let () = |
| 1353 |
if program_mode then |
| 1354 |
|
| 1355 |
let opens = List.exists (fun { body_def } -> Option.is_empty body_def) fixl in |
| 1356 |
if opens then CErrors.user_err Pp.(str"Program Fixpoint requires a body.") in |
| 1357 |
with_obligations program_mode |
| 1358 |
(fun pm -> ComFixpoint.do_mutually_recursive ?pm ~refine ~scope ?clearbody ~kind:(IsDefinition Fixpoint) ~poly ?typing_flags ?user_warns ?using (CFixRecOrder rec_order, fixl)) |
| 1359 |
pm |
| 1360 |
|
| 1361 |
let vernac_cofixpoint_common ~atts l = |
| 1362 |
if Dumpglob.dump () then |
| 1363 |
List.iter (fun { fname } -> Dumpglob.dump_definition fname false "def") l; |
| 1364 |
let scope = atts.DefAttributes.scope in |
| 1365 |
List.iter (fun { fname } -> check_name_freshness scope fname) l; |
| 1366 |
scope |
| 1367 |
|
| 1368 |
let vernac_cofixpoint ~pm ~refine ~atts cofixl = |
| 1369 |
let open DefAttributes in |
| 1370 |
let scope = vernac_cofixpoint_common ~atts cofixl in |
| 1371 |
let poly, typing_flags, program_mode, clearbody, using, user_warns = |
| 1372 |
atts.poly, atts.typing_flags, atts.program, atts.clearbody, atts.using, atts.user_warns in |
| 1373 |
let () = |
| 1374 |
if program_mode then |
| 1375 |
let opens = List.exists (fun { body_def } -> Option.is_empty body_def) cofixl in |
| 1376 |
if opens then |
| 1377 |
CErrors.user_err Pp.(str"Program CoFixpoint requires a body.") in |
| 1378 |
with_obligations program_mode |
| 1379 |
(fun pm -> ComFixpoint.do_mutually_recursive ?pm ~refine ~scope ?clearbody ~kind:(IsDefinition CoFixpoint) ~poly ?typing_flags ?user_warns ?using (CCoFixRecOrder, cofixl)) |
| 1380 |
pm |
| 1381 |
|
| 1382 |
let vernac_scheme atts l = |
| 1383 |
if Dumpglob.dump () then |
| 1384 |
List.iter (fun (lid, sch) -> |
| 1385 |
Option.iter (fun lid -> Dumpglob.dump_definition lid false "def") lid) l; |
| 1386 |
let register = Attributes.(parse (bool_attribute ~name:"register") atts) in |
| 1387 |
let register = Option.default true register in |
| 1388 |
Indschemes.do_scheme ~register (Global.env ()) l |
| 1389 |
|
| 1390 |
let vernac_scheme_equality ?locmap sch id = |
| 1391 |
Indschemes.do_scheme_equality ?locmap sch id |
| 1392 |
|
| 1393 |
|
| 1394 |
let vernac_combined_scheme lid l ~locmap = |
| 1395 |
|
| 1396 |
let l = List.map (fun id -> match qualid_global (qualid_of_ident ?loc:id.loc id.v) with |
| 1397 |
| ConstRef c -> c |
| 1398 |
| _ -> CErrors.user_err ?loc:id.loc Pp.(Pputils.pr_lident id ++ str " is not a constant.")) |
| 1399 |
l |
| 1400 |
in |
| 1401 |
Indschemes.do_combined_scheme lid l |
| 1402 |
|
| 1403 |
let vernac_universe ~poly l = |
| 1404 |
if poly && not (Lib.sections_are_opened ()) then |
| 1405 |
user_err |
| 1406 |
(str"Polymorphic universes can only be declared inside sections, " ++ |
| 1407 |
str "use Monomorphic Universe instead."); |
| 1408 |
DeclareUniv.do_universe ~poly l |
| 1409 |
|
| 1410 |
let vernac_sort ~poly l = |
| 1411 |
if poly && not (Lib.sections_are_opened ()) then |
| 1412 |
user_err |
| 1413 |
(str"Polymorphic sorts can only be declared inside sections, " ++ |
| 1414 |
str "use #[universes(polymorphic=no)] Sort in order to declare a global sort."); |
| 1415 |
DeclareUniv.do_sort ~poly l |
| 1416 |
|
| 1417 |
let vernac_constraint ~poly l = |
| 1418 |
if poly && not (Lib.sections_are_opened ()) then |
| 1419 |
user_err |
| 1420 |
(str"Polymorphic constraints can only be declared" |
| 1421 |
++ str " inside sections, use Monomorphic Constraint instead."); |
| 1422 |
DeclareUniv.do_constraint ~poly l |
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
let warn_not_importable = CWarnings.create ~name:"not-importable" |
| 1428 |
Pp.(fun c -> str "Cannot import local constant " |
| 1429 |
++ Printer.pr_constant (Global.env()) c |
| 1430 |
++ str ", it will be ignored.") |
| 1431 |
|
| 1432 |
let importable_extended_global_of_path ?loc path = |
| 1433 |
match Nametab.extended_global_of_path path with |
| 1434 |
| Globnames.TrueGlobal (GlobRef.ConstRef c) as ref -> |
| 1435 |
if Declare.is_local_constant c then begin |
| 1436 |
warn_not_importable ?loc c; |
| 1437 |
None |
| 1438 |
end |
| 1439 |
else Some ref |
| 1440 |
| ref -> Some ref |
| 1441 |
|
| 1442 |
|
| 1443 |
let add_subnames_of ?loc len n ns full_n ref = |
| 1444 |
let open GlobRef in |
| 1445 |
let add1 r ns = (len, Globnames.TrueGlobal r) :: ns in |
| 1446 |
match ref with |
| 1447 |
| Globnames.Abbrev _ | Globnames.TrueGlobal (ConstRef _ | ConstructRef _ | VarRef _) -> |
| 1448 |
CErrors.user_err ?loc Pp.(str "Only inductive types can be used with Import (...).") |
| 1449 |
| Globnames.TrueGlobal (IndRef (mind,i)) -> |
| 1450 |
let open Declarations in |
| 1451 |
let path_prefix = path_pop_suffix full_n in |
| 1452 |
let mib = Global.lookup_mind mind in |
| 1453 |
let mip = mib.mind_packets.(i) in |
| 1454 |
let ns = add1 (IndRef (mind,i)) ns in |
| 1455 |
let ns = Array.fold_left_i (fun j ns _ -> add1 (ConstructRef ((mind,i),j+1)) ns) |
| 1456 |
ns mip.mind_consnames |
| 1457 |
in |
| 1458 |
List.fold_left (fun ns q -> |
| 1459 |
let s = Elimschemes.elimination_suffix q in |
| 1460 |
let n_elim = Id.of_string (Id.to_string mip.mind_typename ^ s) in |
| 1461 |
match importable_extended_global_of_path ?loc (Libnames.add_path_suffix path_prefix n_elim) with |
| 1462 |
| exception Not_found -> ns |
| 1463 |
| None -> ns |
| 1464 |
| Some ref -> (len, ref) :: ns) |
| 1465 |
ns UnivGen.QualityOrSet.all |
| 1466 |
|
| 1467 |
let interp_names m ns = |
| 1468 |
let dp_m = Nametab.path_of_module m in |
| 1469 |
let ns = |
| 1470 |
List.fold_left (fun ns (n,etc) -> |
| 1471 |
let len, full_n = |
| 1472 |
let dp_n,n = repr_qualid n in |
| 1473 |
List.length (DirPath.repr dp_n), add_path_suffix (append_path dp_m dp_n) n |
| 1474 |
in |
| 1475 |
let ref = try importable_extended_global_of_path ?loc:n.loc full_n |
| 1476 |
with Not_found -> |
| 1477 |
CErrors.user_err ?loc:n.loc |
| 1478 |
Pp.(str "Cannot find name " ++ pr_qualid n ++ spc() ++ |
| 1479 |
str "in module " ++ pr_qualid (Nametab.shortest_qualid_of_module m) ++ str ".") |
| 1480 |
in |
| 1481 |
|
| 1482 |
match ref with |
| 1483 |
| Some ref -> |
| 1484 |
let ns = (len,ref) :: ns in |
| 1485 |
if etc then add_subnames_of ?loc:n.loc len n ns full_n ref else ns |
| 1486 |
| None -> ns) |
| 1487 |
[] ns |
| 1488 |
in |
| 1489 |
ns |
| 1490 |
|
| 1491 |
let cache_name (len,n) = |
| 1492 |
let open Globnames in |
| 1493 |
let open GlobRef in |
| 1494 |
match n with |
| 1495 |
| Abbrev kn -> Abbreviation.import (len+1) (Nametab.path_of_abbreviation kn) kn |
| 1496 |
| TrueGlobal (VarRef _) -> assert false |
| 1497 |
| TrueGlobal (ConstRef c) when Declare.is_local_constant c -> |
| 1498 |
|
| 1499 |
warn_not_importable c |
| 1500 |
| TrueGlobal gr -> |
| 1501 |
Nametab.(push (Exactly (len+1)) (path_of_global gr) gr) |
| 1502 |
|
| 1503 |
let cache_names ns = List.iter cache_name ns |
| 1504 |
|
| 1505 |
let subst_names (subst,ns) = List.Smart.map (on_snd (Globnames.subst_extended_reference subst)) ns |
| 1506 |
|
| 1507 |
let inExportNames = Libobject.declare_object |
| 1508 |
(Libobject.global_object "EXPORTNAMES" |
| 1509 |
~cache:cache_names ~subst:(Some subst_names) |
| 1510 |
~discharge:(fun x -> Some x)) |
| 1511 |
|
| 1512 |
let import_names ~export m ns = |
| 1513 |
let ns = interp_names m ns in |
| 1514 |
match export with |
| 1515 |
| Lib.Export -> Lib.add_leaf (inExportNames ns) |
| 1516 |
| Lib.Import -> cache_names ns |
| 1517 |
|
| 1518 |
let interp_import_cats cats = |
| 1519 |
Option.cata |
| 1520 |
(fun cats -> Libobject.make_filter ~finite:(not cats.negative) cats.import_cats) |
| 1521 |
Libobject.unfiltered |
| 1522 |
cats |
| 1523 |
|
| 1524 |
|
| 1525 |
let import_module_with_filter ~export cats m f = |
| 1526 |
match f with |
| 1527 |
| ImportAll -> |
| 1528 |
Declaremods.Interp.import_module cats ~export m |
| 1529 |
| ImportNames ns -> import_names ~export m ns |
| 1530 |
|
| 1531 |
let check_no_filter_when_using_cats l = |
| 1532 |
List.iter (function |
| 1533 |
| _, ImportAll -> () |
| 1534 |
| q, ImportNames _ -> |
| 1535 |
CErrors.user_err ?loc:q.loc |
| 1536 |
Pp.(str "Cannot combine importing by categories and importing by names.")) |
| 1537 |
l |
| 1538 |
|
| 1539 |
let vernac_import (export, cats) mpl = |
| 1540 |
let import_mod (CAst.{v = mp; loc},f) = |
| 1541 |
try |
| 1542 |
let () = Dumpglob.dump_modref ?loc mp "mod" in |
| 1543 |
let () = if Modops.is_functor @@ Mod_declarations.mod_type (Global.lookup_module mp) |
| 1544 |
then CErrors.user_err ?loc Pp.(str "Cannot import functor " ++ str (ModPath.to_string mp) ++ str".") |
| 1545 |
in |
| 1546 |
import_module_with_filter ~export cats mp f |
| 1547 |
with Not_found -> |
| 1548 |
CErrors.user_err ?loc Pp.(str "Cannot find module " ++ str (ModPath.to_string mp) ++ str ".") |
| 1549 |
in |
| 1550 |
List.iter import_mod mpl |
| 1551 |
|
| 1552 |
let vernac_declare_module export {loc;v=id} binders_ast mty_ast = |
| 1553 |
|
| 1554 |
|
| 1555 |
if Lib.sections_are_opened () then |
| 1556 |
user_err Pp.(str "Modules and Module Types are not allowed inside sections."); |
| 1557 |
let mp = Declaremods.Interp.declare_module id binders_ast (Declaremods.Enforce mty_ast) [] in |
| 1558 |
Dumpglob.dump_moddef ?loc mp "mod"; |
| 1559 |
Flags.if_verbose Feedback.msg_info (str "Module " ++ Id.print id ++ str " is declared"); |
| 1560 |
Option.iter (fun export -> vernac_import export [CAst.make ?loc mp, ImportAll]) export |
| 1561 |
|
| 1562 |
let vernac_define_module export {loc;v=id} binders_ast argsexport mty_ast_o mexpr_ast_l = |
| 1563 |
|
| 1564 |
|
| 1565 |
if Lib.sections_are_opened () then |
| 1566 |
user_err Pp.(str "Modules and Module Types are not allowed inside sections."); |
| 1567 |
match mexpr_ast_l with |
| 1568 |
| [] -> |
| 1569 |
let mp = Declaremods.Interp.start_module export id binders_ast mty_ast_o in |
| 1570 |
Dumpglob.dump_moddef ?loc mp "mod"; |
| 1571 |
Flags.if_verbose Feedback.msg_info |
| 1572 |
(str "Interactive Module " ++ Id.print id ++ str " started"); |
| 1573 |
List.iter |
| 1574 |
(fun (export,mp) -> vernac_import export [CAst.make mp, ImportAll]) |
| 1575 |
argsexport |
| 1576 |
| _::_ -> |
| 1577 |
let mp = |
| 1578 |
Declaremods.Interp.declare_module |
| 1579 |
id binders_ast mty_ast_o mexpr_ast_l |
| 1580 |
in |
| 1581 |
Dumpglob.dump_moddef ?loc mp "mod"; |
| 1582 |
Flags.if_verbose Feedback.msg_info |
| 1583 |
(str "Module " ++ Id.print id ++ str " is defined"); |
| 1584 |
Option.iter (fun export -> vernac_import export [CAst.make ?loc mp, ImportAll]) |
| 1585 |
export |
| 1586 |
|
| 1587 |
let vernac_end_module export {loc;v=id} = |
| 1588 |
let mp = Declaremods.Interp.end_module () in |
| 1589 |
Dumpglob.dump_modref ?loc mp "mod"; |
| 1590 |
Flags.if_verbose Feedback.msg_info (str "Module " ++ Id.print id ++ str " is defined"); |
| 1591 |
Option.iter (fun (export,filter) -> |
| 1592 |
Declaremods.Interp.import_module filter ~export mp) |
| 1593 |
export |
| 1594 |
|
| 1595 |
let vernac_declare_module_type {loc;v=id} binders_ast argsexport mty_sign mty_ast_l = |
| 1596 |
if Lib.sections_are_opened () then |
| 1597 |
user_err Pp.(str "Modules and Module Types are not allowed inside sections."); |
| 1598 |
|
| 1599 |
match mty_ast_l with |
| 1600 |
| [] -> |
| 1601 |
let mp = Declaremods.Interp.start_modtype id binders_ast mty_sign in |
| 1602 |
Dumpglob.dump_moddef ?loc mp "modtype"; |
| 1603 |
Flags.if_verbose Feedback.msg_info |
| 1604 |
(str "Interactive Module Type " ++ Id.print id ++ str " started"); |
| 1605 |
List.iter |
| 1606 |
(fun (export,mp) -> vernac_import export [CAst.make ?loc mp, ImportAll]) |
| 1607 |
argsexport |
| 1608 |
|
| 1609 |
| _ :: _ -> |
| 1610 |
let mp = Declaremods.Interp.declare_modtype id binders_ast mty_sign mty_ast_l in |
| 1611 |
Dumpglob.dump_moddef ?loc mp "modtype"; |
| 1612 |
Flags.if_verbose Feedback.msg_info |
| 1613 |
(str "Module Type " ++ Id.print id ++ str " is defined") |
| 1614 |
|
| 1615 |
|
| 1616 |
let vernac_end_modtype {loc;v=id} = |
| 1617 |
let mp = Declaremods.Interp.end_modtype () in |
| 1618 |
Dumpglob.dump_modref ?loc mp "modtype"; |
| 1619 |
Flags.if_verbose Feedback.msg_info (str "Module Type " ++ Id.print id ++ str " is defined") |
| 1620 |
|
| 1621 |
let vernac_include l = Declaremods.Interp.declare_include l |
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
let vernac_begin_section ~poly {v=id} = |
| 1629 |
Lib.Interp.open_section id; |
| 1630 |
|
| 1631 |
|
| 1632 |
set_bool_option_value_gen ~locality:OptLocal ["Universe"; "Polymorphism"] poly |
| 1633 |
|
| 1634 |
let vernac_end_section {CAst.loc; v} = |
| 1635 |
Declaremods.Interp.close_section () |
| 1636 |
|
| 1637 |
let vernac_name_sec_hyp {v=id} set = Proof_using.name_set id set |
| 1638 |
|
| 1639 |
|
| 1640 |
let msg_of_subsection ss id = |
| 1641 |
let kind = |
| 1642 |
match ss with |
| 1643 |
| Lib.OpenedModule (false,_,_,_) -> "module" |
| 1644 |
| Lib.OpenedModule (true,_,_,_) -> "module type" |
| 1645 |
| Lib.OpenedSection _ -> "section" |
| 1646 |
| _ -> "unknown" |
| 1647 |
in |
| 1648 |
Pp.str kind ++ spc () ++ Id.print id |
| 1649 |
|
| 1650 |
let vernac_end_segment ~pm ~proof ({v=id; loc} as lid) = |
| 1651 |
let ss = Lib.Interp.find_opening_node ?loc id in |
| 1652 |
let what_for = msg_of_subsection ss lid.v in |
| 1653 |
if Option.has_some proof then |
| 1654 |
CErrors.user_err (Pp.str "Command not supported (Open proofs remain)"); |
| 1655 |
Declare.Obls.check_solved_obligations ~pm ~what_for; |
| 1656 |
match ss with |
| 1657 |
| Lib.OpenedModule (false,export,_,_) -> vernac_end_module export lid |
| 1658 |
| Lib.OpenedModule (true,_,_,_) -> vernac_end_modtype lid |
| 1659 |
| Lib.OpenedSection _ -> vernac_end_section lid |
| 1660 |
| _ -> assert false |
| 1661 |
|
| 1662 |
let vernac_end_segment lid = |
| 1663 |
let open Vernactypes in |
| 1664 |
typed_vernac { ignore_state with prog=Pop; proof=ReadOpt; } |
| 1665 |
(fun {proof; prog} -> |
| 1666 |
let () = vernac_end_segment ~pm:prog ~proof lid in |
| 1667 |
no_state) |
| 1668 |
|
| 1669 |
let vernac_begin_segment ~interactive f = |
| 1670 |
let open Vernactypes in |
| 1671 |
let proof = Proof.(if interactive then Reject else Ignore) in |
| 1672 |
let prog = Prog.(if interactive then Push else Ignore) in |
| 1673 |
typed_vernac { ignore_state with prog; proof; } |
| 1674 |
(fun (_:no_state) -> |
| 1675 |
let () = f () in |
| 1676 |
no_state) |
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
let warn_require_in_section = |
| 1681 |
CWarnings.create ~name:"require-in-section" ~category:CWarnings.CoreCategories.fragile |
| 1682 |
(fun () -> strbrk "Use of “Require” inside a section is fragile." ++ spc() ++ |
| 1683 |
strbrk "It is not recommended to use this functionality in finished proof scripts.") |
| 1684 |
|
| 1685 |
let vernac_require_interp needed modrefl export qidl = |
| 1686 |
if Lib.sections_are_opened () then warn_require_in_section (); |
| 1687 |
let () = match export with |
| 1688 |
| None -> List.iter (function |
| 1689 |
| _, ImportAll -> () |
| 1690 |
| {CAst.loc}, ImportNames _ -> |
| 1691 |
CErrors.user_err ?loc Pp.(str "Used an import filter without importing.")) |
| 1692 |
qidl |
| 1693 |
| Some (_,cats) -> if Option.has_some cats then check_no_filter_when_using_cats qidl |
| 1694 |
in |
| 1695 |
if Dumpglob.dump () then |
| 1696 |
List.iter2 (fun ({CAst.loc},_) dp -> Dumpglob.dump_libref ?loc dp "lib") qidl modrefl; |
| 1697 |
Coq_config.gc_ramp_up @@ fun () -> |
| 1698 |
|
| 1699 |
Library.require_library_from_dirpath needed; |
| 1700 |
|
| 1701 |
Option.iter (fun (export,cats) -> |
| 1702 |
let cats = interp_import_cats cats in |
| 1703 |
List.iter2 (fun m (_,f) -> |
| 1704 |
import_module_with_filter ~export cats (MPfile m) f) |
| 1705 |
modrefl qidl) |
| 1706 |
export |
| 1707 |
|
| 1708 |
let vernac_require ~intern from export qidl = |
| 1709 |
let needed, modrefl = Flags.with_modified_ref Flags.in_synterp_phase (fun _ -> Some true) (fun () -> |
| 1710 |
Synterp.synterp_require ~intern from export qidl) |
| 1711 |
() |
| 1712 |
in |
| 1713 |
Flags.with_modified_ref Flags.in_synterp_phase (fun _ -> Some false) (fun () -> |
| 1714 |
vernac_require_interp needed modrefl export qidl) |
| 1715 |
() |
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
let vernac_canonical ~local r = |
| 1720 |
Canonical.declare_canonical_structure ?local (smart_global r) |
| 1721 |
|
| 1722 |
let vernac_coercion ~atts ref qidst = |
| 1723 |
let ref' = smart_global ref in |
| 1724 |
match qidst with |
| 1725 |
| Some (qids, qidt) -> |
| 1726 |
let local, reversible = |
| 1727 |
Attributes.parse Notations.(locality ++ reversible) atts in |
| 1728 |
let local = enforce_locality local in |
| 1729 |
let reversible = Option.default false reversible in |
| 1730 |
let target = cl_of_qualid qidt in |
| 1731 |
let source = cl_of_qualid qids in |
| 1732 |
ComCoercion.try_add_new_coercion_with_target ref' ~local ~reversible |
| 1733 |
~source ~target; |
| 1734 |
Flags.if_verbose Feedback.msg_info (pr_global ref' ++ str " is now a coercion") |
| 1735 |
| None -> |
| 1736 |
match Attributes.parse reversible atts with |
| 1737 |
| None -> user_err (str "Expected `: Sourceclass >-> Targetclass`.") |
| 1738 |
| Some reversible -> ComCoercion.change_reverse ref' ~reversible |
| 1739 |
|
| 1740 |
let vernac_identity_coercion ~atts id qids qidt = |
| 1741 |
let local, poly = Attributes.(parse Notations.(locality ++ polymorphic) atts) in |
| 1742 |
let local = enforce_locality local in |
| 1743 |
let target = cl_of_qualid qidt in |
| 1744 |
let source = cl_of_qualid qids in |
| 1745 |
let poly = PolyFlags.of_univ_poly poly in |
| 1746 |
ComCoercion.try_add_new_identity_coercion id ~local ~poly ~source ~target |
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
let vernac_instance_program ~atts ~pm name bl t props info = |
| 1751 |
Dumpglob.dump_constraint (fst name) false "inst"; |
| 1752 |
let locality, poly = |
| 1753 |
Attributes.(parse (Notations.(hint_locality ++ poly PolyFlags.Definition))) atts |
| 1754 |
in |
| 1755 |
let pm, _id = Classes.new_instance_program ~pm ~locality ~poly name bl t props info in |
| 1756 |
pm |
| 1757 |
|
| 1758 |
let vernac_instance_interactive ~atts name bl t info props = |
| 1759 |
Dumpglob.dump_constraint (fst name) false "inst"; |
| 1760 |
let locality, poly = |
| 1761 |
Attributes.(parse (Notations.(hint_locality ++ poly PolyFlags.Definition))) atts |
| 1762 |
in |
| 1763 |
let _id, pstate = |
| 1764 |
Classes.new_instance_interactive ~locality ~poly name bl t info props in |
| 1765 |
pstate |
| 1766 |
|
| 1767 |
let vernac_instance ~atts name bl t props info = |
| 1768 |
Dumpglob.dump_constraint (fst name) false "inst"; |
| 1769 |
let locality, poly = |
| 1770 |
Attributes.(parse (Notations.(hint_locality ++ poly PolyFlags.Definition))) atts |
| 1771 |
in |
| 1772 |
let _id : lident = |
| 1773 |
Classes.new_instance ~locality ~poly name bl t props info in |
| 1774 |
() |
| 1775 |
|
| 1776 |
let vernac_declare_instance ~atts id bl inst pri = |
| 1777 |
Dumpglob.dump_definition (fst id) false "inst"; |
| 1778 |
let ((program, locality), poly) = |
| 1779 |
Attributes.(parse (Notations.(program ++ hint_locality ++ poly PolyFlags.Definition))) atts |
| 1780 |
in |
| 1781 |
Classes.declare_new_instance ~program_mode:program ~locality ~poly id bl inst pri |
| 1782 |
|
| 1783 |
let vernac_context ~atts ctx = |
| 1784 |
let (program_mode, poly) = Attributes.(parse (Notations.(program ++ poly PolyFlags.Assumption))) atts in |
| 1785 |
ComAssumption.do_context ~program_mode ~poly ctx |
| 1786 |
|
| 1787 |
let vernac_existing_instance ~atts insts = |
| 1788 |
let locality = Attributes.parse hint_locality atts in |
| 1789 |
List.iter (fun (id, info) -> |
| 1790 |
let g = qualid_global id in |
| 1791 |
Classes.existing_instance ?loc:id.loc locality g (Some info)) insts |
| 1792 |
|
| 1793 |
let vernac_existing_class id = |
| 1794 |
Record.declare_existing_class (qualid_global id) |
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
let command_focus = Proof.new_focus_kind "command_focus" |
| 1800 |
let focus_command_cond = Proof.no_cond command_focus |
| 1801 |
|
| 1802 |
let vernac_set_end_tac pstate tac = |
| 1803 |
let tac = Gentactic.intern (Global.env()) tac in |
| 1804 |
Declare.Proof.set_endline_tactic tac pstate |
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
let vernac_create_hintdb ~module_local id b = |
| 1810 |
Hints.create_hint_db module_local id TransparentState.full b |
| 1811 |
|
| 1812 |
let warn_implicit_core_hint_db = |
| 1813 |
CWarnings.create ~name:"implicit-core-hint-db" ~category:Deprecation.Version.v8_10 |
| 1814 |
(fun () -> strbrk "Adding and removing hints in the core database implicitly is deprecated. " |
| 1815 |
++ strbrk"Please specify a hint database.") |
| 1816 |
|
| 1817 |
let warn_implicit_create_hint_db = |
| 1818 |
CWarnings.create ~name:"implicit-create-hint-db" ~category:Deprecation.Version.v9_2 |
| 1819 |
(fun db -> strbrk "Implicitly declaring hint databases is deprecated. Please explicitly create " ++ quote (str db)) |
| 1820 |
|
| 1821 |
let vernac_remove_hints ~atts dbnames ids = |
| 1822 |
let locality = Attributes.(parse hint_locality atts) in |
| 1823 |
let dbnames = |
| 1824 |
if List.is_empty dbnames then |
| 1825 |
(warn_implicit_core_hint_db (); ["core"]) |
| 1826 |
else dbnames |
| 1827 |
in |
| 1828 |
Hints.remove_hints ~locality dbnames (List.map Smartlocate.global_with_alias ids) |
| 1829 |
|
| 1830 |
let vernac_hints ~atts dbnames h = |
| 1831 |
let dbnames = |
| 1832 |
if List.is_empty dbnames then |
| 1833 |
(warn_implicit_core_hint_db (); ["core"]) |
| 1834 |
else dbnames |
| 1835 |
in |
| 1836 |
let locality, poly = Attributes.(parse Notations.(hint_locality ++ polymorphic) atts) in |
| 1837 |
let check_db db = |
| 1838 |
if String.equal db "nocore" then () |
| 1839 |
else match Hints.searchtable_map db with |
| 1840 |
| _ -> () |
| 1841 |
| exception Not_found -> |
| 1842 |
let () = warn_implicit_create_hint_db db in |
| 1843 |
Hints.create_hint_db false db TransparentState.empty false |
| 1844 |
in |
| 1845 |
let () = List.iter check_db dbnames in |
| 1846 |
let poly = PolyFlags.of_univ_poly poly in |
| 1847 |
Hints.add_hints ~locality dbnames (ComHints.interp_hints ~poly h) |
| 1848 |
|
| 1849 |
let warn_deprecated_notation_for_abbreviation = |
| 1850 |
CWarnings.create ~name:"notation-for-abbreviation" ~category:Deprecation.Version.v9_2 |
| 1851 |
~quickfix:(fun ~loc () -> [Quickfix.make ~loc (str "Abbreviation")]) |
| 1852 |
(fun () -> |
| 1853 |
strbrk "Use of \"Notation\" keyword for abbreviations is deprecated, \ |
| 1854 |
use \"Abbreviation\" instead.") |
| 1855 |
|
| 1856 |
let vernac_abbreviation ~warn_old_notation ~atts lid x only_parsing = |
| 1857 |
Option.iter (fun loc -> warn_deprecated_notation_for_abbreviation ~loc ()) |
| 1858 |
warn_old_notation; |
| 1859 |
let local, user_warns = Attributes.(parse Notations.(hint_locality_no_sections ++ user_warns_with_use_globref_instead) atts) in |
| 1860 |
Dumpglob.dump_definition lid false "abbrev"; |
| 1861 |
Metasyntax.add_abbreviation ~local user_warns (Global.env()) lid.v x only_parsing |
| 1862 |
|
| 1863 |
let default_env () = { |
| 1864 |
Notation_term.ninterp_var_type = Id.Map.empty; |
| 1865 |
ninterp_rec_vars = Id.Map.empty; |
| 1866 |
} |
| 1867 |
|
| 1868 |
let vernac_reserve bl = |
| 1869 |
let sb_decl = (fun (idl,c) -> |
| 1870 |
let env = Global.env() in |
| 1871 |
let sigma = Evd.from_env env in |
| 1872 |
let t,ctx = Constrintern.interp_type env sigma c in |
| 1873 |
let t = |
| 1874 |
let flags = { (PrintingFlags.Detype.current()) with universes = false } in |
| 1875 |
Detyping.detype Detyping.Now ~flags env (Evd.from_ctx ctx) t |
| 1876 |
in |
| 1877 |
let t,_ = Notation_ops.notation_constr_of_glob_constr (default_env ()) t in |
| 1878 |
Reserve.declare_reserved_type idl t) |
| 1879 |
in List.iter sb_decl bl |
| 1880 |
|
| 1881 |
let vernac_generalizable ~local = |
| 1882 |
let local = Option.default true local in |
| 1883 |
Implicit_quantifiers.declare_generalizable ~local |
| 1884 |
|
| 1885 |
let () = |
| 1886 |
declare_bool_option |
| 1887 |
{ optstage = Summary.Stage.Interp; |
| 1888 |
optdepr = None; |
| 1889 |
optkey = ["Allow";"StrictProp"]; |
| 1890 |
optread = (fun () -> Global.sprop_allowed()); |
| 1891 |
optwrite = Global.set_allow_sprop } |
| 1892 |
|
| 1893 |
let () = |
| 1894 |
declare_bool_option |
| 1895 |
{ optstage = Summary.Stage.Interp; |
| 1896 |
optdepr = None; |
| 1897 |
optkey = ["Silent"]; |
| 1898 |
optread = (fun () -> !Flags.quiet); |
| 1899 |
optwrite = ((:=) Flags.quiet) } |
| 1900 |
|
| 1901 |
let () = |
| 1902 |
declare_bool_option |
| 1903 |
{ optstage = Summary.Stage.Interp; |
| 1904 |
optdepr = None; |
| 1905 |
optkey = ["Implicit";"Arguments"]; |
| 1906 |
optread = Impargs.is_implicit_args; |
| 1907 |
optwrite = Impargs.make_implicit_args } |
| 1908 |
|
| 1909 |
let () = |
| 1910 |
declare_bool_option |
| 1911 |
{ optstage = Summary.Stage.Interp; |
| 1912 |
optdepr = None; |
| 1913 |
optkey = ["Strict";"Implicit"]; |
| 1914 |
optread = Impargs.is_strict_implicit_args; |
| 1915 |
optwrite = Impargs.make_strict_implicit_args } |
| 1916 |
|
| 1917 |
let () = |
| 1918 |
declare_bool_option |
| 1919 |
{ optstage = Summary.Stage.Interp; |
| 1920 |
optdepr = None; |
| 1921 |
optkey = ["Strongly";"Strict";"Implicit"]; |
| 1922 |
optread = Impargs.is_strongly_strict_implicit_args; |
| 1923 |
optwrite = Impargs.make_strongly_strict_implicit_args } |
| 1924 |
|
| 1925 |
let () = |
| 1926 |
declare_bool_option |
| 1927 |
{ optstage = Summary.Stage.Interp; |
| 1928 |
optdepr = None; |
| 1929 |
optkey = ["Contextual";"Implicit"]; |
| 1930 |
optread = Impargs.is_contextual_implicit_args; |
| 1931 |
optwrite = Impargs.make_contextual_implicit_args } |
| 1932 |
|
| 1933 |
let () = |
| 1934 |
declare_bool_option |
| 1935 |
{ optstage = Summary.Stage.Interp; |
| 1936 |
optdepr = None; |
| 1937 |
optkey = ["Reversible";"Pattern";"Implicit"]; |
| 1938 |
optread = Impargs.is_reversible_pattern_implicit_args; |
| 1939 |
optwrite = Impargs.make_reversible_pattern_implicit_args } |
| 1940 |
|
| 1941 |
let () = |
| 1942 |
declare_bool_option |
| 1943 |
{ optstage = Summary.Stage.Interp; |
| 1944 |
optdepr = None; |
| 1945 |
optkey = ["Maximal";"Implicit";"Insertion"]; |
| 1946 |
optread = Impargs.is_maximal_implicit_args; |
| 1947 |
optwrite = Impargs.make_maximal_implicit_args } |
| 1948 |
|
| 1949 |
let () = |
| 1950 |
declare_bool_option |
| 1951 |
{ optstage = Summary.Stage.Interp; |
| 1952 |
optdepr = None; |
| 1953 |
optkey = ["Kernel"; "Term"; "Sharing"]; |
| 1954 |
optread = (fun () -> (Global.typing_flags ()).Declarations.share_reduction); |
| 1955 |
optwrite = Global.set_share_reduction } |
| 1956 |
|
| 1957 |
let () = |
| 1958 |
declare_bool_option |
| 1959 |
{ optstage = Summary.Stage.Interp; |
| 1960 |
optdepr = None; |
| 1961 |
optkey = ["Printing";"Compact";"Contexts"]; |
| 1962 |
optread = (fun () -> Printer.get_compact_context()); |
| 1963 |
optwrite = (fun b -> Printer.set_compact_context b) } |
| 1964 |
|
| 1965 |
let () = |
| 1966 |
declare_int_option |
| 1967 |
{ optstage = Summary.Stage.Interp; |
| 1968 |
optdepr = None; |
| 1969 |
optkey = ["Printing";"Depth"]; |
| 1970 |
optread = Topfmt.get_depth_boxes; |
| 1971 |
optwrite = Topfmt.set_depth_boxes } |
| 1972 |
|
| 1973 |
let () = |
| 1974 |
declare_int_option |
| 1975 |
{ optstage = Summary.Stage.Interp; |
| 1976 |
optdepr = None; |
| 1977 |
optkey = ["Printing";"Width"]; |
| 1978 |
optread = Topfmt.get_margin; |
| 1979 |
optwrite = Topfmt.set_margin } |
| 1980 |
|
| 1981 |
let () = |
| 1982 |
|
| 1983 |
declare_option ~no_summary:true ~kind:BoolKind |
| 1984 |
{ optstage = Summary.Stage.Interp; |
| 1985 |
optdepr = Some (Deprecation.make ~since:"9.1" ~note:"Set Debug \"vmbytecode\" instead." ()); |
| 1986 |
optkey = ["Dump";"Bytecode"]; |
| 1987 |
optread = (fun () -> CDebug.get_flag Vmbytegen.dump_bytecode_flag); |
| 1988 |
optwrite = (fun b -> CDebug.set_flag Vmbytegen.dump_bytecode_flag b); |
| 1989 |
} |
| 1990 |
|
| 1991 |
let () = |
| 1992 |
|
| 1993 |
declare_option ~no_summary:true ~kind:BoolKind |
| 1994 |
{ optstage = Summary.Stage.Interp; |
| 1995 |
optdepr = Some (Deprecation.make ~since:"9.1" ~note:"Set Debug \"vmlambda\" instead." ()); |
| 1996 |
optkey = ["Dump";"Lambda"]; |
| 1997 |
optread = (fun () -> CDebug.get_flag Vmlambda.dump_lambda_flag); |
| 1998 |
optwrite = (fun b -> CDebug.set_flag Vmlambda.dump_lambda_flag b); |
| 1999 |
} |
| 2000 |
|
| 2001 |
let () = |
| 2002 |
declare_bool_option |
| 2003 |
{ optstage = Summary.Stage.Interp; |
| 2004 |
optdepr = None; |
| 2005 |
optkey = ["Parsing";"Explicit"]; |
| 2006 |
optread = (fun () -> !Constrintern.parsing_explicit); |
| 2007 |
optwrite = (fun b -> Constrintern.parsing_explicit := b) } |
| 2008 |
|
| 2009 |
let () = |
| 2010 |
let preprocess flags = |
| 2011 |
CWarnings.check_unknown_warnings flags; |
| 2012 |
CWarnings.normalize_flags_string flags |
| 2013 |
in |
| 2014 |
declare_append_only_option ~preprocess ~sep:"," |
| 2015 |
{ optstage = Summary.Stage.Synterp; |
| 2016 |
optdepr = None; |
| 2017 |
optkey = ["Warnings"]; |
| 2018 |
optread = CWarnings.get_flags; |
| 2019 |
optwrite = CWarnings.set_flags } |
| 2020 |
|
| 2021 |
let () = |
| 2022 |
declare_append_only_option ~sep:"," |
| 2023 |
{ optstage = Summary.Stage.Synterp; |
| 2024 |
optdepr = None; |
| 2025 |
optkey = ["Debug"]; |
| 2026 |
optread = CDebug.get_flags; |
| 2027 |
optwrite = CDebug.set_flags } |
| 2028 |
|
| 2029 |
let () = |
| 2030 |
declare_bool_option |
| 2031 |
{ optstage = Summary.Stage.Interp; |
| 2032 |
optdepr = None; |
| 2033 |
optkey = ["Guard"; "Checking"]; |
| 2034 |
optread = (fun () -> (Global.typing_flags ()).Declarations.check_guarded); |
| 2035 |
optwrite = (fun b -> Global.set_check_guarded b) } |
| 2036 |
|
| 2037 |
let () = |
| 2038 |
declare_bool_option |
| 2039 |
{ optstage = Summary.Stage.Interp; |
| 2040 |
optdepr = None; |
| 2041 |
optkey = ["Positivity"; "Checking"]; |
| 2042 |
optread = (fun () -> (Global.typing_flags ()).Declarations.check_positive); |
| 2043 |
optwrite = (fun b -> Global.set_check_positive b) } |
| 2044 |
|
| 2045 |
let () = |
| 2046 |
declare_bool_option |
| 2047 |
{ optstage = Summary.Stage.Interp; |
| 2048 |
optdepr = None; |
| 2049 |
optkey = ["Universe"; "Checking"]; |
| 2050 |
optread = (fun () -> (Global.typing_flags ()).Declarations.check_universes); |
| 2051 |
optwrite = (fun b -> Global.set_check_universes b) } |
| 2052 |
|
| 2053 |
let () = |
| 2054 |
declare_bool_option |
| 2055 |
{ optstage = Summary.Stage.Interp; |
| 2056 |
optdepr = None; |
| 2057 |
optkey = ["Definitional"; "UIP"]; |
| 2058 |
optread = (fun () -> (Global.typing_flags ()).Declarations.allow_uip); |
| 2059 |
optwrite = (fun b -> Global.set_typing_flags |
| 2060 |
{(Global.typing_flags ()) with Declarations.allow_uip = b}) |
| 2061 |
} |
| 2062 |
|
| 2063 |
let vernac_set_strategy ~local l = |
| 2064 |
let local = Option.default false local in |
| 2065 |
let glob_ref r = |
| 2066 |
match smart_global r with |
| 2067 |
| GlobRef.ConstRef sp -> |
| 2068 |
begin |
| 2069 |
match Structures.PrimitiveProjections.find_opt sp with |
| 2070 |
| None -> Evaluable.EvalConstRef sp |
| 2071 |
| Some p -> Evaluable.EvalProjectionRef p |
| 2072 |
end |
| 2073 |
| GlobRef.VarRef id -> Evaluable.EvalVarRef id |
| 2074 |
| _ -> user_err Pp.(str |
| 2075 |
"Cannot set an inductive type or a constructor as transparent.") in |
| 2076 |
let l = List.map (fun (lev,ql) -> (lev,List.map glob_ref ql)) l in |
| 2077 |
Redexpr.set_strategy local l |
| 2078 |
|
| 2079 |
let vernac_set_opacity ~on_proj_constant ~local (v,l) = |
| 2080 |
let local = Option.default true local in |
| 2081 |
let glob_ref r = |
| 2082 |
match smart_global r with |
| 2083 |
| GlobRef.ConstRef sp -> |
| 2084 |
begin |
| 2085 |
match Structures.PrimitiveProjections.find_opt sp with |
| 2086 |
| None when on_proj_constant -> user_err Pp.(str |
| 2087 |
"Only compatibility constant opacity can be set this way.") |
| 2088 |
| None -> Evaluable.EvalConstRef sp |
| 2089 |
| Some _ when on_proj_constant -> Evaluable.EvalConstRef sp |
| 2090 |
| Some p -> Evaluable.EvalProjectionRef p |
| 2091 |
end |
| 2092 |
| GlobRef.VarRef id -> Evaluable.EvalVarRef id |
| 2093 |
| _ -> user_err Pp.(str |
| 2094 |
"Cannot set an inductive type or a constructor as transparent.") in |
| 2095 |
let l = List.map glob_ref l in |
| 2096 |
Redexpr.set_strategy local [v,l] |
| 2097 |
|
| 2098 |
let get_current_context_of_args ~pstate = |
| 2099 |
match pstate with |
| 2100 |
| None -> fun _ -> |
| 2101 |
let env = Global.env () in Evd.(from_env env, env) |
| 2102 |
| Some lemma -> |
| 2103 |
function |
| 2104 |
| Some n -> Declare.Proof.get_goal_context lemma n |
| 2105 |
| None -> Declare.Proof.get_current_context lemma |
| 2106 |
|
| 2107 |
let query_command_selector ?loc = function |
| 2108 |
| None -> None |
| 2109 |
| Some (Goal_select.SelectList [NthSelector n]) -> Some n |
| 2110 |
| _ -> user_err ?loc |
| 2111 |
(str "Query commands only support the single numbered goal selector.") |
| 2112 |
|
| 2113 |
let check_may_eval env sigma redexp rc = |
| 2114 |
let gc = Constrintern.intern_unknown_if_term_or_type env sigma rc in |
| 2115 |
let sigma, c = Pretyping.understand_tcc env sigma gc in |
| 2116 |
let sigma = Evarconv.solve_unif_constraints_with_heuristics env sigma in |
| 2117 |
Evarconv.check_problems_are_solved env sigma; |
| 2118 |
let sigma = Evd.minimize_universes sigma in |
| 2119 |
let (qs, us), csts as uctx = Evd.sort_context_set sigma in |
| 2120 |
let { Environ.uj_val=c; uj_type=ty; } = |
| 2121 |
if Evarutil.has_undefined_evars sigma c |
| 2122 |
|| List.exists (Context.Named.Declaration.exists (Evarutil.has_undefined_evars sigma)) |
| 2123 |
(EConstr.named_context env) |
| 2124 |
then |
| 2125 |
Evarutil.j_nf_evar sigma (Retyping.get_judgment_of env sigma c) |
| 2126 |
else |
| 2127 |
let env = Evarutil.nf_env_evar sigma env in |
| 2128 |
let env = Environ.push_qualities ~rigid:false (qs, fst csts) env in |
| 2129 |
let env = Environ.push_context_set (us, snd csts) env in |
| 2130 |
let c = EConstr.to_constr sigma c in |
| 2131 |
let env = Safe_typing.push_private_constants env (Evd.seff_private @@ Evd.eval_side_effects sigma) in |
| 2132 |
|
| 2133 |
Environ.on_judgment EConstr.of_constr (Arguments_renaming.rename_typing env c) |
| 2134 |
in |
| 2135 |
let sigma, c = match redexp with |
| 2136 |
| None -> sigma, c |
| 2137 |
| Some r -> |
| 2138 |
let sigma, r = Redexpr.interp_redexp_no_ltac env sigma r in |
| 2139 |
let r, _ = Redexpr.reduction_of_red_expr env r in |
| 2140 |
let sigma, c = r env sigma c in |
| 2141 |
sigma, c |
| 2142 |
in |
| 2143 |
let pp = |
| 2144 |
let evars_of_term c = Evarutil.undefined_evars_of_term sigma c in |
| 2145 |
let l = Evar.Set.union (evars_of_term c) (evars_of_term ty) in |
| 2146 |
let j = { Environ.uj_val = c; uj_type = Reductionops.nf_betaiota env sigma ty } in |
| 2147 |
Prettyp.print_judgment env sigma j ++ |
| 2148 |
pr_ne_evar_set (fnl () ++ str "where" ++ fnl ()) (mt ()) sigma l |
| 2149 |
in |
| 2150 |
let hdr = if Option.has_some redexp then str " = " else mt() in |
| 2151 |
hdr ++ pp ++ Printer.pr_sort_context_set sigma uctx |
| 2152 |
|
| 2153 |
let vernac_check_may_eval ~pstate redexp glopt rc = |
| 2154 |
let glopt = query_command_selector glopt in |
| 2155 |
let sigma, env = get_current_context_of_args ~pstate glopt in |
| 2156 |
check_may_eval env sigma redexp rc |
| 2157 |
|
| 2158 |
let vernac_declare_reduction ~local s r = |
| 2159 |
let local = Option.default false local in |
| 2160 |
let env = Global.env () in |
| 2161 |
let sigma = Evd.from_env env in |
| 2162 |
Redexpr.declare_red_expr local s (snd (Redexpr.interp_redexp_no_ltac env sigma r)) |
| 2163 |
|
| 2164 |
|
| 2165 |
let vernac_global_check c = |
| 2166 |
let env = Global.env() in |
| 2167 |
let sigma = Evd.from_env env in |
| 2168 |
let c = Constrintern.intern_constr env sigma c in |
| 2169 |
let sigma, c = Pretyping.understand_tcc ~flags:Pretyping.all_and_fail_flags env sigma c in |
| 2170 |
let sigma = Evd.collapse_sort_variables sigma in |
| 2171 |
let senv = Global.safe_env() in |
| 2172 |
let (qs, us), (qcst, ucst) as uctx = Evd.sort_context_set sigma in |
| 2173 |
let senv = Safe_typing.push_qualities ~rigid:false (qs, qcst) senv in |
| 2174 |
let senv = Safe_typing.push_context_set ~strict:false (us, ucst) senv in |
| 2175 |
let c = EConstr.to_constr sigma c in |
| 2176 |
let j = Safe_typing.typing senv c in |
| 2177 |
Prettyp.print_safe_judgment j ++ |
| 2178 |
Printer.pr_sort_context_set sigma uctx |
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
let print_about_hyp_globs ~pstate ?loc ref_or_by_not udecl glopt = |
| 2185 |
let exception NoHyp in |
| 2186 |
let open Context.Named.Declaration in |
| 2187 |
try |
| 2188 |
|
| 2189 |
let pstate = match pstate with |
| 2190 |
| None -> raise Not_found |
| 2191 |
| Some pstate -> pstate |
| 2192 |
in |
| 2193 |
|
| 2194 |
let glnumopt = query_command_selector ?loc glopt in |
| 2195 |
let pf = Declare.Proof.get pstate in |
| 2196 |
let Proof.{goals; sigma} = Proof.data pf in |
| 2197 |
let ev, id = |
| 2198 |
let open Constrexpr in |
| 2199 |
match glnumopt, ref_or_by_not.v with |
| 2200 |
| None,AN qid when qualid_is_ident qid -> |
| 2201 |
(match List.nth_opt goals 0 with |
| 2202 |
| None -> raise NoHyp |
| 2203 |
| Some goal -> goal), qualid_basename qid |
| 2204 |
| Some n,AN qid when qualid_is_ident qid -> |
| 2205 |
(match List.nth_opt goals (n - 1) with |
| 2206 |
| None -> user_err ?loc |
| 2207 |
(str "No such goal: " ++ int n ++ str ".") |
| 2208 |
| Some goal -> goal), qualid_basename qid |
| 2209 |
| _ , _ -> raise NoHyp in |
| 2210 |
let hyps = Evd.evar_filtered_context (Evd.find_undefined sigma ev) in |
| 2211 |
let decl = Context.Named.lookup id hyps in |
| 2212 |
let natureofid = match decl with |
| 2213 |
| LocalAssum _ -> "Hypothesis" |
| 2214 |
| LocalDef (_,bdy,_) ->"Constant (let in)" in |
| 2215 |
let sigma, env = Declare.Proof.get_current_context pstate in |
| 2216 |
v 0 (Id.print id ++ str":" ++ pr_econstr_env env sigma (NamedDecl.get_type decl) ++ fnl() ++ fnl() |
| 2217 |
++ str natureofid ++ str " of the goal context.") |
| 2218 |
with |
| 2219 |
| NoHyp | Not_found -> |
| 2220 |
let sigma, env = get_current_or_global_context ~pstate in |
| 2221 |
Prettyp.print_about env sigma ref_or_by_not udecl |
| 2222 |
|
| 2223 |
let prglob_without_notations env sigma c = |
| 2224 |
let flags = PrintingFlags.Extern.current() in |
| 2225 |
let flags = { flags with notations = false } in |
| 2226 |
pr_glob_constr_env ~flags env sigma c |
| 2227 |
|
| 2228 |
let vernac_print = |
| 2229 |
let no_state f = |
| 2230 |
Vernactypes.(typed_vernac_gen ignore_state (fun _ -> no_state, f ())) |
| 2231 |
in |
| 2232 |
let with_pstate f = |
| 2233 |
let f {Vernactypes.proof} = |
| 2234 |
Vernactypes.no_state, f ~pstate:proof |
| 2235 |
in |
| 2236 |
Vernactypes.(typed_vernac_gen { ignore_state with proof = ReadOpt } f) |
| 2237 |
in |
| 2238 |
let with_proof_env f = with_pstate (fun ~pstate -> |
| 2239 |
let sigma, env = get_current_or_global_context ~pstate in |
| 2240 |
f env sigma) |
| 2241 |
in |
| 2242 |
let with_proof_env_and_opaques f = |
| 2243 |
let open Vernactypes in |
| 2244 |
let f {proof; opaque_access} = |
| 2245 |
let sigma, env = get_current_or_global_context ~pstate:proof in |
| 2246 |
no_state, f ~opaque_access env sigma |
| 2247 |
in |
| 2248 |
typed_vernac_gen { ignore_state with proof = ReadOpt; opaque_access = Access } f |
| 2249 |
in |
| 2250 |
function |
| 2251 |
| PrintTypingFlags -> with_proof_env @@ fun env _sigma -> pr_typing_flags (Environ.typing_flags env) |
| 2252 |
| PrintTables -> no_state print_tables |
| 2253 |
| PrintFullContext -> with_proof_env Prettyp.print_full_context_typ |
| 2254 |
| PrintSectionContext qid -> with_proof_env @@ fun env sigma -> |
| 2255 |
Prettyp.print_sec_context_typ env sigma qid |
| 2256 |
| PrintInspect n -> with_proof_env @@ fun env sigma -> |
| 2257 |
Prettyp.inspect env sigma n |
| 2258 |
| PrintGrammar ent -> no_state @@ fun () -> Metasyntax.pr_grammar ent |
| 2259 |
| PrintCustomGrammar ent -> no_state @@ fun () -> Metasyntax.pr_custom_grammar ent |
| 2260 |
| PrintKeywords -> no_state Metasyntax.pr_keywords |
| 2261 |
| PrintLoadPath dir -> no_state @@ fun () -> print_loadpath dir |
| 2262 |
| PrintLibraries -> no_state print_libraries |
| 2263 |
| PrintModule qid -> no_state @@ fun () -> print_module qid |
| 2264 |
| PrintModuleType qid -> no_state @@ fun () -> print_modtype qid |
| 2265 |
| PrintNamespace ns -> with_pstate @@ print_namespace ns |
| 2266 |
| PrintMLLoadPath -> no_state @@ fun () -> |
| 2267 |
let paths = Findlib.search_path () in |
| 2268 |
v 0 (prlist_with_sep cut str paths ) |
| 2269 |
| PrintMLModules -> no_state Mltop.print_ml_modules |
| 2270 |
| PrintDebugGC -> no_state Mltop.print_gc |
| 2271 |
| PrintName (qid,udecl) -> with_proof_env_and_opaques @@ fun ~opaque_access env sigma -> |
| 2272 |
Prettyp.print_name opaque_access env sigma qid udecl |
| 2273 |
| PrintGraph -> no_state Prettyp.print_graph |
| 2274 |
| PrintClasses -> no_state Prettyp.print_classes |
| 2275 |
| PrintTypeclasses -> no_state Prettyp.print_typeclasses |
| 2276 |
| PrintInstances c -> no_state @@ fun () -> Prettyp.print_instances (smart_global c) |
| 2277 |
| PrintCoercions -> no_state Prettyp.print_coercions |
| 2278 |
| PrintNotation (entry, ntnstr) -> with_proof_env @@ fun env sigma -> |
| 2279 |
Prettyp.print_notation env sigma entry ntnstr |
| 2280 |
| PrintCoercionPaths (cls,clt) -> no_state @@ fun () -> |
| 2281 |
Prettyp.print_coercion_paths (cl_of_qualid cls) (cl_of_qualid clt) |
| 2282 |
| PrintCanonicalConversions qids -> with_proof_env @@ fun env sigma -> |
| 2283 |
let grefs = List.map Smartlocate.smart_global qids in |
| 2284 |
Prettyp.print_canonical_projections env sigma grefs |
| 2285 |
| PrintUniverses prunivs -> no_state @@ fun ()-> |
| 2286 |
print_universes prunivs |
| 2287 |
| PrintSorts -> no_state print_sorts |
| 2288 |
| PrintHint r -> with_proof_env @@ fun env sigma -> |
| 2289 |
Hints.pr_hint_ref env sigma (smart_global r) |
| 2290 |
| PrintHintGoal -> with_pstate @@ fun ~pstate -> |
| 2291 |
begin match pstate with |
| 2292 |
| Some pstate -> |
| 2293 |
let pf = Declare.Proof.get pstate in |
| 2294 |
Hints.pr_applicable_hint pf |
| 2295 |
| None -> |
| 2296 |
str "No proof in progress" |
| 2297 |
end |
| 2298 |
| PrintHintDbName s -> with_proof_env @@ fun env sigma -> |
| 2299 |
Hints.pr_hint_db_by_name env sigma s |
| 2300 |
| PrintHintDb -> with_proof_env @@ fun env sigma -> |
| 2301 |
Hints.pr_searchtable env sigma |
| 2302 |
| PrintScopes -> with_proof_env @@ fun env sigma -> |
| 2303 |
Notation.pr_scopes (prglob_without_notations env sigma) |
| 2304 |
| PrintScope s -> with_proof_env @@ fun env sigma -> |
| 2305 |
Notation.pr_scope (prglob_without_notations env sigma) s |
| 2306 |
| PrintVisibility s -> with_proof_env @@ fun env sigma -> |
| 2307 |
Notation.pr_visibility (prglob_without_notations env sigma) s |
| 2308 |
| PrintAbout (ref_or_by_not,udecl,glnumopt) -> with_pstate @@ |
| 2309 |
print_about_hyp_globs ref_or_by_not udecl glnumopt |
| 2310 |
| PrintImplicit qid -> with_proof_env @@ fun env _sigma -> |
| 2311 |
Prettyp.print_impargs env (smart_global qid) |
| 2312 |
| PrintAssumptions (o,t,rs) -> with_proof_env_and_opaques @@ fun ~opaque_access env sigma -> |
| 2313 |
|
| 2314 |
let st = Conv_oracle.get_transp_state (Environ.oracle env) in |
| 2315 |
let grs = List.map smart_global rs in |
| 2316 |
let nassums = |
| 2317 |
Assumptions.assumptions opaque_access st ~add_opaque:o ~add_transparent:t grs in |
| 2318 |
Printer.pr_assumptionset env sigma nassums |
| 2319 |
| PrintStrategy r -> no_state @@ fun () -> print_strategy r |
| 2320 |
| PrintRegistered -> no_state print_registered |
| 2321 |
| PrintRegisteredSchemes -> no_state print_registered_schemes |
| 2322 |
|
| 2323 |
let vernac_search ~pstate ~atts s gopt r = |
| 2324 |
let open ComSearch in |
| 2325 |
let gopt = query_command_selector gopt in |
| 2326 |
let sigma, env = |
| 2327 |
match gopt with |
| 2328 |
|
| 2329 |
| None -> begin |
| 2330 |
try get_goal_or_global_context ~pstate 1 |
| 2331 |
with Proof.NoSuchGoal _ -> let env = Global.env () in Evd.from_env env, env |
| 2332 |
end |
| 2333 |
|
| 2334 |
| Some g -> get_goal_or_global_context ~pstate g |
| 2335 |
in |
| 2336 |
interp_search env sigma s r |
| 2337 |
|
| 2338 |
let vernac_locate ~pstate query = |
| 2339 |
let open Constrexpr in |
| 2340 |
let sigma, env = get_current_or_global_context ~pstate in |
| 2341 |
match query with |
| 2342 |
| LocateAny {v=AN qid} -> Prettyp.print_located_qualid env qid |
| 2343 |
| LocateTerm {v=AN qid} -> Prettyp.print_located_term env qid |
| 2344 |
| LocateAny {v=ByNotation (ntn, sc)} |
| 2345 |
| LocateTerm {v=ByNotation (ntn, sc)} -> |
| 2346 |
Notation.locate_notation |
| 2347 |
(prglob_without_notations env sigma) ntn sc |
| 2348 |
| LocateLibrary qid -> print_located_library qid |
| 2349 |
| LocateModule qid -> Prettyp.print_located_module env qid |
| 2350 |
| LocateOther (s, qid) -> Prettyp.print_located_other env s qid |
| 2351 |
| LocateFile f -> locate_file f |
| 2352 |
|
| 2353 |
let warn_unknown_scheme_kind = CWarnings.create ~name:"unknown-scheme-kind" |
| 2354 |
Pp.(fun sk -> str "Unknown scheme kind " ++ Libnames.pr_qualid sk ++ str ".") |
| 2355 |
|
| 2356 |
let vernac_register ~atts qid r = |
| 2357 |
let gr = Smartlocate.global_with_alias qid in |
| 2358 |
match r with |
| 2359 |
| RegisterInline -> |
| 2360 |
unsupported_attributes atts; |
| 2361 |
begin match gr with |
| 2362 |
| GlobRef.ConstRef c -> Global.register_inline c |
| 2363 |
| _ -> CErrors.user_err ?loc:qid.loc (Pp.str "Register Inline: expecting a constant.") |
| 2364 |
end |
| 2365 |
| RegisterCoqlib n -> |
| 2366 |
let ns, id = Libnames.repr_qualid n in |
| 2367 |
if DirPath.equal (dirpath_of_string "kernel") ns then begin |
| 2368 |
unsupported_attributes atts; |
| 2369 |
if Lib.sections_are_opened () then |
| 2370 |
user_err Pp.(str "Registering a kernel type is not allowed in sections."); |
| 2371 |
let CPrimitives.PIE pind = match Id.to_string id with |
| 2372 |
| "ind_bool" -> CPrimitives.(PIE PIT_bool) |
| 2373 |
| "ind_carry" -> CPrimitives.(PIE PIT_carry) |
| 2374 |
| "ind_pair" -> CPrimitives.(PIE PIT_pair) |
| 2375 |
| "ind_cmp" -> CPrimitives.(PIE PIT_cmp) |
| 2376 |
| "ind_f_cmp" -> CPrimitives.(PIE PIT_f_cmp) |
| 2377 |
| "ind_f_class" -> CPrimitives.(PIE PIT_f_class) |
| 2378 |
| k -> CErrors.user_err ?loc:n.loc Pp.(str "Register: unknown identifier “" ++ str k ++ str "” in the \"kernel\" namespace.") |
| 2379 |
in |
| 2380 |
match gr with |
| 2381 |
| GlobRef.IndRef ind -> Global.register_inductive ind pind |
| 2382 |
| _ -> CErrors.user_err ?loc:qid.loc (Pp.str "Register in kernel: expecting an inductive type.") |
| 2383 |
end |
| 2384 |
else |
| 2385 |
let local = Attributes.parse hint_locality_default_superglobal atts in |
| 2386 |
Rocqlib.register_ref local (Libnames.string_of_qualid n) gr |
| 2387 |
| RegisterScheme { inductive; scheme_kind } -> |
| 2388 |
let local = Attributes.parse hint_locality_default_superglobal atts in |
| 2389 |
let scheme_kind_s = Libnames.string_of_qualid scheme_kind in |
| 2390 |
|
| 2391 |
let test_all prefix s = |
| 2392 |
String.starts_with ~prefix s && |
| 2393 |
String.for_all (function '0' | '1' -> true | _ -> false) @@ |
| 2394 |
String.sub s (String.length prefix) (String.length s - String.length prefix) |
| 2395 |
in |
| 2396 |
let () = |
| 2397 |
if not (Ind_tables.is_declared_scheme_object scheme_kind_s |
| 2398 |
|| String.equal "All" scheme_kind_s || String.equal "AllForall" scheme_kind_s |
| 2399 |
|| test_all "All_" scheme_kind_s || test_all "AllForall_" scheme_kind_s) then |
| 2400 |
warn_unknown_scheme_kind ?loc:scheme_kind.loc scheme_kind |
| 2401 |
in |
| 2402 |
let ind = Smartlocate.global_inductive_with_alias inductive in |
| 2403 |
Dumpglob.add_glob ?loc:inductive.loc (IndRef ind); |
| 2404 |
DeclareScheme.declare_scheme local scheme_kind_s (ind, gr) |
| 2405 |
|
| 2406 |
let vernac_library_attributes atts = |
| 2407 |
if Global.is_curmod_library () && not (Lib.sections_are_opened ()) then |
| 2408 |
let user_warns = Attributes.parse user_warns atts in |
| 2409 |
let user_warns = Option.default UserWarn.empty user_warns in |
| 2410 |
Lib.Synterp.declare_info user_warns |
| 2411 |
else |
| 2412 |
user_err (Pp.str "A library attribute should be at toplevel of the library.") |
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
let vernac_focus ~pstate gln = |
| 2418 |
Declare.Proof.map ~f:(fun p -> |
| 2419 |
match gln with |
| 2420 |
| None -> Proof.focus focus_command_cond () 1 p |
| 2421 |
| Some 0 -> |
| 2422 |
user_err Pp.(str "Invalid goal number: 0. Goal numbering starts with 1.") |
| 2423 |
| Some n -> |
| 2424 |
Proof.focus focus_command_cond () n p) |
| 2425 |
pstate |
| 2426 |
|
| 2427 |
|
| 2428 |
let vernac_unfocus ~pstate = |
| 2429 |
Declare.Proof.map |
| 2430 |
~f:(fun p -> Proof.unfocus command_focus p ()) |
| 2431 |
pstate |
| 2432 |
|
| 2433 |
|
| 2434 |
let vernac_unfocused ~pstate = |
| 2435 |
let p = Declare.Proof.get pstate in |
| 2436 |
if Proof.unfocused p then |
| 2437 |
str"The proof is indeed fully unfocused." |
| 2438 |
else |
| 2439 |
user_err Pp.(str "The proof is not fully unfocused.") |
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
let subproof_kind = Proof.new_focus_kind "subproof" |
| 2445 |
let subproof_cond = Proof.done_cond subproof_kind |
| 2446 |
|
| 2447 |
let vernac_subproof gln ~pstate = |
| 2448 |
Declare.Proof.map ~f:(fun p -> |
| 2449 |
match gln with |
| 2450 |
| None -> Proof.focus subproof_cond () 1 p |
| 2451 |
| Some (Goal_select.SelectList [NthSelector n]) -> Proof.focus subproof_cond () n p |
| 2452 |
| Some (Goal_select.SelectList [IdSelector id]) -> Proof.focus_id subproof_cond () id p |
| 2453 |
| _ -> user_err |
| 2454 |
(str "Brackets do not support multi-goal selectors.")) |
| 2455 |
pstate |
| 2456 |
|
| 2457 |
let vernac_end_subproof ~pstate = |
| 2458 |
Declare.Proof.map ~f:(fun p -> |
| 2459 |
Proof.unfocus subproof_kind p ()) |
| 2460 |
pstate |
| 2461 |
|
| 2462 |
let vernac_bullet (bullet : Proof_bullet.t) ~pstate = |
| 2463 |
Declare.Proof.map ~f:(fun p -> |
| 2464 |
Proof_bullet.put p bullet) pstate |
| 2465 |
|
| 2466 |
let show_goal goalref proof oldp = |
| 2467 |
match goalref with |
| 2468 |
| OpenSubgoals -> pr_open_subgoals ~oldp proof |
| 2469 |
| NthGoal n -> pr_nth_open_subgoal ~oldp ~proof n |
| 2470 |
| GoalId qid -> |
| 2471 |
pr_goal_by_id ~oldp ~proof qid |
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
let vernac_show ~pstate = |
| 2476 |
match pstate with |
| 2477 |
|
| 2478 |
| None -> |
| 2479 |
begin function |
| 2480 |
| ShowProof -> show_proof ~pstate:None |
| 2481 |
| ShowMatch id -> show_match id |
| 2482 |
| _ -> |
| 2483 |
user_err (str "This command requires an open proof.") |
| 2484 |
end |
| 2485 |
|
| 2486 |
| Some pstate -> |
| 2487 |
let proof = Declare.Proof.get pstate in |
| 2488 |
begin function |
| 2489 |
| ShowGoal goalref -> show_goal goalref proof None |
| 2490 |
| ShowExistentials -> show_top_evars ~proof |
| 2491 |
| ShowUniverses -> show_universes ~proof |
| 2492 |
|
| 2493 |
| ShowProofNames -> |
| 2494 |
Id.print (Declare.Proof.get_name pstate) |
| 2495 |
| ShowIntros all -> show_intro ~proof all |
| 2496 |
| ShowProof -> show_proof ~pstate:(Some pstate) |
| 2497 |
| ShowMatch id -> show_match id |
| 2498 |
end |
| 2499 |
|
| 2500 |
let vernac_check_guard ~pstate = |
| 2501 |
Declare.Proof.control_only_guard pstate; |
| 2502 |
str "The condition holds up to here." |
| 2503 |
|
| 2504 |
let vernac_validate_proof ~pstate = |
| 2505 |
let pts = Declare.Proof.get pstate in |
| 2506 |
let { Proof.entry; Proof.sigma } = Proof.data pts in |
| 2507 |
let hyps, pfterm, pftyp = List.hd (Proofview.initial_goals entry) in |
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
let env = Environ.reset_with_named_context hyps (Global.env ()) in |
| 2513 |
let sigma = Evarconv.solve_unif_constraints_with_heuristics env sigma in |
| 2514 |
let sigma' = Typing.check env sigma pfterm pftyp in |
| 2515 |
let evar_issues = |
| 2516 |
|
| 2517 |
Evar.Map.merge (fun e orig now -> match orig, now with |
| 2518 |
| None, None -> assert false |
| 2519 |
| Some _, Some _ -> None |
| 2520 |
| Some evi, None -> |
| 2521 |
let EvarInfo evi' = Evd.find sigma' e in |
| 2522 |
let body = match Evd.evar_body evi' with |
| 2523 |
| Evar_empty -> assert false |
| 2524 |
| Evar_defined body -> body |
| 2525 |
in |
| 2526 |
Some |
| 2527 |
Pp.(str "Evar " ++ Printer.pr_evar sigma (e, evi) |
| 2528 |
++ spc() ++ str "was inferred by unification to be" ++ spc() |
| 2529 |
++ pr_econstr_env (Evd.evar_env env evi') sigma' body) |
| 2530 |
| None, Some _ -> |
| 2531 |
assert (not (Evd.is_defined sigma e)); |
| 2532 |
None |
| 2533 |
) |
| 2534 |
(Evd.undefined_map sigma) |
| 2535 |
(Evd.undefined_map sigma') |
| 2536 |
in |
| 2537 |
|
| 2538 |
|
| 2539 |
if Evar.Map.is_empty evar_issues then |
| 2540 |
str "No issues found." |
| 2541 |
else prlist_with_sep fnl snd (Evar.Map.bindings evar_issues) |
| 2542 |
|
| 2543 |
let vernac_proof pstate tac using = |
| 2544 |
let is_let = match Declare.Proof.definition_scope pstate with |
| 2545 |
| Discharge -> true |
| 2546 |
| Global _ -> false |
| 2547 |
in |
| 2548 |
let using = if not is_let then Option.append using (Proof_using.get_default_proof_using ()) |
| 2549 |
else |
| 2550 |
let () = if Option.has_some using |
| 2551 |
then CErrors.user_err Pp.(str "Let does not support Proof using.") |
| 2552 |
in |
| 2553 |
None |
| 2554 |
in |
| 2555 |
let tacs = if Option.is_empty tac then "tac:no" else "tac:yes" in |
| 2556 |
let usings = if Option.is_empty using then "using:no" else "using:yes" in |
| 2557 |
Aux_file.record_in_aux_at "VernacProof" (tacs^" "^usings); |
| 2558 |
let pstate = Option.fold_left vernac_set_end_tac pstate tac in |
| 2559 |
let set_proof_using ps using = Declare.Proof.set_proof_using ps using |> snd in |
| 2560 |
let pstate = Option.fold_left set_proof_using pstate using in |
| 2561 |
pstate |
| 2562 |
|
| 2563 |
let translate_vernac_synterp ?loc ~atts v = let open Vernactypes in match v with |
| 2564 |
| EVernacNotation { local; decl } -> |
| 2565 |
vtdefault(fun () -> Metasyntax.add_notation_interpretation ~local (Global.env()) decl) |
| 2566 |
|
| 2567 |
| EVernacDeclareMLModule f -> vtdefault (fun () -> Mltop.run_interp_fun f) |
| 2568 |
|
| 2569 |
| EVernacDefineModule (export,lid,bl,argsexport,mtys,mexprl) -> |
| 2570 |
let i () = |
| 2571 |
unsupported_attributes atts; |
| 2572 |
vernac_define_module export lid bl argsexport mtys mexprl in |
| 2573 |
|
| 2574 |
|
| 2575 |
vernac_begin_segment ~interactive:(List.is_empty mexprl) i |
| 2576 |
|
| 2577 |
| EVernacDeclareModuleType (lid,bl,argsexport,mtys,exprl) -> |
| 2578 |
vernac_begin_segment ~interactive:(List.is_empty exprl) (fun () -> |
| 2579 |
unsupported_attributes atts; |
| 2580 |
vernac_declare_module_type lid bl argsexport mtys exprl) |
| 2581 |
|
| 2582 |
|
| 2583 |
| EVernacDeclareModule (export,lid,bl,mty) -> |
| 2584 |
vtdefault(fun () -> |
| 2585 |
unsupported_attributes atts; |
| 2586 |
vernac_declare_module export lid bl mty) |
| 2587 |
|
| 2588 |
| EVernacInclude in_asts -> |
| 2589 |
vtdefault(fun () -> |
| 2590 |
unsupported_attributes atts; |
| 2591 |
vernac_include in_asts) |
| 2592 |
|
| 2593 |
|
| 2594 |
| EVernacBeginSection lid -> |
| 2595 |
vernac_begin_segment ~interactive:true (fun () -> |
| 2596 |
vernac_begin_section ~poly:(only_polymorphism atts) lid) |
| 2597 |
|
| 2598 |
| EVernacEndSegment lid -> |
| 2599 |
unsupported_attributes atts; |
| 2600 |
vernac_end_segment lid |
| 2601 |
|
| 2602 |
| EVernacRequire (needed, modrefl, export, qidl) -> |
| 2603 |
vtdefault(fun () -> |
| 2604 |
unsupported_attributes atts; |
| 2605 |
vernac_require_interp needed modrefl export qidl) |
| 2606 |
| EVernacImport (export,mpl) -> |
| 2607 |
vtdefault(fun () -> |
| 2608 |
unsupported_attributes atts; |
| 2609 |
vernac_import export mpl) |
| 2610 |
|
| 2611 |
| EVernacSetOption { export; key; value } -> |
| 2612 |
vtdefault(fun () -> |
| 2613 |
let atts = if export then CAst.make ?loc ("export", VernacFlagEmpty) :: atts else atts in |
| 2614 |
Vernacoptions.vernac_set_option ~locality:(parse option_locality atts) ~stage:Summary.Stage.Interp key value) |
| 2615 |
|
| 2616 |
| EVernacNoop -> |
| 2617 |
vtdefault(fun () -> ()) |
| 2618 |
|
| 2619 |
| EVernacLoad _ -> |
| 2620 |
anomaly (str "type_vernac") |
| 2621 |
|
| 2622 |
|
| 2623 |
| EVernacExtend f -> f |
| 2624 |
|
| 2625 |
let translate_pure_vernac ?loc ~atts v = let open Vernactypes in match v with |
| 2626 |
| VernacAbortAll |
| 2627 |
| VernacRestart |
| 2628 |
| VernacUndo _ |
| 2629 |
| VernacUndoTo _ |
| 2630 |
| VernacResetName _ |
| 2631 |
| VernacResetInitial |
| 2632 |
| VernacBack _ -> |
| 2633 |
anomaly (str "type_vernac") |
| 2634 |
|
| 2635 |
|
| 2636 |
| VernacDeclareScope sc -> |
| 2637 |
vtdefault(fun () -> with_module_locality ~atts vernac_declare_scope sc) |
| 2638 |
| VernacDelimiters (sc,lr) -> |
| 2639 |
vtdefault(fun () -> with_module_locality ~atts vernac_delimiters sc lr) |
| 2640 |
| VernacBindScope (sc,rl) -> |
| 2641 |
vtdefault(fun () -> vernac_bind_scope ~atts sc rl) |
| 2642 |
| VernacOpenCloseScope (b, s) -> |
| 2643 |
vtdefault(fun () -> with_section_locality ~atts vernac_open_close_scope (b,s)) |
| 2644 |
| VernacEnableNotation (on,rule,interp,flags,scope) -> |
| 2645 |
vtdefault(fun () -> with_module_locality ~atts vernac_enable_notation on rule interp flags scope) |
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
| VernacDefinition ((discharge,kind as dkind),lid,DefineBody (bl,red_option,c,typ)) -> |
| 2650 |
let coercion = match kind with Decls.Coercion -> true | _ -> false in |
| 2651 |
let atts, refine = Attributes.(parse_with_extra Classes.refine_att) atts in |
| 2652 |
if refine then |
| 2653 |
vtopenproof(fun () -> |
| 2654 |
with_def_attributes ~coercion ~discharge:(discharge, "\"Let\"", "\"#[local] Definition\"") ~atts |
| 2655 |
vernac_definition_refine dkind lid bl red_option c typ) |
| 2656 |
else |
| 2657 |
vtmodifyprogram (fun ~pm -> |
| 2658 |
with_def_attributes ~coercion ~discharge:(discharge, "\"Let\"", "\"#[local] Definition\"") ~atts |
| 2659 |
vernac_definition ~pm dkind lid bl red_option c typ) |
| 2660 |
| VernacDefinition ((discharge,kind as dkind),lid,ProveBody(bl,typ)) -> |
| 2661 |
let coercion = match kind with Decls.Coercion -> true | _ -> false in |
| 2662 |
vtopenproof(fun () -> |
| 2663 |
with_def_attributes ~coercion ~discharge:(discharge, "\"Let\"", "\"#[local] Definition\"") ~atts |
| 2664 |
vernac_definition_interactive dkind lid bl typ) |
| 2665 |
|
| 2666 |
| VernacStartTheoremProof (k,l) -> |
| 2667 |
vtopenproof(fun () -> with_def_attributes ~atts vernac_start_proof k l) |
| 2668 |
| VernacExactProof c -> |
| 2669 |
vtcloseproof (fun ~lemma -> |
| 2670 |
unsupported_attributes atts; |
| 2671 |
vernac_exact_proof ~lemma c) |
| 2672 |
|
| 2673 |
| VernacAssumption ((discharge,kind),nl,l) -> |
| 2674 |
vtdefault(fun () -> |
| 2675 |
with_def_attributes ~atts |
| 2676 |
~discharge:(discharge, |
| 2677 |
"\"Variable\" or \"Hypothesis\"", |
| 2678 |
"\"#[local] Parameter\" or \"#[local] Axiom\"") |
| 2679 |
vernac_assumption kind l nl) |
| 2680 |
|
| 2681 |
| VernacSymbol l -> |
| 2682 |
vtdefault (fun () -> |
| 2683 |
let (unfold_fix, poly) = |
| 2684 |
Attributes.(parse Notations.(unfold_fix ++ poly PolyFlags.Assumption)) atts |
| 2685 |
in |
| 2686 |
ComRewriteRule.do_symbols ~poly ~unfold_fix l) |
| 2687 |
|
| 2688 |
| VernacInductive (finite, l) -> |
| 2689 |
vtdefault(fun () -> vernac_inductive ~atts finite l) |
| 2690 |
|
| 2691 |
| VernacFixpoint (discharge, l) -> |
| 2692 |
let atts, refine = Attributes.(parse_with_extra Classes.refine_att) atts in |
| 2693 |
let opens = refine || List.exists (fun { body_def } -> Option.is_empty body_def) (snd l) in |
| 2694 |
let discharge = discharge, "\"Let Fixpoint\"", "\"#[local] Fixpoint\"" in |
| 2695 |
(if opens then |
| 2696 |
vtopenproof (fun () -> |
| 2697 |
let pm, proof = with_def_attributes ~discharge ~atts (vernac_fixpoint ~refine ~pm:None) l in |
| 2698 |
assert (Option.is_empty pm); |
| 2699 |
Option.get proof) |
| 2700 |
else |
| 2701 |
vtmodifyprogram (fun ~pm -> |
| 2702 |
let pm, proof = with_def_attributes ~discharge ~atts (vernac_fixpoint ~refine ~pm:(Some pm)) l in |
| 2703 |
assert (Option.is_empty proof); |
| 2704 |
Option.get pm)) |
| 2705 |
|
| 2706 |
| VernacCoFixpoint (discharge, l) -> |
| 2707 |
let atts, refine = Attributes.(parse_with_extra Classes.refine_att) atts in |
| 2708 |
let opens = refine || List.exists (fun { body_def } -> Option.is_empty body_def) l in |
| 2709 |
let discharge = discharge, "\"Let CoFixpoint\"", "\"#[local] CoFixpoint\"" in |
| 2710 |
(if opens then |
| 2711 |
vtopenproof (fun () -> |
| 2712 |
let pm, proof = with_def_attributes ~discharge ~atts (vernac_cofixpoint ~refine ~pm:None) l in |
| 2713 |
assert (Option.is_empty pm); |
| 2714 |
Option.get proof) |
| 2715 |
else |
| 2716 |
vtmodifyprogram (fun ~pm -> |
| 2717 |
let pm, proof = with_def_attributes ~discharge ~atts (vernac_cofixpoint ~refine ~pm:(Some pm)) l in |
| 2718 |
assert (Option.is_empty proof); |
| 2719 |
Option.get pm)) |
| 2720 |
|
| 2721 |
| VernacScheme l -> |
| 2722 |
vtdefault(fun () -> |
| 2723 |
vernac_scheme atts l) |
| 2724 |
| VernacSchemeAll (id, strpos) -> |
| 2725 |
vtdefault(fun () -> |
| 2726 |
unsupported_attributes atts; |
| 2727 |
DeclareInd.do_scheme_all id strpos) |
| 2728 |
| VernacSchemeEquality (sch,id) -> |
| 2729 |
vtdefault(fun () -> |
| 2730 |
unsupported_attributes atts; |
| 2731 |
vernac_scheme_equality sch id ~locmap:(Ind_tables.Locmap.default loc)) |
| 2732 |
| VernacCombinedScheme (id, l) -> |
| 2733 |
vtdefault(fun () -> |
| 2734 |
unsupported_attributes atts; |
| 2735 |
vernac_combined_scheme id l ~locmap:(Ind_tables.Locmap.default loc)) |
| 2736 |
| VernacUniverse l -> |
| 2737 |
vtdefault(fun () -> vernac_universe ~poly:(only_polymorphism atts) l) |
| 2738 |
|
| 2739 |
| VernacSort l -> |
| 2740 |
vtdefault(fun () -> vernac_sort ~poly:(only_polymorphism atts) l) |
| 2741 |
|
| 2742 |
| VernacConstraint l -> |
| 2743 |
vtdefault(fun () -> vernac_constraint ~poly:(only_polymorphism atts) l) |
| 2744 |
|
| 2745 |
| VernacAddRewRule (id, c) -> |
| 2746 |
vtdefault (fun () -> |
| 2747 |
unsupported_attributes atts; |
| 2748 |
ComRewriteRule.do_rules id.v c) |
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
| VernacNameSectionHypSet (lid, set) -> |
| 2753 |
vtdefault(fun () -> |
| 2754 |
unsupported_attributes atts; |
| 2755 |
vernac_name_sec_hyp lid set) |
| 2756 |
|
| 2757 |
| VernacCanonical qid -> |
| 2758 |
vtdefault(fun () -> |
| 2759 |
vernac_canonical ~local:(only_locality atts) qid) |
| 2760 |
|
| 2761 |
| VernacCoercion (r,st) -> |
| 2762 |
vtdefault(fun () -> vernac_coercion ~atts r st) |
| 2763 |
|
| 2764 |
| VernacIdentityCoercion (id,s,t) -> |
| 2765 |
vtdefault(fun () -> vernac_identity_coercion ~atts id s t) |
| 2766 |
|
| 2767 |
|
| 2768 |
| VernacInstance (name, bl, t, props, info) -> |
| 2769 |
let atts, program = Attributes.(parse_with_extra program) atts in |
| 2770 |
if program then |
| 2771 |
vtmodifyprogram (vernac_instance_program ~atts name bl t props info) |
| 2772 |
else begin match props with |
| 2773 |
| None -> |
| 2774 |
vtopenproof (fun () -> |
| 2775 |
vernac_instance_interactive ~atts name bl t info None) |
| 2776 |
| Some props -> |
| 2777 |
let atts, refine = Attributes.parse_with_extra Classes.refine_att atts in |
| 2778 |
if refine then |
| 2779 |
vtopenproof (fun () -> |
| 2780 |
vernac_instance_interactive ~atts name bl t info (Some props)) |
| 2781 |
else |
| 2782 |
vtdefault (fun () -> |
| 2783 |
vernac_instance ~atts name bl t props info) |
| 2784 |
end |
| 2785 |
|
| 2786 |
| VernacDeclareInstance (id, bl, inst, info) -> |
| 2787 |
vtdefault(fun () -> vernac_declare_instance ~atts id bl inst info) |
| 2788 |
| VernacContext sup -> |
| 2789 |
vtdefault(fun () -> vernac_context ~atts sup) |
| 2790 |
| VernacExistingInstance insts -> |
| 2791 |
vtdefault(fun () -> vernac_existing_instance ~atts insts) |
| 2792 |
|
| 2793 |
| VernacExistingClass id -> |
| 2794 |
vtdefault(fun () -> |
| 2795 |
unsupported_attributes atts; |
| 2796 |
vernac_existing_class id) |
| 2797 |
|
| 2798 |
|
| 2799 |
| VernacCreateHintDb (dbname,b) -> |
| 2800 |
vtdefault(fun () -> |
| 2801 |
with_module_locality ~atts vernac_create_hintdb dbname b) |
| 2802 |
|
| 2803 |
| VernacRemoveHints (dbnames,ids) -> |
| 2804 |
vtdefault(fun () -> |
| 2805 |
vernac_remove_hints ~atts dbnames ids) |
| 2806 |
|
| 2807 |
| VernacHints (dbnames,hints) -> |
| 2808 |
vtdefault(fun () -> |
| 2809 |
vernac_hints ~atts dbnames hints) |
| 2810 |
|
| 2811 |
| VernacAbbreviation (id,c,b,warn_old_notation) -> |
| 2812 |
vtdefault(fun () -> vernac_abbreviation ~warn_old_notation ~atts id c b) |
| 2813 |
|
| 2814 |
| VernacArguments (qid, args, more_implicits, flags) -> |
| 2815 |
vtdefault(fun () -> |
| 2816 |
with_section_locality ~atts |
| 2817 |
(ComArguments.vernac_arguments qid args more_implicits flags)) |
| 2818 |
|
| 2819 |
| VernacReserve bl -> |
| 2820 |
vtdefault(fun () -> |
| 2821 |
unsupported_attributes atts; |
| 2822 |
vernac_reserve bl) |
| 2823 |
|
| 2824 |
| VernacGeneralizable gen -> |
| 2825 |
vtdefault(fun () -> with_locality ~atts vernac_generalizable gen) |
| 2826 |
|
| 2827 |
| VernacSetOpacity (qidl, on_proj_constant) -> |
| 2828 |
vtdefault(fun () -> |
| 2829 |
with_locality ~atts (vernac_set_opacity ~on_proj_constant) qidl) |
| 2830 |
|
| 2831 |
| VernacSetStrategy l -> |
| 2832 |
vtdefault(fun () -> with_locality ~atts vernac_set_strategy l) |
| 2833 |
|
| 2834 |
| VernacRemoveOption (key,v) -> |
| 2835 |
vtdefault(fun () -> |
| 2836 |
let local = Attributes.parse Attributes.hint_locality atts in |
| 2837 |
Vernacoptions.vernac_remove_option local key v) |
| 2838 |
|
| 2839 |
| VernacAddOption (key,v) -> |
| 2840 |
vtdefault(fun () -> |
| 2841 |
let local = Attributes.parse Attributes.hint_locality atts in |
| 2842 |
Vernacoptions.vernac_add_option local key v) |
| 2843 |
|
| 2844 |
| VernacMemOption (key,v) -> |
| 2845 |
vtdefault(fun () -> |
| 2846 |
unsupported_attributes atts; |
| 2847 |
Vernacoptions.vernac_mem_option key v) |
| 2848 |
|
| 2849 |
| VernacPrintOption key -> |
| 2850 |
vtdefault(fun () -> |
| 2851 |
unsupported_attributes atts; |
| 2852 |
Vernacoptions.vernac_print_option key) |
| 2853 |
|
| 2854 |
| VernacCheckMayEval (r,g,c) -> |
| 2855 |
vtreadproofopt(fun ~pstate -> |
| 2856 |
unsupported_attributes atts; |
| 2857 |
Feedback.msg_notice @@ |
| 2858 |
vernac_check_may_eval ~pstate r g c) |
| 2859 |
|
| 2860 |
| VernacDeclareReduction (s,r) -> |
| 2861 |
vtdefault(fun () -> |
| 2862 |
with_locality ~atts vernac_declare_reduction s r) |
| 2863 |
|
| 2864 |
| VernacGlobalCheck c -> |
| 2865 |
vtdefault(fun () -> |
| 2866 |
unsupported_attributes atts; |
| 2867 |
Feedback.msg_notice @@ vernac_global_check c) |
| 2868 |
|
| 2869 |
| VernacPrint p -> |
| 2870 |
unsupported_attributes atts; |
| 2871 |
Vernactypes.map_typed_vernac |
| 2872 |
Feedback.msg_notice |
| 2873 |
(vernac_print p) |
| 2874 |
|
| 2875 |
| VernacSearch (s,g,r) -> |
| 2876 |
vtreadproofopt( |
| 2877 |
unsupported_attributes atts; |
| 2878 |
vernac_search ~atts s g r) |
| 2879 |
|
| 2880 |
| VernacLocate l -> |
| 2881 |
vtreadproofopt(fun ~pstate -> |
| 2882 |
unsupported_attributes atts; |
| 2883 |
Feedback.msg_notice @@ vernac_locate ~pstate l) |
| 2884 |
|
| 2885 |
| VernacRegister (qid, r) -> |
| 2886 |
vtnoproof(fun () -> |
| 2887 |
vernac_register ~atts qid r) |
| 2888 |
|
| 2889 |
| VernacPrimitive ((id, udecl), prim, typopt) -> |
| 2890 |
vtdefault(fun () -> |
| 2891 |
unsupported_attributes atts; |
| 2892 |
ComPrimitive.do_primitive id udecl prim typopt) |
| 2893 |
|
| 2894 |
| VernacComments l -> |
| 2895 |
vtdefault(fun () -> |
| 2896 |
unsupported_attributes atts; |
| 2897 |
Flags.if_verbose Feedback.msg_info (str "Comments ok\n")) |
| 2898 |
|
| 2899 |
| VernacAttributes atts -> |
| 2900 |
vtdefault(fun () -> |
| 2901 |
vernac_library_attributes atts) |
| 2902 |
|
| 2903 |
|
| 2904 |
| VernacFocus n -> |
| 2905 |
vtmodifyproof(unsupported_attributes atts;vernac_focus n) |
| 2906 |
| VernacUnfocus -> |
| 2907 |
vtmodifyproof(unsupported_attributes atts;vernac_unfocus) |
| 2908 |
| VernacUnfocused -> |
| 2909 |
vtreadproof(fun ~pstate -> |
| 2910 |
unsupported_attributes atts; |
| 2911 |
Feedback.msg_notice @@ vernac_unfocused ~pstate) |
| 2912 |
| VernacBullet b -> |
| 2913 |
vtmodifyproof( |
| 2914 |
unsupported_attributes atts; |
| 2915 |
vernac_bullet b) |
| 2916 |
| VernacSubproof n -> |
| 2917 |
vtmodifyproof( |
| 2918 |
unsupported_attributes atts; |
| 2919 |
vernac_subproof n) |
| 2920 |
| VernacEndSubproof -> |
| 2921 |
vtmodifyproof( |
| 2922 |
unsupported_attributes atts; |
| 2923 |
vernac_end_subproof) |
| 2924 |
| VernacShow s -> |
| 2925 |
vtreadproofopt(fun ~pstate -> |
| 2926 |
unsupported_attributes atts; |
| 2927 |
Feedback.msg_notice @@ vernac_show ~pstate s) |
| 2928 |
| VernacCheckGuard -> |
| 2929 |
vtreadproof(fun ~pstate -> |
| 2930 |
unsupported_attributes atts; |
| 2931 |
Feedback.msg_notice @@ vernac_check_guard ~pstate) |
| 2932 |
| VernacValidateProof -> |
| 2933 |
vtreadproof(fun ~pstate -> |
| 2934 |
unsupported_attributes atts; |
| 2935 |
Feedback.msg_notice @@ vernac_validate_proof ~pstate) |
| 2936 |
| VernacProof (tac, using) -> |
| 2937 |
vtmodifyproof(fun ~pstate -> |
| 2938 |
unsupported_attributes atts; |
| 2939 |
vernac_proof pstate tac using) |
| 2940 |
|
| 2941 |
| VernacEndProof pe -> |
| 2942 |
unsupported_attributes atts; |
| 2943 |
vtcloseproof (vernac_end_proof pe) |
| 2944 |
|
| 2945 |
| VernacAbort -> |
| 2946 |
unsupported_attributes atts; |
| 2947 |
vtcloseproof vernac_abort |
| 2948 |
|
| 2949 |
let translate_vernac ?loc ~atts v = |
| 2950 |
match v with |
| 2951 |
| VernacSynterp e -> translate_vernac_synterp ?loc ~atts e |
| 2952 |
| VernacSynPure e -> translate_pure_vernac ?loc ~atts e |