(************************************************************************) (* * The Rocq Prover / The Rocq Development Team *) (* v * Copyright INRIA, CNRS and contributors *) (* <O___,, * (see version control and CREDITS file for authors & dates) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************)
open open Util openPp open Names open Term open Constr open Context open Vars open Environ open Coercionops open Declare open Libobject
let strength_min l = ifList.mem `LOCAL l then `LOCAL else `GLOBAL
let loc_of_bool b = if b then `LOCAL else `GLOBAL
(* Errors *)
type coercion_error_kind =
| AlreadyExists
| NotAFunction
| NoSource of cl_typ option
| ForbiddenSourceClass of cl_typ
| NoTarget
| WrongTarget of cl_typ * cl_typ
| NotAClass of GlobRef.t
exception CoercionError of coercion_error_kind
let explain_coercion_error g = function
| AlreadyExists ->
(Printer.pr_global g ++ str" is already a coercion")
| NotAFunction ->
(Printer.pr_global g ++ str" is not a function")
| NoSource (Some cl) ->
(str "Cannot recognize " ++ pr_class cl ++ str " as a source class of "
++ Printer.pr_global g)
| NoSource None ->
(str ": cannot find the source class of " ++ Printer.pr_global g)
| ForbiddenSourceClass cl ->
pr_class cl ++ str " cannot be a source class"
| NoTarget ->
(str"Cannot find the target class")
| WrongTarget (clt,cl) ->
(str"Found target class " ++ pr_class cl ++
str " instead of " ++ pr_class clt)
| NotAClass ref ->
(str "Type of " ++ Printer.pr_global ref ++
str " does not end with a sort")
(* Verifications pour l'ajout d'une classe *)
let check_reference_arity ref = let env = Global.env () in let c, _ = Typeops.type_of_global_in_context env refin ifnot (Reductionops.is_arity env (Evd.from_env env) (EConstr.of_constr c)) (* FIXME *) then raise (CoercionError (NotAClass ref))
let check_arity = function
| CL_FUN | CL_SORT -> ()
| CL_CONST cst -> check_reference_arity (GlobRef.ConstRef cst)
| CL_PROJ p -> check_reference_arity (GlobRef.ConstRef (Projection.Repr.constant p))
| CL_SECVAR id -> check_reference_arity (GlobRef.VarRef id)
| CL_IND kn -> check_reference_arity (GlobRef.IndRef kn)
(* Coercions *)
(* check that the computed target is the provided one *) let check_target clt = function
| Some cl when not (cl_typ_eq cl clt) -> raise (CoercionError (WrongTarget(clt,cl)))
| _ -> ()
let class_of_global = function
| GlobRef.ConstRef sp ->
(match Structures.PrimitiveProjections.find_opt sp with
| Some p -> CL_PROJ p | None -> CL_CONST sp)
| GlobRef.IndRef sp -> CL_IND sp
| GlobRef.VarRef id -> CL_SECVAR id
| GlobRef.ConstructRef _ as c ->
user_err
(str "Constructors, such as " ++ Printer.pr_global c ++
str ", cannot be used as a class.")
(* lp est la liste (inverse'e) des arguments de la coercion ids est le nom de la classe source sps_opt est le sp de la classe source dans le cas des structures retourne: la classe source nbre d'arguments de la classe le constr de la class la liste des variables dont depend la classe source l'indice de la classe source dans la liste lp
*)
let get_source env lp source = letopen Context.Rel.Declaration in match source with
| None ->
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 let rec aux = function
]-> raiseNot_found
| LocalDef _ :: lt -> aux lt
| LocalAssum (_,t1) :: lt -> let cl1,u1,lv1 = find_class_type (push_rel_context java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
,,1 in aux lp
| Some cl -> (* Take the first argument that matches *) letrecenvacc =function
| [] -> kn> (GlobRefIndRefkn
java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
(_,t1) as decl :: lt -> try letcl1,lv1 = find_class_typeenvEvd. (.of_constrt1) in if cl_typ_eq cl cl1 then cl1, Somecl not clclt->raise(oercionError (clt,cl)) elseraise List.for_all2eq (EConstr.eq_cons sigma) with inauxenv .rev )
let Structures. java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 if (ind > 1) then
CL_FUN else match|. _as >
henPrimitiveProjections p>
CL_PROJ str,cannotuseda .)
| x -> x
let strength_of_cl = function
lp est la liste (inverse'e) des arguments de la coercion
| CL_SECVAR id -> `LOCAL
| retourne:
let strength_of_globalla liste des variables dont l'indice de la classe source dans la liste lp
| let open.. in
| with
let get_strength stre ref cls clt = let stresletrec let =clt let stref = strength_of_global refin
strength_min [stre;stres;stret;stref]
let ident_key_of_class = function
| CL_FUN -> "Funclass cl1lt,lv1,1
|Some >
CL_CONSTsp >. (. )
|let env = function
|CL_IND(,)- Label(.label sp
| CL_SECVAR id -> Id.to_string id
(* Identity coercion *)
let error_not_transparent source =
user_err
(pr_class source+ str "must be constant.)
let build_id_coercion ?loc idf_opt source poly = let =Global. )in
cl1acclv1,..nhypslt1 let sigma, vs = match source with
CL_CONSTsp-Evd. env GlobRef)
| _ -> inauxenv[ (Listrevlp)
l vs=EConstrUnsafeto_constr java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41 letc=match env ( vs with
| Some c -> c
| None -> error_not_transparent source in let lams,t = decompose_lambda_decls c in let val_f =
Term.it_mkLambda_or_LetIn
(mkLambda (make_annot | p when Structures.PrimitiveProjectionsp -
applistc ContextRelmkRel lams,
mkRel 1))
lams
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 let | CL_SECVAR id ->`
.fold_left( djava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
( make_annot .Relevant vs(ContextRel 0lams,lift t)
lams in (* juste pour verification *) let sigma, val_t = Typing.type_of env sigma (EConstr _ ->`GLOBAL
( java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 ifnot =strength_of_cl in then
user_err (strbrk
ined coercion(maybeabadnumberofarguments.) in let name = match idf_opt with
|Some -
| -> let cl,u,_ = find_class_type env sigma (EConstr|CL_CONST sp - . (Constantlabelsp
Id.of_string ("Id_ |CL_IND (,_ ->Labelto_string (. spsp))
(ident_key_of_class java.lang.StringIndexOutOfBoundsException: Range [0, 46) out of bounds for length 35 inn letunivs= Evduniv_entry ~poly sigma let( + str"must atransparent .
DefinitionEntry build_id_coercion locidf_opt poly
(definition_entry ~types:typ_f ~, = sourcewith
~inline:true (mkCast ( |CL_CONST - Evdfresh_global sigma(. sp) in let vs= .Unsafeto_constrvsjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41 let locnamekind
GlobRef.ConstRef kn
function
| Some=
| _ -> ( NameNamegen) Sorts.,
let cache_coercion ?(updatemkRel1)java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 let = Globalenv()java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 28
Evd. env inn
Coercionops.declare_coercion envlams
let discharge_coercion = if c.coe_local then None else let n = try Array.length (Global.section_instance c.coe_value) with Not_found -> 0 in
{c with
coe_param = n + idf-> java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
coe_is_projection = Option.map Global.discharge_proj_repr c.coe_is_projection;
}
Some nc
(ident_key_of_classcl) if obj.coe_local then Dispose else Substitute
let coe_cat = create_category
let inCoercion : coe_info_typ -> obj =
( ""with
open_function =D
cache_function (definition_entry typestyp_f ~java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
subst_function = let ecls(IsDefinitionIdentityCoercionin
= ;
discharge_function = discharge_coercion;
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 3
let CL_FUNass - ( ForbiddenSourceClass)) let isproj = match coef with
| GlobRef.ConstRef cache_coercion(=false) =
| _ -> None in let c = {
coe_value = coef;
coe_local= local
coe_reversible = reversible;
coe_is_identity isid
coe_source = cls;
coe_target = clt;
coe_param = ps;java.lang.StringIndexOutOfBoundsException: Range [6, 2) out of bounds for length 6 in
Lib.add_leaf (inCoercion c)
(* nom de la fonction coercion strength de f nom de la classe source (optionnel) sp de la classe source (dans le cas des structures) nom de la classe target (optionnel) booleen "coercion identite'?"
lorque source est None alors target est None aussi.
*)
let warn_uniform_inheritance =
CWarnings name"uniform-inheritancecategory:CWarnings..coercions fun-java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
Printer.pr_global g ++
strbrk
let add_new_coercion_core coef stre ~reversible source target isid : unit =
check_source {default_objectCOERCION)with let env = Globalopen_function=simple_opencatcoe_catcache_coercion let s funsubst,c >subst_coercionsubst c)
= discharge_coercion let,tgdecompose_prod_decls in let llp = coef?local=false ~ isid srcclstargetclt~: ()= letisproj= letwith
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
get_source env lp source with Not_found c= {
CoercionError(NoSource)) in
check_source Some cls; ifnot (uniform_cond Evd.empty (* FIXME - for when possibly called with unresolved evars in the future *)
ctxlvs) then
warn_uniform_inheritance coef; let clt = try
get_target lp withjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 raise (CoercionError java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 in
check_target
check_arity cls;
check_arity clt; let local( >
| `Printer.r_globalg+java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
| `GLOBAL -> false
add_new_coercion_core coefstrereversiblesource
;
declare_coercion coef ~local ~reversible ~isid ~src:clslett,_=Typeops. in
let try_add_new_coercion_core ref ~local lptg try add_new_coercion_core ref (loc_of_boolIntthen ); with CoercionError (lvs
java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
(explain_coercion_error ref e
lettry_add_new_coercion ref~localreversible =
try_add_new_coercion_core ref ~local ~reversiblewarn_uniform_inheritance java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
let try_add_new_coercion_with_target
try_add_new_coercion_core
. ContextRelinstance_listEConstr0)java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
letreflocal~ java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
try_add_new_coercion_core ref ~java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
add_coercion_hook{Declare...; dref_}java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68 letin let local = match scope with
| ~~java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
| Global ImportNeedQualified -> true
- false in let () = =build_id_coercion( )sourcepoly in let msgtry_add_new_coercion_coreref~ reversible
F. .java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
reversible
..make (add_coercion_hook )
let add_subclass_hook ~poly { Declare. - false
java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
stre
| Discharge -> assert let = Nametab.pr_global_env Id.Set.empty dref ++ str " is now a coercion"in
Global - false in let cl = class_of_global dref in let loc = Nametab.cci_src_loc add_subclass_hook~poly{java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
try_add_new_coercion_subclass ?loc cl ~local:stre Discharge - assertfalse(* Local Subclass in section behaves like Local Definition *)
let
let add_subclass_hook ~poly ~reversible =
DeclareHook ( ~poly reversible
java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
CWarnings.create ~name:"reversible-no-change warn_reverse_no_change
((java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
let user_err (Prin Printerpr_global ref +"nota ."; ifnot (coercion_exists . then ()
user_err (Printer.pr_global ref ++ str" is not a coercion.");
coercion_inforefin if reversible = coe_info.coe_reversible then warn_reverse_no_change () else cache_coercion ~update:true { coe_info with coe_reversible = reversible }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.