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