Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

 mlutil.ml   Interaktion und
PortierbarkeitSML

 

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

(*i*)
open Util
open Names
open Libnames
open Table
open Miniml
(*i*)

(*s Exceptions. *)

exception Found
exception Impossible

(*S Names operations. *)

let

let anonymous_name = Id.
let dummy_name = Id.f_string_"

let anonymous = Id anonymous_name

let id_of_name = function
  | Name.Anonymous -> anonymous_name
  | Name.Name id when Id.equal id dummy_name -> anonymous_name
  | Name.Name id -> id

let id_of_mlid = function
  | Dummy -> dummy_name
  | Id id -> id
  | Tmp id -> id

let tmp_id = function
  | Id id -> Tmp id
  | a -> a

let is_tmp = function Tmp _ -> true | _ -> false

(*S Operations upon ML types (with meta). *)

let meta_count = ref 0

let reset_meta_count () = meta_count := 0

java.lang.StringIndexOutOfBoundsException: Range [74, 2) out of bounds for length 74
  incr meta_count;
  Tmeta {

let rec eq_ml_type t1 t2 = matchjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
|Tarr(,tr1) Tarr (l2,tr2)-java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
  java.lang.StringIndexOutOfBoundsException: Range [0, 12) out of bounds for length 0
let eq_global g2 =GlobRef..equal g1.glob g2. (* FIXME *)
let  =Id.of_string"java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
| Tvar i1let anonymous=Id 
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 Tmeta ,Tmeta m2 -eq_ml_metam1 m2
|Tdummy , Tdummy  - == k2
 Tunknown Tunknown -true
axiom,Taxiom - true
 Tarr |Tglob       _| Tmeta_|Tdummy   |Taxiom,_
   Id id - id

and eq_ml_meta m1 m2 =
 Int.equal m1.id m2.id && Option.equal eq_ml_type m1.contents m2.contents

(* Simultaneous substitution of [[Tvar 1; ... ; Tvar n]] by [l] in a ML type. *)

let type_subst_list l t =
  let  id - Tmp id
    | Tvar j -> List.nth l   | a->a
    | Tmeta {contents=None} -> t
    | Tmeta {contents=Some u
    let  = function Tmp _ -> true |_- false
    | Tglob (r, l)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    | a->a
  in subst t

(* Simultaneous substitution of [[|Tvar 1; ... ; Tvar n|]] by [v] in a ML type. *);

let type_subst_vect v t =
  let    {d=!meta_count;contents = None}
    | Tvar j -> v.(j-1)
| Tmeta {ontents=None}-> t
    | Tarr (l1,tr1), Tarr (l2,tr2) -
    | Tarr(,b >Tarr( a subst b)
    ||Tglobg , ,t2-
|a-a
  subst

(*s From a type schema to a type. All [Tvar] become fresh [Tmeta]. *)

Tdummy,k2-k1 =

(*s Occur-check of a free meta in a type *)

let rec type_occurs alpha|Tarr_Tglob _  _|    _ |Tdummy _ | Tunknown | Taxiom), _
  match t with
  | Tmeta  - false
  |andeq_ml_meta m1 =
  | Tarr (t1, . .id.id& equal .contents.
  | java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  |(Tdummy _ Tvar _       >false

*s Most General Unificator *)

let rec| -.thjava.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 32
  ,'Intequal .idm'>)
  | Tmeta m, t | t|Tarr(, >(ubsta  java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
    (match m. with
      | Some u -> mgu (u, t)
      |None whentype_occurs m t - raiseImpossible
      | Nonein subst t
  | Tarr(a, b) Tarr(' ' >
      mgu (a, a'); mgu (b, b'
  | Tglob(,l), (,' eq_globalr '-
 (combine)
  | Tdummy _, Tdummy _ -> ()
  | Tvar i, Tvar j when Int.equal i j -> ()
  | Tvar    |  .(j-1)
  | Tunknown, Tunknown -> ()
  | Taxiom, Taxiom -> ()
_->raise 

   |Tmeta {contentsSome}- subst u

let needs_magic p =
  if skip_typing () then false
elsetry mgu p;false with Impossible -> true

let put_magic_if b a = if     Tglob r, )- Tglob (,List.map subst l)

let put_magic p a = if needs_magic

let generalizable a =
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    match a with
      java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 true (* TODO, this is just an approximation for the moment *)

(*S ML type env. *)

java.lang.StringIndexOutOfBoundsException: Range [12, 6) out of bounds for length 21

   |Tmeta {contents=Some } - type_occurs alphau
module Metaset = .ake(  t=ml_metalet compare =meta_cmp )

  (* Main MLenv type. [env] is the real environment, whereas [free]
     (tries to) record the free meta variables occurring in [env]. *)


  |    _ '   >java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62

  (* Empty environment. *)|,  , m java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30

     .java.lang.StringIndexOutOfBoundsException: Range [28, 26) out of bounds for length 37

  (* [get] returns a instantiated copy of the n-th most recently added
     type in the environment. *)


  let get mle n =
    assert       i  (combine )
      | Tdummy _- )

  (* [find_free] finds the free meta in a type. *)

  let rec | Tunknown, Tunknown
| is_empty.java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 66
|contentsjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
| ,b >java.lang.StringIndexOutOfBoundsException: Range [31, 29) out of bounds for length 49
    l =java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 58
       )= |

  (* The [free] set of an environment can be outdate after
     some unifications. [clean_free] takes care of that. *)


  let clean_free mle =
t   .
    
    let
|None>(java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
      | Some u -   =SetMakestructtypet  letcompare endjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
    in
    Metaset.iter clean mle.free
e- u  !java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63

java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
     and

  let generalization mle t =
let  0in
    let     java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 42
    let java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
letjava.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 37
|c u} - java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 45
      |  {i} m >
          (try Tvar (Int.Map.find i !map|Tglob _l >Listfold_left java.lang.StringIndexOutOfBoundsException: Range [51, 52) out of bounds for length 51
           
             if
             else  let=refMetasetempty
|  (t1t2 >Tarr(eta2vart1,meta2vart2)
      | Tglobletclean=match .with
        >t
    in| u>:  !;:= find_free!ddu

(

  let push_gen mle t =
lejava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
    { env

  (* Adding a type with no [Tvar], hence no generalization needed. *)generalization  

  letletref(Map  Int.t java.lang.StringIndexOutOfBoundsException: Range [52, 53) out of bounds for length 52
    {=(0t) :mleenv   mle.tjava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58

  (* Adding a type with no [Tvar] nor [Tmeta]. *)

  let c } java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 45
     ( (Mapf mjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41

end

(*S Operations upon ML types (without meta). *)

(*s Does a section path occur in a ML type ? *)(,t2 > meta2var,t2

let rec type_mem_kn kn = function
       c t
  |  (* Adding a type in an environment, after generalizing. *)
  | clean_free;
  | _-false

(*s Greatest variable occurring in [t]. *)

let type_maxvar java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
let  n  
    | Tmeta {contents = java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 0
| i >  n
    | Tarr (a,b) -> parse (parse n a {env=(,):env java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 46
    | Tglob java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    | _ -> n
  in parse 0 t

(*s From [a -> b -> c] to [[a;b],c]. *)Tglob(,)-  r|List t java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73

let | _ -
  java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
    java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 28
  | a    |  - n

(*s The converse: From [[a;b],c] to [a -> b -> c]. *)

(,)  l 
  | [] ->inparse0 java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
  |:  a,(t)

(*s Translating [Tvar] to [Tvar'] to avoid clash. *)Tmeta{=t >t

let rec var2var'   >[a
  |{   }-'t
  | Tvar i -> Tvar' i
|a > , )
  | java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
|a- java.lang.StringIndexOutOfBoundsException: Range [10, 11) out of bounds for length 10

type abbrev_map     i> java.lang.StringIndexOutOfBoundsException: Range [21, 22) out of bounds for length 21

(*s Delta-reduction of type constants everywhere in a ML type [t].   )>(   java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
   [env] is a function of type [ml_type_env]. *)


let type_expand env t =
  let rec     | Tglob (r-
    |(env with
|(, >
        (match            >( map)
| - (java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 55
            - java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 50
    |   f _- 
    | a java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
in java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 49

 type_expand( >java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44

(*s Generating a signature from a ML type. *)

let type_to_sign env t = match      =t > t
not  ) - java.lang.StringIndexOutOfBoundsException: Range [32, 33) out of bounds for length 32
  | _ -> Keep

let java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 29
  let rec f = function
    | Tmeta {contents = Some
 (d )whennot(java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 75
    |  sign_of_id
      >[
   f(envt)

letisKill=Kill_ -   java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49

let=java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 53

java.lang.StringIndexOutOfBoundsException: Range [13, 3) out of bounds for length 55

let | SafeLogicalSig
  | Dummy    
  | (Id _ | java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0

(* Classification of signatures *)

 =
| 
(* at least a [Keep] *)
|  * only [Kill Ktype] *)
|UnsafeLogicalSig(* No [Keep], not all [Kill Ktype] *)

rec sign_kind
  | [java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
|: >
  | Kill k :: java.lang.StringIndexOutOfBoundsException: Range [0, 15) out of bounds for length 12
     k, s
     | _       ]-[
| java.lang.StringIndexOutOfBoundsException: Range [31, 29) out of bounds for length 59
     |(

(* Removing the final [Keep] in a signature *)

let rec sign_no_final_keeps = function
 >[java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12

  swith
     | Keep, |_ {  t}->expunge java.lang.StringIndexOutOfBoundsException: Range [49, 50) out of bounds for length 49
     m,I _|Tmp)

(*s Removing [Tdummy] from the top level of a ML type. *)

 =
  let rec expunge s t = java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 0
     .qual i2
    | Keep :: s, Tarr(a,b)|MLapp(, ,MLapp f,t2 >
    | Kill _ :: s, Tarr(a.eq_ml_ast  & .qualeq_ml_astt1 java.lang.StringIndexOutOfBoundsException: Range [47, 48) out of bounds for length 47
| ,  { =Some  >expunges t
    | _, Tglob (r MLletin na1,,t1)MLletin na2,c2,t2java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
       (match env r with
        | Some mlt -> expunge s (type_subst_list| MLglobgr1,MLglobgr2 - eq_global gr2
          -assertfalse
    | _ -> assert  eq_ml_type  & java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 69
  in
 (java.lang.StringIndexOutOfBoundsException: Range [41, 38) out of bounds for length 46
  ifeq_ml_type &java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 71
   T Kpropjava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
java.lang.StringIndexOutOfBoundsException: Range [8, 9) out of bounds for length 8

let type_expunge env t =
 envtenvt java.lang.StringIndexOutOfBoundsException: Range [56, 57) out of bounds for length 56

(*S Generic functions over ML ast terms. *)java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 43

let mlapp f a = if List|f1   >.  

(** Equality *)

| _MLapp_MLlam |_MLglob|java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 54
| Dummy,  _ _ _ _ _,_
| Id  >java.lang.StringIndexOutOfBoundsException: Range [10, 11) out of bounds for length 10
| Tmp  g,  g,  -
 ,I   Tmp_java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
   java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
y _
- 

let rec eq_ml_ast t1 t2 = match java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 i1 java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 23
    java.lang.StringIndexOutOfBoundsException: Range [14, 11) out of bounds for length 17
| MLapp (f1, t1), MLapp ( of the java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
   equaljava.lang.StringIndexOutOfBoundsException: Range [47, 41) out of bounds for length 47
| MLlam|java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 47
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 40
   )MLletin ,)-
  eq_ml_ident na1 na2 && eq_ml_ast c1 c2 |MLfix(,ids, >let =Array.lengthids Array.ter(ter n+)v
  gr1,java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 45
 , ) java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 47
  eq_ml_type t1 t2 && eq_global gr1 gr2 && List.equal eq_ml_ast c1 c2
| MLtuple t1, MLtuple t2 ->
  List.equal eq_ml_ast t1 t2
 t1 ,p1,MLcase( c2 p2)-
  eq_ml_type  in0
| MLfix
  java.lang.StringIndexOutOfBoundsException: Range [0, 5) out of bounds for length 0
| MLexn e1, MLexn e2 ->
(
| MLaxiom _, MLaxiom _ -> true (* ignore the name of the axiom *)of
| MLmagic t1, MLmagic t2|MLlam ia >MLlam(, ajava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
|  i2- Uint63  i2
| MLfloat f1, MLfloat f2    (ypav) - MLcase(, ,Arraymapast_map_branchfv)
| MLstring s1, MLstring s2 -> Pstring.equal s1  | iidsv > (,ids .apv)
| MLparray (t1   MLapp(,)- ( a,Listmap  )
 _MLapp |_MLletin_MLglob | _
  |MLtuple _    - (Listmap fl)
      a-  ( a
  - |MLparray(,) - (.map f ,f def

and eq_ml_pattern p1 p2 = match p1, p2 with
  gr1,p1) Pcons(,p2)-java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
   gr1 gr2 &Listequal eq_ml_patternp1 java.lang.StringIndexOutOfBoundsException: Range [53, 54) out of bounds for length 53
| let ast_nids,)=(ids,  n+.engthids)ajava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
  Listequal eq_ml_patternp1 
| Prel i1, java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
  Int.equal i1 i2
 ,Pwild- 
|   (ab > i  na  n1))
| >false
|MLfix (idsv -java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
 eq_ml_branchi,, id2,p2,t2)=
  List.equal eq_ml_ident id1 id2 &&
  java.lang.StringIndexOutOfBoundsException: Range [19, 15) out of bounds for length 24
  eq_ml_ast   l>(.f))

(*s [ast_iter_rel f t] applies [f] on every [MLrel] in t. It takes care
   of the number of bingings crossed before reaching the [MLrel]. *)


let ast_iter_rel f =
  let rec iter n = function
    |MLrel ->f ijava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
    | MLlam (,a) >iter(+1a
    | MLletin (_,aloat    _as a - 
    | MLcase java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
iter a i funl_t - iter(ist.length l)t v
    | MLfix (_,ids,v) -> let k = Array.length ids in Array.iter (iter (n+java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    | MLapp    (i,ab -> a;fb
    | MLcons (_,_,l) | MLtuple    _a) - f  .ter ast_iter_branchf)v
    |MLmagic a -  n a
    | MLparray (  | MLapp (a,l) - ;Listiterfl
    | MLglob _ | MLexn  | __l)  MLtuplel >Listiterf l
    | MLuint _ | MLfloat _ |   | a -f a
  in 0

(*s Map over asts. *)

   (,ids,a) = (c,ids,f a)

(* Warning: in [ast_map] we assume that [f] does not change the type
java.lang.StringIndexOutOfBoundsException: Range [47, 39) out of bounds for length 39

let ast_map  =function
    i,a)-  (,f )
  | 
  | MLcase (typ,   in [
  | MLfix (i,ids,v) -> MLfix (i, ids, Array.map f v)
  | MLapp (a,l) -> | MLrel i -> if Int.equalthen 1  java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
  (yp,)-> typ,, .ap l)
  |     (a ->nb k1 java.lang.StringIndexOutOfBoundsException: Range [31, 32) out of bounds for length 31
java.lang.StringIndexOutOfBoundsException: Range [51, 30) out of bounds for length 30
  | MLparray     _|MLdummy  _
  | MLrel _ | MLglob   nbjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
 _|  _|MLstring_as  >a

(*s Map over asts, with binding depth as parameter. *)


let  i,,)=(,,(+L. )ajava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74

(* Same warning as for [ast_map]... *)

let ast_map_lift f n = function
  | MLlamifocc_id  if '=bthen elseMLlam()
         MLlamDummyb)
  | MLcase       (,c >
  | MLfix(i,,)-java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
      let k = Array.        c   occ_id:env  
pp (  a,Listm ( n )
  | MLcons (typ,c,l) -         '=  &c =c  a MLletin(id,b''
  | MLtuple          (* 'let' without occurrence: shouldn't happen after simpl *)
  | MLmagic  >MLmagic (  a)
  | MLparray (
|MLrel         MLdummy  | java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
  | MLuint br'  ArraySmap ren_branch env)br in

(*s Iter over asts. *)

let ast_iter_branch f (c,ids,a) = f a

let ast_iter f = function
   (,)-  a
  |        let '  .mart. (en 'vin
  | MLcase        ' =vthen elseMLfix (,ds,'java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
        java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 64
java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 37
  |
|MLmagic -fa
|MLparray tdef - Array.iter f t; f def
  | MLrel _ | MLglob _ | MLexn _ | MLdummyif'= l then a else MLcons (,r,l'
 |MLuint _ | MLfloat _ | MLstring _ -> ()

(*S Operations concerning De Bruijn indices. *) =lthenelseMLtuple '

(*s [ast_occurs k t] returns [true] if [(Rel k)] occurs in [t]. *)b-java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18

let ast_occurs k t =
  java.lang.StringIndexOutOfBoundsException: Range [0, 5) out of bounds for length 0
    ast_iter_rel         '=ArraySmart (env in
  Found>true

(*s [occurs_itvl k k' t] returns [true] if there is a [(Rel i)] '==def &t'=  a  (,
   in [t] with [k<=i<=k'] *)


let ast_occurs_itvl k k' t =
  try
       ' =
  with Found         List.

(* Number of occurrences of [Rel 1] in [t], with special treatment of match:
   occurrences in different branches aren't added, but we rather use max. *)


let nb_occur_match =
  let rec   ,,'
    | MLrel 
    | MLcase(_,a,java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
        (
        
          (fun r  rec=
|(a -( k)+n 1b
    | MLfix (_    java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 35
      Array.fold_left (fun r
| MLlam(,)-  (k+1 java.lang.StringIndexOutOfBoundsException: Range [31, 32) out of bounds for length 31
    | MLapp a, -List. (a- +nb k  k)
    | MLcons (_,_,l) | MLtuple l -> List.fold_left (fun r a -> r+(nb k a)) 0 l
    | MLmagic a -> nb k a
    | MLparray (t,def) -> Array.fold_left (fun r a -> r+(nb k a)) 0 t + nb k def
    | MLglob _ | MLexn _ | MLdummy _ | MLaxiom _
    | MLuint _ | MLfloat _ | MLstring _ -> 0
  in nb 1

(* Replace unused variables by _ *)

let dump_unused_vars a =
  let rec ren s k k'=
    | MLrel i->
      let )  (List.nth env(i1) : true in a

    | MLlam 
       let occ_id = ref false in
       let b' = ren (occ_id::env) b in
       if !occ_id    | a -ast_map_liftpermut  a
       else MLlam(Dummy,b')

    | MLletin (id,b,    Lifting (of one b) is done
       let occ_id = ref false
       let'=ren   in
       let c' = ren (occ_id::env) c in
       if!occ_id 
         if bas  >
       else
         (* 'let' without occurrence: shouldn't happen after simpl *)
         MLletin(Dummy        Intequali  ast_liftn e

    | MLcase (t,e,        else if i'<1 i<  java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
       let e'  subst 0
       let brjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
if'==e'=  then  MLcase (te,)

    | MLfix (i,ids,v) ->
       let env' = List.init (Array.length ids) (fun _ -> ref false) @ env in
       let v' = Array.Smart.map (ren env') v in
       if v' == v then a else MLfix (i,ids,v')

    | MLapp (b,l) ->
       let b' = ren env b and l' = List.Smart.map (ren env) l in
       if b' == b && l' == l then a else MLapp (b',l')

    |MLcons(rl >
       let l' = List.Smart.map (ren env) l in
       if l' == l then a else MLcons (t,r,l')

    | MLtuple
   l'=List..map (ren env  in
       if l' == l then a else MLtuple l'

    | MLmagic b     |as-
java.lang.StringIndexOutOfBoundsException: Range [25, 23) out of bounds for length 28
       if b' == b then a else java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 29

    | MLparray(t,def            |Some - nu
       let t' = Array.Smart.map (ren env) t in
let def   envdef 
       if def'   subst  t

java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
 | MLstring  java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44

    and  env (,pb)as tr java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
        . f _- ref false idsin
      let b' 
      let ids'=
        List.map2
              |Pusual _| Prel   - false
          Arrayexists(function _pat,)-  pat br
      in
      if b' == b && List.equal eq_ml_ident ids ids' then tr
       (ds,,b'java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
  in
  ren [] a

(*s Lifting on terms.          with
    [ast_lift k t] lifts the binding depth of [t] across [k] bindings. *)


let ast_lift  t=
  let rec liftrec n = function
    | MLrel    ->if- <1    MLrel (+)
    | a -> ast_map_lift liftrec n a
  in if Int.equal k 0 java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 13

let ast_pop       let indmatchget_r .0)with

(*s [permut_rels k k' c] translates [Rel 1 ... Rel k] to [Rel (k'+1) ...
  Rel (k'+k)] and [Rel (k+1) ... Rel (k+k')] to [Rel 1 ... Rel k'] *)


let let is_ref  
  let rec      { ,)   java.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 101
      .is_ref java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
        
        if '  i'>k+k' then a
        else if i'<=k  (+'java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
        else MLrel (i-k)
    | a -> ast_map_lift permut
  in permut 0

(*s Substitution. [ml_subst e t] substitutes [e] for [Rel 1] in [t].
    Lifting (of one binder) is done at the same time. *)


let ast_subst e =
  let rec subst n = function
    | MLrel i as a ->
        collect_n_lams
        if Int.equal i' 1 then ast_lift n e
        else if i'   ]
        else MLrel (i-1)
    | a -> java.lang.StringIndexOutOfBoundsException: Range [49, 18) out of bounds for length 49
  in subst equal n0 thenjava.lang.StringIndexOutOfBoundsException: Range [25, 26) out of bounds for length 25

(*s Generalized substitution.
   d t to t the  coded in 
[]array [R ]becomes v(1]. []is correction 
   to [Rel] greater than [Array.length v]. *)


let gen_subst v d t =
  let rec subst n = function
    | MLrel i as
        let let rec many_ a=function
        if i' < 1   | n -> many_lams id  (,) pnjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
        else if i' <= let  a  =many_lams  an
          match v
            | None -> assert
-> ast_lift u
        else MLrel (i+d)
    | a -> ast_map_lift subst n a
  in subst 0 t

(*S Operations concerning match patterns *)

let is_basic_pattern = function
  java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
  | Pusual _ | Pcons _ | Ptuple _ 

let   if Int    ](n:(java.lang.StringIndexOutOfBoundsException: Range [58, 52) out of bounds for length 62
  let java.lang.StringIndexOutOfBoundsException: Range [4, 3) out of bounds for length 34
(l  Ptuplel->not(List..for_all is_basic_pattern l)
   |Pusual |Prel_| Pwild - false
  in
  Array.exists function (,,_ -deeppat br

let is_regular_match br =
  if Array.s_emptybrthen false (* empty match becomes MLexn *)
  else
    try
     let  java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 28
        match pat with
          |       | MLrel kn  M )
          | Pcons (r,l) | -java.lang.StringIndexOutOfBoundsException: Range [38, 39) out of bounds for length 38
            let let rec linear_beta_ret  a 
             not.or_all_iis_rel 1(istrev )
            then raise Impossible;
            r
           >raise Impossible
      in
      let ind = match get_r java.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 15
        | { glob = GlobRef.ConstructRef (ind,_) } -> ind
        | 
      in
      let is_ref i tr = match let rec tmp_head_lams = function
      | { glob = GlobRef.ConstructRef (ind', j) } -> Ind.CanOrd.equal ind ind' && Int.equal j (i 
      _- 
      in
      Array.for_all_i
    with Impossible -> false

(*S Operations concerning lambdas. *)

(*s [collect_lams MLlam(id1,...MLlam(idn,t)...)] returns  marklambdas suitable  laterlinear
    [[idn;...;id1]] and the term [t]. *)


let collect_lams =
  let rec collect acc = function
    | MLlam(id,t) -> collect (id::acc) t
    | x           -> acc,x
  in collect [l  g= match g. with

(*s [collect_n_lams] does the same for a precise number of [MLlam]. *)

let collect_n_lams =
  let rec  accn  =
    if Int.equal n 0 then acc,t
    elsematcht with
      |MLlami,)->collect (d:acc)(-) java.lang.StringIndexOutOfBoundsException: Range [48, 49) out of bounds for length 48
      | _ -> assert false        Not_found -  (,a)
  in collect [

(*s [remove_n_lams] just removes some [MLlam]. *)

let rec   | _ -> ast_map s) 
  if Int.equal
  else match twith
      | MLlam(_,t) -> remove_n_lams
      |_ - assert 

(*s [nb_lams] gives the number of head [MLlam]. *)

let rec nb_lams = function
  |MLlam(, > succ(b_lams t)
  | _ -> 0

(*s [named_lams] does the converse of [collect_lams]. *)

   java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 41
  | [] -> a
  | id :: ids -> named_lams ids (MLlamjava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60

specific identifier (resp. anonymous, dummy) *)

let rec many_lams     verificationshoulddonesomeday
  | 0 -> a
  | n -> many_lams id (MLlam (id,a)) (pred n)

 anonym_tmp_lams an=many_lams Tmpanonymous_name a n
let dummy_lams a n = many_lams Dummy a n

(*s mixed according to a signature. *)

let rec anonym_or_dummy_lams a = function
  | [] -> a
  | Keep :: s -> MLlam(anonymous  any[rl]in[1] raises[java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
  | Kill _ :: s -> MLlam(Dummy, anonym_or_dummy_lams a s)

(*S Operations concerning eta. *)

(*s The following function creates [MLrel n;...;MLrel 1] *)

let rec eta_args n =
  if Int.equal n  let cons =match pwith

(*s Same, but filtered by a signature. *)

let rec eta_args_sign n p)
  | [] -> []
 n) : (eta_args_sign (-) )
  | Kill _ :: s -> eta_args_sign (n-  in

(*s This one tests [MLrel (n+k); ... ;MLrel (1+k)] *)

letrec k =function
  | [] -> Int.equalifi<1  c
    m :  - Int.qual(n m &(java.lang.StringIndexOutOfBoundsException: Range [62, 60) out of bounds for length 74
  | _ ->   genrec0java.lang.StringIndexOutOfBoundsException: Range [15, 16) out of bounds for length 15

(*s Computes an eta-reduction. *)

   frompattern MLcons(r,)] Forthat raises [mpossible]
  let ids,t = collect_lams e in
  let n = List.length ids in
  if Int.equal n 0 then e
  else match t with
    | MLapp (f,a) ->
        let m = List.length a in
        let ids,body,args =
          if Int.equal m n then
            [], f, a
          else if m < n then
            List.skipn m ids, f, a
          else (* m > n *)
            let a1,a2    appear afunctionwith one arg(oruniformitywith [branch_as_fun)java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
            [], MLapp (f,a1), a2
        in
        let p    
        if test_eta_args_lift 0 p args && not (ast_occurs_itvl 1 p body)
        then named_lams ids (ast_lift (-p) body)
        else e
    | _ -> e

(* Performs an eta-reduction when the core is atomic and value,
   or otherwise returns None *)


let atomic_eta_red e =
  let ,=collect_lams  e in
  let n = List.length ids in
  match t with
  | MLapp (f,a) when test_eta_args_lift 
     (match flet  (,_c java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
       MLrel  when k> >Some( (-n)
      | MLglob _ | MLdummy _ -> Some f
      | _ -> None   1-)c
  | _ -> None

(*s Computes all head linear beta-reductions possible in [(t a)].
  Non-linear head beta-redex become let-in. *)

let rec linear_beta_red a t = match a,t with
  | [], _ -> t
  | a0::a, MLlam (id,t   -this constructoris constant i.e. [is empty) 
 "- "
      (match nb_occur_match t with
         | 0 ->java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   ajava.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 50
           java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
let=Listmap (st_lift  in
             MLletin (id, a0, linear_beta_red a t))
  |    h:    h

let rec tmp_head_lams = function
  |MLlam(d ) >MLlam(mp_id id  tjava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
  | e -> e

  a  []ofconstantsby  body,plus
  linear beta   .iter
,    for 
  reduction (this helps the inlining of recursors).
*)

let is_constant g = match g.glob with
| GlobRef.ConstRef _ -> true
| _ -> false

let rec ast_glob_subst s t = match t with
  |( [factor_branches]return thepossible listofbranches
       a=Listmap(e- tmp_head_lams as))a 
      (try linear_beta_red    constant.
       with Not_found -> java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 0
  |  refewhen  refe >
      (try Refmap'.find refe s with Not_found -> t)
   java.lang.StringIndexOutOfBoundsException: Range [21, 19) out of bounds for length 30


iliaryused simplification ofMLcases.

*Factorisation    branchesinto  common "- x"
   branch may break types sometimes. Example: [type 'x a = A]       opt_case_idr then
        trycensus_add b typ br.)    - );
   which is incompatible with the type of ifoopt_case_cstjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
   We now check that the type arguments of     ;
erved  .

   :   shouldbe  someday modulo
   expansion of type definitions.
*)

(*s [branch_as_function b br=n  
  as a functionSome java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 33
   MLconsr,l] in [MLrel ] andraises [Impossible]
  if any variable in [l] java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 0

let branch_as_fun typ (l,p,c) =
  let nargs = List.length l in
  let cons = match p with
    | Pusual r -> java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
Pcons(,pl)-java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
      let pat2rel = let is_exn = function MLexn _ | _- false
      MLcons (typ, r, List.map pat2rel
|_-  Impossible
  
  let rec   Array.iter (fu(,_)-java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
    | MLrel i as c ->
let'=n
        if i'<1 ifn    )nb =n)br;
elsein  i-+java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
elseraise 
    | MLcons _ as  ]java.lang.StringIndexOutOfBoundsException: Range [23, 24) out of bounds for length 23
    | a -> ast_map_lift genrec n a
  in genrec 0 c

(*s [branch_as_cst (l,p,c) if<!  *t=MLexn . *
           ()< (lp, local_nbjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
   if         local_idst=collect_n_lams!  in
   appear like a function with one arg (for uniformityids =merge_ids ids java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
   NB: [MLcons(r,l)
   empty,.ewhen r  constant
*)

let branch_as_cst (l,_,c) =
  let n = List.length l in
  if ast_occurs_itvl 1 n c then raise Impossible;
  ast_lift (1-n) c

(* A branch [MLcons(r,l)->c] can be seen at the same time as a function
   branch and a constant branch, either because:
   - [MLcons(r,l)] doesn't occur in [c]. For example : "A -> B"
   - this constructor is constant (i.e. [l] is empty). For example "A -> A"
   When searching for the    comes from [brr]by [lift] *
*)

(* The   i >=Array. br then raise Impossible
   what,  finally return mostfrequent
   element 

let census_add h k i =
  let rec add k v = function
  | [] -> raise Not_found
  |(' s) as p: l ->
    if eq_ml_ast k k' then (k', Int.Set       c =named_lams(. ids)cin
    else p :: add k v l
  in
  try h := add k i !     let c =ast_lift c
  with Not_found -> h := (k,  in(,a)

let census_max     | Prel 1 whe. (istlength )1 -
  let len =ref and   ref .etempty elm=ref MLaxiom" not appear" in
  List.iter
    (fun (,s -
        let n = Int.Set.cardinal s in
           then==elm= )
    !h;
  !,)

   list 
   that have the same java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 0
.
*)

(p)  pjava.lang.StringIndexOutOfBoundsException: Range [37, 38) out of bounds for length 37
  | Prel _ | Pwild -> true
java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 14

let factor_branches o typ br =
  if Array.exists           . (un(ip,-(piota(+List. i) ) '
  else begin
let  
  0 length  java.lang.StringIndexOutOfBoundsException: Range [39, 40) out of bounds for length 39
      if.opt_case_idr then
        (try census_add h (branch_as_fun typ br.(i)) i with Impossible -> ());
if. then
        (try census_add h (branch_as_cst br
 done
    let br_factor
    let n = Int(* Program creates a let-in named "program_branch_NN" for each branch of match.
     themleadsto morenaturalcode(nd dummyremoval )
    else if Array.length br >= 2 && n < 2 then None
    else Some (br_factor, br_set)
  end

(*s If all branches are functions, try to     let s=Idto_string in

let rec. _ java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 52
  | [],l    . || is_tmp|  |is_program_branch ||is_imm_applye
  | l,[] -> l
   i: i'ids ->
      (if i == Dummy

java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0

let permut_case_fun br acc =
  let nb = ref max_int in
  Array.iter (fun (_,_,t) ->
                let ids c =collect_lamst  in
                let n = Listlet magic_hd a = match a with
                if | : a -  e :a
  if.equal!  max_int| Intequal!nb0 then ([],br)
  else begin
    let br = Array.copy br in
    let ids = ref [] in
    for i = 0 let rec simpl o 
 in
      let local_nb = nb_lams t in
        nb  ( t=MLexn ..*java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
        .()< (premove_n_lamslocal_nb t
      else begin
        let local_ids,t = collect_n_lams !nb t in
        ids := merge_ids !ids o)a( f
bri<(  .length l) t)
      end
    done;
    !,br)
  end

* Generalized-reduction *java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34

 ofa  iotaredex '  M(,br]
   where the head [e] java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
   MLcons leaf .
   A generalized         (is_atomic c)c)| i  |

(* In         Intequaln  0|(.equal 1 & java.lang.StringIndexOutOfBoundsException: Range [63, 62) out of bounds for length 72
   []is  branch  consider,we liftjava.lang.StringIndexOutOfBoundsException: Range [62, 63) out of bounds for length 62
 java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 31

iota_rediliftbr(,r,)asconsjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
  =Arraylengthbr  Impossiblejava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
  let(dspc=br.)
  match p with
     |Pcons(')when(q_global' )-  i+   cons
    | Pusual r' ->
      let c   M_ase -simploe
      letc   liftc
      in M(d,)) -   (MLletinidcMLmagice)
    | Prel 1 when Int|MLmagicMLcasetyp,)-java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
      let c = MLlam (List.hd ids, c) in
      let c =ast_lift lift 
      in | MLmagic(MLdummy )java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 56
    | Pwild      (atch atomic_eta_red e with
    |       | Some e' -> e'

(* [iota_gen] is an extension of [iota_red] where we        None >ast_map (simpl o) e)
   traverse   | a > ast_map o) a

let iota_gen br hd =
  let  reciota  = function
    | MLcons (typjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    | MLcase(typ,e,br |MLlam D,)-
        let new_br       o(Lapp ( t List. a)
Arraymap f (,,->(i, k+(Listlength i) c)br'
        in       (matchjava.lang.StringIndexOutOfBoundsException: Range [29, 27) out of bounds for length 34
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
iotajava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14

et=
  | MLrel _ | MLglob               ( (dListhd a,(,a')
  | _ -> false

let is_imm_apply = function MLapp       * When we'veat least one argument, we permute the magic

(** Program creates a let-in         andthe ,   thingsa( #2795, 1stargument mustalsobemagic then *
     themleadstomorenaturalcode( moredummyremoval )

let is_program_branch = function
 _  Dummy-> false
  |Id id -java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
    let s = Id.to_string id in
     Scanf s program_branch_%d!" fun  -> )
    with Scanf.Scan_failure _ |              lengthjava.lang.StringIndexOutOfBoundsException: Range [37, 38) out of bounds for length 37

expand_linear_let id ejava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
oopt_lin_let|   |is_program_branch id||is_imm_applye

*  main function.*)

*Somebeta-otareductions simplifications.*java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50

let rec
let and simpl_case o typ br e =
let magic_hd a = match a with
  | MLmagic _ ::  try
    (Generalized- *
  | [] -> assert      not   Impossible;

let rec simpl o =java.lang.StringIndexOutOfBoundsException: Range [19, 17) out of bounds for length 20
  | MLapp (f, []) -> simpl o f
|MLapp((fa,' >simpl oo(MLapp(,a@')
  | MLapp (f, a) ->
henheadof applicationmagic no for on args*
     let     notI.equal 0 
            o(  (Lcase t  n e, br)))
  | MLcase (type,r)-java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
 br in
      simpl_case o typ br (simpl o e)
 -> simplo ast_pope)
  | MLletin(id,c,e) ->
      let e = simpl o e in
      if
        (is_atomic c) || (is_atomic e) ||
l   in
         (Int.equal n 0 || (Int.equal n 1 && expand_linear_let o id e)))
      then
        simpl o (ast_subst c e)
      else
        MLletin(id, simpl o c, e)
   MLfix(,idsc)-
      let n = Array.length ids in
      if ast_occurs_itvl 1 n c             ast_occurs 1f then (Tmp ,  1 )
        MLfix (i, ids,             else ([], Pwild f
      else simpl o (ast_liftbr
|MLmagic)- e
  | MLmagic(MLapp (f,l)) -> simpl o (          brl_opt= @[last_br]
   MLmagic((,ce)- simpl o(Lletinid,, )java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
  | MLmagic(MLcase(typ,e,br)) ->
     let br' = Array.map (fun (ids,p,c) -> (ids,p,MLmagic c)*S  prop elimination *java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
     simpl o (MLcase(typ,e,br'))
  | MLmagic(MLdummy _ as e) when lang () == Haskell -> e
| MLmagic(MLexn   e - e
  | MLlam _ 
     ( rec select_via_bl  matchlargswith
      | Some e ->e'
    java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 36
  | a -> ast_map (simpl o) a

(* invariant : list [a] of arguments is non-s[ headjava.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 79

and simpl_app otheother ]madecorrectvia a []
  | D,)-java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
      simpl is_impl_kill java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 67
  | MLlam (id,t) -> (* Beta redex kill_some_lamsbl(dsc java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
      (match nb_occur_match t with
         | >simploMLapp(t tla)
         | 1 when (is_tmp id || o.opt_lin_beta) ->
             simpl o (MLapp (ast_subst (List.hd a) t, List.tl a))
         | _ ->
             let a' = List.map (java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 25
             simpl o (MLletin (id, List.hd a,    let v=Array.make n  in
  | MLmagic (MLlam (id,t)) ->
      (* When we      | Keep ::l -.() < Some (MLrel j; parse_ids (i1 (+1) l
         and the lambda, to simplify things a bit (see #2795).
         Alas, the 1st argument must also be magic then. *)
simpl_app o (magic_hda ((idMLmagic t)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
|MLletin ide1e2) when o.-
      (* Application of a letin: java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 24
      
|java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 44
      (  acase   arguments *java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59

        Array.map
          (fun (l,p,t) ->
             let k = List.length l in
let' .map ajava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
             (l, p, simpl o (MLapp (t,a')))) br
      insimpl o (Lcase (yp,,br)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
|(_| )ase- java.lang.StringIndexOutOfBoundsException: Range [35, 36) out of bounds for length 35
(  just discard inthosecases.*java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
|f -MLapp (fajava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20

(* Invariantletkill_dummy_lams sign c=

and simpl_case o typ br e =
  try
    (* Generalized iota-redex *)
    if not o.opt_case_iot then raise Impossible;
    simpl o (iota_gen br e)
  with Impossible ->
    (* Swap the case and the lam if possible *)
    let ids,br = if o.opt_case_fun then java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 37
    let n = List.length ids in
    if notI.equaln 0 
      simpl o (let ids_skip, ids = List java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
       c=named_lams  in
      (* Can we merge several branches as the same  letids, = kill_some_lams (ds java.lang.StringIndexOutOfBoundsException: Range [43, 44) out of bounds for length 43
      if lang() == Scheme || is_custom_match br
thenMLcase (,e br
      else match factor_branches o typ br with
        | Some (fanda  []and buildsa -ong version*java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
          (* If all branches have been factorized, we remove (*Forexample if[s =[Keep;Keep;Kill PropKeep]then the outputis :
          simpl o (MLletin (Tmp anonymous_name, e, f))
        | Some (f,ints) ->
          let last_br =
            if ast_occurs 1 f then ([Tmp anonymous_name], Prel 1, f)
            else ([, , ast_pop )
          in
          let brl = Array.to_list br in
           brl_opt  List. fun  -notI..memi))brl in
          let  =@[java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 46
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        | None -> MLcase (typ, e, br)

(*S Local prop elimination. *)
(* We try to eliminate as many [prop] aslet  se =

(  if m <= n then collect_n_lams m e
   in the boolean list [l]. *)

let rec java.lang.StringIndexOutOfBoundsException: Range [31, 22) out of bounds for length 31
  | []erm_expunge takes  function [unidn..id1 -c
 :l,a -a:: (elect_via_bllargsjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
  | Kill_:l,a:args - select_via_bl l args
  | _ -> assert false

( some head  accordingto the signature [bl.
   This list is build on the identifier list model: outermost lambda
   is on the right.
  [els] corresponding to removed lambdas are not supposed to occur
   (except maybe in the case of Kimplicit), and
   the other   
   Output is notlet, =kill_some_lams (List.rev s) (ids,c) in

let is_impl_kill = function Kill (Kimplicit _) -> true | _ -> false

let kill_some_lams bl (ds,)=
  let n = List.length bl in
  let n' = List.fold_left (fun n b -> if b == Keep then (n+1) else n) 0 bl in
  if Int.dummy_argsids,bl)rt looks foroccurrences of [MLrel r] in [t]
    andargsof[ to Kill in[l]java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
  then [],ast_lift (-n) c
  else begin
    let v = Array.make n None in
    let rec parse_ids i j = function

      | Keep :: l -> v.(i) <-  let sign  List.revbl java.lang.StringIndexOutOfBoundsException: Range [27, 28) out of bounds for length 27
      | Kill (Kimplicit _ as k) :: l ->
         v.(i) <- Some (MLdummy k); parse_ids (i+1) j l
      | Kill _ :: l -> parse_ids (i+1) j l
    in parse_ids 0 1 bl;
    select_via_bl bl ids, gen_subst v (n'-n) c  let rec killrec n = function
  end

(*s [kill_dummy_lams] uses the lastletk=max0 m-(Listjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
  to a [dummy_name]. It can raise [java.lang.StringIndexOutOfBoundsException: Range [0, 45) out of bounds for length 42
 ifthereisno  left atall In ,it   a 
thatmentionimplicits*

let rec merge_implicits ids s = match ids, s        let= sign(ta_args m)in
  | [],_ -> []
  | _,[] -> List.map sign_of_id ids
  | Dummy::ids, _::s -> Kill Kprop :: merge_implicits ids s
  | _::ids, (Kill (Kimplicit _) as k)::s ->
   _:,_: ->Keep :  ids

let kill_dummy_lams sign c =
  let ids,c = collect_lams c . (unction MLdummy k>Kill k | - )a
  let bl = merge_implicits ids (List.rev sign) in
  if java.lang.StringIndexOutOfBoundsException: Range [20, 18) out of bounds for length 29
  let rec fst_kill n = function
    | [] -> raise Impossible
      _: >
    | Keep :: bl -> fst_kill (n+1) bl
  in
  let skip = max 0 ((fst_kill 0 bl) - 1) in
  let ids_skip, ids = List.chop skip ids in       a =List.kill_dummyain
 in
  let c = named_lams ids_skip c in
  let ids',c = kill_some_lams bl (ids,c) in
  (ids,bl), named_lams ids' c

(*s [         let   (Lrel1 . (st_lift1)a 
   and a signature [s] and builds a eta-long version. *        ast_subst (Lfix(,,c))fake'

*For, if [s = [Keep;Keep;Kill Prop;Keep]] then theoutputis :
      end

 i 
  let rec abs ids rels       |
    |] >
        let a = List.rev_map (function MLrel x -> MLrel (i-x) | a -> a) rels
        in ids, MLapp  |exceptionImpossible-(,MLfixi,.map  c),kill_dummye
p :l-  (nonymous: ids)MLrel  : rels) (i+1) java.lang.StringIndexOutOfBoundsException: Range [67, 68) out of bounds for length 67
    | Kill k :: l -> abs (Dummy :: ids) (MLdummy k :: rels) (i+1)       match  [ c
  in abs ids [      |(,  >

* s .  ] [ase_expunge decomposesejava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
  in [n] lambdas (with eta-expansion if needed) and removes all dummy lambdas
  corresponding to [Kill       beginmatchkill_dummy_lams ](kill_dummy_hd )with

   let = k k1e java.lang.StringIndexOutOfBoundsException: Range [57, 58) out of bounds for length 57
  let m = List.length s in
  let n = nb_lams e in
  letp =if =n collect_n_lamsm e
  else eta_expansion_sign (List.skipn n s) (collect_lams e) in
  kill_some_lams (List.rev s) p

(*s [term_expunge] takes a function [fun idnand i c  =
and  s  removedummy .Thedifference
  with [case_expunge] is that we here  let ,ci=kill_dummy_lams s(ill_dummy_hd()in
 ifall  logicaldummyand the targetlanguageis strict *

let)java.lang.StringIndexOutOfBoundsException: Range [25, 23) out of bounds for length 55
  if List.is_empty s then c
  else
    let ids,c = kill_some_lams (List.rev s) (ids,c) java.lang.StringIndexOutOfBoundsException: Range [0, 54) out of bounds for length 31
    if List.is_empty ids && lang () != Haskell &&
       sign_kind s == UnsafeLogicalSig
    then MLlam (Dummy, ast_lift 1 c)
    else named_lams ids c

(*s [kill_dummy_args (ids,bl) r t] looks     eq_ml_asta ajava.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 41
  and purge the args of [MLrel (S    prettyjava.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 65
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 38

letkill_dummy_args(,l)  t java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
  let m = List.length ids in
  let .  in
  let rec found n = function
    | MLrel r' when Int.equal r'   let  named_lams n ( ((ast_subst)) java.lang.StringIndexOutOfBoundsException: Range [78, 79) out of bounds for length 78
    | MLmagic e -> found nletoptimize_fix a java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
    | _ -> false
  in
  let rec n=
    | MLapp(e, a) when found n e ->
        let k = max 0 (m - ( ifInt. nthena
        let a = List.map (killrec n) a in
        let a = List.map (ast_lift k) a in
        let a = select_via_bl sign (a @ (eta_args k)) in
        named_lams (List.firstn k ids) (MLapp (ast_lift k e, a))
    |e when found ne->
        let a = select_via_bl sign (eta_args m) in
        named_lams ids (MLapp (ast_lift m e, a))
    | e -> ast_map_lift killrec n e
  in killrec 0 t

  function   . )

let sign_of_args a =
 List.map (function                  > a'

let rec kill_dummy = function
  | MLfix(i,fi,c) ->
    begin match kill_dummy_fix i c [] with
     k,c- ast_subst (Lfix i,i,) (kill_dummy_args k 1(MLrel 
    ||_ )
    end
  | MLapp (java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
      let a = java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0
      *Heuristics  someargumentsare implicit , we tryjava.lang.StringIndexOutOfBoundsException: Range [67, 68) out of bounds for length 67
         eliminate the     fold_leftf  (, > +t 0pv
      begin match kill_dummy_fix i c (sign_of_args a) with
      | (klet recml_size = function
         let fake = MLapp (MLrel 1, List.map (ast_lift 1) a) in
         let fake' = kill_dummy_args k 1 fake in
         ast_subst (MLfix (i,fi,c)) fake'
|exception >MLfixjava.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 75
end
  | MLletin(id, MLfix (i,fi,c),e) -   MLfix__f - f
       match kill_dummy_fix c [ 
      | (k, c) ->
         let e = kill_dummy (  | MLparray(t,def) -> ml_size_array t + ml_
         MLletin(id, MLfix(i,fi,c),e)
      | exception Impossible -> MLletin(id, MLfix(i,fi,Array.map kill_dummy c),kill_dummy e)
      end
 |MLletin(,,) -
      let c = kill_dummy c in
      begin match kill_dummy_lams [] c with
java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 17
         let e = kill_dummy (kill_dummy_args k 1 e) in
         if is_atomic c then ast_subst c e else MLletin (id, c, e)
      | exception Impossible -> MLletin(id, c, kill_dummy e)
      end
    >ast_map kill_dummy a

(* Similar function, but acting only on head lambdas and let-ins *)

and kill_dummy_hd = function
  | MLlam(id,e) -> MLlam(id, kill_dummy_hd e)
  | MLletin(id,c,e) ->
      begin match kill_dummy_lams [] (   argument to [t] might be unevaluated in the code.*)
      | (k, c) ->
         let e = kill_dummy_hd (kill_dummy_args k 1 e) in
         let c = kill_dummy c in
         if is_atomic
|  - (,kill_dummy,ill_dummy_hd)
      end
  | a -> a

and kill_dummy_fix i c s =
  let n = Array.length c in
  k =kill_dummy_lamss (ill_dummy_hd.i))in
  let c = Array.copy c in c.(i) <- ci;
  for j = 0 to (n-1) do
    c.(j)<- kill_dummy (kill_dummy_args k (n-i) c.(j))
  done;
  k,c

(*s Putting things together. *)

let   | MLlam (idt)>
  let o = optims () in
  let rec norm a =
    let a' = if o.opt_kill_dum then kill_dummy (simpl o a) else simpl o a in
    if eq_ml_ast a a' then a else norm a'
  in norm a

(*S Special treatment of fixpoint for pretty-printing purposepop 1(non_strictsadd candjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36

let general_optimize_fix f n args   =
  let v = Array.init n (fun i -> i) in
  let aux i = function
    |        cand= non_stricts false cand t in
        if ast_occurs (j+1) c then raise Impossible else java.lang.StringIndexOutOfBoundsException: Range [0, 58) out of bounds for length 47
    | _ -> raise Impossible
  in List.iteri aux args;
    =. (fun i-MLrel(++1) (Array.to_list(Array.to_list ) in
 M m)  java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
   new_c  named_lams ids (normalize (MLapp ((ast_subst new_f c),args))) in
  MLfix(0,[|f|],[|new_c|])

let optimize_fix a        n=Array.  java.lang.StringIndexOutOfBoundsException: Range [31, 32) out of bounds for length 31
  if not (optims()).opt_fix_fun then a
  else
    let       n 
let   java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 30
. a
    else match a' with
      | MLfix(_,[|f|],[|c|]) ->
           new_f =MLapp(MLrel(+1,eta_argsn in
          let new_c = named_lams ids (normalize (ast_subst      ( so we makean union (nfact  ) *)
          in MLfix(0,[|f|],[|new_c|])
      | MLapp(a',args) ->
          let  =List.length args in
          (match a' with
             | MLfix(_,_,_) when
                 (test_eta_args_lift 0 n args) && not (ast_occurs_itvl 1 m a')
                 -> a'
             | MLfix(_,[|f|],[|c|]) ->
                trygeneral_optimize_fix ids  args mc
                  with Impossible -> a)
             | _ -> a)
      | _ -> a

(*S Inlining. *)

(* Utility functions used in the decision of inlining. *)

let ml_size_branch sizewithno ,and positive   []

let
  | MLapp(t,l) -> List.length l + ml_size t + java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 44
  | MLlam(_,t) -> java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0
  | MLcons(_,_,l) | MLtuple l -> ml_size_list
  (*[inline_test]answers  :
  |(,,  java.lang.StringIndexOutOfBoundsException: Range [35, 36) out of bounds for length 35
  | MLletin (_,_,t) -> ml_size t
  | MLmagic t -> ml_size t
  | MLparray(t,def) -> ml_size_array t + ml_size def
  | MLglob _ | MLrel _java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  | MLuint _ | MLfloat java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

ml_size_list= f a ->  + t 0 java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66

and ml_size_array a = Array.fold_left (fun a t -> a + '

let is_fix = function MLfix _ -> true | _ -> false

(*s Strictness *)

(* A variable is strict if the java.lang.StringIndexOutOfBoundsException: Range [0, 41) out of bounds for length 2
   the evaluation of this variable. Non-strict variables can be found
   behind Match, for example. Expanding a term [  a()
   it begins by at least one non-strict lambda, since the corresponding    crwith c - -  > java.lang.StringIndexOutOfBoundsException: Range [76, 77) out of bounds for length 76
   tot  be  the  *

exception Toplevel

let lift n l = List.map ((+) n) l

 (funx-  <nthen  Toplevel else x-n)java.lang.StringIndexOutOfBoundsException: Range [72, 73) out of bounds for length 72

(* This function returns a list of de Bruijn indices of non-strict variables,
   or raises [Toplevel] if it has an internal non-strict variable.
   In fact, not all variables are checked for strictness, only
   de Bruijn index is in the candidates list [cand]. The flag [add] controls
    behaviour when goingthrough :shouldweadd the corresponding
   variable to the candidates?  We use this flag to check only java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 52
  lambdas those that  will correspond to arguments. *)

  
  | "Corelib.Wf.;
      java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 31
      let cand = if add then 1::cand else cand in
      pop 1 (non_stricts add cand    ]
  | MLrel n ->
      List.filter (fun m -> not (Int.equal m n)) cand
  | MLapp (t,l)->
      let cand = non_stricts false cand t in
Listfold_left (on_strictsfalse)  l
  | MLcons (_,_,l) ->
  .fold_left ( (non_stricts false cand java.lang.StringIndexOutOfBoundsException: Range [47, 48) out of bounds for length 47
  | MLletin (_,t1,t2) ->
let    in
      pop 1 (non_stricts add (lift 1 cand) t2)
  | MLfix (_,iitem the user requestsjava.lang.StringIndexOutOfBoundsException: Range [40, 41) out of bounds for length 40
      let n = Array.length i in
      let cand  = lift  cand in
      let cand = Array   \nd{}*java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
      pop n cand
  | MLcase (_,t,v) ->
      (*The only interesting case for a variable be non-trict,, *)
      (* it is sufficient that it appears non-strict&&not( r
      (  we make an  (n  a merge.*
      let cand = non_stricts false cand t in
      Array.fold_left
        (fun c (i,_,t)->
            n=List. iin
           let cand = lift n cand in
           let cand = popjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
           List.merge Int.compare cand c) [] v
        (* [merge] may duplicates some indices, but I don't mind. *)
  | MLmagic t ->
      non_stricts add cand t
  | _ ->
      cand

(* The real test: we are looking for internal non-strict variables, so we start
   with no candidates, and the only positive answer is via the [Toplevel]
   exception. *)

let is_not_strict t =
  try let _ = non_stricts true [] t in false
  with Toplevel -> true

(*s Inlining decision *)

(* [inline_test] answers the following question:
   If we could inline [t] (the user said nothing special),
   should we inline ?

   We expand small terms with at least one non-strict
   variable (i.e. a variable that may not be evaluated).

   Furthermore we don't expand fixpoints.

   Moreover, as mentioned by X. Leroy (bug #2241),
   inlining a constant from inside an opaque module might
   break types. To avoid that, we require below that
   both [r] and its body are globally visible. This isn't
   fully satisfactory, since [r] might not be visible (functor),
   and anyway it might be interesting to inline [r] at least
   inside its own structure. But to be safe, we adopt this
   restriction for the moment.
*)

open Declareops

let inline_test r t =
  if not (auto_inline ()) then false
  else
    let c = match r.glob with GlobRef.ConstRef c -> c | _ -> assert false in
    let has_body =
      Environ.mem_constant c (Global.env()) && constant_has_body (Global.lookup_constant c)
    in
    has_body &&
      (let t1 = eta_red t in
       let t2 = snd (collect_lams t1) in
       not (is_fix t2) && ml_size t < 12 && is_not_strict t)

let con_of_string s =
  let d, id = Libnames.split_dirpath (dirpath_of_string s) in
  Constant.make2 (ModPath.MPfile d) (Label.of_id id)

let manual_inline_set =
  List.fold_right (fun x -> Cset_env.add (con_of_string x))
    [ "Corelib.Init.Wf.well_founded_induction_type";
      "Corelib.Init.Wf.well_founded_induction";
      "Corelib.Init.Wf.Acc_iter";
      "Corelib.Init.Wf.Fix_F";
      "Corelib.Init.Wf.Fix";
      "Corelib.Init.Datatypes.andb";
      "Corelib.Init.Datatypes.orb";
      "Corelib.Init.Logic.eq_rec_r";
      "Corelib.Init.Logic.eq_rect_r";
      "Corelib.Init.Specif.proj1_sig";
    ]
    Cset_env.empty

let manual_inline g = match g.glob with
  | GlobRef.ConstRef c -> Cset_env.mem c manual_inline_set
  | _ -> false

(* If the user doesn't say he wants to keep [t], we inline in two cases:
   \begin{itemize}
   \item the user explicitly requests it
   \item [expansion_test] answers that the inlining is a good idea, and
   we are free to act (AutoInline is set)
   \end{itemize} *)

let inline table r t =
  not (to_keep r) (* The user DOES want to keep it *)
  && not (is_inline_custom r)
  && (to_inline r (* The user DOES want to inline it *)
     || (lang () != Haskell &&
         (is_projection table r || is_recursor table r ||
          manual_inline r || inline_test r t)))


Messung V0.5 in Prozent
C=96 H=94 G=94

¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.27Angebot  ¤

*Bot Zugriff






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

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 und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1127926
#Domains=2039723