X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Facic_procedural%2FproceduralOptimizer.ml;h=6910613d29b3b2d2bf778b751e1ce0b268339277;hb=ef05c795559108c1d33cfa048531849807867a81;hp=52192f723de1f0181a3f0cb1474307de068dc025;hpb=04c05cf08605156ba8c6fa7225b4a90496c03698;p=helm.git diff --git a/helm/software/components/acic_procedural/proceduralOptimizer.ml b/helm/software/components/acic_procedural/proceduralOptimizer.ml index 52192f723..6910613d2 100644 --- a/helm/software/components/acic_procedural/proceduralOptimizer.ml +++ b/helm/software/components/acic_procedural/proceduralOptimizer.ml @@ -35,6 +35,7 @@ module PEH = ProofEngineHelpers module TC = CicTypeChecker module Un = CicUniv module L = Librarian +module Ut = CicUtil module H = ProceduralHelpers module Cl = ProceduralClassify @@ -45,6 +46,8 @@ let debug = ref false (* term optimization ********************************************************) +let critical = ref true + type status = { dummy: unit; info: string @@ -67,8 +70,8 @@ let clear_absts m = aux 0 (pred n) (S.lift (-1) t) | t when n > 0 -> Printf.eprintf "PO.clear_absts: %u %s\n" n (Pp.ppterm t); - assert false - | t -> t + assert false + | t -> t in aux m @@ -176,7 +179,7 @@ and opt_appl g st es c t vs = in if es then H.list_fold_right_cps g map vs (st, []) else g (st, vs) -and opt_mutcase g st es c uri tyno outty arg cases = +and opt_mutcase_critical g st es c uri tyno outty arg cases = let eliminator = H.get_default_eliminator c uri tyno outty in let lpsno, (_, _, _, constructors) = H.get_ind_type uri tyno in let ps, sort_disp = H.get_ind_parameters c arg in @@ -205,6 +208,19 @@ and opt_mutcase g st es c uri tyno outty arg cases = let x = H.refine c (C.Appl args) in opt_proof g (info st "Optimizer: remove 3") es c x +and opt_mutcase_plain g st es c uri tyno outty arg cases = + let g st v = + let g (st, ts) = g st (C.MutCase (uri, tyno, outty, v, ts)) in + let map h v (st, vs) = + let h st vv = h (st, vv :: vs) in opt_proof h st es c v + in + if es then H.list_fold_right_cps g map cases (st, []) else g (st, cases) + in + if es then opt_proof g st es c arg else g st arg + +and opt_mutcase g = + if !critical then opt_mutcase_critical g else opt_mutcase_plain g + and opt_cast g st es c t w = let g st t = g (info st "Optimizer: remove 4") t in if es then opt_proof g st es c t else g st t @@ -237,23 +253,24 @@ let wrap g st c bo = let optimize_obj = function | C.Constant (name, Some bo, ty, pars, attrs) -> + let count_nodes = I.count_nodes ~meta:false 0 in let st, c = {info = ""; dummy = ()}, [] in let bo, ty = H.cic_bc c bo, H.cic_bc c ty in let g st bo = if !debug then begin Printf.eprintf "Optimized : %s\n" (Pp.ppterm bo); - prerr_string "H.pp_term : "; - H.pp_term prerr_string [] c bo; prerr_newline () + prerr_string "Ut.pp_term : "; + Ut.pp_term prerr_string [] c bo; prerr_newline () end; (* let _ = H.get_type "opt" [] (C.Cast (bo, ty)) in *) - let nodes = Printf.sprintf "Optimized nodes: %u" (I.count_nodes 0 bo) in + let nodes = Printf.sprintf "Optimized nodes: %u" (count_nodes bo) in let st = info st nodes in L.time_stamp ("PO: DONE " ^ name); C.Constant (name, Some bo, ty, pars, attrs), st.info in L.time_stamp ("PO: OPTIMIZING " ^ name); if !debug then Printf.eprintf "BEGIN: %s\n" name; - let nodes = Printf.sprintf "Initial nodes: %u" (I.count_nodes 0 bo) in + let nodes = Printf.sprintf "Initial nodes: %u" (count_nodes bo) in wrap g (info st nodes) c bo | obj -> obj, ""