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