]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_omdoc/doubleTypeInference.ml
Universes introduction
[helm.git] / helm / ocaml / cic_omdoc / doubleTypeInference.ml
index 8880ff3f4d1dadb43a035a18bbb9a804cad43a64..441d7c9a938425a573c15f7236308f189e2be165 100644 (file)
@@ -58,7 +58,7 @@ let rec does_not_occur n =
    | C.Rel _
    | C.Meta _
    | C.Sort _
-   | C.Implicit -> true 
+   | C.Implicit -> true 
    | C.Cast (te,ty) ->
       does_not_occur n te && does_not_occur n ty
    | C.Prod (name,so,dest) ->
@@ -123,7 +123,7 @@ let rec head_beta_reduce =
          (function None -> None | Some t -> Some (head_beta_reduce t)) l
        )
     | C.Sort _ as t -> t
-    | C.Implicit -> assert false
+    | C.Implicit -> assert false
     | C.Cast (te,ty) ->
        C.Cast (head_beta_reduce te, head_beta_reduce ty)
     | C.Prod (n,s,t) ->
@@ -403,8 +403,14 @@ let rec type_of_aux' subterms_to_types metasenv context t expectedty =
            in
             (* Checks suppressed *)
             CicSubstitution.lift_meta l ty
-     | C.Sort s -> C.Sort C.Type (*CSC manca la gestione degli universi!!! *)
-     | C.Implicit -> raise (Impossible 21)
+     | C.Sort (C.Type t) -> (* TASSI: CONSTRAINT *)
+        let t' = CicUniv.fresh() in
+        if not (CicUniv.add_gt t' t ) then
+         assert false (* t' is fresh! an error in CicUniv *)
+       else
+          C.Sort (C.Type t')
+     | C.Sort _ -> C.Sort (C.Type (CicUniv.fresh())) (* TASSI: CONSTRAINT *)
+     | C.Implicit _ -> raise (Impossible 21)
      | C.Cast (te,ty) ->
         (* Let's visit all the subterms that will not be visited later *)
         let _ = type_of_aux context te (Some (head_beta_reduce ty)) in
@@ -447,7 +453,7 @@ let rec type_of_aux' subterms_to_types metasenv context t expectedty =
           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        *)
-           CicSubstitution.subst C.Implicit t_typ
+           CicSubstitution.subst (C.Implicit None) t_typ
           else
            C.LetIn (n,s,t_typ)
      | C.Appl (he::tl) when List.length tl > 0 ->
@@ -668,10 +674,23 @@ let rec type_of_aux' subterms_to_types metasenv context t expectedty =
    let t1' = CicReduction.whd context t1 in
    let t2' = CicReduction.whd ((Some (name,C.Decl s))::context) t2 in
    match (t1', t2') with
-      (C.Sort s1, C.Sort s2)
-        when (s2 = C.Prop or s2 = C.Set or s2 = C.CProp) -> (* different from Coq manual!!! *)
+      (C.Sort _, C.Sort s2)
+        when (s2 = C.Prop or s2 = C.Set or s2 = C.CProp) -> 
+        (* different from Coq manual!!! *)
          C.Sort s2
-    | (C.Sort s1, C.Sort s2) -> C.Sort C.Type (*CSC manca la gestione degli universi!!! *)
+    | (C.Sort (C.Type t1), C.Sort (C.Type t2)) -> 
+       (* TASSI: CONSRTAINTS: the same in cictypechecker,cicrefine *)
+       let t' = CicUniv.fresh() in
+       if not (CicUniv.add_ge t' t1) || not (CicUniv.add_ge t' t2) then
+         assert false ; (* not possible, error in CicUniv *)
+       C.Sort (C.Type t')
+    | (C.Sort _,C.Sort (C.Type t1)) -> 
+        (* TASSI: CONSRTAINTS: the same in cictypechecker,cicrefine *)
+       C.Sort (C.Type t1) (* c'e' bisogno di un fresh? *)
+    | (C.Meta _, C.Sort _) -> t2'
+    | (C.Meta _, (C.Meta (_,_) as t))
+    | (C.Sort _, (C.Meta (_,_) as t)) when CicUtil.is_closed t ->
+        t2'
     | (_,_) ->
       raise
        (NotWellTyped