2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
15 let ignore_exc = false
16 let rank_all_dependencies = false
17 let trust_environment = false
18 let print_object = false
22 let load_graph, get_graph =
23 let oldg = ref CicUniv.empty_ugraph in
25 let _,g = CicEnvironment.get_obj !oldg uri in
31 let do_indent () = String.make !indent ' ' in
33 | `Start_type_checking s ->
35 prerr_endline (do_indent () ^ "Start: " ^ NUri.string_of_uri s);
37 | `Type_checking_completed s ->
40 prerr_endline (do_indent () ^ "End: " ^ NUri.string_of_uri s)
41 | `Type_checking_interrupted s ->
44 prerr_endline (do_indent () ^ "Break: " ^ NUri.string_of_uri s)
45 | `Type_checking_failed s ->
48 prerr_endline (do_indent () ^ "Fail: " ^ NUri.string_of_uri s)
51 prerr_endline (do_indent () ^ "Trust: " ^ NUri.string_of_uri s))
56 [false, NUri.uri_of_string ("cic:/matita/pts/Type.univ")]
58 [false, NUri.uri_of_string ("cic:/matita/pts/Type"^string_of_int n^".univ")]
62 [false, NUri.uri_of_string ("cic:/matita/pts/CProp.univ")]
64 [false, NUri.uri_of_string ("cic:/matita/pts/CProp"^string_of_int n^".univ")]
70 let do_old_logging = ref true in
71 HelmLogger.register_log_callback
72 (fun ?append_NL html_msg ->
73 if !do_old_logging then
74 prerr_endline (HelmLogger.string_of_html_msg html_msg));
75 CicParser.impredicative_set := false;
76 NCicTypeChecker.set_logger logger;
77 Helm_registry.load_from "conf.xml";
80 let s = Sys.argv.(1) in
81 if s = "-alluris" then
83 let uri_re = Str.regexp ".*\\(ind\\|con\\)$" in
84 let uris = Http_getter.getalluris () in
85 let alluris = List.filter (fun u -> Str.string_match uri_re u 0) uris in
86 let oc = open_out "alluris.txt" in
87 List.iter (fun s -> output_string oc (s^"\n")) alluris;
92 with Invalid_argument _ ->
94 let ic = open_in "alluris.txt" in
95 try while true do r := input_line ic :: !r; done; []
100 (fun u -> try Some (UriManager.uri_of_string u) with _ -> None) alluris
103 prerr_endline "computing graphs to load...";
105 if not rank_all_dependencies then
108 let dbd = HSql.quick_connect (LibraryDb.parse_dbd_conf ()) in
109 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
111 HExtlib.list_uniq (List.sort UriManager.compare l) in
113 uniq (List.map (fun (uri,_) -> UriManager.strip_xpointer uri)
114 (MetadataDeps.inverse_deps ~dbd u)) in
117 List.fold_left (fun (acc,todo) x ->
118 let w = who_uses x in
119 if w = [] then (x::acc,todo) else (acc,uniq (todo@w)))
122 if todo = [] then uniq acc else fix acc todo
126 prerr_endline "generating Coq graphs...";
127 CicEnvironment.set_trust (fun _ -> trust_environment);
130 prerr_endline (" - " ^ UriManager.string_of_uri u);
132 ignore(CicTypeChecker.typecheck u);
134 | CicTypeChecker.AssertFailure s
135 | CicTypeChecker.TypeCheckerFailure s ->
136 prerr_endline (Lazy.force s);
139 prerr_endline "loading...";
142 prerr_endline (" - "^UriManager.string_of_uri u);
143 try load_graph u with exn -> ())
145 prerr_endline "finished....";
146 let lll, uuu =(CicUniv.do_rank (get_graph ())) in
147 let lll = List.sort compare lll in
149 prerr_endline (CicUniv.string_of_universe k ^ " = " ^ string_of_int (CicUniv.get_rank k))) uuu;
152 let rec aux = function
154 NCicEnvironment.add_constraint true (mk_type a) (mk_type b);
155 NCicEnvironment.add_constraint true (mk_cprop a) (mk_cprop b);
156 NCicEnvironment.add_constraint true (mk_cprop a) (mk_type b);
157 NCicEnvironment.add_constraint true (mk_type a) (mk_cprop b);
158 NCicEnvironment.add_constraint false (mk_cprop a) (mk_type a);
159 NCicEnvironment.add_constraint false (mk_type a) (mk_cprop a);
162 NCicEnvironment.add_constraint false (mk_type a) (mk_cprop a);
163 NCicEnvironment.add_constraint false (mk_cprop a) (mk_type a);
167 with NCicEnvironment.BadConstraint s as e ->
168 prerr_endline (Lazy.force s); raise e
170 prerr_endline "ranked....";
171 prerr_endline (NCicEnvironment.pp_constraints ());
173 let [_,type0_uri] = mk_type 0 in
174 let [_,type1_uri] = mk_type 1 in
175 let [_,type2_uri] = mk_type 2 in
178 (match NCicEnvironment.sup [true,type0_uri;true,type2_uri] with
180 | Some t -> NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[]
181 (NCic.Sort (NCic.Type t))));
183 HExtlib.profiling_enabled := false;
185 let uu= OCic2NCic.nuri_of_ouri uu in
187 let o = NCicLibrary.get_obj uu in
188 if print_object then prerr_endline (NCicPp.ppobj o);
190 NCicTypeChecker.typecheck_obj o
192 | NCicTypeChecker.AssertFailure s
193 | NCicTypeChecker.TypeCheckerFailure s
194 | NCicEnvironment.ObjectNotFound s
195 | NCicEnvironment.BadConstraint s
196 | NCicEnvironment.BadDependency (s,_) as e ->
197 prerr_endline ("######### " ^ Lazy.force s);
198 if not ignore_exc then raise e
201 NCicEnvironment.invalidate ();
203 HExtlib.profiling_enabled := true;
204 NCicTypeChecker.set_logger (fun _ -> ());
205 do_old_logging := false;
206 prerr_endline "typechecking, first with the new and then with the old kernel";
209 let u = OCic2NCic.nuri_of_ouri u in
211 match NCicLibrary.get_obj u with
212 | _,_,_,_,NCic.Constant (_,_,Some bo, ty, _) ->
213 let rec intros = function
214 | NCic.Prod (name, s, t) ->
215 let ctx, t = intros t in
216 ctx @ [(name, (NCic.Decl s))] , t
219 let rec perforate ctx metasenv = function
220 | NCic.Appl (NCic.Const (NReference.Ref (u,_))::ty::_)
221 when NUri.string_of_uri u = "cic:/matita/tests/hole.con" ->
222 let metasenv, ty = perforate ctx metasenv ty in
224 NCicMetaSubst.mk_meta metasenv ctx (`WithType ty) in a,b
226 NCicUntrusted.map_term_fold_a
227 (fun e ctx -> e::ctx) ctx perforate metasenv t
229 let rec curryfy ctx = function
230 | NCic.Lambda (name, (NCic.Sort _ as s), tgt) ->
231 NCic.Lambda (name, s, curryfy ((name,NCic.Decl s) :: ctx) tgt)
232 | NCic.Lambda (name, s, tgt) ->
233 let tgt = curryfy ((name,NCic.Decl s) :: ctx) tgt in
234 NCic.Lambda (name, NCic.Implicit `Type, tgt)
237 (fun e ctx -> e::ctx) ctx curryfy t
240 let ctx, pty = intros ty in
241 let metasenv, pty = perforate ctx [] pty in
244 let sty, metasenv, _ =
245 NCicMetaSubst.saturate ~delta:max_int [] ctx ty 0
248 (* let ctx, ty = intros ty in *)
251 match NCicReduction.whd ~delta:max_int ctx pty with
252 | NCic.Appl [eq;t;a;b] -> a, b
260 | NCic.Appl [eq;t;a;b] ->
261 NCic.Appl [eq;t;NCicReduction.whd ~delta:0 ctx a;b]
262 | t -> NCicReduction.whd ~delta:0 ctx t
267 (Printf.sprintf "%s == %s"
268 (NCicPp.ppterm ~metasenv:metasenv ~subst:[] ~context:ctx ity)
269 (NCicPp.ppterm ~metasenv:metasenv ~subst:[] ~context:ctx sty));
271 prerr_endline ("start: " ^ NUri.string_of_uri u);
272 let bo = curryfy [] bo in
274 let metasenv, subst, bo, infty =
276 ~look_for_coercion:(fun _ _ _ _ _ -> [])
277 NCicUnifHint.empty_db [] [] [] bo None
279 let metasenv, subst =
281 NCicUnification.unify NCicUnifHint.empty_db metasenv subst [] infty ty
283 | NCicUnification.Uncertain msg
284 | NCicUnification.UnificationFailure msg
285 | NCicMetaSubst.MetaSubstFailure msg ->
286 prerr_endline (Lazy.force msg);
288 | Sys.Break -> metasenv, subst
290 if (NCicReduction.are_convertible ~metasenv ~subst [] infty ty)
292 prerr_endline ("OK: " ^ NUri.string_of_uri u)
299 prerr_endline ("FAIL: " ^ NUri.string_of_uri u);
302 ("\t\tRESULT OF UNIF\n\nsubst:\n%s\nmetasenv:\n%s\n" ^^
303 "context:\n%s\nTERMS NO SUBST:\n%s\n==\n%s\n"^^
304 "TERMS:\n%s\n==\n%s\n")
305 (NCicPp.ppsubst ~metasenv subst)
306 (NCicPp.ppmetasenv ~subst metasenv)
307 (NCicPp.ppcontext ~metasenv ~subst ctx)
308 (NCicPp.ppterm ~metasenv ~subst:[] ~context:ctx left)
309 (NCicPp.ppterm ~metasenv ~subst:[] ~context:ctx right)
310 (NCicPp.ppterm ~metasenv ~subst ~context:ctx left)
311 (NCicPp.ppterm ~metasenv ~subst ~context:ctx right) ))
313 NCicTypeChecker.typeof ~subst:[] ~metasenv:[] [] bo
317 | NCicRefiner.RefineFailure msg
318 | NCicRefiner.Uncertain msg ->
319 let _, msg = Lazy.force msg in
321 prerr_endline ("FAIL: " ^ NUri.string_of_uri u)
323 prerr_endline (Printexc.to_string e);
324 prerr_endline ("FAIL: " ^ NUri.string_of_uri u)