X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fcic_proof_checking%2FcicTypeChecker.ml;h=cd742d4cdff80a1e7baf25b6d122542265b34c3c;hb=f553eb12e42b11d37dbf1ae3f8ceb859a875df98;hp=611585400c69251e86d8b34b5ee8a67b1121e70d;hpb=aa055bebbc6cd0e99df64020b7f6e26eb19e569a;p=helm.git diff --git a/helm/ocaml/cic_proof_checking/cicTypeChecker.ml b/helm/ocaml/cic_proof_checking/cicTypeChecker.ml index 611585400..cd742d4cd 100644 --- a/helm/ocaml/cic_proof_checking/cicTypeChecker.ml +++ b/helm/ocaml/cic_proof_checking/cicTypeChecker.ml @@ -23,6 +23,8 @@ * http://cs.unibo.it/helm/. *) +(* $Id$ *) + (* TODO factorize functions to frequent errors (e.g. "Unknwon mutual inductive * ...") *) @@ -52,10 +54,11 @@ let rec split l n = raise (TypeCheckerFailure (lazy "Parameters number < left parameters number")) ;; -let debrujin_constructor uri number_of_types = - let rec aux k = +let debrujin_constructor ?(cb=fun _ _ -> ()) uri number_of_types = + let rec aux k t = let module C = Cic in - function + let res = + match t with C.Rel n as t when n <= k -> t | C.Rel _ -> raise (TypeCheckerFailure (lazy "unbound variable found in constructor type")) @@ -66,7 +69,7 @@ let debrujin_constructor uri number_of_types = C.Var (uri,exp_named_subst') | C.Meta (i,l) -> let l' = List.map (function None -> None | Some t -> Some (aux k t)) l in - C.Meta (i,l) + C.Meta (i,l') | C.Sort _ | C.Implicit _ as t -> t | C.Cast (te,ty) -> C.Cast (aux k te, aux k ty) @@ -114,6 +117,9 @@ let debrujin_constructor uri number_of_types = fl in C.CoFix (i, liftedfl) + in + cb t res; + res in aux 0 ;; @@ -545,7 +551,7 @@ and typecheck_mutual_inductive_defs ~logger uri (itl,_,indparamsno) ugraph = ugraph' ) ugraph cl in (i + 1),ugraph'' - ) itl (1,ugraph) + ) itl (1,ugrap1) in ugraph2 @@ -1126,11 +1132,10 @@ and guarded_by_constructors ~subst context n nn h te args coInductiveTypeURI = | C.Lambda _ | C.LetIn _ -> raise (AssertFailure (lazy "25"))(* due to type-checking *) - | C.Appl ((C.MutInd (uri,_,_))::_) as ty - when uri == coInductiveTypeURI -> + | C.Appl ((C.MutInd (uri,_,_))::_) when uri == coInductiveTypeURI -> guarded_by_constructors ~subst context n nn true te [] coInductiveTypeURI - | C.Appl ((C.MutInd (uri,_,_))::_) as ty -> + | C.Appl ((C.MutInd (uri,_,_))::_) -> guarded_by_constructors ~subst context n nn true te tl coInductiveTypeURI | C.Appl _ -> @@ -1308,7 +1313,7 @@ and check_allowed_sort_elimination ~subst ~metasenv ~logger context uri i let itl_len = List.length itl in let (name,_,ty,cl) = List.nth itl i in let cl_len = List.length cl in - if (itl_len = 1 && cl_len <= 1) then + if (cl_len = 0 || (itl_len = 1 && cl_len = 1)) then let non_informative,ugraph = if cl_len = 0 then true,ugraph else @@ -1319,12 +1324,7 @@ and check_allowed_sort_elimination ~subst ~metasenv ~logger context uri i definition? *) non_informative, ugraph else - let is_empty = - List.fold_left - (fun b (_,_,_,cl) -> b && List.length cl = 0) true itl - in - (* is it a block of mutual inductive empty definitions? *) - is_empty,ugraph + false,ugraph | _ -> raise (TypeCheckerFailure (lazy ("Unknown mutual inductive definition:" ^ @@ -1692,8 +1692,7 @@ and type_of_aux' ~logger ?(subst = []) metasenv context t ugraph = (lazy (sprintf ("Case analysys: analysed term type is %s (%s#1/%d{_}), but is expected to be (an application of) %s#1/%d{_}") (CicPp.ppterm typ) (U.string_of_uri uri') i' (U.string_of_uri uri) i))) - | C.Appl - ((C.MutInd (uri',i',exp_named_subst) as typ):: tl) as typ' -> + | C.Appl ((C.MutInd (uri',i',exp_named_subst) as typ):: tl) -> if U.eq uri uri' && i = i' then let params,args = split tl (List.length tl - k)