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