]> matita.cs.unibo.it Git - helm.git/commitdiff
New style debugging/profiling for NCicMetaSubst.
authorClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Fri, 30 Oct 2009 10:21:00 +0000 (10:21 +0000)
committerClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Fri, 30 Oct 2009 10:21:00 +0000 (10:21 +0000)
helm/software/components/ng_refiner/nCicMetaSubst.ml
helm/software/components/ng_refiner/nCicMetaSubst.mli
helm/software/matita/matita.ml

index 6deaaf572b7914f9ad3edba29b1a937b4bc1a711..b69984f3d5c2c15a0e6d761529c2cd69fe935c04 100644 (file)
 
 (* $Id$ *)
 
+let debug = ref false;;
+let indent = ref "";;
+let times = ref [];;
+let pp s =
+ if !debug then
+  prerr_endline (Printf.sprintf "%-20s" !indent ^ " " ^ Lazy.force s)
+;;
+let inside c =
+ if !debug then
+  begin
+   let time1 = Unix.gettimeofday () in
+   indent := !indent ^ String.make 1 c;
+   times := time1 :: !times;
+   prerr_endline ("{{{" ^ !indent ^ " ")
+  end
+;;
+let outside exc_opt =
+ if !debug then
+  begin
+   let time2 = Unix.gettimeofday () in
+   let time1 =
+    match !times with time1::tl -> times := tl; time1 | [] -> assert false in
+   prerr_endline ("}}} " ^ string_of_float (time2 -. time1));
+   (match exc_opt with
+   | Some e ->  prerr_endline ("exception raised: " ^ Printexc.to_string e)
+   | None -> ());
+   try
+    indent := String.sub !indent 0 (String.length !indent -1)
+   with
+    Invalid_argument _ -> indent := "??"; ()
+  end
+;;
+
 exception MetaSubstFailure of string Lazy.t
 exception Uncertain of string Lazy.t
 
@@ -255,6 +288,7 @@ exception Found;;
    otherwise the occur check does not make sense in case of unification
    of ?n with ?n *)
 let delift ~unify metasenv subst context n l t =
+  (*D*)  inside 'D'; try let rc =  
   let is_in_scope_meta subst = function
     | NCic.Meta (i,_) ->
         (try 
@@ -407,15 +441,12 @@ let delift ~unify metasenv subst context n l t =
                         | NotInTheList | MetaSubstFailure _ -> ms, j::tbr, tl
                   in
                   let (metasenv, subst), to_be_r, lc1' = deliftl [] 1 ms lc1 in
-(*
-                  prerr_endline ("TO BE RESTRICTED: " ^ 
-                   (String.concat "," (List.map string_of_int to_be_r)));
-*)
+                  pp (lazy ("TO BE RESTRICTED: " ^ 
+                   (String.concat "," (List.map string_of_int to_be_r))));
                   let l1 = pack_lc (0, NCic.Ctx lc1') in
-(*
-                  prerr_endline ("newmeta:" ^ NCicPp.ppterm
-                   ~metasenv ~subst ~context (NCic.Meta (999,l1)));
-*)
+                  pp (lazy ("newmeta:" ^ NCicPp.ppterm
+                   ~metasenv ~subst ~context (NCic.Meta (999,l1))));
+                  pp (lazy (NCicPp.ppmetasenv ~subst metasenv));
                   if to_be_r = [] then
                     (metasenv, subst), 
                     (if lc1' = lc1 then orig else NCic.Meta (i,l1))
@@ -459,6 +490,7 @@ let delift ~unify metasenv subst context n l t =
         raise (Uncertain msg)
        else
         raise (MetaSubstFailure msg)
+ (*D*)  in outside None; rc with exn -> outside (Some exn); raise exn 
 ;;
 
 let mk_meta ?(attrs=[]) metasenv context ?with_type kind = 
index 0cedc5258db577288cc0e1be10173c9229b1dd97..94a77f287e40b76d21f141e46a012f000da9f255 100644 (file)
@@ -14,6 +14,8 @@
 exception MetaSubstFailure of string Lazy.t
 exception Uncertain of string Lazy.t
 
+val debug: bool ref
+
 (* the index of the last created meta *)
 val maxmeta: unit -> int
 
index 9699bdaa2fd21b14d0120b4cea19540e28afd4e4..4fdc704e220a8593610a18635bf9f72a37304e23 100644 (file)
@@ -213,9 +213,9 @@ let _ =
       (fun mi () -> NTacStatus.debug := mi#active);
     addDebugCheckbox "auto logging"
       (fun mi () -> NAuto.debug := mi#active);
-    addDebugCheckbox "disambiguation/refiner/unification logging"
+    addDebugCheckbox "disambiguation/refiner/unification/metasubst logging"
       (fun mi () -> NCicRefiner.debug := mi#active; NCicUnification.debug :=
-              mi#active; MultiPassDisambiguator.debug := mi#active);
+              mi#active; MultiPassDisambiguator.debug := mi#active; NCicMetaSubst.debug := mi#active);
     addDebugCheckbox "reduction logging"
       (fun mi () -> NCicReduction.debug := mi#active; CicReduction.ndebug := mi#active);
     addDebugSeparator ();