]> matita.cs.unibo.it Git - helm.git/blob - components/ng_kernel/check.ml
tagged 0.5.0-rc1
[helm.git] / components / ng_kernel / check.ml
1 let debug = false
2 let ignore_exc = false
3
4 let indent = ref 0;;
5
6 let logger =
7     let do_indent () = String.make !indent ' ' in  
8     (function 
9     | `Start_type_checking s -> ();
10         if debug then
11          prerr_endline (do_indent () ^ "Start: " ^ NUri.string_of_uri s); 
12         incr indent
13
14     | `Type_checking_completed s ->  ();
15         decr indent;
16         if debug then
17          prerr_endline (do_indent () ^ "End: " ^ NUri.string_of_uri s))
18 ;;
19
20 let _ =
21   CicParser.impredicative_set := false;
22   NCicTypeChecker.set_logger logger;
23   NCicPp.set_ppterm NCicPp.trivial_pp_term;
24   Helm_registry.load_from "conf.xml";
25   let alluris = 
26     try
27       let s = Sys.argv.(1) in
28       if s = "-alluris" then
29        begin
30         let uri_re = Str.regexp ".*\\(ind\\|con\\)$" in
31         let uris = Http_getter.getalluris () in
32         let alluris = List.filter (fun u -> Str.string_match uri_re u 0) uris in
33         let oc = open_out "alluris.txt" in
34         List.iter (fun s -> output_string oc (s^"\n")) alluris;
35         close_out oc; 
36         []
37        end
38       else [s]
39     with Invalid_argument _ -> 
40       let r = ref [] in
41       let ic = open_in "alluris.txt" in
42       try while true do r := input_line ic :: !r; done; []
43       with _ -> List.rev !r
44   in
45   let alluris = 
46     HExtlib.filter_map
47       (fun u -> try Some (UriManager.uri_of_string u) with _ -> None) alluris 
48   in
49   (* brutal *)
50   prerr_endline "computing graphs to load...";
51   let dbd = HSql.quick_connect (LibraryDb.parse_dbd_conf ()) in
52   MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
53   let uniq l = 
54      HExtlib.list_uniq (List.sort UriManager.compare l)
55   in
56   let who_uses u = 
57     uniq (List.map (fun (uri,_) -> UriManager.strip_xpointer uri)
58      (MetadataDeps.inverse_deps ~dbd u)) in
59   let roots_alluris = 
60    let rec fix acc l = 
61     let acc, todo = 
62      List.fold_left (fun (acc,todo) x ->
63         let w = who_uses x in
64         if w = [] then (x::acc,todo) else (acc,uniq (todo@w)))
65      (acc,[]) l
66     in
67     if todo = [] then uniq acc else fix acc todo
68    in
69    (fix [] alluris)
70   in
71 (*
72  BARO!
73   let roots_alluris = alluris in *)
74   prerr_endline "generating Coq graphs...";
75   (* per barare *)
76    let roots_alluris = alluris in
77   (* /per barare *)
78   CicEnvironment.set_trust (fun _ -> false);
79   List.iter (fun u ->
80           prerr_endline (" - " ^ UriManager.string_of_uri u);
81           try
82             ignore(CicTypeChecker.typecheck u);
83           with 
84           | CicTypeChecker.AssertFailure s
85           | CicTypeChecker.TypeCheckerFailure s -> prerr_endline (Lazy.force s)
86     ) roots_alluris;
87   prerr_endline "loading...";
88   List.iter 
89     (fun u -> 
90        prerr_endline ("  - "^UriManager.string_of_uri u);
91        try NCicEnvironment.load_graph u with exn -> ())
92     roots_alluris;
93   prerr_endline "finished....";
94   CicUniv.do_rank (NCicEnvironment.get_graph ());
95   prerr_endline "caching objects";
96   prerr_endline "ranked....";
97   HExtlib.profiling_enabled := false;
98   List.iter (fun uu ->
99      let uu= NUri.nuri_of_ouri uu in
100      indent := 0;
101      logger (`Start_type_checking uu);
102     let _,o = NCicEnvironment.get_obj uu in
103     try 
104       NCicTypeChecker.typecheck_obj o;
105       logger (`Type_checking_completed uu);
106     with 
107     | NCicTypeChecker.AssertFailure s 
108     | NCicTypeChecker.TypeCheckerFailure s as e -> 
109        prerr_endline ("######### " ^ Lazy.force s);
110        if not ignore_exc then raise e
111     | CicEnvironment.Object_not_found s -> 
112        prerr_endline ("Obj not found: " ^ UriManager.string_of_uri s)
113     )
114     alluris;
115   NCicEnvironment.invalidate ();
116   Gc.compact ();
117   HExtlib.profiling_enabled := true;
118   NCicTypeChecker.set_logger (fun _ -> ());
119   prerr_endline "typechecking, first with the new and then with the old kernel";
120   let prima = Unix.gettimeofday () in
121   List.iter 
122     (fun u ->
123        let u= NUri.nuri_of_ouri u in
124       indent := 0;
125       NCicTypeChecker.typecheck_obj (snd (NCicEnvironment.get_obj u)))
126     alluris;
127   let dopo = Unix.gettimeofday () in
128   Gc.compact ();
129   let dopo2 = Unix.gettimeofday () in
130   Printf.eprintf "NEW typing: %3.2f, gc: %3.2f\n%!" (dopo -. prima) (dopo2 -.  dopo);
131   CicEnvironment.invalidate ();
132   Gc.compact ();
133   let prima = Unix.gettimeofday () in
134   List.iter (fun u -> ignore (CicTypeChecker.typecheck u)) alluris;
135   let dopo = Unix.gettimeofday () in
136   Gc.compact ();
137   let dopo2 = Unix.gettimeofday () in
138   Printf.eprintf "OLD typing: %3.2f, gc: %3.2f\n%!" (dopo -. prima) (dopo2 -. dopo)
139 ;;