]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_refiner/nCicRefiner.ml
First attempt to implement unification hints.
[helm.git] / helm / software / components / ng_refiner / nCicRefiner.ml
index c8f6bdb59eb763e99cc03d7875804e6c412452f8..d47767528a79801a84763e2537236d9e7b12bfe7 100644 (file)
@@ -49,7 +49,7 @@ let exp_implicit metasenv context expty =
 ;;
 
 
-let check_allowed_sort_elimination localise r orig =
+let check_allowed_sort_elimination hdb localise r orig =
    let mkapp he arg =
      match he with
      | C.Appl l -> C.Appl (l @ [arg])
@@ -67,7 +67,7 @@ let check_allowed_sort_elimination localise r orig =
           NCicMetaSubst.mk_meta metasenv ((name,C.Decl so1)::context) `Type 
         in
         let metasenv, subst = 
-          try NCicUnification.unify metasenv subst context 
+          try NCicUnification.unify hdb metasenv subst context 
                 arity2 (C.Prod (name, so1, meta)) 
           with exc -> raise (wrap_exc (lazy (localise orig, Printf.sprintf
             "expected %s, found %s" (* XXX localizzare meglio *)
@@ -79,7 +79,7 @@ let check_allowed_sort_elimination localise r orig =
      | C.Sort _ (* , t ==?== C.Prod _ *) ->
         let metasenv, meta, _ = NCicMetaSubst.mk_meta metasenv [] `Type in
         let metasenv, subst = 
-          try NCicUnification.unify metasenv subst context 
+          try NCicUnification.unify hdb metasenv subst context 
                 arity2 (C.Prod ("_", ind, meta)) 
           with exc -> raise (wrap_exc (lazy (localise orig, Printf.sprintf
             "expected %s, found %s" (* XXX localizzare meglio *)
@@ -97,7 +97,7 @@ let check_allowed_sort_elimination localise r orig =
     aux
 ;;
 
-let rec typeof 
+let rec typeof hdb 
   ?(localise=fun _ -> Stdpp.dummy_loc) 
   ~look_for_coercion metasenv subst context term expty 
 =
@@ -114,11 +114,11 @@ let rec typeof
           (NCicPp.ppterm ~metasenv ~subst ~context expty)));
            try 
              let metasenv, subst =
-               NCicUnification.unify metasenv subst context infty expty 
+               NCicUnification.unify hdb metasenv subst context infty expty 
              in
              metasenv, subst, t, expty
            with exc -> 
-             try_coercions ~look_for_coercion ~localise 
+             try_coercions hdb ~look_for_coercion ~localise 
                metasenv subst context t orig infty expty true exc)
     | None -> metasenv, subst, t, infty
     (*D*)in outside(); rc with exc -> outside (); raise exc
@@ -165,12 +165,12 @@ let rec typeof
     | C.Prod (name,(s as orig_s),(t as orig_t)) ->
        let metasenv, subst, s, s1 = typeof_aux metasenv subst context None s in
        let metasenv, subst, s, s1 = 
-         force_to_sort ~look_for_coercion
+         force_to_sort hdb ~look_for_coercion
            metasenv subst context s orig_s localise s1 in
        let context1 = (name,(C.Decl s))::context in
        let metasenv, subst, t, s2 = typeof_aux metasenv subst context1 None t in
        let metasenv, subst, t, s2 = 
-         force_to_sort ~look_for_coercion
+         force_to_sort hdb ~look_for_coercion
            metasenv subst context1 t orig_t localise s2 in
        let metasenv, subst, s, t, ty = 
          sort_of_prod localise metasenv subst 
@@ -189,12 +189,12 @@ let rec typeof
        let metasenv, subst, s, ty_s = 
          typeof_aux metasenv subst context None s in
        let metasenv, subst, s, _ = 
-         force_to_sort ~look_for_coercion
+         force_to_sort hdb ~look_for_coercion
            metasenv subst context s orig_s localise ty_s in
        let (metasenv,subst), exp_ty_t = 
          match exp_s with 
          | Some exp_s -> 
-             (try NCicUnification.unify metasenv subst context s exp_s,exp_ty_t
+             (try NCicUnification.unify hdb metasenv subst context s exp_s,exp_ty_t
              with exc -> raise (wrap_exc (lazy (localise orig_s, Printf.sprintf
                "Source type %s was expected to be %s" (NCicPp.ppterm ~metasenv
                ~subst ~context s) (NCicPp.ppterm ~metasenv ~subst ~context
@@ -210,7 +210,7 @@ let rec typeof
        let metasenv, subst, ty, ty_ty = 
          typeof_aux metasenv subst context None ty in
        let metasenv, subst, ty, _ = 
-         force_to_sort ~look_for_coercion
+         force_to_sort hdb ~look_for_coercion
            metasenv subst context ty orig_ty localise ty_ty in
        let metasenv, subst, t, _ = 
          typeof_aux metasenv subst context (Some ty) t in
@@ -223,7 +223,7 @@ let rec typeof
     | C.Appl ((he as orig_he)::(_::_ as args)) ->
        let metasenv, subst, he, ty_he = 
          typeof_aux metasenv subst context None he in
-       eat_prods ~localise ~look_for_coercion 
+       eat_prods hdb ~localise ~look_for_coercion 
          metasenv subst context orig_he he ty_he args
    | C.Appl _ -> raise (AssertFailure (lazy "Appl of length < 2"))
    | C.Match (Ref.Ref (_,Ref.Ind (_,tyno,_)) as r,
@@ -246,7 +246,7 @@ let rec typeof
       let metasenv, subst, ind, ind_ty = 
         typeof_aux metasenv subst context None ind in
       let metasenv, subst = 
-         check_allowed_sort_elimination localise r orig_term metasenv subst 
+         check_allowed_sort_elimination hdb localise r orig_term metasenv subst 
            context ind ind_ty outsort 
       in
       (* let's check if the type of branches are right *)
@@ -288,7 +288,7 @@ let rec typeof
   in
     typeof_aux metasenv subst context expty term
 
-and try_coercions 
+and try_coercions hdb 
   ~localise ~look_for_coercion 
   metasenv subst context t orig_t infty expty perform_unification exc 
 =
@@ -310,7 +310,7 @@ and try_coercions
             NCicPp.ppterm ~metasenv ~subst ~context meta ^  " === " ^
             NCicPp.ppterm ~metasenv ~subst ~context t ^ "\n"));
         let metasenv, subst = 
-          NCicUnification.unify metasenv subst context meta t
+          NCicUnification.unify hdb metasenv subst context meta t
         in
           pp (lazy ( "UNIFICATION in CTX:\n"^ 
             NCicPp.ppcontext ~metasenv ~subst context
@@ -321,7 +321,7 @@ and try_coercions
             NCicPp.ppterm ~metasenv ~subst ~context expty ^ "\n"));
         let metasenv, subst = 
           if perform_unification then
-            NCicUnification.unify metasenv subst context newtype expty
+            NCicUnification.unify hdb metasenv subst context newtype expty
           else metasenv, subst
         in
         metasenv, subst, newterm, newtype
@@ -332,7 +332,7 @@ and try_coercions
     first exc
       (look_for_coercion metasenv subst context infty expty)
 
-and force_to_sort 
+and force_to_sort hdb 
   ~look_for_coercion metasenv subst context t orig_t localise ty 
 =
   match NCicReduction.whd ~subst context ty with
@@ -350,7 +350,7 @@ and force_to_sort
      metasenv, subst, t, C.Meta (newmeta,(0,C.Irl 0))
   | C.Sort _ as ty -> metasenv, subst, t, ty 
   | ty -> 
-      try_coercions ~localise ~look_for_coercion metasenv subst context
+      try_coercions hdb ~localise ~look_for_coercion metasenv subst context
         t orig_t ty (NCic.Sort (NCic.Type NCicEnvironment.type0)) false 
          (Uncertain (lazy (localise orig_t, 
          "The type of " ^ NCicPp.ppterm ~metasenv ~subst ~context t
@@ -378,7 +378,7 @@ and sort_of_prod
          (NCicPp.ppterm ~subst ~metasenv ~context y) 
          (NCicPp.ppterm ~subst ~metasenv ~context x))))
 
-and eat_prods 
+and eat_prods hdb
   ~localise ~look_for_coercion metasenv subst context orig_he he ty_he args 
 =
   (*D*)inside 'E'; try let rc = 
@@ -388,14 +388,14 @@ and eat_prods
       match NCicReduction.whd ~subst context ty_he with 
       | C.Prod (_,s,t) ->
           let metasenv, subst, arg, _ = 
-            typeof ~look_for_coercion ~localise 
+            typeof hdb ~look_for_coercion ~localise 
               metasenv subst context arg (Some s) in
           let t = NCicSubstitution.subst ~avoid_beta_redexes:true arg t in
           aux metasenv subst (arg :: args_so_far) he t tl
       | C.Meta _
       | C.Appl (C.Meta _ :: _) as t ->
           let metasenv, subst, arg, ty_arg = 
-            typeof ~look_for_coercion ~localise 
+            typeof hdb ~look_for_coercion ~localise 
               metasenv subst context arg None in
           let metasenv, meta, _ = 
             NCicMetaSubst.mk_meta metasenv 
@@ -404,7 +404,7 @@ and eat_prods
           let flex_prod = C.Prod ("_", ty_arg, meta) in
           (* next line grants that ty_args is a type *)
           let metasenv,subst, flex_prod, _ =
-           typeof ~look_for_coercion ~localise metasenv subst
+           typeof hdb ~look_for_coercion ~localise metasenv subst
             context flex_prod None in
           pp (lazy ( "UNIFICATION in CTX:\n"^ 
             NCicPp.ppcontext ~metasenv ~subst context
@@ -412,7 +412,7 @@ and eat_prods
             NCicPp.ppterm ~metasenv ~subst ~context t ^  " === " ^
             NCicPp.ppterm ~metasenv ~subst ~context flex_prod ^ "\n"));
           let metasenv, subst = 
-             try NCicUnification.unify metasenv subst context t flex_prod 
+             try NCicUnification.unify hdb metasenv subst context t flex_prod 
              with exc -> raise (wrap_exc (lazy (localise orig_he, Printf.sprintf
               ("The term %s has an inferred type %s, but is applied to the" ^^
                " argument %s of type %s")
@@ -433,7 +433,7 @@ and eat_prods
             (List.length args) (List.length args_so_far))))
       | ty ->
           let metasenv, subst, newhead, newheadty = 
-            try_coercions ~localise ~look_for_coercion metasenv subst context
+            try_coercions hdb ~localise ~look_for_coercion metasenv subst context
               (NCicUntrusted.mk_appl he (List.rev args_so_far)) orig_he ty
               (NCic.Prod ("_",NCic.Implicit `Term,NCic.Implicit `Term))
               false