let optimize_obj = function
| C.Constant (name, Some bo, ty, pars, attrs) ->
+ let count_nodes = I.count_nodes ~implicit: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 =
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, ""
| T.Elim _ :: _ -> assert false
| T.Cut _ :: _ -> assert false
-and xls frm ls =
- let map l = F.fprintf frm "{%a}" xl l in
- List.iter map (List.rev ls)
+and xls frm = function
+ | [] -> F.fprintf frm "{}"
+ | ls ->
+ let map l = F.fprintf frm "{%a}" xl l in
+ List.iter map (List.rev ls)
in
F.fprintf frm "%a@\n" xl l
and count_steps a = List.fold_left count_step a
+let count = I.count_nodes ~implicit:false
+
let rec count_node a = function
| Note _
| Inductive _
| ClearBody _ -> a
| Cut (_, t, _)
| LetIn (_, t, _)
- | Apply (t, _) -> I.count_nodes a (H.cic t)
+ | Apply (t, _) -> count a (H.cic t)
| Rewrite (_, t, _, p, _)
| Elim (t, _, p, _)
| Cases (t, p, _)
- | Change (t, _, _, p, _) ->
- let a = I.count_nodes a (H.cic t) in
- I.count_nodes a (H.cic p)
+ | Change (t, _, _, p, _) -> let a = count a (H.cic t) in count a (H.cic p)
| Branch (ss, _) -> List.fold_left count_nodes a ss
and count_nodes a = List.fold_left count_node a
let g a = a in
aux g t S.empty
-let rec aux n = function
- | C.Sort _
- | C.Implicit _
- | C.Rel _ -> succ n
- | C.Appl ts -> List.fold_left aux (succ n) ts
- | C.Const (_, ss)
- | C.MutConstruct (_, _, _, ss)
- | C.MutInd (_, _, ss)
- | C.Var (_, ss) ->
- let map n (_, t) = aux n t in
- List.fold_left map (succ n) ss
- | C.Meta (_, ss) ->
- let map n = function
- | None -> n
- | Some t -> aux n t
- in
- List.fold_left map (succ n) ss
- | C.Cast (t1, t2)
- | C.Lambda (_, t1, t2)
- | C.Prod (_, t1, t2) -> aux (aux (succ n) t2) t1
- | C.LetIn (_, t1, ty, t2) -> aux (aux (aux (succ n) t2) ty) t1
- | C.MutCase (_, _, t1, t2, ss) ->
- aux (aux (List.fold_left aux (succ n) ss) t2) t1
- | C.Fix (_, ss) ->
- let map n (_, _, t1, t2) = aux (aux n t2) t1 in
- List.fold_left map (succ n) ss
- | C.CoFix (_, ss) ->
- let map n (_, t1, t2) = aux (aux n t2) t1 in
- List.fold_left map (succ n) ss
-
-let count_nodes = aux
+let count_nodes ~implicit n t =
+ let rec aux n = function
+ | C.Implicit _ -> if implicit then succ n else n
+ | C.Sort _
+ | C.Rel _ -> succ n
+ | C.Appl ts -> List.fold_left aux (succ n) ts
+ | C.Const (_, ss)
+ | C.MutConstruct (_, _, _, ss)
+ | C.MutInd (_, _, ss)
+ | C.Var (_, ss) ->
+ let map n (_, t) = aux n t in
+ List.fold_left map (succ n) ss
+ | C.Meta (_, ss) ->
+ let map n = function
+ | None -> n
+ | Some t -> aux n t
+ in
+ List.fold_left map (succ n) ss
+ | C.Cast (t1, t2)
+ | C.Lambda (_, t1, t2)
+ | C.Prod (_, t1, t2) -> aux (aux (succ n) t2) t1
+ | C.LetIn (_, t1, ty, t2) -> aux (aux (aux (succ n) t2) ty) t1
+ | C.MutCase (_, _, t1, t2, ss) ->
+ aux (aux (List.fold_left aux (succ n) ss) t2) t1
+ | C.Fix (_, ss) ->
+ let map n (_, _, t1, t2) = aux (aux n t2) t1 in
+ List.fold_left map (succ n) ss
+ | C.CoFix (_, ss) ->
+ let map n (_, t1, t2) = aux (aux n t2) t1 in
+ List.fold_left map (succ n) ss
+in
+aux n t
val get_mutinds_of_uri: UriManager.uri -> Cic.term -> S.t
(* count_nodes n t returns n + the number of nodes in t *)
-val count_nodes: int -> Cic.term -> int
+(* Cic.Implict nodes are counted if ~implicit:true *)
+val count_nodes: implicit:bool -> int -> Cic.term -> int