X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fng_kernel%2FnCicReduction.ml;h=236f5778e86394317930eababfede4aaedc8fb3e;hb=ccf5878f2a2ec7f952f140e162391708a740517b;hp=e1e5bc7cb566d45fa4fa6a15c3b3aeb222a362b3;hpb=56d3455abc6bcffd9d0e2af3ed370bf0751057a0;p=helm.git diff --git a/helm/software/components/ng_kernel/nCicReduction.ml b/helm/software/components/ng_kernel/nCicReduction.ml index e1e5bc7cb..236f5778e 100644 --- a/helm/software/components/ng_kernel/nCicReduction.ml +++ b/helm/software/components/ng_kernel/nCicReduction.ml @@ -17,6 +17,9 @@ module E = NCicEnvironment exception AssertFailure of string Lazy.t;; +let debug = ref false;; +let pp m = if !debug then prerr_endline (Lazy.force m) else ();; + module type Strategy = sig type stack_term type env_term @@ -58,7 +61,7 @@ module CallByValueByNameForUnwind' : Strategy = struct lazy (fst (reduce ~delta:0 c)), (fun delta -> fst (reduce ~delta c)), lazy (unwind c) - let from_stack ~delta (c0,c,_) = if delta = 0 then Lazy.force c0 else c delta + let from_stack ~delta (c0,c,_) = if delta = 0 then Lazy.force c0 else c delta let from_stack_list_for_unwind ~unwind:_ l = List.map (fun (_,_,c) -> Lazy.force c) l let from_env ~delta (c0,c,_) = if delta = 0 then Lazy.force c0 else c delta @@ -141,46 +144,32 @@ module Reduction(RS : Strategy) = struct (Ref.Decl|Ref.Ind _|Ref.Con _|Ref.CoFix _))), _) as config -> config, true | (_, _, (C.Const (Ref.Ref - (_,Ref.Fix (fixno,recindex,height)) as refer) as head),s) as config -> - (match - try - let recarg = RS.from_stack ~delta:max_int (List.nth s recindex) in - let fixes,(_,_,pragma),_ = + (_,Ref.Fix (fixno,recindex,height)) as refer)),s) as config -> + (let arg = try Some (List.nth s recindex) with Failure _ -> None in + match arg with + None -> config, true + | Some arg -> + let fixes,(_,_,pragma),_ = NCicEnvironment.get_checked_fixes_or_cofixes refer in - Some (recarg, fixes, pragma) - with Failure _ -> None - with - | None -> config, true - | Some((_,_,C.Const(Ref.Ref(_,Ref.Con _)),_::_ as c),fs,`Projection) -> - let new_s = - replace recindex s (RS.compute_to_stack ~reduce:(reduce ~subst - context) ~unwind c) - in - let _,_,_,_,body = List.nth fs fixno in - aux (0, [], body, new_s) - | Some (recparam, fixes, pragma) -> - match reduce ~delta:0 ~subst context recparam with - | (_,_,C.Const (Ref.Ref (_,Ref.Con _)), _) as c, _ - when delta >= height -> - let new_s = - (* FIXME, we should push on the stack - * c for CBV and recparam for CBN *) - if pragma = `Projection then - replace recindex s (RS.compute_to_stack ~reduce:(reduce ~subst - context) ~unwind recparam) - else - replace recindex s (RS.compute_to_stack ~reduce:(reduce ~subst - context) ~unwind c) - in - (0, [], head, new_s), false - | (_,_,C.Const (Ref.Ref (_,Ref.Con _)), _) as c, _ -> - let new_s = - replace recindex s (RS.compute_to_stack ~reduce:(reduce ~subst - context) ~unwind c) - in - let _,_,_,_,body = List.nth fixes fixno in - aux (0, [], body, new_s) - | _ -> config, true) + if delta >= height then + match pragma with + | `Projection -> + (match RS.from_stack ~delta:max_int arg with + | _,_,C.Const(Ref.Ref(_,Ref.Con _)),_::_ -> + let _,_,_,_,body = List.nth fixes fixno in + aux (0, [], body, s) + | _ -> config,false) + | _ -> config,false + else + match RS.from_stack ~delta:0 arg with + | (_,_,C.Const (Ref.Ref (_,Ref.Con _)), _) as c -> + let new_s = + replace recindex s + (RS.compute_to_stack ~reduce:(reduce ~subst context) + ~unwind c) in + let _,_,_,_,body = List.nth fixes fixno in + aux (0, [], body, new_s) + | _ -> config, true) | (k, e, C.Match (_,_,term,pl),s) as config -> let decofix = function | (_,_,C.Const(Ref.Ref(_,Ref.CoFix c)as refer),s)-> @@ -280,12 +269,14 @@ let alpha_eq ~test_lambda_source aux test_eq_only metasenv subst context t1 t2 = when (Ref.eq r1 r2 && List.length (E.get_relevance r1) >= List.length tl1) -> let relevance = E.get_relevance r1 in +(* if the types were convertible the following optimization is sound let relevance = match r1 with | Ref.Ref (_,Ref.Con (_,_,lno)) -> let _,relevance = HExtlib.split_nth lno relevance in HExtlib.mk_list false lno @ relevance | _ -> relevance in +*) (try HExtlib.list_forall_default3_var (fun t1 t2 b -> not b || aux true context t1 t2 ) @@ -442,6 +433,7 @@ type machine = int * environment_item list * NCic.term * stack_item list let reduce_machine = R.reduce let from_stack = RS.from_stack +let from_env = RS.from_env let unwind = R.unwind let _ =