]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matitaSync.ml
More notation here and there.
[helm.git] / helm / matita / matitaSync.ml
index a77c2476101f5546acf3cb2445bb6e54f6921f04..5f1f5b6c29e676ac84cb49ac7595f9df3c9ee7e4 100644 (file)
@@ -29,37 +29,34 @@ open MatitaTypes
 
 let alias_diff ~from status = 
   let module Map = DisambiguateTypes.Environment in
-  Map.fold_flatten
-    (fun domain_item codomain_item acc ->
-       if not (Map.mem domain_item from.aliases) then
-         Map.cons domain_item codomain_item acc
-       else
-         begin
-           try 
-             let codomain1 = Map.find domain_item from.aliases in
-             let codomain2 = Map.find domain_item status.aliases in
-             List.fold_right
-              (fun item env ->
-                let dsc = fst item in
-                if not (List.exists (fun (dsc', _) -> dsc'=dsc) codomain1) then
-                  Map.cons domain_item codomain_item env
-                else
-                  env)
-              codomain2 acc
-           with Not_found -> acc
-         end)
+  Map.fold
+    (fun domain_item (description1,_ as codomain_item) acc ->
+      try
+       let description2,_ = Map.find domain_item from.aliases in
+        if description1 <> description2 then
+          Map.add domain_item codomain_item acc
+        else
+          acc
+      with
+       Not_found ->
+         Map.add domain_item codomain_item acc)
     status.aliases Map.empty
 
+let alias_diff =
+ let profiler = CicUtil.profile "alias_diff (conteggiato anche in include)" in
+ fun ~from status -> profiler.CicUtil.profile (alias_diff ~from) status
+
 let set_proof_aliases status aliases =
  let new_status = { status with aliases = aliases } in
  let diff = alias_diff ~from:status new_status in
- let textual_diff =
-  if DisambiguateTypes.Environment.is_empty diff then
-   ""
-  else
-   DisambiguatePp.pp_environment diff ^ "\n" in
- let moo_content_rev = textual_diff :: status.moo_content_rev in
- {new_status with moo_content_rev = moo_content_rev}
+ let multi_aliases =
+  DisambiguateTypes.Environment.fold DisambiguateTypes.Environment.cons
+   diff status.multi_aliases in
+ let new_status = { new_status with multi_aliases = multi_aliases } in
+ if DisambiguateTypes.Environment.is_empty diff then
+   new_status
+ else
+   add_moo_content (DisambiguatePp.commands_of_environment diff) new_status
   
 (** given a uri and a type list (the contructors types) builds a list of pairs
  *  (name,uri) that is used to generate authomatic aliases **)
@@ -119,17 +116,11 @@ let save_object_to_disk status uri obj =
     MatitaMisc.mkdir dir
   in
   (* generate annobj, ids_to_inner_sorts and ids_to_inner_types *)
-  let annobj,_,_,ids_to_inner_sorts,ids_to_inner_types,_,_ =
-    Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
-  in 
+  let annobj = Cic2acic.plain_acic_object_of_cic_object obj in 
   (* prepare XML *)
   let xml, bodyxml =
-   Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
-    annobj 
-  in
-  let xmlinnertypes =
-   Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
-    ~ask_dtd_to_the_getter:false
+   Cic2Xml.print_object
+    uri ?ids_to_inner_sorts:None ~ask_dtd_to_the_getter:false annobj 
   in
   let xmlpath, xmlbodypath, innertypespath, bodyuri, innertypesuri = 
     paths_and_uris_of_obj uri status 
@@ -138,12 +129,10 @@ let save_object_to_disk status uri obj =
   List.iter MatitaMisc.mkdir
     (List.map Filename.dirname [innertypespath; xmlpath]);
   (* now write to disk *)
-  ensure_path_exists innertypespath;
-  Xml.pp ~gzip:true xmlinnertypes (Some innertypespath);
   ensure_path_exists xmlpath;
   Xml.pp ~gzip:true xml (Some xmlpath) ;
   (* we return a list of uri,path we registered/created *)
-  (uri,xmlpath) :: (innertypesuri,innertypespath) ::
+  (uri,xmlpath) ::
     (* now the optional body, both write and register *)
     (match bodyxml,bodyuri with
        None,None -> []
@@ -153,15 +142,29 @@ let save_object_to_disk status uri obj =
          [bodyuri, xmlbodypath]
      | _-> assert false) 
 
+let typecheck_obj =
+ let profiler = CicUtil.profile "add_obj.typecheck_obj" in
+  fun uri obj -> profiler.CicUtil.profile (CicTypeChecker.typecheck_obj uri) obj
+
+let index_obj =
+ let profiler = CicUtil.profile "add_obj.index_obj" in
+  fun ~dbd ~uri ->
+   profiler.CicUtil.profile (fun uri -> MetadataDb.index_obj ~dbd ~uri) uri
+
+let save_object_to_disk =
+ let profiler = CicUtil.profile "add_obj.save_object_to_disk" in
+  fun status uri obj ->
+   profiler.CicUtil.profile (save_object_to_disk status uri) obj
+
 let add_obj uri obj status =
   let dbd = MatitaDb.instance () in
   let suri = UriManager.string_of_uri uri in
   if CicEnvironment.in_library uri then
     command_error (sprintf "%s already defined" suri)
   else begin
-    CicTypeChecker.typecheck_obj uri obj; (* 1 *)
+    typecheck_obj uri obj; (* 1 *)
     try 
-      MetadataDb.index_obj ~dbd ~uri; (* 2 must be in the env *)
+      index_obj ~dbd ~uri; (* 2 must be in the env *)
       try
         let new_stuff = save_object_to_disk status uri obj in (* 3 *)
         try 
@@ -179,6 +182,10 @@ let add_obj uri obj status =
       CicEnvironment.remove_obj uri; (* -1 *)
       raise exc
   end
+
+let add_obj =
+ let profiler = CicUtil.profile "add_obj" in
+  fun uri obj status -> profiler.CicUtil.profile (add_obj uri obj) status
    
 module OrderedUri =
 struct