aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--engine/termops.ml2
-rw-r--r--pretyping/detyping.ml13
2 files changed, 13 insertions, 2 deletions
diff --git a/engine/termops.ml b/engine/termops.ml
index cf7c0cc20..2bd0c06d6 100644
--- a/engine/termops.ml
+++ b/engine/termops.ml
@@ -994,12 +994,14 @@ let rec strip_outer_cast sigma c = match EConstr.kind sigma c with
(* flattens application lists throwing casts in-between *)
let collapse_appl sigma c = match EConstr.kind sigma c with
| App (f,cl) ->
+ if EConstr.isCast sigma f then
let rec collapse_rec f cl2 =
match EConstr.kind sigma (strip_outer_cast sigma f) with
| App (g,cl1) -> collapse_rec g (Array.append cl1 cl2)
| _ -> EConstr.mkApp (f,cl2)
in
collapse_rec f cl
+ else c
| _ -> c
(* First utilities for avoiding telescope computation for subst_term *)
diff --git a/pretyping/detyping.ml b/pretyping/detyping.ml
index cac411183..a27debe73 100644
--- a/pretyping/detyping.ml
+++ b/pretyping/detyping.ml
@@ -475,8 +475,8 @@ let rec detype flags avoid env sigma t = CAst.make @@
GApp (f',args''@args')
| _ -> GApp (f',args')
in
- mkapp (detype flags avoid env sigma f)
- (Array.map_to_list (detype flags avoid env sigma) args)
+ mkapp (detype flags avoid env sigma f)
+ (detype_array flags avoid env sigma args)
| Const (sp,u) -> GRef (ConstRef sp, detype_instance sigma u)
| Proj (p,c) ->
let noparams () =
@@ -694,6 +694,15 @@ and detype_binder (lax,isgoal as flags) bk avoid env sigma na body ty c =
let t = if s != InProp && not !Flags.raw_print then None else Some (detype (lax,false) avoid env sigma ty) in
GLetIn (na', c, t, r)
+(** We use a dedicated function here to prevent overallocation from
+ Array.map_to_list. *)
+and detype_array flags avoid env sigma args =
+ let ans = ref [] in
+ for i = Array.length args - 1 downto 0 do
+ ans := detype flags avoid env sigma args.(i) :: !ans;
+ done;
+ !ans
+
let detype_rel_context ?(lax=false) where avoid env sigma sign =
let where = Option.map (fun c -> EConstr.it_mkLambda_or_LetIn c sign) where in
let rec aux avoid env = function