]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/check.ml
objects are typechecked to ensure there is a graph before doing all the stuff......
[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 "computing graphs to load...";
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   prerr_endline "generating Coq graphs...";
63   CicEnvironment.set_trust (fun _ -> false);
64   List.iter (fun u ->
65           prerr_endline (" - " ^ UriManager.string_of_uri u);
66           ignore(CicTypeChecker.typecheck u);
67     ) alluris;
68   prerr_endline "loading...";
69   List.iter 
70     (fun u -> 
71        prerr_endline ("  - "^UriManager.string_of_uri u);
72        try NCicEnvironment.load_graph u with exn -> ())
73     roots_alluris;
74   prerr_endline "finished....";
75   CicUniv.do_rank (NCicEnvironment.get_graph ());
76   prerr_endline "ranked....";
77   prerr_endline "caching objects";
78   HExtlib.profiling_enabled := false;
79   List.iter (fun uu ->
80      let uu= NUri.nuri_of_ouri uu in
81      indent := 0;
82 (*     prerr_endline ("************* INIZIO **************** " ^ NUri.string_of_uri uu); *)
83     let _,o = NCicEnvironment.get_obj uu in
84 (*     prerr_endline (NCicPp.ppobj o);  *)
85     try 
86       NCicTypeChecker.typecheck_obj o;
87 (*       prerr_endline ("************* FINE ****************" ^ NUri.string_of_uri uu); *)
88     with 
89     | NCicTypeChecker.AssertFailure s 
90     | NCicTypeChecker.TypeCheckerFailure s as e -> 
91 (*        prerr_endline ("Obj: " ^ NCicPp.ppobj o); *)
92        prerr_endline ("######### " ^ Lazy.force s); raise e
93     | CicEnvironment.Object_not_found s -> 
94                     prerr_endline ("Obj not found: " ^ UriManager.string_of_uri s);
95     )
96     alluris;
97   NCicEnvironment.invalidate ();
98   Gc.compact ();
99   HExtlib.profiling_enabled := true;
100   prerr_endline "typechecking, first with the new and then with the old kernel";
101   let prima = Unix.gettimeofday () in
102   List.iter 
103     (fun u ->
104        let u= NUri.nuri_of_ouri u in
105       indent := 0;
106       NCicTypeChecker.typecheck_obj (snd (NCicEnvironment.get_obj u)))
107     alluris;
108   let dopo = Unix.gettimeofday () in
109   Gc.compact ();
110   let dopo2 = Unix.gettimeofday () in
111   Printf.eprintf "NEW typing: %3.2f, gc: %3.2f\n%!" (dopo -. prima) (dopo2 -.  dopo);
112   CicEnvironment.invalidate ();
113   Gc.compact ();
114   let prima = Unix.gettimeofday () in
115   List.iter (fun u -> ignore (CicTypeChecker.typecheck u)) alluris;
116   let dopo = Unix.gettimeofday () in
117   Gc.compact ();
118   let dopo2 = Unix.gettimeofday () in
119   Printf.eprintf "OLD typing: %3.2f, gc: %3.2f\n%!" (dopo -. prima) (dopo2 -. dopo)
120 ;;