@@ -1054,13 +1054,7 @@ open Declarations
1054
1054
1055
1055
let get_arity t =
1056
1056
let decls, s = Term. decompose_prod_decls t in
1057
- match Constr. kind s with
1058
- | Sort (Type s ) ->
1059
- begin match Univ.Universe. level s with
1060
- | None -> None
1061
- | Some l -> Some (decls, l)
1062
- end
1063
- | _ -> None
1057
+ decls
1064
1058
1065
1059
(* Workaround to ensure that template universe levels are linear *)
1066
1060
let fix_template_params order evdr env temp b params =
@@ -1070,76 +1064,91 @@ let fix_template_params order evdr env temp b params =
1070
1064
| [] ->
1071
1065
let () = assert (List. is_empty params) in
1072
1066
umap, []
1073
- | false :: templ ->
1067
+ | None :: templ ->
1074
1068
let decls, params = List. chop (order + 1 ) params in
1075
1069
let umap, params = freshen umap templ params in
1076
1070
umap, decls @ params
1077
- | true :: templ ->
1071
+ | Some bind_sort :: templ ->
1078
1072
let decls, params = List. chop (order + 1 ) params in
1079
1073
let umap, params = freshen umap templ params in
1080
1074
let rel, pdecls = match decls with
1081
1075
| rel :: decls -> rel, decls
1082
1076
| _ -> assert false
1083
1077
in
1084
- let u0 = match get_arity (Context.Rel.Declaration. get_type rel) with
1085
- | None -> assert false
1086
- | Some (_ , l ) -> l
1087
- in
1088
- let umap, (ur, repl) = match Univ.Level.Map. find_opt u0 umap with
1089
- | None ->
1090
- let ur = UnivGen. fresh_level () in
1091
- let r = List. init order (fun _ -> UnivGen. fresh_level () ) in
1092
- let r = (ur, r) in
1093
- Univ.Level.Map. add u0 r umap, r
1094
- | Some r -> umap, r
1078
+ let q0, u0 = Inductive.Template. bind_kind bind_sort in
1079
+ let umap, urrepl = match u0 with
1080
+ | None -> umap, None
1081
+ | Some u0 -> match Int.Map. find_opt u0 umap with
1082
+ | None ->
1083
+ let ur = UnivGen. fresh_level () in
1084
+ let r = List. init order (fun _ -> UnivGen. fresh_level () ) in
1085
+ Int.Map. add u0 (ur,r) umap, Some (ur, r)
1086
+ | Some r -> umap, Some r
1095
1087
in
1096
1088
let map pdecl u = match pdecl with
1097
1089
| Context.Rel.Declaration. LocalDef _ -> assert false
1098
1090
| Context.Rel.Declaration. LocalAssum (na , pdecl ) ->
1099
- match get_arity pdecl with
1100
- | Some (ctx , _ ) ->
1101
- let u = Univ.Universe. make u in
1102
- let pdecl = Term. it_mkProd_or_LetIn (Constr. mkType u) ctx in
1103
- Context.Rel.Declaration. LocalAssum (na, pdecl)
1104
- | None -> assert false
1091
+ let ctx, _ = Term. decompose_prod_decls pdecl in
1092
+ let s = match u with
1093
+ | Some u ->
1094
+ let u = Univ.Universe. make u in
1095
+ begin match bind_sort with
1096
+ | Sorts. QSort (q ,_ ) -> Sorts. qsort q u
1097
+ | Type _ -> Sorts. sort_of_univ u
1098
+ | SProp | Prop | Set -> assert false
1099
+ end
1100
+ | None -> bind_sort
1101
+ in
1102
+ let pdecl = Term. it_mkProd_or_LetIn (Constr. mkSort s) ctx in
1103
+ Context.Rel.Declaration. LocalAssum (na, pdecl)
1104
+ in
1105
+ let ur, repl = match urrepl with
1106
+ | None -> None , List. make order None
1107
+ | Some (ur , repl ) -> Some ur, List. map (fun r -> Some r) repl
1105
1108
in
1106
1109
let rel = map rel ur in
1107
1110
let pdecls = List. map2 map pdecls repl in
1108
1111
umap, rel :: pdecls @ params
1109
1112
in
1110
- let umap, decls = freshen Univ.Level .Map. empty templ params in
1113
+ let umap, decls = freshen Int .Map. empty templ params in
1111
1114
(* Add corresponding declaration and constraints for each new level *)
1112
- let fold_univs u0 accu = match Univ.Level.Map. find_opt u0 umap with
1113
- | None -> assert false (* unbound template level *)
1114
- | Some (ur , repl ) ->
1115
- let accu = Univ.Level.Set. add ur accu in
1116
- let fold accu u = Univ.Level.Set. add u accu in
1117
- List. fold_left fold accu repl
1115
+ let map_univs u0 =
1116
+ match Univ.Level. var_index u0 with
1117
+ | None -> assert false
1118
+ | Some u0 ->
1119
+ match Int.Map. find_opt u0 umap with
1120
+ | None -> assert false (* unbound template level *)
1121
+ | Some (ur , repl ) ->
1122
+ Array. of_list (ur :: repl)
1118
1123
in
1119
1124
let fold_cstrs (u0 , cst , v ) accu =
1120
1125
(* We know that v cannot be template because of the unbounded-from-below property *)
1121
- let () = assert (not (Univ.Level.Map. mem v umap )) in
1122
- match Univ.Level.Map. find_opt u0 umap with
1126
+ let () = assert (not (Option. has_some @@ Univ.Level. var_index v )) in
1127
+ match Univ.Level. var_index u0 with
1123
1128
| None ->
1124
1129
(* not template, this is technically allowed but dubious *)
1125
1130
Univ.Constraints. add (u0, cst, v) accu
1126
- | Some (ur , repl ) ->
1127
- let accu = Univ.Constraints. add (ur, cst, v) accu in
1128
- let fold accu u = Univ.Constraints. add (u, cst, v) accu in
1129
- List. fold_left fold accu repl
1130
- in
1131
- let fold_templ u0 (ur , repl ) accu =
1132
- (* This is needed to typecheck inner template applications of the inductive.
1133
- FIXME: when new-template-poly lands this can probably be removed. *)
1134
- let accu = Univ.Constraints. add (ur, Le , u0) accu in
1135
- let fold accu u = Univ.Constraints. add (u, Le , u0) accu in
1136
- List. fold_left fold accu repl
1131
+ | Some u0 -> match Int.Map. find_opt u0 umap with
1132
+ | None -> assert false (* unbound template level *)
1133
+ | Some (ur , repl ) ->
1134
+ let accu = Univ.Constraints. add (ur, cst, v) accu in
1135
+ let fold accu u = Univ.Constraints. add (u, cst, v) accu in
1136
+ List. fold_left fold accu repl
1137
1137
in
1138
- let (univs, cstrs) = temp.template_context in
1139
- let univs = Univ.Level.Set. fold fold_univs univs Univ.Level.Set. empty in
1138
+ let uctx = UVars.AbstractContext. repr temp.template_context in
1139
+ let univs = UVars.UContext. instance uctx in
1140
+ let qvars, univs = UVars.Instance. to_array univs in
1141
+ let cstrs = UVars.UContext. constraints uctx in
1142
+ let univs = Array. concat @@ Array. map_to_list map_univs univs in
1140
1143
let cstrs = Univ.Constraints. fold fold_cstrs cstrs Univ.Constraints. empty in
1141
- let cstrs = Univ.Level.Map. fold fold_templ umap cstrs in
1142
- umap, (univs, cstrs), decls
1144
+ let unames = Array. make (Array. length qvars) Anonymous , Array. make (Array. length univs) Anonymous in
1145
+ let uctx = UVars.UContext. make unames (UVars.Instance. of_array (qvars,univs), cstrs) in
1146
+ let default_univs =
1147
+ let qs, us = UVars.Instance. to_array temp.template_defaults in
1148
+ let us = Array. concat @@ Array. map_to_list (fun u -> Array. make (order+ 1 ) u) us in
1149
+ UVars.Instance. of_array (qs,us)
1150
+ in
1151
+ umap, temp.template_concl, (uctx, default_univs), decls
1143
1152
1144
1153
let rec translate_mind_body name order evdr env kn b inst =
1145
1154
(* XXX: What is going on here? This doesn't make sense after cumulativity *)
@@ -1174,8 +1183,8 @@ let rec translate_mind_body name order evdr env kn b inst =
1174
1183
let template_univs, mind_entry_params_R = match b.mind_template with
1175
1184
| None -> None , mind_entry_params_R
1176
1185
| Some temp ->
1177
- let umap, univs, params = fix_template_params order evdr env temp b mind_entry_params_R in
1178
- Some (umap, univs, temp.template_pseudo_sort_poly ), params
1186
+ let umap, concl, univs, params = fix_template_params order evdr env temp b mind_entry_params_R in
1187
+ Some (umap, concl, univs ), params
1179
1188
in
1180
1189
debug_string [`Inductive ] " translatation of inductive ..." ;
1181
1190
let mind_entry_inds_R =
@@ -1188,31 +1197,37 @@ let rec translate_mind_body name order evdr env kn b inst =
1188
1197
| Monomorphic ->
1189
1198
begin match template_univs with
1190
1199
| None -> Monomorphic_ind_entry
1191
- | Some (_ , ctx , pseudo_sort_poly ) -> Template_ind_entry { univs = ctx; pseudo_sort_poly }
1200
+ | Some (_ , _ , ( uctx , default_univs )) -> Template_ind_entry { uctx; default_univs }
1192
1201
end
1193
1202
| Polymorphic _ ->
1194
1203
let uctx, _ = (Evd. univ_entry ~poly: true ! evdr) in
1195
1204
match uctx with Polymorphic_entry uctx -> Polymorphic_ind_entry uctx | _ -> assert false
1196
1205
in
1197
1206
let mind_entry_inds_R = match template_univs with
1198
1207
| None -> mind_entry_inds_R
1199
- | Some (umap , _ , _ ) ->
1208
+ | Some (umap , concl , _ ) ->
1200
1209
let entry = match mind_entry_inds_R with
1201
1210
| [entry] -> entry
1202
1211
| _ -> assert false
1203
1212
in
1204
- let decls, sort = Term. decompose_prod_decls entry.mind_entry_arity in
1205
- let sort = match Constr. kind sort with
1206
- | Sort (Type u ) ->
1213
+ let decls, _ = Term. decompose_prod_decls entry.mind_entry_arity in
1214
+ let map_univ u =
1207
1215
let u = Univ.Universe. repr u in
1208
- let map (u0 , n ) = match Univ.Level.Map. find_opt u0 umap with
1216
+ let map (u0 , n ) =
1217
+ match Option. bind (Univ.Level. var_index u0) (fun u0 ->
1218
+ Some (Int.Map. get u0 umap))
1219
+ with
1209
1220
| None -> [u0, n]
1210
1221
| Some (ur , repl ) -> (ur, n) :: List. map (fun u -> u, n) repl
1211
1222
in
1212
- Constr. mkType (Univ.Universe. unrepr (List. map_append map u))
1213
- | _ -> sort
1223
+ Univ.Universe. unrepr (List. map_append map u)
1224
+ in
1225
+ let sort = match concl with
1226
+ | (Type u ) -> Sorts. sort_of_univ (map_univ u)
1227
+ | QSort (q ,u ) -> Sorts. qsort q (map_univ u)
1228
+ | SProp | Prop | Set -> concl
1214
1229
in
1215
- let arity = Term. it_mkProd_or_LetIn sort decls in
1230
+ let arity = Term. it_mkProd_or_LetIn ( Constr. mkSort sort) decls in
1216
1231
let entry = { entry with mind_entry_arity = arity } in
1217
1232
[entry]
1218
1233
in
0 commit comments