]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_omdoc/doubleTypeInference.ml
A few modifications, here and there...
[helm.git] / helm / ocaml / cic_omdoc / doubleTypeInference.ml
index f51c00c74dc3271d861a2d7ab0b9a65313b75baf..8880ff3f4d1dadb43a035a18bbb9a804cad43a64 100644 (file)
@@ -31,6 +31,7 @@ exception WrongUriToMutualInductiveDefinitions of string;;
 exception ListTooShort;;
 exception RelToHiddenHypothesis;;
 
+let syntactic_equality_add_time = ref 0.0;;
 let type_of_aux'_add_time = ref 0.0;;
 let number_new_type_of_aux'_double_work = ref 0;;
 let number_new_type_of_aux' = ref 0;;
@@ -244,6 +245,15 @@ let syntactic_equality t t' =
    _ -> false
 ;;
 
+let xxx_syntactic_equality t t' =
+ let t1 = Sys.time () in
+ let res = syntactic_equality t t' in
+ let t2 = Sys.time () in
+ syntactic_equality_add_time := !syntactic_equality_add_time +. t2 -. t1 ;
+ res
+;;
+
+
 let rec split l n =
  match (l,n) with
     (l,0) -> ([], l)
@@ -407,7 +417,7 @@ let rec type_of_aux' subterms_to_types metasenv context t expectedty =
          sort_of_prod context (name,s) (sort1,sort2)
      | C.Lambda (n,s,t) ->
         (* Let's visit all the subterms that will not be visited later *)
-        let _ = type_of_aux context s None in
+         let _ = type_of_aux context s None in 
          let expected_target_type =
           match expectedty with
              None -> None
@@ -419,7 +429,7 @@ let rec type_of_aux' subterms_to_types metasenv context t expectedty =
                 | _ -> assert false
               in
                Some ty
-         in
+         in 
           let type2 =
            type_of_aux ((Some (n,(C.Decl s)))::context) t expected_target_type
           in
@@ -433,7 +443,7 @@ let rec type_of_aux' subterms_to_types metasenv context t expectedty =
          let t_typ =
           (* Checks suppressed *)
           type_of_aux ((Some (n,(C.Def (s,Some ty))))::context) t None
-         in
+         in  (* CicSubstitution.subst s t_typ *)
           if does_not_occur 1 t_typ then
            (* since [Rel 1] does not occur in typ, substituting any term *)
            (* in place of [Rel 1] is equivalent to delifting once        *)
@@ -441,13 +451,25 @@ let rec type_of_aux' subterms_to_types metasenv context t expectedty =
           else
            C.LetIn (n,s,t_typ)
      | C.Appl (he::tl) when List.length tl > 0 ->
+        (* 
         let expected_hetype =
          (* Inefficient, the head is computed twice. But I know *)
-         (* of no other solution.                               *)
+         (* of no other solution. *)                               
          (head_beta_reduce
           (R.whd context (xxx_type_of_aux' metasenv context he)))
-        in
-         let hetype = type_of_aux context he (Some expected_hetype) in
+        in 
+         let hetype = type_of_aux context he (Some expected_hetype) in 
+         let tlbody_and_type =
+          let rec aux =
+           function
+              _,[] -> []
+            | C.Prod (n,s,t),he::tl ->
+               (he, type_of_aux context he (Some (head_beta_reduce s)))::
+                (aux (R.whd context (S.subst he t), tl))
+            | _ -> assert false
+          in
+           aux (expected_hetype, tl) *)
+         let hetype = R.whd context (type_of_aux context he None) in 
          let tlbody_and_type =
           let rec aux =
            function
@@ -457,7 +479,7 @@ let rec type_of_aux' subterms_to_types metasenv context t expectedty =
                 (aux (R.whd context (S.subst he t), tl))
             | _ -> assert false
           in
-           aux (expected_hetype, tl)
+           aux (hetype, tl)
          in
           eat_prods context hetype tlbody_and_type
      | C.Appl _ -> raise (NotWellTyped "Appl: no arguments")
@@ -602,7 +624,7 @@ let rec type_of_aux' subterms_to_types metasenv context t expectedty =
          None ->
           (* No expected type *)
           {synthesized = synthesized' ; expected = None}, synthesized
-       | Some ty when syntactic_equality synthesized' ty ->
+       | Some ty when xxx_syntactic_equality synthesized' ty ->
           (* The expected type is synthactically equal to *)
           (* the synthesized type. Let's forget it.       *)
           {synthesized = synthesized' ; expected = None}, synthesized