@@ -13,138 +13,8 @@ open Util
13
13
open Names
14
14
open Constr
15
15
open Context
16
- open Evd
17
-
18
- module API :
19
- sig
20
- module ESorts :
21
- sig
22
- type t
23
- val make : Sorts .t -> t
24
- val kind : Evd .evar_map -> t -> Sorts .t
25
- val unsafe_to_sorts : t -> Sorts .t
26
- end
27
- module EInstance :
28
- sig
29
- type t
30
- val make : Univ.Instance .t -> t
31
- val kind : Evd .evar_map -> t -> Univ.Instance .t
32
- val empty : t
33
- val is_empty : t -> bool
34
- val unsafe_to_instance : t -> Univ.Instance .t
35
- end
36
- type t
37
- val kind : Evd .evar_map -> t -> (t , t , ESorts .t , EInstance .t ) Constr .kind_of_term
38
- val kind_upto : Evd .evar_map -> constr -> (constr , types , Sorts .t , Univ.Instance .t ) Constr .kind_of_term
39
- val kind_of_type : Evd .evar_map -> t -> (t , t ) Term .kind_of_type
40
- val whd_evar : Evd .evar_map -> t -> t
41
- val of_kind : (t , t , ESorts .t , EInstance .t ) Constr .kind_of_term -> t
42
- val of_constr : Constr .t -> t
43
- val to_constr : ?abort_on_undefined_evars : bool -> evar_map -> t -> Constr .t
44
- val unsafe_to_constr : t -> Constr .t
45
- val unsafe_eq : (t , Constr .t ) eq
46
- val of_named_decl : (Constr .t , Constr .types ) Context.Named.Declaration .pt -> (t , t ) Context.Named.Declaration .pt
47
- val unsafe_to_named_decl : (t , t ) Context.Named.Declaration .pt -> (Constr .t , Constr .types ) Context.Named.Declaration .pt
48
- val unsafe_to_rel_decl : (t , t ) Context.Rel.Declaration .pt -> (Constr .t , Constr .types ) Context.Rel.Declaration .pt
49
- val of_rel_decl : (Constr .t , Constr .types ) Context.Rel.Declaration .pt -> (t , t ) Context.Rel.Declaration .pt
50
- val to_rel_decl : Evd .evar_map -> (t , t ) Context.Rel.Declaration .pt -> (Constr .t , Constr .types ) Context.Rel.Declaration .pt
51
- end =
52
- struct
53
-
54
- module ESorts =
55
- struct
56
- type t = Sorts .t
57
- let make s = s
58
- let kind sigma = function
59
- | Sorts. Type u -> Sorts. sort_of_univ (Evd. normalize_universe sigma u)
60
- | s -> s
61
- let unsafe_to_sorts s = s
62
- end
63
16
64
- module EInstance =
65
- struct
66
- type t = Univ.Instance .t
67
- let make i = i
68
- let kind sigma i =
69
- if Univ.Instance. is_empty i then i
70
- else Evd. normalize_universe_instance sigma i
71
- let empty = Univ.Instance. empty
72
- let is_empty = Univ.Instance. is_empty
73
- let unsafe_to_instance t = t
74
- end
75
-
76
- type t = Constr .t
77
-
78
- let safe_evar_value sigma ev =
79
- try Some (Evd. existential_value sigma ev)
80
- with NotInstantiatedEvar | Not_found -> None
81
-
82
- let rec whd_evar sigma c =
83
- match Constr. kind c with
84
- | Evar ev ->
85
- begin match safe_evar_value sigma ev with
86
- | Some c -> whd_evar sigma c
87
- | None -> c
88
- end
89
- | App (f , args ) when isEvar f ->
90
- (* * Enforce smart constructor invariant on applications *)
91
- let ev = destEvar f in
92
- begin match safe_evar_value sigma ev with
93
- | None -> c
94
- | Some f -> whd_evar sigma (mkApp (f, args))
95
- end
96
- | Cast (c0 , k , t ) when isEvar c0 ->
97
- (* * Enforce smart constructor invariant on casts. *)
98
- let ev = destEvar c0 in
99
- begin match safe_evar_value sigma ev with
100
- | None -> c
101
- | Some c -> whd_evar sigma (mkCast (c, k, t))
102
- end
103
- | _ -> c
104
-
105
- let kind sigma c = Constr. kind (whd_evar sigma c)
106
- let kind_upto = kind
107
- let kind_of_type sigma c = Term. kind_of_type (whd_evar sigma c)
108
- let of_kind = Constr. of_kind
109
- let of_constr c = c
110
- let unsafe_to_constr c = c
111
- let unsafe_eq = Refl
112
-
113
- let to_constr ?(abort_on_undefined_evars =true ) sigma c =
114
- let rec to_constr c = match Constr. kind c with
115
- | Evar ev ->
116
- begin match safe_evar_value sigma ev with
117
- | Some c -> to_constr c
118
- | None ->
119
- if abort_on_undefined_evars then
120
- anomaly ~label: " econstr" Pp. (str " grounding a non evar-free term" )
121
- else
122
- Constr. map (fun c -> to_constr c) c
123
- end
124
- | Sort (Sorts. Type u ) ->
125
- let u' = Evd. normalize_universe sigma u in
126
- if u' == u then c else mkSort (Sorts. sort_of_univ u')
127
- | Const (c' , u ) when not (Univ.Instance. is_empty u) ->
128
- let u' = Evd. normalize_universe_instance sigma u in
129
- if u' == u then c else mkConstU (c', u')
130
- | Ind (i , u ) when not (Univ.Instance. is_empty u) ->
131
- let u' = Evd. normalize_universe_instance sigma u in
132
- if u' == u then c else mkIndU (i, u')
133
- | Construct (co , u ) when not (Univ.Instance. is_empty u) ->
134
- let u' = Evd. normalize_universe_instance sigma u in
135
- if u' == u then c else mkConstructU (co, u')
136
- | _ -> Constr. map (fun c -> to_constr c) c
137
- in to_constr c
138
-
139
- let of_named_decl d = d
140
- let unsafe_to_named_decl d = d
141
- let of_rel_decl d = d
142
- let unsafe_to_rel_decl d = d
143
- let to_rel_decl sigma d = Context.Rel.Declaration. map_constr (to_constr sigma) d
144
-
145
- end
146
-
147
- include API
17
+ include Evd. MiniEConstr
148
18
149
19
type types = t
150
20
type constr = t
@@ -387,8 +257,7 @@ let decompose_prod_n_assum sigma n c =
387
257
in
388
258
prodec_rec Context.Rel. empty n c
389
259
390
- let existential_type sigma (evk , args ) =
391
- of_constr (existential_type sigma (evk, Array. map unsafe_to_constr args))
260
+ let existential_type = Evd. existential_type
392
261
393
262
let map sigma f c = match kind sigma c with
394
263
| (Rel _ | Meta _ | Var _ | Sort _ | Const _ | Ind _
@@ -749,7 +618,7 @@ let universes_of_constr env sigma c =
749
618
LSet. fold LSet. add (Universe. levels u) s
750
619
| Evar (k , args ) ->
751
620
let concl = Evd. evar_concl (Evd. find sigma k) in
752
- fold sigma aux (aux s (of_constr concl) ) c
621
+ fold sigma aux (aux s concl) c
753
622
| _ -> fold sigma aux s c
754
623
in aux LSet. empty c
755
624
@@ -907,6 +776,10 @@ let named_context e = cast_named_context (sym unsafe_eq) (named_context e)
907
776
let val_of_named_context e = val_of_named_context (cast_named_context unsafe_eq e)
908
777
let named_context_of_val e = cast_named_context (sym unsafe_eq) (named_context_of_val e)
909
778
779
+ let of_existential : Constr.existential -> existential =
780
+ let gen : type a b. (a,b) eq -> 'c * b array -> 'c * a array = fun Refl x -> x in
781
+ gen unsafe_eq
782
+
910
783
let lookup_rel i e = cast_rel_decl (sym unsafe_eq) (lookup_rel i e)
911
784
let lookup_named n e = cast_named_decl (sym unsafe_eq) (lookup_named n e)
912
785
let lookup_named_val n e = cast_named_decl (sym unsafe_eq) (lookup_named_val n e)
@@ -922,7 +795,7 @@ let map_rel_context_in_env f env sign =
922
795
923
796
let fresh_global ?loc ?rigid ?names env sigma reference =
924
797
let (evd,t) = Evd. fresh_global ?loc ?rigid ?names env sigma reference in
925
- evd, of_constr t
798
+ evd, t
926
799
927
800
let is_global sigma gr c =
928
801
Globnames. is_global gr (to_constr sigma c)
@@ -934,5 +807,10 @@ let to_instance = EInstance.unsafe_to_instance
934
807
let to_constr = unsafe_to_constr
935
808
let to_rel_decl = unsafe_to_rel_decl
936
809
let to_named_decl = unsafe_to_named_decl
810
+ let to_named_context =
811
+ let gen : type a b . (a , b ) eq -> (a ,a ) Context.Named. pt -> (b ,b ) Context.Named. pt
812
+ = fun Refl x -> x
813
+ in
814
+ gen unsafe_eq
937
815
let eq = unsafe_eq
938
816
end
0 commit comments