Debian Codegraph @

kernel/type_errors.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Names
12 open Constr
13 open Environ
14 open Univ
15 open UVars
16
17 (* Type errors. *)
18
19 type 'constr pfix_guard_error =
20 (* Fixpoints *)
21 | NotEnoughAbstractionInFixBody of int
22 | RecursionNotOnInductiveType of 'constr
23 | RecursionOnIllegalTerm of int * (env * 'constr) * (int list * int list) Lazy.t
24 | NotEnoughArgumentsForFixCall of int
25 | FixpointOnNonEliminable of Sorts.t * Sorts.t
26
27 type 'constr pcofix_guard_error =
28 (* CoFixpoints *)
29 | CodomainNotInductiveType of 'constr
30 | NestedRecursiveOccurrences
31 | UnguardedRecursiveCall of 'constr
32 | RecCallInTypeOfAbstraction of 'constr
33 | RecCallInNonRecArgOfConstructor of 'constr
34 | RecCallInTypeOfDef of 'constr
35 | RecCallInCaseFun of 'constr
36 | RecCallInCaseArg of 'constr
37 | RecCallInCasePred of 'constr
38 | NotGuardedForm of 'constr
39 | ReturnPredicateNotCoInductive of 'constr
40
41 type 'constr pguard_error =
42 | FixGuardError of 'constr pfix_guard_error
43 | CoFixGuardError of 'constr pcofix_guard_error
44
45 type fix_guard_error = constr pfix_guard_error
46 type cofix_guard_error = constr pcofix_guard_error
47 type guard_error = constr pguard_error
48
49 type ('constr, 'types) pcant_apply_bad_type =
50 (int * 'constr * 'constr) * ('constr, 'types) punsafe_judgment * ('constr, 'types) punsafe_judgment array
51
52 type ('constr, 'types, 'r) ptype_error =
53 | UnboundRel of int
54 | UnboundVar of variable
55 | NotAType of ('constr, 'types) punsafe_judgment
56 | BadAssumption of ('constr, 'types) punsafe_judgment
57 | ReferenceVariables of Id.t * GlobRef.t
58 | ElimArity of pinductive * 'constr * Sorts.t option
59 | CaseNotInductive of ('constr, 'types) punsafe_judgment
60 | CaseOnPrivateInd of inductive
61 | WrongCaseInfo of pinductive * case_info
62 | NumberBranches of ('constr, 'types) punsafe_judgment * int
63 | IllFormedCaseParams
64 | IllFormedBranch of 'constr * pconstructor * 'constr * 'constr
65 | BadProjType of ('constr, 'types) punsafe_judgment * Projection.t
66 | Generalization of (Name.t * 'types) * ('constr, 'types) punsafe_judgment
67 | ActualType of ('constr, 'types) punsafe_judgment * 'types
68 | IncorrectPrimitive of (CPrimitives.op_or_type,'types) punsafe_judgment * 'types
69 | CantApplyBadType of ('constr, 'types) pcant_apply_bad_type
70 | CantApplyNonFunctional of ('constr, 'types) punsafe_judgment * ('constr, 'types) punsafe_judgment array
71 | IllFormedRecBody of 'constr pguard_error * (Name.t, 'r) Context.pbinder_annot array * int * env * ('constr, 'types) punsafe_judgment array
72 | IllTypedRecBody of
73 int * (Name.t, 'r) Context.pbinder_annot array * ('constr, 'types) punsafe_judgment array * 'types array
74 | UnsatisfiedUnivConstraints of UnivConstraints.t
75 | UnsatisfiedPConstraints of PConstraints.t
76 | UndeclaredQualities of Sorts.QVar.Set.t
77 | UndeclaredUniverses of Level.Set.t
78 | NotAllowedSProp
79 | BadBinderRelevance of 'r * ('constr, 'types, 'r) Context.Rel.Declaration.pt
80 | BadCaseRelevance of 'r * 'constr
81 | BadInvert
82 | BadVariance of { lev : Level.t; expected : Variance.t; actual : Variance.t }
83 | UndeclaredUsedVariables of { declared_vars : Id.Set.t; inferred_vars : Id.Set.t }
84 | IllFormedConstant of Constant.t * KerName.t
85 | IllFormedInductive of MutInd.t * KerName.t
86
87 type type_error = (constr, types, Sorts.relevance) ptype_error
88
89 exception TypeError of env * type_error
90
91 type inductive_error =
92 | NonPos of constr * constr
93 | NotEnoughArgs of constr * constr
94 | NotConstructor of Id.t * constr * constr * int * int
95 | NonPar of constr * int * constr * constr
96 | SameNamesTypes of Id.t
97 | SameNamesConstructors of Id.t
98 | SameNamesOverlap of Id.t list
99 | NotAnArity of constr
100 | BadEntry
101 | LargeNonPropInductiveNotInType
102 | MissingUnivConstraints of (Sorts.t list * Sorts.t)
103
104 exception InductiveError of env * inductive_error
105
106 let error_unbound_rel env n =
107 raise (TypeError (env, UnboundRel n))
108
109 let error_unbound_var env v =
110 raise (TypeError (env, UnboundVar v))
111
112 let error_not_type env j =
113 raise (TypeError (env, NotAType j))
114
115 let error_assumption env j =
116 raise (TypeError (env, BadAssumption j))
117
118 let error_reference_variables env id c =
119 raise (TypeError (env, ReferenceVariables (id,c)))
120
121 let error_elim_arity env ind c okinds =
122 raise (TypeError (env, ElimArity (ind, c, okinds)))
123
124 let error_case_not_inductive env j =
125 raise (TypeError (env, CaseNotInductive j))
126
127 let error_case_on_private_ind env ind =
128 raise (TypeError (env, CaseOnPrivateInd ind))
129
130 let error_number_branches env cj expn =
131 raise (TypeError (env, NumberBranches (cj, expn)))
132
133 let error_ill_formed_branch env c i actty expty =
134 raise (TypeError (env, IllFormedBranch (c, i, actty, expty)))
135
136 let error_bad_proj_type env cj p =
137 raise (TypeError (env, BadProjType (cj, p)))
138
139 let error_generalization env nvar c =
140 raise (TypeError (env, Generalization (nvar,c)))
141
142 let error_actual_type env j expty =
143 raise (TypeError (env, ActualType (j,expty)))
144
145 let error_incorrect_primitive env p t =
146 raise (TypeError (env, IncorrectPrimitive (p, t)))
147
148 let error_cant_apply_not_functional env rator randl =
149 raise (TypeError (env, CantApplyNonFunctional (rator,randl)))
150
151 let error_cant_apply_bad_type env t rator randl =
152 raise (TypeError (env, CantApplyBadType (t,rator,randl)))
153
154 let error_ill_formed_rec_body env why lna i fixenv vdefj =
155 raise (TypeError (env, IllFormedRecBody (why,lna,i,fixenv,vdefj)))
156
157 let error_ill_typed_rec_body env i lna vdefj vargs =
158 raise (TypeError (env, IllTypedRecBody (i,lna,vdefj,vargs)))
159
160 let error_unsatisfied_univ_constraints env c =
161 raise (TypeError (env, UnsatisfiedUnivConstraints c))
162
163 let error_unsatisfied_poly_constraints env c =
164 raise (TypeError (env, UnsatisfiedPConstraints c))
165
166 let error_undeclared_qualities env l =
167 raise (TypeError (env, UndeclaredQualities l))
168
169 let error_undeclared_universes env l =
170 raise (TypeError (env, UndeclaredUniverses l))
171
172 let error_not_allowed_sprop env =
173 raise (TypeError (env, NotAllowedSProp))
174
175 let error_bad_binder_relevance env rlv decl =
176 raise (TypeError (env, BadBinderRelevance (rlv, decl)))
177
178 let error_bad_case_relevance env rlv case =
179 raise (TypeError (env, BadCaseRelevance (rlv, mkCase case)))
180
181 let error_bad_invert env =
182 raise (TypeError (env, BadInvert))
183
184 let error_bad_variance env ~lev ~expected ~actual =
185 raise (TypeError (env, BadVariance {lev;expected;actual}))
186
187 let error_undeclared_used_variables env ~declared_vars ~inferred_vars =
188 raise (TypeError (env, UndeclaredUsedVariables {declared_vars; inferred_vars}))
189
190 let error_ill_formed_constant env cst kn =
191 raise (TypeError (env, IllFormedConstant (cst, kn)))
192
193 let error_ill_formed_inductive env ind kn =
194 raise (TypeError (env, IllFormedInductive (ind, kn)))
195
196 let map_pfix_guard_error f = function
197 | NotEnoughAbstractionInFixBody _ | NotEnoughArgumentsForFixCall _ as e -> e
198 | RecursionNotOnInductiveType c -> RecursionNotOnInductiveType (f c)
199 | RecursionOnIllegalTerm (n, (env, c), l1_l2) -> RecursionOnIllegalTerm (n, (env, f c), l1_l2)
200 | FixpointOnNonEliminable (s, s') -> FixpointOnNonEliminable (s, s')
201
202 let map_pcofix_guard_error f = function
203 | CodomainNotInductiveType c -> CodomainNotInductiveType (f c)
204 | NestedRecursiveOccurrences -> NestedRecursiveOccurrences
205 | UnguardedRecursiveCall c -> UnguardedRecursiveCall (f c)
206 | RecCallInTypeOfAbstraction c -> RecCallInTypeOfAbstraction (f c)
207 | RecCallInNonRecArgOfConstructor c -> RecCallInNonRecArgOfConstructor (f c)
208 | RecCallInTypeOfDef c -> RecCallInTypeOfDef (f c)
209 | RecCallInCaseFun c -> RecCallInCaseFun (f c)
210 | RecCallInCaseArg c -> RecCallInCaseArg (f c)
211 | RecCallInCasePred c -> RecCallInCasePred (f c)
212 | NotGuardedForm c -> NotGuardedForm (f c)
213 | ReturnPredicateNotCoInductive c -> ReturnPredicateNotCoInductive (f c)
214
215 let map_pguard_error f = function
216 | FixGuardError e -> FixGuardError (map_pfix_guard_error f e)
217 | CoFixGuardError e -> CoFixGuardError (map_pcofix_guard_error f e)
218
219 let map_ptype_error fr f = function
220 | UnboundRel _ | UnboundVar _ | CaseOnPrivateInd _ | IllFormedCaseParams
221 | UndeclaredQualities _ | UndeclaredUniverses _ | NotAllowedSProp
222 | UnsatisfiedUnivConstraints _
223 | UnsatisfiedPConstraints _
224 | ReferenceVariables _ | BadInvert | BadVariance _ | UndeclaredUsedVariables _ | IllFormedConstant _ | IllFormedInductive _ as e -> e
225 | NotAType j -> NotAType (on_judgment f j)
226 | BadAssumption j -> BadAssumption (on_judgment f j)
227 | ElimArity (pi, c, ar) -> ElimArity (pi, f c, ar)
228 | CaseNotInductive j -> CaseNotInductive (on_judgment f j)
229 | WrongCaseInfo (pi, ci) -> WrongCaseInfo (pi, ci)
230 | NumberBranches (j, n) -> NumberBranches (on_judgment f j, n)
231 | IllFormedBranch (c, pc, t1, t2) -> IllFormedBranch (f c, pc, f t1, f t2)
232 | BadProjType (j, p) -> BadProjType (on_judgment f j, p)
233 | Generalization ((na, t), j) -> Generalization ((na, f t), on_judgment f j)
234 | ActualType (j, t) -> ActualType (on_judgment f j, f t)
235 | IncorrectPrimitive (p, t) -> IncorrectPrimitive ({p with uj_type=f p.uj_type}, f t)
236 | CantApplyBadType ((n, c1, c2), j, vj) ->
237 CantApplyBadType ((n, f c1, f c2), on_judgment f j, Array.map (on_judgment f) vj)
238 | CantApplyNonFunctional (j, jv) -> CantApplyNonFunctional (on_judgment f j, Array.map (on_judgment f) jv)
239 | IllFormedRecBody (ge, na, n, env, jv) ->
240 IllFormedRecBody (map_pguard_error f ge, Array.map (Context.map_annot_relevance_het fr) na, n, env, Array.map (on_judgment f) jv)
241 | IllTypedRecBody (n, na, jv, t) ->
242 IllTypedRecBody (n, Array.map (Context.map_annot_relevance_het fr) na, Array.map (on_judgment f) jv, Array.map f t)
243 | BadBinderRelevance (rlv, decl) -> BadBinderRelevance (fr rlv, Context.Rel.Declaration.map_constr_het fr f decl)
244 | BadCaseRelevance (rlv, case) -> BadCaseRelevance (fr rlv, f case)