1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(* $Id: term_typing.ml 11309 2008-08-06 10:30:35Z herbelin $ *)
25
let constrain_type env j cst1 = function
27
make_polymorphic_if_constant_for_ind env j, cst1
29
let (tj,cst2) = infer_type env t in
30
let (_,cst3) = judge_of_cast env j DEFAULTcast tj in
31
assert (t = tj.utj_val);
32
NonPolymorphicType t, Constraint.union (Constraint.union cst1 cst2) cst3
34
let local_constrain_type env j cst1 = function
38
let (tj,cst2) = infer_type env t in
39
let (_,cst3) = judge_of_cast env j DEFAULTcast tj in
40
assert (t = tj.utj_val);
41
t, Constraint.union (Constraint.union cst1 cst2) cst3
43
let translate_local_def env (b,topt) =
44
let (j,cst) = infer env b in
45
let (typ,cst) = local_constrain_type env j cst topt in
48
let translate_local_assum env t =
49
let (j,cst) = infer env t in
50
let t = Typeops.assumption_of_judgment env j in
55
(* Same as push_named, but check that the variable is not already
56
there. Should *not* be done in Environ because tactics add temporary
57
hypothesis many many times, and the check performed here would
59
let safe_push_named (id,_,_ as d) env =
62
let _ = lookup_named id env in
63
error ("Identifier "^string_of_id id^" already defined.")
64
with Not_found -> () in
67
let push_named_def = push_rel_or_named_def safe_push_named
68
let push_rel_def = push_rel_or_named_def push_rel
70
let push_rel_or_named_assum push (id,t) env =
71
let (j,cst) = safe_infer env t in
72
let t = Typeops.assumption_of_judgment env j in
73
let env' = add_constraints cst env in
74
let env'' = push (id,None,t) env' in
77
let push_named_assum = push_rel_or_named_assum push_named
78
let push_rel_assum d env = snd (push_rel_or_named_assum push_rel d env)
80
let push_rels_with_univ vars env =
81
List.fold_left (fun env nvar -> push_rel_assum nvar env) env vars
85
(* Insertion of constants and parameters in environment. *)
87
let infer_declaration env dcl =
89
| DefinitionEntry c ->
90
let (j,cst) = infer env c.const_entry_body in
91
let (typ,cst) = constrain_type env j cst c.const_entry_type in
92
Some (Declarations.from_val j.uj_val), typ, cst,
93
c.const_entry_opaque, c.const_entry_boxed, false
94
| ParameterEntry (t,nl) ->
95
let (j,cst) = infer env t in
96
None, NonPolymorphicType (Typeops.assumption_of_judgment env j), cst,
99
let global_vars_set_constant_type env = function
100
| NonPolymorphicType t -> global_vars_set env t
101
| PolymorphicArity (ctx,_) ->
102
Sign.fold_rel_context
103
(fold_rel_declaration
104
(fun t c -> Idset.union (global_vars_set env t) c))
105
ctx ~init:Idset.empty
107
let build_constant_declaration env kn (body,typ,cst,op,boxed,inline) =
110
| None -> global_vars_set_constant_type env typ
113
(global_vars_set env (Declarations.force b))
114
(global_vars_set_constant_type env typ)
116
let tps = Cemitcodes.from_val (compile_constant_body env body op boxed) in
117
let hyps = keep_hyps env ids in
121
const_body_code = tps;
122
(* const_type_code = to_patch env typ;*)
123
const_constraints = cst;
125
const_inline = inline}
127
(*s Global and local constant declaration. *)
129
let translate_constant env kn ce =
130
build_constant_declaration env kn (infer_declaration env ce)
132
let translate_recipe env kn r =
133
build_constant_declaration env kn (Cooking.cook_constant env r)
135
(* Insertion of inductive types. *)
137
let translate_mind env mie = check_inductive env mie