Skip to content

Commit

Permalink
Make Program a regular attribute
Browse files Browse the repository at this point in the history
We remove all calls to `Flags.is_program_mode` except one (to compute
the default value of the attribute). Everything else is passed
explicitely, and we remove the special logic in the interpretation loop
to set/unset the flag.

This is especially important since the value of the flag has an impact on
proof modes, so on the separation of parsing and execution phases.
  • Loading branch information
maximedenes committed Feb 5, 2019
1 parent 5c1d7fc commit 49a545b
Show file tree
Hide file tree
Showing 53 changed files with 543 additions and 538 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Vernacular commands
class will have to be changed into `Instance foo : C := {}.` or
`Instance foo : C. Proof. Qed.`.

- Option `Program Mode` now means that the `Program` attribute is enabled
for all commands that support it. In particular, it does not have any effect
on tactics anymore. May cause some incompatibilities.

Tools

- The `-native-compiler` flag of `coqc` and `coqtop` now takes an argument which can have three values:
Expand Down
6 changes: 4 additions & 2 deletions engine/evarutil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ type naming_mode =
| KeepUserNameAndRenameExistingEvenSectionNames
| KeepExistingNames
| FailIfConflict
| ProgramNaming

let push_rel_decl_to_named_context
?(hypnaming=KeepUserNameAndRenameExistingButSectionNames)
Expand Down Expand Up @@ -364,15 +365,16 @@ let push_rel_decl_to_named_context
using this function. For now, we only attempt to preserve the
old behaviour of Program, but ultimately, one should do something
about this whole name generation problem. *)
if Flags.is_program_mode () then next_name_away na avoid
if hypnaming = ProgramNaming then next_name_away na avoid
else
(* id_of_name_using_hdchar only depends on the rel context which is empty
here *)
next_ident_away (id_of_name_using_hdchar empty_env sigma (RelDecl.get_type decl) na) avoid
in
match extract_if_neq id na with
| Some id0 when hypnaming = KeepUserNameAndRenameExistingEvenSectionNames ||
hypnaming = KeepUserNameAndRenameExistingButSectionNames &&
(hypnaming = KeepUserNameAndRenameExistingButSectionNames ||
hypnaming = ProgramNaming) &&
not (is_section_variable id0) ->
(* spiwack: if [id<>id0], rather than introducing a new
binding named [id], we will keep [id0] (the name given
Expand Down
1 change: 1 addition & 0 deletions engine/evarutil.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type naming_mode =
| KeepUserNameAndRenameExistingEvenSectionNames
| KeepExistingNames
| FailIfConflict
| ProgramNaming

val new_evar :
?src:Evar_kinds.t Loc.located -> ?filter:Filter.t ->
Expand Down
45 changes: 24 additions & 21 deletions interp/constrintern.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2328,36 +2328,38 @@ let interp_open_constr env sigma c =

(* Not all evars expected to be resolved and computation of implicit args *)

let interp_constr_evars_gen_impls env sigma
let interp_constr_evars_gen_impls ?(program_mode=false) env sigma
?(impls=empty_internalization_env) expected_type c =
let c = intern_gen expected_type ~impls env sigma c in
let imps = Implicit_quantifiers.implicits_of_glob_constr ~with_products:(expected_type == IsType) c in
let sigma, c = understand_tcc env sigma ~expected_type c in
let flags = { Pretyping.all_no_fail_flags with program_mode } in
let sigma, c = understand_tcc ~flags env sigma ~expected_type c in
sigma, (c, imps)

let interp_constr_evars_impls env sigma ?(impls=empty_internalization_env) c =
interp_constr_evars_gen_impls env sigma ~impls WithoutTypeConstraint c
let interp_constr_evars_impls ?program_mode env sigma ?(impls=empty_internalization_env) c =
interp_constr_evars_gen_impls ?program_mode env sigma ~impls WithoutTypeConstraint c

let interp_casted_constr_evars_impls env evdref ?(impls=empty_internalization_env) c typ =
interp_constr_evars_gen_impls env evdref ~impls (OfType typ) c
let interp_casted_constr_evars_impls ?program_mode env evdref ?(impls=empty_internalization_env) c typ =
interp_constr_evars_gen_impls ?program_mode env evdref ~impls (OfType typ) c

let interp_type_evars_impls env sigma ?(impls=empty_internalization_env) c =
interp_constr_evars_gen_impls env sigma ~impls IsType c
let interp_type_evars_impls ?program_mode env sigma ?(impls=empty_internalization_env) c =
interp_constr_evars_gen_impls ?program_mode env sigma ~impls IsType c

(* Not all evars expected to be resolved, with side-effect on evars *)

let interp_constr_evars_gen env sigma ?(impls=empty_internalization_env) expected_type c =
let interp_constr_evars_gen ?(program_mode=false) env sigma ?(impls=empty_internalization_env) expected_type c =
let c = intern_gen expected_type ~impls env sigma c in
understand_tcc env sigma ~expected_type c
let flags = { Pretyping.all_no_fail_flags with program_mode } in
understand_tcc ~flags env sigma ~expected_type c

let interp_constr_evars env evdref ?(impls=empty_internalization_env) c =
interp_constr_evars_gen env evdref WithoutTypeConstraint ~impls c
let interp_constr_evars ?program_mode env evdref ?(impls=empty_internalization_env) c =
interp_constr_evars_gen ?program_mode env evdref WithoutTypeConstraint ~impls c

let interp_casted_constr_evars env sigma ?(impls=empty_internalization_env) c typ =
interp_constr_evars_gen env sigma ~impls (OfType typ) c
let interp_casted_constr_evars ?program_mode env sigma ?(impls=empty_internalization_env) c typ =
interp_constr_evars_gen ?program_mode env sigma ~impls (OfType typ) c

let interp_type_evars env sigma ?(impls=empty_internalization_env) c =
interp_constr_evars_gen env sigma IsType ~impls c
let interp_type_evars ?program_mode env sigma ?(impls=empty_internalization_env) c =
interp_constr_evars_gen ?program_mode env sigma IsType ~impls c

(* Miscellaneous *)

Expand Down Expand Up @@ -2419,16 +2421,17 @@ let intern_context global_level env impl_env binders =
with InternalizationError (loc,e) ->
user_err ?loc ~hdr:"internalize" (explain_internalization_error e)

let interp_glob_context_evars env sigma k bl =
let interp_glob_context_evars ?(program_mode=false) env sigma k bl =
let open EConstr in
let flags = { Pretyping.all_no_fail_flags with program_mode } in
let env, sigma, par, _, impls =
List.fold_left
(fun (env,sigma,params,n,impls) (na, k, b, t) ->
let t' =
if Option.is_empty b then locate_if_hole ?loc:(loc_of_glob_constr t) na t
else t
in
let sigma, t = understand_tcc env sigma ~expected_type:IsType t' in
let sigma, t = understand_tcc ~flags env sigma ~expected_type:IsType t' in
match b with
None ->
let d = LocalAssum (na,t) in
Expand All @@ -2440,13 +2443,13 @@ let interp_glob_context_evars env sigma k bl =
in
(push_rel d env, sigma, d::params, succ n, impls)
| Some b ->
let sigma, c = understand_tcc env sigma ~expected_type:(OfType t) b in
let sigma, c = understand_tcc ~flags env sigma ~expected_type:(OfType t) b in
let d = LocalDef (na, c, t) in
(push_rel d env, sigma, d::params, n, impls))
(env,sigma,[],k+1,[]) (List.rev bl)
in sigma, ((env, par), impls)

let interp_context_evars ?(global_level=false) ?(impl_env=empty_internalization_env) ?(shift=0) env sigma params =
let interp_context_evars ?program_mode ?(global_level=false) ?(impl_env=empty_internalization_env) ?(shift=0) env sigma params =
let int_env,bl = intern_context global_level env impl_env params in
let sigma, x = interp_glob_context_evars env sigma shift bl in
let sigma, x = interp_glob_context_evars ?program_mode env sigma shift bl in
sigma, (int_env, x)
14 changes: 7 additions & 7 deletions interp/constrintern.mli
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,26 @@ val interp_open_constr : env -> evar_map -> constr_expr -> evar_map * constr

(** Accepting unresolved evars *)

val interp_constr_evars : env -> evar_map ->
val interp_constr_evars : ?program_mode:bool -> env -> evar_map ->
?impls:internalization_env -> constr_expr -> evar_map * constr

val interp_casted_constr_evars : env -> evar_map ->
val interp_casted_constr_evars : ?program_mode:bool -> env -> evar_map ->
?impls:internalization_env -> constr_expr -> types -> evar_map * constr

val interp_type_evars : env -> evar_map ->
val interp_type_evars : ?program_mode:bool -> env -> evar_map ->
?impls:internalization_env -> constr_expr -> evar_map * types

(** Accepting unresolved evars and giving back the manual implicit arguments *)

val interp_constr_evars_impls : env -> evar_map ->
val interp_constr_evars_impls : ?program_mode:bool -> env -> evar_map ->
?impls:internalization_env -> constr_expr ->
evar_map * (constr * Impargs.manual_implicits)

val interp_casted_constr_evars_impls : env -> evar_map ->
val interp_casted_constr_evars_impls : ?program_mode:bool -> env -> evar_map ->
?impls:internalization_env -> constr_expr -> types ->
evar_map * (constr * Impargs.manual_implicits)

val interp_type_evars_impls : env -> evar_map ->
val interp_type_evars_impls : ?program_mode:bool -> env -> evar_map ->
?impls:internalization_env -> constr_expr ->
evar_map * (types * Impargs.manual_implicits)

Expand All @@ -158,7 +158,7 @@ val interp_binder_evars : env -> evar_map -> Name.t -> constr_expr -> evar_map *
(** Interpret contexts: returns extended env and context *)

val interp_context_evars :
?global_level:bool -> ?impl_env:internalization_env -> ?shift:int ->
?program_mode:bool -> ?global_level:bool -> ?impl_env:internalization_env -> ?shift:int ->
env -> evar_map -> local_binder_expr list ->
evar_map * (internalization_env * ((env * rel_context) * Impargs.manual_implicits))

Expand Down
6 changes: 0 additions & 6 deletions lib/flags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ let polymorphic_inductive_cumulativity = ref false
let make_polymorphic_inductive_cumulativity b = polymorphic_inductive_cumulativity := b
let is_polymorphic_inductive_cumulativity () = !polymorphic_inductive_cumulativity

(** [program_mode] tells that Program mode has been activated, either
globally via [Set Program] or locally via the Program command prefix. *)

let program_mode = ref false
let is_program_mode () = !program_mode

let warn = ref true
let make_warn flag = warn := flag; ()
let if_warn f x = if !warn then f x
Expand Down
4 changes: 0 additions & 4 deletions lib/flags.mli
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ val verbosely : ('a -> 'b) -> 'a -> 'b
val if_silent : ('a -> unit) -> 'a -> unit
val if_verbose : ('a -> unit) -> 'a -> unit

(* Miscellaneus flags for vernac *)
val program_mode : bool ref
val is_program_mode : unit -> bool

(** Global polymorphic inductive cumulativity flag. *)
val make_polymorphic_inductive_cumulativity : bool -> unit
val is_polymorphic_inductive_cumulativity : unit -> bool
Expand Down
2 changes: 1 addition & 1 deletion plugins/derive/derive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let start_deriving f suchthat lemma =
let f_type = EConstr.Unsafe.to_constr f_type in
let ef = EConstr.Unsafe.to_constr ef in
let env' = Environ.push_named (LocalDef (f, ef, f_type)) env in
let sigma, suchthat = Constrintern.interp_type_evars env' sigma suchthat in
let sigma, suchthat = Constrintern.interp_type_evars ~program_mode:false env' sigma suchthat in
TCons ( env' , sigma , suchthat , (fun sigma _ ->
TNil sigma))))))
in
Expand Down
2 changes: 1 addition & 1 deletion plugins/funind/indfun.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ let build_newrecursive
let arityc = Constrexpr_ops.mkCProdN bl arityc in
let arity,ctx = Constrintern.interp_type env0 sigma arityc in
let evd = Evd.from_env env0 in
let evd, (_, (_, impls')) = Constrintern.interp_context_evars env evd bl in
let evd, (_, (_, impls')) = Constrintern.interp_context_evars ~program_mode:false env evd bl in
let impl = Constrintern.compute_internalization_data env0 evd Constrintern.Recursive arity impls' in
let open Context.Named.Declaration in
(EConstr.push_named (LocalAssum (recname,arity)) env, Id.Map.add recname impl impls))
Expand Down
4 changes: 2 additions & 2 deletions plugins/funind/recdef.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1518,10 +1518,10 @@ let recursive_definition is_mes function_name rec_impls type_of_f r rec_arg_num
let open CVars in
let env = Global.env() in
let evd = Evd.from_env env in
let evd, function_type = interp_type_evars env evd type_of_f in
let evd, function_type = interp_type_evars ~program_mode:false env evd type_of_f in
let env = EConstr.push_named (Context.Named.Declaration.LocalAssum (function_name,function_type)) env in
(* Pp.msgnl (str "function type := " ++ Printer.pr_lconstr function_type); *)
let evd, ty = interp_type_evars env evd ~impls:rec_impls eq in
let evd, ty = interp_type_evars ~program_mode:false env evd ~impls:rec_impls eq in
let evd = Evd.minimize_universes evd in
let equation_lemma_type = Reductionops.nf_betaiotazeta env evd (Evarutil.nf_evar evd ty) in
let function_type = EConstr.to_constr ~abort_on_undefined_evars:false evd function_type in
Expand Down
7 changes: 5 additions & 2 deletions plugins/ltac/extratactics.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ let with_delayed_uconstr ist c tac =
Pretyping.use_typeclasses = false;
solve_unification_constraints = true;
fail_evar = false;
expand_evars = true
expand_evars = true;
program_mode = false;
} in
let c = Tacinterp.type_uconstr ~flags ist c in
Tacticals.New.tclDELAYEDWITHHOLES false c tac
Expand Down Expand Up @@ -344,7 +345,9 @@ let constr_flags () = {
Pretyping.use_typeclasses = true;
Pretyping.solve_unification_constraints = Pfedit.use_unification_heuristics ();
Pretyping.fail_evar = false;
Pretyping.expand_evars = true }
Pretyping.expand_evars = true;
Pretyping.program_mode = false;
}

let refine_tac ist simple with_classes c =
Proofview.Goal.enter begin fun gl ->
Expand Down
3 changes: 2 additions & 1 deletion plugins/ltac/g_auto.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ let eval_uconstrs ist cs =
Pretyping.use_typeclasses = false;
solve_unification_constraints = true;
fail_evar = false;
expand_evars = true
expand_evars = true;
program_mode = false;
} in
let map c env sigma = c env sigma in
List.map (fun c -> map (Tacinterp.type_uconstr ~flags ist c)) cs
Expand Down
16 changes: 12 additions & 4 deletions plugins/ltac/tacinterp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,9 @@ let constr_flags () = {
use_typeclasses = true;
solve_unification_constraints = true;
fail_evar = true;
expand_evars = true }
expand_evars = true;
program_mode = false;
}

(* Interprets a constr; expects evars to be solved *)
let interp_constr_gen kind ist env sigma c =
Expand All @@ -558,19 +560,25 @@ let open_constr_use_classes_flags () = {
use_typeclasses = true;
solve_unification_constraints = true;
fail_evar = false;
expand_evars = true }
expand_evars = true;
program_mode = false;
}

let open_constr_no_classes_flags () = {
use_typeclasses = false;
solve_unification_constraints = true;
fail_evar = false;
expand_evars = true }
expand_evars = true;
program_mode = false;
}

let pure_open_constr_flags = {
use_typeclasses = false;
solve_unification_constraints = true;
fail_evar = false;
expand_evars = false }
expand_evars = false;
program_mode = false;
}

(* Interprets an open constr *)
let interp_open_constr ?(expected_type=WithoutTypeConstraint) ?(flags=open_constr_no_classes_flags ()) ist env sigma c =
Expand Down
4 changes: 3 additions & 1 deletion plugins/ssr/ssrcommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ let interp_refine ist gl rc =
Pretyping.use_typeclasses = true;
solve_unification_constraints = true;
fail_evar = false;
expand_evars = true }
expand_evars = true;
program_mode = false;
}
in
let sigma, c = Pretyping.understand_ltac flags (pf_env gl) (project gl) vars kind rc in
(* ppdebug(lazy(str"sigma@interp_refine=" ++ pr_evar_map None sigma)); *)
Expand Down
Loading

0 comments on commit 49a545b

Please sign in to comment.