| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
module CVars = Vars |
| 12 |
|
| 13 |
open Pp |
| 14 |
open CErrors |
| 15 |
open Util |
| 16 |
open Constr |
| 17 |
open Context |
| 18 |
open Inductiveops |
| 19 |
open Names |
| 20 |
open Reductionops |
| 21 |
open Environ |
| 22 |
open Termops |
| 23 |
open EConstr |
| 24 |
open Vars |
| 25 |
open Arguments_renaming |
| 26 |
open Context.Rel.Declaration |
| 27 |
|
| 28 |
module RelDecl = Context.Rel.Declaration |
| 29 |
module NamedDecl = Context.Named.Declaration |
| 30 |
|
| 31 |
type retype_error = |
| 32 |
| NotASort |
| 33 |
| NotAnArity |
| 34 |
| NotAType |
| 35 |
| BadRel |
| 36 |
| BadVariable of Id.t |
| 37 |
| BadEvar of Evar.t |
| 38 |
| BadMeta of int |
| 39 |
| BadRecursiveType |
| 40 |
| NonFunctionalConstruction |
| 41 |
|
| 42 |
let print_retype_error = function |
| 43 |
| NotASort -> str "Not a sort" |
| 44 |
| NotAnArity -> str "Not an arity" |
| 45 |
| NotAType -> str "Not a type" |
| 46 |
| BadRel -> str "Unbound local variable" |
| 47 |
| BadVariable id -> str "Variable " ++ Id.print id ++ str " unbound" |
| 48 |
| BadEvar e -> str "Unknown evar " ++ Evar.print e |
| 49 |
| BadMeta n -> str "Unknown meta " ++ int n |
| 50 |
| BadRecursiveType -> str "Bad recursive type" |
| 51 |
| NonFunctionalConstruction -> str "Non-functional construction" |
| 52 |
|
| 53 |
exception RetypeError of retype_error |
| 54 |
|
| 55 |
let retype_error re = raise (RetypeError re) |
| 56 |
|
| 57 |
let anomaly_on_error f x = |
| 58 |
try f x |
| 59 |
with RetypeError e -> anomaly ~label:"retyping" (print_retype_error e ++ str ".") |
| 60 |
|
| 61 |
let get_type_from_constraints env sigma t = |
| 62 |
if isEvar sigma (fst (decompose_app sigma t)) then |
| 63 |
match |
| 64 |
List.map_filter (fun (pbty,env,t1,t2) -> |
| 65 |
if is_fconv Conversion.CONV env sigma t t1 then Some t2 |
| 66 |
else if is_fconv Conversion.CONV env sigma t t2 then Some t1 |
| 67 |
else None) |
| 68 |
(snd (Evd.extract_all_conv_pbs sigma)) |
| 69 |
with |
| 70 |
| t::l -> t |
| 71 |
| _ -> raise Not_found |
| 72 |
else raise Not_found |
| 73 |
|
| 74 |
let sort_of_arity_with_constraints env sigma t = |
| 75 |
try Reductionops.sort_of_arity env sigma t |
| 76 |
with Reduction.NotArity -> |
| 77 |
try |
| 78 |
let t = get_type_from_constraints env sigma t in |
| 79 |
Reductionops.sort_of_arity env sigma t |
| 80 |
with Not_found | Reduction.NotArity -> retype_error NotAnArity |
| 81 |
|
| 82 |
let rec subst_type env sigma subs typ = function |
| 83 |
| [] -> substl subs typ |
| 84 |
| h::rest -> |
| 85 |
|
| 86 |
match EConstr.kind sigma typ with |
| 87 |
| Prod (_, _, c2) -> subst_type env sigma (h :: subs) c2 rest |
| 88 |
| _ -> |
| 89 |
let typ = substl subs typ in |
| 90 |
match EConstr.kind sigma (whd_all env sigma typ) with |
| 91 |
| Prod (_, _, c2) -> subst_type env sigma [h] c2 rest |
| 92 |
| _ -> retype_error NonFunctionalConstruction |
| 93 |
|
| 94 |
let subst_type env sigma typ args = subst_type env sigma [] typ args |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
let sort_of_atomic_type env sigma ft args = |
| 101 |
let rec concl_of_arity env n ar args = |
| 102 |
match EConstr.kind sigma (whd_all env sigma ar), args with |
| 103 |
| Prod (na, t, b), h::l -> |
| 104 |
concl_of_arity (push_rel (LocalDef (na, lift n h, t)) env) (n + 1) b l |
| 105 |
| Sort s, [] -> s |
| 106 |
| _ -> retype_error NotASort |
| 107 |
in concl_of_arity env 0 ft (Array.to_list args) |
| 108 |
|
| 109 |
let type_of_var env id = |
| 110 |
try NamedDecl.get_type (lookup_named id env) |
| 111 |
with Not_found -> retype_error (BadVariable id) |
| 112 |
|
| 113 |
let decomp_sort env sigma t = |
| 114 |
let t = whd_all env sigma t in |
| 115 |
match EConstr.kind sigma t with |
| 116 |
| Sort s -> s |
| 117 |
| _ -> |
| 118 |
let t = try get_type_from_constraints env sigma t |
| 119 |
with Not_found -> retype_error NotASort |
| 120 |
in |
| 121 |
match EConstr.kind sigma (whd_all env sigma t) with |
| 122 |
| Sort s -> s |
| 123 |
| _ -> retype_error NotASort |
| 124 |
|
| 125 |
let betazetaevar_applist sigma n c l = |
| 126 |
let rec stacklam n env t stack = |
| 127 |
if Int.equal n 0 then applist (substl env t, stack) else |
| 128 |
match EConstr.kind sigma t, stack with |
| 129 |
| Lambda(_,_,c), arg::stacktl -> stacklam (n-1) (arg::env) c stacktl |
| 130 |
| LetIn(_,b,_,c), _ -> stacklam (n-1) (substl env b::env) c stack |
| 131 |
| Evar _, _ -> applist (substl env t, stack) |
| 132 |
| _ -> anomaly (Pp.str "Not enough lambda/let's.") in |
| 133 |
stacklam n [] c l |
| 134 |
|
| 135 |
let type_of_constant env sigma (c,u) = |
| 136 |
let cb = lookup_constant env sigma c in |
| 137 |
let () = check_hyps_inclusion env sigma (GlobRef.ConstRef c) cb.const_hyps in |
| 138 |
let ty = CVars.subst_instance_constr (EConstr.Unsafe.to_instance u) cb.const_type in |
| 139 |
EConstr.of_constr (rename_type env ty (GlobRef.ConstRef c)) |
| 140 |
|
| 141 |
let safe_meta_type metas n = match metas with |
| 142 |
| None -> None |
| 143 |
| Some f -> f n |
| 144 |
|
| 145 |
exception SingletonInductiveBecomesProp of inductive |
| 146 |
|
| 147 |
let template_sort ~forbid_polyprop subst (s:Sorts.t) = |
| 148 |
let s' = Inductive.Template.template_subst_sort subst s in |
| 149 |
let () = match forbid_polyprop with |
| 150 |
| None -> () |
| 151 |
| Some indna -> |
| 152 |
if Sorts.is_prop s' && not (Sorts.is_prop s) then |
| 153 |
raise (SingletonInductiveBecomesProp indna) |
| 154 |
in |
| 155 |
ESorts.make s' |
| 156 |
|
| 157 |
let bind_template bind_sort s (qsubst,usubst) = |
| 158 |
let qbind, ubind = Inductive.Template.bind_kind bind_sort in |
| 159 |
let qsubst = match qbind with |
| 160 |
| None -> qsubst |
| 161 |
| Some qbind -> |
| 162 |
let sq = Sorts.quality s in |
| 163 |
Int.Map.update qbind (function |
| 164 |
| None -> Some sq |
| 165 |
| Some q0 -> Some (Inductive.Template.max_template_quality q0 sq)) |
| 166 |
qsubst |
| 167 |
in |
| 168 |
let usubst = match ubind with |
| 169 |
| None -> usubst |
| 170 |
| Some ubind -> |
| 171 |
let u = match s with |
| 172 |
| SProp | Prop | Set -> Univ.Universe.type0 |
| 173 |
| Type u | QSort (_,u) -> u |
| 174 |
in |
| 175 |
Int.Map.update ubind (function |
| 176 |
| None -> Some u |
| 177 |
| Some _ -> |
| 178 |
CErrors.anomaly Pp.(str "Retyping.bind_template found non linear template level.")) |
| 179 |
usubst |
| 180 |
in |
| 181 |
qsubst, usubst |
| 182 |
|
| 183 |
let rec finish_template ~forbid_polyprop usubst = let open TemplateArity in function |
| 184 |
| CtorType (_,typ) -> typ |
| 185 |
| IndType (_, ctx, s) -> |
| 186 |
let s = template_sort ~forbid_polyprop usubst s in |
| 187 |
mkArity (ctx,s) |
| 188 |
| DefParam (na,v,t,codom) -> |
| 189 |
let codom = finish_template ~forbid_polyprop usubst codom in |
| 190 |
mkLetIn (na,v,t,codom) |
| 191 |
| NonTemplateArg (na,dom,codom) -> |
| 192 |
let codom = finish_template ~forbid_polyprop usubst codom in |
| 193 |
mkProd (na,dom,codom) |
| 194 |
| TemplateArg (na,ctx,binder,codom) -> |
| 195 |
let usubst = bind_template binder.bind_sort binder.default usubst in |
| 196 |
let codom = finish_template ~forbid_polyprop usubst codom in |
| 197 |
mkProd (na, mkArity (ctx, ESorts.make binder.default), codom) |
| 198 |
|
| 199 |
let rec type_of_template_knowing_parameters ~forbid_polyprop arity_sort_of usubst typ args = |
| 200 |
let open TemplateArity in |
| 201 |
match args, typ with |
| 202 |
| [], _ |
| 203 |
| _, (CtorType _ | IndType _) -> |
| 204 |
finish_template ~forbid_polyprop usubst typ |
| 205 |
| _, DefParam (na, v, t, codom) -> |
| 206 |
let codom = type_of_template_knowing_parameters ~forbid_polyprop arity_sort_of usubst codom args in |
| 207 |
mkLetIn (na, v, t, codom) |
| 208 |
| _ :: args, NonTemplateArg (na, dom, codom) -> |
| 209 |
let codom = type_of_template_knowing_parameters ~forbid_polyprop arity_sort_of usubst codom args in |
| 210 |
mkProd (na, dom, codom) |
| 211 |
| arg :: args, TemplateArg (na, ctx, binder, codom) -> |
| 212 |
let s = arity_sort_of arg in |
| 213 |
let usubst = bind_template binder.bind_sort s usubst in |
| 214 |
let codom = type_of_template_knowing_parameters ~forbid_polyprop arity_sort_of usubst codom args in |
| 215 |
|
| 216 |
mkProd (na, mkArity (ctx, ESorts.make s), codom) |
| 217 |
|
| 218 |
let type_of_template_knowing_parameters ~forbid_polyprop arity_sort_of typ args = |
| 219 |
let empty_subst = Int.Map.empty, Int.Map.empty in |
| 220 |
type_of_template_knowing_parameters ~forbid_polyprop arity_sort_of empty_subst typ args |
| 221 |
|
| 222 |
let retype ?metas ?(polyprop=true) sigma = |
| 223 |
let rec type_of env cstr = |
| 224 |
match EConstr.kind sigma cstr with |
| 225 |
| Meta n -> |
| 226 |
begin match safe_meta_type metas n with |
| 227 |
| None -> retype_error (BadMeta n) |
| 228 |
| Some ty -> strip_outer_cast sigma ty |
| 229 |
end |
| 230 |
| Rel n -> |
| 231 |
let ty = try RelDecl.get_type (lookup_rel n env) |
| 232 |
with Not_found -> retype_error BadRel |
| 233 |
in |
| 234 |
lift n ty |
| 235 |
| Var id -> type_of_var env id |
| 236 |
| Const c -> type_of_constant env sigma c |
| 237 |
| Evar ev -> begin match Evd.existential_type_opt sigma ev with |
| 238 |
| Some t -> t |
| 239 |
| None -> retype_error (BadEvar (fst ev)) |
| 240 |
end |
| 241 |
| Ind ind -> Inductiveops.e_type_of_inductive env sigma ind |
| 242 |
| Construct c -> Inductiveops.e_type_of_constructor env sigma c |
| 243 |
| Case (ci,u,pms,p,iv,c,lf) -> |
| 244 |
let (_,(p,_),iv,c,lf) = EConstr.expand_case env sigma (ci,u,pms,p,iv,c,lf) in |
| 245 |
let Inductiveops.IndType(indf,realargs) = |
| 246 |
let t = type_of env c in |
| 247 |
try Inductiveops.find_rectype env sigma t |
| 248 |
with Not_found -> |
| 249 |
try |
| 250 |
let t = get_type_from_constraints env sigma t in |
| 251 |
Inductiveops.find_rectype env sigma t |
| 252 |
with Not_found -> retype_error BadRecursiveType |
| 253 |
in |
| 254 |
let n = inductive_nrealdecls env (fst (fst (dest_ind_family indf))) in |
| 255 |
let t = betazetaevar_applist sigma n p realargs in |
| 256 |
(match EConstr.kind sigma (whd_all env sigma (type_of env t)) with |
| 257 |
| Prod _ -> whd_beta env sigma (applist (t, [c])) |
| 258 |
| _ -> t) |
| 259 |
| Lambda (name,c1,c2) -> |
| 260 |
mkProd (name, c1, type_of (push_rel (LocalAssum (name,c1)) env) c2) |
| 261 |
| LetIn (name,b,c1,c2) -> |
| 262 |
subst1 b (type_of (push_rel (LocalDef (name,b,c1)) env) c2) |
| 263 |
| Fix ((_,i),(_,tys,_)) -> tys.(i) |
| 264 |
| CoFix (i,(_,tys,_)) -> tys.(i) |
| 265 |
| App(f,args) -> |
| 266 |
if Termops.is_template_polymorphic_ref env sigma f then |
| 267 |
substituted_type_of_global_reference_knowing_parameters env f args |
| 268 |
else |
| 269 |
strip_outer_cast sigma |
| 270 |
(subst_type env sigma (type_of env f) (Array.to_list args)) |
| 271 |
| Proj (p,_,c) -> |
| 272 |
let ty = type_of env c in |
| 273 |
(try Inductiveops.type_of_projection_knowing_arg env sigma p c ty |
| 274 |
with Invalid_argument _ -> retype_error BadRecursiveType) |
| 275 |
| Cast (c,_, t) -> t |
| 276 |
| Sort _ | Prod _ -> mkSort (sort_of env cstr) |
| 277 |
| Int _ -> EConstr.of_constr (Typeops.type_of_int env) |
| 278 |
| Float _ -> EConstr.of_constr (Typeops.type_of_float env) |
| 279 |
| String _ -> EConstr.of_constr (Typeops.type_of_string env) |
| 280 |
| Array(u, _, _, ty) -> |
| 281 |
let arr = EConstr.of_constr @@ Typeops.type_of_array env (EInstance.kind sigma u) in |
| 282 |
mkApp(arr, [|ty|]) |
| 283 |
|
| 284 |
and sort_of env t : ESorts.t = |
| 285 |
match EConstr.kind sigma t with |
| 286 |
| Cast (c,_, s) when isSort sigma s -> destSort sigma s |
| 287 |
| Sort s -> |
| 288 |
begin match ESorts.kind sigma s with |
| 289 |
| SProp | Prop | Set -> ESorts.type1 |
| 290 |
| Type u | QSort (_, u) -> ESorts.make (Sorts.sort_of_univ (Univ.Universe.super u)) |
| 291 |
end |
| 292 |
| Prod (name,t,c2) -> |
| 293 |
let dom = sort_of env t in |
| 294 |
let rang = sort_of (push_rel (LocalAssum (name,t)) env) c2 in |
| 295 |
ESorts.make (Typeops.sort_of_product env (ESorts.kind sigma dom) (ESorts.kind sigma rang)) |
| 296 |
| App(f,args) when Termops.is_template_polymorphic_ind env sigma f -> |
| 297 |
let t = type_of_global_reference_knowing_parameters env f args in |
| 298 |
sort_of_atomic_type env sigma t args |
| 299 |
| App(f,args) -> sort_of_atomic_type env sigma (type_of env f) args |
| 300 |
| Lambda _ | Fix _ | Construct _ -> retype_error NotAType |
| 301 |
| _ -> decomp_sort env sigma (type_of env t) |
| 302 |
|
| 303 |
and substituted_type_of_global_reference_knowing_parameters env c args = |
| 304 |
match EConstr.kind sigma c with |
| 305 |
| Ind (ind, u) -> |
| 306 |
let ty = type_of_global_reference_knowing_parameters env c args in |
| 307 |
strip_outer_cast sigma (subst_type env sigma ty (Array.to_list args)) |
| 308 |
| Construct ((ind, i as ctor), u) -> |
| 309 |
let mib, mip = Inductive.lookup_mind_specif env ind in |
| 310 |
let ty = |
| 311 |
if mib.mind_nparams <= Array.length args then |
| 312 |
|
| 313 |
EConstr.of_constr (rename_type env mip.mind_user_lc.(i - 1) (ConstructRef ctor)) |
| 314 |
else |
| 315 |
type_of_global_reference_knowing_parameters env c args |
| 316 |
in |
| 317 |
strip_outer_cast sigma (subst_type env sigma ty (Array.to_list args)) |
| 318 |
| _ -> assert false |
| 319 |
|
| 320 |
and type_of_global_reference_knowing_parameters env c args = |
| 321 |
let arity_sort_of arg = |
| 322 |
let t = type_of env arg in |
| 323 |
let s = sort_of_arity_with_constraints env sigma t in |
| 324 |
ESorts.kind sigma s |
| 325 |
in |
| 326 |
let rename_type typ gr = |
| 327 |
EConstr.of_constr @@ rename_type env (EConstr.Unsafe.to_constr typ) gr |
| 328 |
in |
| 329 |
match EConstr.kind sigma c with |
| 330 |
| Ind (ind, _) -> |
| 331 |
let typ = TemplateArity.get_template_arity env ind ~ctoropt:None in |
| 332 |
let forbid_polyprop = if polyprop then None |
| 333 |
else Some ind |
| 334 |
in |
| 335 |
let typ = type_of_template_knowing_parameters ~forbid_polyprop arity_sort_of typ (Array.to_list args) in |
| 336 |
rename_type typ (IndRef ind) |
| 337 |
| Construct ((ind,ctor as cstr), _) -> |
| 338 |
let typ = TemplateArity.get_template_arity env ind ~ctoropt:(Some ctor) in |
| 339 |
let typ = type_of_template_knowing_parameters ~forbid_polyprop:None arity_sort_of typ (Array.to_list args) in |
| 340 |
rename_type typ (ConstructRef cstr) |
| 341 |
| _ -> assert false |
| 342 |
|
| 343 |
in type_of, sort_of, type_of_global_reference_knowing_parameters |
| 344 |
|
| 345 |
let get_sort_quality_of ?(polyprop=true) env sigma t = |
| 346 |
let type_of,_,type_of_global_reference_knowing_parameters = retype ~polyprop sigma in |
| 347 |
let rec sort_quality_of env t = |
| 348 |
let open UnivGen in |
| 349 |
match EConstr.kind sigma t with |
| 350 |
| Cast (c,_, s) when isSort sigma s -> ESorts.quality_or_set sigma (destSort sigma s) |
| 351 |
| Sort _ -> QualityOrSet.qtype |
| 352 |
| Prod (name,t,c2) -> |
| 353 |
let s2 = sort_quality_of (push_rel (LocalAssum (name,t)) env) c2 in |
| 354 |
if not (is_impredicative_set env) && |
| 355 |
QualityOrSet.is_set s2 && QualityOrSet.is_type (sort_quality_of env t) |
| 356 |
then QualityOrSet.qtype else s2 |
| 357 |
| App(f,args) when Termops.is_template_polymorphic_ind env sigma f -> |
| 358 |
let t = type_of_global_reference_knowing_parameters env f args in |
| 359 |
ESorts.quality_or_set sigma (sort_of_atomic_type env sigma t args) |
| 360 |
| App(f,args) -> |
| 361 |
ESorts.quality_or_set sigma (sort_of_atomic_type env sigma (type_of env f) args) |
| 362 |
| Lambda _ | Fix _ | Construct _ -> retype_error NotAType |
| 363 |
| _ -> |
| 364 |
ESorts.quality_or_set sigma (decomp_sort env sigma (type_of env t)) |
| 365 |
in sort_quality_of env t |
| 366 |
|
| 367 |
let get_sort_of ?(polyprop=true) env sigma t = |
| 368 |
let _,f,_ = retype ~polyprop sigma in anomaly_on_error (f env) t |
| 369 |
let type_of_global_reference_knowing_parameters env sigma c args = |
| 370 |
let _,_,f = retype sigma in anomaly_on_error (f env c) args |
| 371 |
|
| 372 |
let get_type_of ?metas ?(polyprop=true) ?(lax=false) env sigma c = |
| 373 |
let f,_,_ = retype ?metas ~polyprop sigma in |
| 374 |
if lax then f env c else anomaly_on_error (f env) c |
| 375 |
|
| 376 |
let rec check_named env sigma c = |
| 377 |
match EConstr.kind sigma c with |
| 378 |
| Var id -> |
| 379 |
(try ignore (lookup_named id env) |
| 380 |
with Not_found -> retype_error (BadVariable id)) |
| 381 |
| Evar _ -> |
| 382 |
|
| 383 |
|
| 384 |
() |
| 385 |
| _ -> EConstr.iter sigma (check_named env sigma) c |
| 386 |
|
| 387 |
let reinterpret_get_type_of ~src env sigma c = |
| 388 |
try |
| 389 |
check_named env sigma c; |
| 390 |
get_type_of ~lax:true env sigma c |
| 391 |
with RetypeError e -> |
| 392 |
user_err |
| 393 |
(str "Cannot reinterpret " ++ Id.print src ++ str " bound to " ++ |
| 394 |
quote (Termops.Internal.print_constr_env env sigma c) ++ |
| 395 |
str " in the current environment" ++ spc() ++ |
| 396 |
surround (print_retype_error e)) |
| 397 |
|
| 398 |
|
| 399 |
let get_judgment_of env evc c = { uj_val = c; uj_type = get_type_of env evc c } |
| 400 |
|
| 401 |
let get_type_of_constr ?polyprop ?lax env ?(uctx=UState.from_env env) c = |
| 402 |
EConstr.Unsafe.to_constr (get_type_of ?polyprop ?lax env (Evd.from_ctx uctx) (EConstr.of_constr c)) |
| 403 |
|
| 404 |
|
| 405 |
let sorts_of_context env evc ctxt = |
| 406 |
let rec aux = function |
| 407 |
| [] -> env,[] |
| 408 |
| d :: ctxt -> |
| 409 |
let env,sorts = aux ctxt in |
| 410 |
let s = get_sort_of env evc (RelDecl.get_type d) in |
| 411 |
(push_rel d env,s::sorts) in |
| 412 |
snd (aux ctxt) |
| 413 |
|
| 414 |
let expand_projection env sigma pr c args = |
| 415 |
let ty = get_type_of ~lax:true env sigma c in |
| 416 |
let (i,u), ind_args = |
| 417 |
try Inductiveops.find_mrectype env sigma ty |
| 418 |
with Not_found -> retype_error BadRecursiveType |
| 419 |
in |
| 420 |
mkApp (mkConstU (Projection.constant pr,u), |
| 421 |
Array.of_list (ind_args @ (c :: args))) |
| 422 |
|
| 423 |
let relevance_of_constant env sigma (c, u) = |
| 424 |
let u = Unsafe.to_instance u in |
| 425 |
let decl = EConstr.lookup_constant env sigma c in |
| 426 |
ERelevance.make @@ UVars.subst_instance_relevance u decl.const_relevance |
| 427 |
|
| 428 |
let relevance_of_projection_repr env (p, u) = |
| 429 |
ERelevance.make @@ Relevanceops.relevance_of_projection_repr env (p, EConstr.Unsafe.to_instance u) |
| 430 |
|
| 431 |
let relevance_of_term env sigma c = |
| 432 |
if Environ.sprop_allowed env then |
| 433 |
let rec aux rels c = |
| 434 |
match kind sigma c with |
| 435 |
| Rel n -> |
| 436 |
let len = Range.length rels in |
| 437 |
if n <= len then Range.get rels (n - 1) |
| 438 |
else ERelevance.make @@ Relevanceops.relevance_of_rel env (n - len) |
| 439 |
| Var x -> ERelevance.make @@ Relevanceops.relevance_of_var env x |
| 440 |
| Sort _ -> ERelevance.relevant |
| 441 |
| Cast (c, _, _) -> aux rels c |
| 442 |
| Prod _ -> ERelevance.relevant |
| 443 |
| Lambda ({binder_relevance=r}, _, bdy) -> |
| 444 |
aux (Range.cons r rels) bdy |
| 445 |
| LetIn ({binder_relevance=r}, _, _, bdy) -> |
| 446 |
aux (Range.cons r rels) bdy |
| 447 |
| App (c, _) -> aux rels c |
| 448 |
| Const (c,u) -> |
| 449 |
relevance_of_constant env sigma (c, u) |
| 450 |
| Ind _ -> ERelevance.relevant |
| 451 |
| Construct (c,u) -> |
| 452 |
let u = Unsafe.to_instance u in |
| 453 |
ERelevance.make @@ Relevanceops.relevance_of_constructor env (c,u) |
| 454 |
| Case (_, _, _, (_, r), _, _, _) -> r |
| 455 |
| Fix ((_,i),(lna,_,_)) -> (lna.(i)).binder_relevance |
| 456 |
| CoFix (i,(lna,_,_)) -> (lna.(i)).binder_relevance |
| 457 |
| Proj (p, r, _) -> r |
| 458 |
| Evar (evk, _) -> |
| 459 |
let evi = Evd.find_undefined sigma evk in |
| 460 |
Evd.evar_relevance evi |
| 461 |
| Int _ | Float _ | String _ | Array _ -> ERelevance.relevant |
| 462 |
| Meta _ -> ERelevance.relevant |
| 463 |
in |
| 464 |
aux Range.empty c |
| 465 |
else ERelevance.relevant |
| 466 |
|
| 467 |
let is_term_irrelevant env sigma c = |
| 468 |
let r = relevance_of_term env sigma c in |
| 469 |
Evd.is_relevance_irrelevant sigma r |
| 470 |
|
| 471 |
let relevance_of_type env sigma t = |
| 472 |
let s = get_sort_of env sigma t in |
| 473 |
ESorts.relevance_of_sort s |
| 474 |
|
| 475 |
let relevance_of_sort = ESorts.relevance_of_sort |