aboutsummaryrefslogtreecommitdiffhomepage
path: root/pretyping/pretyping.ml
diff options
context:
space:
mode:
authorGravatar Maxime Dénès <mail@maximedenes.fr>2017-04-11 14:53:55 +0200
committerGravatar Maxime Dénès <mail@maximedenes.fr>2017-04-11 14:53:55 +0200
commitb5155a6690c9c768182cbedac9d6f61d11df2965 (patch)
treea56db5eec3627dbadf6ccd8417dc592e1458c4a8 /pretyping/pretyping.ml
parent97f1d0b6ddfce894941d34fc3b3e4c4df0efadd2 (diff)
parent49890d56dce567b029f57731c6586a6749cccb52 (diff)
Merge PR#543: Sanitize instance interpretation
Diffstat (limited to 'pretyping/pretyping.ml')
-rw-r--r--pretyping/pretyping.ml42
1 files changed, 23 insertions, 19 deletions
diff --git a/pretyping/pretyping.ml b/pretyping/pretyping.ml
index a042b73c2..ae87cd8c0 100644
--- a/pretyping/pretyping.ml
+++ b/pretyping/pretyping.ml
@@ -229,7 +229,7 @@ let interp_universe ?loc evd = function
(evd', Univ.sup u (Univ.Universe.make l)))
(evd, Univ.Universe.type0m) l
-let interp_universe_level loc evd = function
+let interp_level_info loc evd : Misctypes.level_info -> _ = function
| None -> new_univ_level_variable ~loc univ_rigid evd
| Some (loc,s) -> interp_universe_level_name evd (loc,s)
@@ -489,11 +489,28 @@ let pretype_id pretype k0 loc env evdref lvar id =
(*************************************************************************)
(* Main pretyping function *)
-let interp_universe_level_name loc evd l =
- match l with
+let interp_glob_level loc evd : Misctypes.glob_level -> _ = function
| GProp -> evd, Univ.Level.prop
| GSet -> evd, Univ.Level.set
- | GType s -> interp_universe_level loc evd s
+ | GType s -> interp_level_info loc evd s
+
+let interp_instance loc evd ~len l =
+ if len != List.length l then
+ user_err ~loc ~hdr:"pretype"
+ (str "Universe instance should have length " ++ int len)
+ else
+ let evd, l' =
+ List.fold_left
+ (fun (evd, univs) l ->
+ let evd, l = interp_glob_level loc evd l in
+ (evd, l :: univs)) (evd, [])
+ l
+ in
+ if List.exists (fun l -> Univ.Level.is_prop l) l' then
+ user_err ~loc ~hdr:"pretype"
+ (str "Universe instances cannot contain Prop, polymorphic" ++
+ str " universe instances must be greater or equal to Set.");
+ evd, Some (Univ.Instance.of_array (Array.of_list (List.rev l')))
let pretype_global loc rigid env evd gr us =
let evd, instance =
@@ -501,21 +518,8 @@ let pretype_global loc rigid env evd gr us =
| None -> evd, None
| Some l ->
let _, ctx = Universes.unsafe_constr_of_global gr in
- let arr = Univ.Instance.to_array (Univ.UContext.instance ctx) in
- let len = Array.length arr in
- if len != List.length l then
- user_err ~loc ~hdr:"pretype"
- (str "Universe instance should have length " ++ int len)
- else
- let evd, l' = List.fold_left (fun (evd, univs) l ->
- let evd, l = interp_universe_level_name loc evd l in
- (evd, l :: univs)) (evd, []) l
- in
- if List.exists (fun l -> Univ.Level.is_prop l) l' then
- user_err ~loc ~hdr:"pretype"
- (str "Universe instances cannot contain Prop, polymorphic" ++
- str " universe instances must be greater or equal to Set.");
- evd, Some (Univ.Instance.of_array (Array.of_list (List.rev l')))
+ let len = Univ.UContext.size ctx in
+ interp_instance loc evd ~len l
in
let (sigma, c) = Evd.fresh_global ~loc ~rigid ?names:instance env.ExtraEnv.env evd gr in
(sigma, EConstr.of_constr c)