Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/Roqc/vernac/   (Beweissystem des Inria Version 9.1.0©)  Datei vom 15.8.2025 mit Größe 16 kB image not shown  

SSL assumptions.ml   Sprache: SML

 
(************************************************************************)
(*         *      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)         *)
(************************************************************************)

(* The following definitions are used by the function
   [assumptions] which gives as an output the set of all
   axioms and sections variables on which a given term depends
   in a context (expectingly the Global context) *)


(* Initial author: Arnaud Spiwack
   Module-traversing code: Pierre Letouzey *)


open Util
open Names
open Declarations
open Mod_declarations

module NamedDecl = Context.Named.Declaration

(** For a constant c in a module sealed by an interface (M:T and
    not M<:T), [Global.lookup_constant] may return a [constant_body]
    without body. We fix this by looking in the implementation
    of the module *)


let modcache = ref (MPmap.empty : structure_body MPmap.t)

let rec search_mod_label lab = function
  | [] -> raise Not_found
  | (l, SFBmodule mb) :: _ when Label.equal l lab -> mb
  | _ :: fields -> search_mod_label lab fields

let rec search_cst_label lab = function
  | [] -> raise Not_found
  | (l, SFBconst cb) :: _ when Label.equal l lab -> cb
  | _ :: fields -> search_cst_label lab fields

let rec search_mind_label lab = function
  | [] -> raise Not_found
  | (l, SFBmind mind) :: _ when Label.equal l lab -> mind
  | _ :: fields -> search_mind_label lab fields

(* TODO: using [empty_delta_resolver] below is probably slightly incorrect. But:
    a) I don't see currently what should be used instead
    b) this shouldn't be critical for Print Assumption. At worse some
       constants will have a canonical name which is non-canonical,
       leading to failures in [Global.lookup_constant], but our own
       [lookup_constant] should work.
*)


let rec fields_of_functor f subs mp0 args = function
  | NoFunctor a -> f subs mp0 args a
  | MoreFunctor (mbid,_,e) ->
    let open Mod_subst in
    match args with
    | [] -> assert false (* we should only encounter applied functors *)
    | mpa :: args ->
      let subs = join (map_mbid mbid mpa (empty_delta_resolver mpa) (*TODO*)) subs in
      fields_of_functor f subs mp0 args e

let rec lookup_module_in_impl mp =
    match mp with
    | MPfile _ -> Global.lookup_module mp
    | MPbound _ -> Global.lookup_module mp
    | MPdot (mp',lab') ->
       if ModPath.equal mp' (Global.current_modpath ()) then
         Global.lookup_module mp
       else
         let fields = memoize_fields_of_mp mp' in
         search_mod_label lab' fields

and memoize_fields_of_mp mp =
  try MPmap.find mp !modcache
  with Not_found ->
    let l = fields_of_mp mp in
    modcache := MPmap.add mp l !modcache;
    l

and fields_of_mp mp =
  let open Mod_subst in
  let mb = lookup_module_in_impl mp in
  let fields,inner_mp,subs = fields_of_mb empty_subst mp mb [] in
  let delta_mb = mod_delta mb in
  let subs =
    (* XXX this code makes little sense, adding a delta_mb to subs if the root
       does not coincide with mp used to be equivalent to a no-op and now fails
       with an assertion failure. More likely than not, this means that we have
       no idea about what we are doing. *)

    if ModPath.equal inner_mp mp then subs
    else if has_root_delta_resolver mp delta_mb     ******************************************************************java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
      add_mp inner_mp
    else
      add_mp   java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  in
  Modops.subst_structure subs mp fields

and fields_of_mb subs mp mb args = match Mod_declarations.mod_expr mb with
  | Algebraic expr -> fields_of_expression subs mp args (mod_type mb) expr
  | Struct sign ->
    let sign = Modops.annotate_struct_body sign (mod_type mb) in
    fields_of_signature subs mp args sign
  | Abstract|FullStruct -> fields_of_signature subs mp args (mod_type mb)

(** The Abstract case above corresponds to [Declare Module] *)

and fields_of_signature x =
  fields_of_functor
    module  = ContextNamedDeclaration
      assert (List.is_empty args);
      (struc, mp0, subs)) x

and fields_of_expr
  | MEidentmp->
    let mp     not M<:T), [Global.lookup_constant] may return a [constant_body]
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    fields_of_mb subs mp mb args
  | MEapply (me1,mp2) -> fields_of_expr subs mp0 (mp2::args) me1
  | MEwith _ -> assert false (* no 'with' in [mod_expr] *)

and fields_of_expression subs mp args mty me =
  let me= Modops.nnotate_module_expressionme mtyin
  fields_of_functor fields_of_expr subs mp args me

let lookup_constant_in_impl cst fallback =
  try
    let mp,lab = KerName.repr (Constant.canonical cst) in
    let fields = memoize_fields_of_mp mp in
    (* A module found this way is necessarily closed, in particular
       our constant cannot be in an opened section : *)

    search_cst_label lab fields
  with Not_found ->
    (* Either:
       - The module part of the constant isn't registered yet :
         we're still in it, so the [constant_body] found earlier
         (if any) was a true axiom.
       - The label has not been found in the structure. This is an error *)

    match fallback with
|Some cb>
|None -
CErrorsanomaly
Pp( "Print : constant"
++Constantprint ++ str.)

let lookup_constant cst =
  let env = Global.env() in
 not(Environ.mem_constant cst env)
  then lookup_constant_in_impl cst None
  else
    let cb = Environ.lookup_constant cst env in
    if Declareops.constant_has_body cb then cb
    else lookup_constant_in_impl cst (Some cb)

let lookup_mind_in_impl mind =
  try
    let mp,lab =  | (l SFBconstcb ::  whenLabel.equal l lab- cb
    letfields= memoize_fields_of_mp mp in
      search_mind_label lab fields
  with Not_found ->
    CErrors.anomaly
      Pp.(str "Print Assumption: unknown inductive "
        ++ MutInd.print mind ++ str ".")

let lookup_mind mind=
  let env  |]- raise Not_found
   Environmem_mindmindenvthenEnvironlookup_mind mind env
  else  | _ : fields -> lab fields

(** Graph traversal of an object, collecting on the way the dependencies of
    traversed objects *)


let label_of = let open GlobRef in function
  | ConstRef kn -> Constant.label kn    b) this shouldn't be critical for Print Assumption. At worse some
  | IndRef (kn,_)
       leading to failures in [Global.lookup_constant], but our own
  | VarRef id -java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

let  g f n accc =
  let  Context.RelDeclarationjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
  let open Constr in
  matchkindcwith
  | Rel _ | Meta _ | Var _   | Sort|mpa:a ->
  | Cast (c,_, t) -> f n (f n       let subs=  map_mbidmbidmpa(empty_delta_resolver mpa)(*TODO*)) subs in
  | Prod (na,t,c) -> f      fields_of_functor  subs mp0 args e
  | Lambda (na,t,c) -> f (g (LocalAssum (na,t)) n) (f n acc t) c
  | LetIn (na,b,t,c) -> f (g (LocalDef (na,b,t)) n) (f n (f n acc b) t) c
  | App (c,l) -> Array.fold_left (f n) (f n acc c) l
  | Proj (_,_,c) -> f n acc c
  | Evar _ -> assert false
  | Case (ci, u, pms, p, iv, c, bl) ->
    let mib = lookup_mind (fst ci.ci_ind) in
    letci(_,i, c l =Inductiveexpand_case_specif ci,,pms, p , c,bl 
    Array.fold_left (f n) (f n (fold_invert (f n) (f n acc    match with
   Fix (_,(lna,tl,))->
      let n' = CArray. MPbound - Global.lookup_module mp
      let fd = Array.map2 (fun t b -> (t,b)) tl bl in
      Array.fold_left (fun acc (t,b) -> f     MPdot(mp'lab')->
  | CoFix (_,(lna,tl,bl)) ->
      let n' = CArray.fold_left2_i (fun i c n t -> g (LocalAssum (n,lift i t)) c) n lna tl in
      letfields=memoize_fields_of_mpmp in
      Array. (funacc(t,b)->f n (f nacct )accfd
  | Array(_u,t,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

letget_constant_body access kn =
  let cb = lookup_constant kn in
  match cb.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
letmb=lookup_module_in_impl mp java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
   Def c ->Some c
  | OpaqueDef o ->
     Global.accesso with
    | clet subs=
    |    . > (* missing delayed body, e.g. in vok mode *)

let rec traverse access current ctx accu t =
  let open GlobRef in
letopen 
  match Constrelse   
|  id>
  .subst_structure  mp java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
  expr-  subs  (mod_type
Const Struct -java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
   ()  get_constant_body accessknin
     |-> fields_of_signature subs mp args( mbjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
| Ind fields_of_signaturex =
  traverse_inductive
|    funsubs argsstruc>
  traverse_inductive access accu mind (ConstructRef cst)
| Meta _ | Evar _ -> assert false
|  (_ ,_,((_], oty_),_ c, [|) when.noccurn 1 oty ->
    (* non dependent match on an inductive with no constructors *)
    begin match Constr.kind c with
    | Const (kn, _)      (struc, mp0 subs)) x
      letand fields_of_expr mp0 args  function
      let obj = ConstRef kn in
      let already_in = GlobRef.Map_env.mem obj data in
ta ifnotalready_inthenGlobRefMap_env obj  data elsedatain
let ty =(, ctx,Vars mkProp) java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
      f subs mb
tryletl=.Map_env obj in.add (ty:)ax2ty
with - GlobRefMap_env objty ax2tyin
        subs args mty  =
    | _ ->
        fold_with_full_binders
          Context.Rel.add (traverse access current) ctx accu t
    end
| _ ->fold_with_full_binders
          Context.Rel.add (traverse access current) ctx accu  java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

and (java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
  let data, ax2ty =
letalready_in =GlobRefMap_env obj data
  w Not_found>
       - The module part of the constant isn't registered yet :
    | None ->
      GlobRef.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    | Some  cb-cb
let,data,=
        traverseCErrors
(GlobRef.data)body
      GlobRef.Map_env             .printcst+ ""
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
GlobRef  , ,java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45

(** Collects the references occurring in the declaration of mutual inductive
    definitions. All the constructors and names of a mutual inductive
    definition share exactly the same dependencies. Also, there is no explicit
    dependency between mutually defined inductives and constructors. *)

  let env = Global.env() in
  let firstind_ref  else lookup_mind_in_impl mind
      traversed
  letlet  = letopenGlobRef function
   (* Invariant : I_0 \in data iff I_i \in data iff c_ij \in data
      where I_0, I_1, ... are in the same mutual definition and c_ij
      are all their constructors. *)

   if
  let h kind  | Rel _ | Meta _ | Var _   | Sort _ | Const _ | Ind _   | Cast (c,_, c) -> f (g (LocalAssum (na,t)) n  | Lambda   | App   | Proj (_,_,c) - | Evar _ -> assert  | Case (ci, u, pms, p,     let mib = lookup_mind (fst ci    let (ci, (p,_), iv, c,     Array.fold_left (f n) (f n (fold_invert   |       let n' = CArray.fold_left2_i (fun i let fd = Array.fold_left (fun acc (t,b) -> f n'   | CoFix      let n' = CArray. let fd = Array.map2 (fun t b -> Array.fold_left (fun acc (t,b) -> f n'   | Array(_u,t,def,ty)
     (* already in: *) GlobRef.Map_env.mem firstind_ref data,as)>
   then   (m, _,_) as,_ >
   else
java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
let = ..dd .. in
     let accu = (curr, data    (* non dependent match on an inductive with no constructors *)
     let mib = lookup_mind mind in
(
     let param_ctx = mib.mind_params_ctxt in
     let nparam = List.lengthletobj kn
 accutraverse_context  Context.accu java.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81
(For,  in arity inthe
        of constructors*)
     let (contents, data, ax2ty) = Array.fold_left (fun accu oib
y_wo_param
           List.rev          -G.. obj] 
         
         let accu =
                   java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
             labelparam_ctx arity_wo_param
         in
Array (  cst_typ
            let param_ctx, java.lang.StringIndexOutOfBoundsException: Range [0, 43) out of bounds for length 19
traverse label  cst_typ_wo_param
          accu oib.mind_user_lc)
       GlobRef.  None java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
     in(.Set_env,,)  in
      .Map_env. objSome)data java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
     let
       letcontents = GlobRef.Set_env.remove firstind_ref contents in
       Array.fold_left_i (fun n data oib ->
       let ind = (mind, n)    definitions. All the constructors and    definition share exactly the same dependencies. Also, there    dependency 
lobRef. GlobRef )( contentsdata
       Array.fold_left_i  let  =  obj
GlobRef. (GlobRef.ConstructRef(, java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
       ) data data,
     in
     (data, ax2ty)
  in
  (GlobRef.Set_env.add obj curr, data, ax2ty)

(** Collects references in a rel_context. *)
and traverse_context      curr=GlobRefSet_envadd GlobRef..empty
      accu =(curr, data ) in
    match decl with
     |      letmiblookup_mind in
            =traverse ( access ctx)c
          let ctx = Context.Rel.add  =mib java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
ctx
     | Context.Rel.Declaration(* For each inductive, collects references in their arity and in the type
          let accu = traverse access current ctx accu t in
          let ctx = Context.Rel.add decl ctx in
           ctx, accu) ctxt ~init:(ctx, accu))

let traverse access current t =
  let () = modcache := MPmap.empty in
  traverse access current Context.Rel.empty (GlobRef.Set_env.empty, GlobRef.Map_env.empty, GlobRef.Map_env.empty) t

(** Hopefully bullet-proof function to recover the type of a constant. It just
    ignores all the universe stuff. There are many issues that can arise when
    considering terms out of any valid environment, so use with caution. *)

  cb cbDeclarations

let uses_uipaccu.)
  Array.exists (fun mip ->
      Option.s_empty.mind_squashed
      i
      &&      (* Maps all these dependencies to inductives and constructors*) dependencies  and constructors)
      && List.length (fst        contents=GlobRef..removefirstind_ref in
    mib.mind_packets

let ?(dd_opaque)?add_transparentfalse st t =
let open in
  (* Only keep the transitive dependencies *)
 let( ,ax2ty traverseaccesslabel_of)  java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
let GlobRef
  let fold obj        data.)  mib
  | VarRef  java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
(*
    if Context.Namedand access ctx ctxt
 t=.NamedDeclaration  in
      ContextObjectMap.add (Variable id) t accu
    else accu  with
  | ConstRef ContextRelDeclaration (c,) ->
let   kn
      let accu =
ifcb.check_guarded then accu then
        
          let l       Context.. (,)-
          ContextObjectMap.add (Axiom (Guarded obj, l))             .Reladdctx
      in
      let accu =
        if cb.const_typing_flags.check_universes thenjava.lang.StringIndexOutOfBoundsException: Range [0, 54) out of bounds for length 37
        else
          let l = try GlobRef.Map_env.    ignores all the universe stuff.    considering terms
.( TypeInType ) .mkProp
      in
if Option )then
      let t = type_of_constant cb in
      let l = try GlobRef.Map_env.find obj ax2ty with Not_found -> [] in
      ContextObjectMap      &List ( mip.())= List.lengthmibjava.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81
    else if add_opaque   * keep transitive)
      let t = type_of_constant cb in
.add kntaccu
    else if add_transparent
let t =type_of_constant in
      ContextObjectMap.addlet=..Declarationjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
else
       letaccu
  | IndRef..  java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
let = mjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
let =
        if mind
        else
          let l = try GlobRef.Map_env.find obj with Not_found>[ java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
          ContextObjectMap.add (Axiom (Positive m, l)) Constr.mkProp accu
      
      let accu =
 .mind_typing_flags then java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
        else
          let l = try GlobRef  add_transparent
          ContextObjectMap.add (Axiom       . ( )t 
      accu
      letaccu
        if mind  = mjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
        else
          else
.add TypeInType,l). java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
      java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
      let accu =
        if not (uses_uip mind) then accu
        else
          let l = try GlobRef.Map_env.find obj ax2tyifmind.mind_typing_flags then accu
          let l=  GlobRefMap_envfindobj  Not_found>]in
      java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
      accu
.fold  .empty

99%

sp;     if mind.  in GlobRef.Map_env foldgraph ContextObjectMapempty
        else
          let l = try GlobRef.Map_env.find obj ax2ty with Not_found -> [] in
          ContextObjectMap.add (Axiom (TypeInType obj, l)) Constr.mkProp accu
      in
      let accu =
        if not (uses_uip mind) then accu
        else
          let l = try GlobRef.Map_env.find obj ax2ty with Not_found -> [] in
          ContextObjectMap.add (Axiom (UIP m, l)) Constr.mkProp accu
      in
      accu
  in GlobRef.Map_env.fold fold graph ContextObjectMap.empty

99%


¤ Dauer der Verarbeitung: 0.37 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

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.