aboutsummaryrefslogtreecommitdiff
path: root/vernac
diff options
context:
space:
mode:
authorPierre-Marie Pédrot2020-03-05 15:14:47 +0100
committerPierre-Marie Pédrot2020-03-08 15:31:27 +0100
commit4481b95f6f89acd7013b16a345d379dc44d67705 (patch)
treecd1d0f1c59a3a27aa1fd777797834fc15ac71a38 /vernac
parent6143ac9f9307b2f6863cca019a66cdcbfd52d7ce (diff)
Template polymorphism is now a property of the inductive block.
For an inductive block to be template, all its components must also be. This is probably fixing a few soundness bugs in the process, but I do not want to think too much about it.
Diffstat (limited to 'vernac')
-rw-r--r--vernac/comInductive.ml20
-rw-r--r--vernac/record.ml17
2 files changed, 21 insertions, 16 deletions
diff --git a/vernac/comInductive.ml b/vernac/comInductive.ml
index 08a8d1b320..718e62b9b7 100644
--- a/vernac/comInductive.ml
+++ b/vernac/comInductive.ml
@@ -367,6 +367,14 @@ let interp_mutual_inductive_constr ~sigma ~template ~udecl ~ctx_params ~indnames
(* Build the inductive entries *)
let entries = List.map4 (fun indname (templatearity, arity) concl (cnames,ctypes) ->
+ { mind_entry_typename = indname;
+ mind_entry_arity = arity;
+ mind_entry_consnames = cnames;
+ mind_entry_lc = ctypes
+ })
+ indnames arities arityconcl constructors
+ in
+ let template = List.map4 (fun indname (templatearity, _) concl (_, ctypes) ->
let template_candidate () =
templatearity ||
let ctor_levels =
@@ -382,22 +390,17 @@ let interp_mutual_inductive_constr ~sigma ~template ~udecl ~ctx_params ~indnames
in
template_polymorphism_candidate ~ctor_levels uctx ctx_params concl
in
- let template = match template with
+ match template with
| Some template ->
if poly && template then user_err
Pp.(strbrk "Template-polymorphism and universe polymorphism are not compatible.");
template
| None ->
should_auto_template indname (template_candidate ())
- in
- { mind_entry_typename = indname;
- mind_entry_arity = arity;
- mind_entry_template = template;
- mind_entry_consnames = cnames;
- mind_entry_lc = ctypes
- })
+ )
indnames arities arityconcl constructors
in
+ let is_template = List.for_all (fun t -> t) template in
(* Build the mutual inductive entry *)
let mind_ent =
{ mind_entry_params = ctx_params;
@@ -406,6 +409,7 @@ let interp_mutual_inductive_constr ~sigma ~template ~udecl ~ctx_params ~indnames
mind_entry_inds = entries;
mind_entry_private = if private_ind then Some false else None;
mind_entry_universes = uctx;
+ mind_entry_template = is_template;
mind_entry_cumulative = poly && cumulative;
}
in
diff --git a/vernac/record.ml b/vernac/record.ml
index 3e44cd85cc..065641989d 100644
--- a/vernac/record.ml
+++ b/vernac/record.ml
@@ -423,7 +423,13 @@ let declare_structure ~cumulative finite ubinders univs paramimpls params templa
let args = Context.Rel.to_extended_list mkRel nfields params in
let ind = applist (mkRel (ntypes - i + nparams + nfields), args) in
let type_constructor = it_mkProd_or_LetIn ind fields in
- let template =
+ { mind_entry_typename = id;
+ mind_entry_arity = arity;
+ mind_entry_consnames = [idbuild];
+ mind_entry_lc = [type_constructor] }
+ in
+ let blocks = List.mapi mk_block record_data in
+ let check_template (id, _, min_univ, _, _, fields, _, _) =
let template_candidate () =
(* we use some dummy values for the arities in the rel_context
as univs_of_constr doesn't care about localassums and
@@ -454,14 +460,8 @@ let declare_structure ~cumulative finite ubinders univs paramimpls params templa
| None, template ->
(* auto detect template *)
ComInductive.should_auto_template id (template && template_candidate ())
- in
- { mind_entry_typename = id;
- mind_entry_arity = arity;
- mind_entry_template = template;
- mind_entry_consnames = [idbuild];
- mind_entry_lc = [type_constructor] }
in
- let blocks = List.mapi mk_block record_data in
+ let template = List.for_all check_template record_data in
let primitive =
!primitive_flag &&
List.for_all (fun (_,_,_,_,_,fields,_,_) -> List.exists is_local_assum fields) record_data
@@ -473,6 +473,7 @@ let declare_structure ~cumulative finite ubinders univs paramimpls params templa
mind_entry_inds = blocks;
mind_entry_private = None;
mind_entry_universes = univs;
+ mind_entry_template = template;
mind_entry_cumulative = poly && cumulative;
}
in