+ pp (lazy(string_of_int n ^ " := 222 = "^
+ ppterm ~metasenv ~subst ~context:cc t^ppmetasenv ~subst metasenv));
+ (* Unifying the types may have already instantiated n. *)
+ try
+ let _, _,oldt,_ = NCicUtils.lookup_subst n subst in
+ let oldt = NCicSubstitution.subst_meta lc oldt in
+ let t = NCicSubstitution.subst_meta lc t in
+ (* conjecture: always fail --> occur check *)
+ unify rdb test_eq_only metasenv subst context t oldt false
+ with NCicUtils.Subst_not_found _ ->
+ move_to_subst n (attrs,cc,t,ty) metasenv subst
+ in
+ let attrs,cc,ty = NCicUtils.lookup_meta n metasenv in
+ let kind = NCicUntrusted.kind_of_meta attrs in
+ let metasenv,t = fix metasenv subst swap test_eq_only exc t in
+ let ty_t = NCicTypeChecker.typeof ~metasenv ~subst context t in
+ let metasenv,subst,t =
+ match kind with
+ `IsSort -> sortfy exc metasenv subst context t
+ | `IsType -> tipify exc metasenv subst context t ty_t
+ | `IsTerm -> metasenv,subst,t in
+ match kind with
+ | `IsSort ->
+ (match ty,t with
+ NCic.Implicit (`Typeof _), NCic.Sort _ ->
+ move_to_subst n (attrs,cc,t,ty_t) metasenv subst
+ | NCic.Sort (NCic.Type u1), NCic.Sort s ->
+ let s =
+ match s,swap with
+ NCic.Type u2, false ->
+ NCic.Sort (NCic.Type
+ (unopt exc (NCicEnvironment.inf ~strict:false
+ (unopt exc (NCicEnvironment.inf ~strict:true u1) @ u2))))
+ | NCic.Type u2, true ->
+ if NCicEnvironment.universe_lt u2 u1 then
+ NCic.Sort (NCic.Type u2)
+ else (raise exc)
+ | NCic.Prop,_ -> NCic.Sort NCic.Prop
+ in
+ move_to_subst n (attrs,cc,s,ty) metasenv subst
+ | NCic.Implicit (`Typeof _), NCic.Meta _ ->
+ move_to_subst n (attrs,cc,t,ty_t) metasenv subst
+ | _, NCic.Meta _
+ | NCic.Meta _, NCic.Sort _ ->
+ pp (lazy ("On the types: " ^
+ ppterm ~metasenv ~subst ~context ty ^ "=<=" ^
+ ppterm ~metasenv ~subst ~context ty_t));
+ let metasenv, subst =
+ unify rdb false metasenv subst context ty_t ty false in
+ delift_to_subst test_eq_only n lc (attrs,cc,ty) t
+ context metasenv subst
+ | _ -> assert false)
+ | `IsType
+ | `IsTerm ->
+ (match ty with
+ NCic.Implicit (`Typeof _) ->
+ let (metasenv, subst), ty_t =
+ try
+ NCicMetaSubst.delift
+ ~unify:(fun m s c t1 t2 ->
+ let ind = !indent in
+ let res = try Some (unify rdb test_eq_only m s c t1 t2 false )
+ with UnificationFailure _ | Uncertain _ -> None
+ in
+ indent := ind; res)
+ metasenv subst context n lc ty_t
+ with NCicMetaSubst.Uncertain msg ->
+ pp (lazy ("delift is uncertain: " ^ Lazy.force msg));
+ raise (Uncertain msg)
+ | NCicMetaSubst.MetaSubstFailure msg ->
+ pp (lazy ("delift fails: " ^ Lazy.force msg));
+ raise (UnificationFailure msg)
+ in
+ delift_to_subst test_eq_only n lc (attrs,cc,ty_t) t context metasenv
+ subst
+ | _ ->
+ let lty = NCicSubstitution.subst_meta lc ty in
+ pp (lazy ("On the types: " ^
+ ppterm ~metasenv ~subst ~context ty_t ^ "=<=" ^
+ ppterm ~metasenv ~subst ~context lty));
+ let metasenv, subst =
+ unify rdb false metasenv subst context ty_t lty false
+ in
+ delift_to_subst test_eq_only n lc (attrs,cc,ty) t context metasenv
+ subst)
+ (*D*) in outside None; rc with exn -> outside (Some exn); raise exn