| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Util |
| 12 |
open Names |
| 13 |
open EConstr |
| 14 |
|
| 15 |
type template_binder = { |
| 16 |
bind_sort : Sorts.t; |
| 17 |
default : Sorts.t; |
| 18 |
} |
| 19 |
|
| 20 |
type template_arity = |
| 21 |
| NonTemplateArg of Name.t binder_annot * types * template_arity |
| 22 |
| TemplateArg of Name.t binder_annot * rel_context * template_binder * template_arity |
| 23 |
| DefParam of Name.t binder_annot * constr * types * template_arity |
| 24 |
| CtorType of Declarations.template_universes * types |
| 25 |
| IndType of Declarations.template_universes * rel_context * Sorts.t |
| 26 |
|
| 27 |
let get_template_arity env ind ~ctoropt = |
| 28 |
let mib, mip = Inductive.lookup_mind_specif env ind in |
| 29 |
let template = match mib.mind_template with |
| 30 |
| None -> assert false |
| 31 |
| Some t -> t |
| 32 |
in |
| 33 |
let type_after_params = match ctoropt with |
| 34 |
| None -> |
| 35 |
let ctx = List.rev @@ List.skipn (List.length mib.mind_params_ctxt) @@ |
| 36 |
List.rev mip.mind_arity_ctxt |
| 37 |
in |
| 38 |
IndType (template, EConstr.of_rel_context ctx, template.template_concl) |
| 39 |
| Some ctor -> |
| 40 |
let ctyp = mip.mind_user_lc.(ctor-1) in |
| 41 |
let _, ctyp = Term.decompose_prod_n_decls (List.length mib.mind_params_ctxt) ctyp in |
| 42 |
|
| 43 |
CtorType (template, EConstr.of_constr ctyp) |
| 44 |
in |
| 45 |
let rec aux is_template (params:Constr.rel_context) = match is_template, params with |
| 46 |
| _, LocalDef (na,v,t) :: params -> |
| 47 |
let codom = aux is_template params in |
| 48 |
DefParam (EConstr.of_binder_annot na, EConstr.of_constr v, EConstr.of_constr t, codom) |
| 49 |
| [], [] -> type_after_params |
| 50 |
| _ :: _, [] | [], LocalAssum _ :: _ -> assert false |
| 51 |
| None :: is_template, LocalAssum (na,t) :: params -> |
| 52 |
let codom = aux is_template params in |
| 53 |
NonTemplateArg (EConstr.of_binder_annot na, EConstr.of_constr t, codom) |
| 54 |
| Some bind_sort :: is_template, LocalAssum (na,t) :: params -> |
| 55 |
let ctx, _ = Term.decompose_prod_decls t in |
| 56 |
let codom = aux is_template params in |
| 57 |
let default = UVars.subst_instance_sort template.template_defaults bind_sort in |
| 58 |
let binder = { bind_sort; default } in |
| 59 |
TemplateArg (EConstr.of_binder_annot na, EConstr.of_rel_context ctx, binder, codom) |
| 60 |
in |
| 61 |
let res = aux template.template_param_arguments (List.rev mib.mind_params_ctxt) in |
| 62 |
res |