aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/extraction/mlutil.ml19
-rw-r--r--plugins/subtac/subtac_cases.ml2
2 files changed, 19 insertions, 2 deletions
diff --git a/plugins/extraction/mlutil.ml b/plugins/extraction/mlutil.ml
index 03b62f8364..d8b7d364f1 100644
--- a/plugins/extraction/mlutil.ml
+++ b/plugins/extraction/mlutil.ml
@@ -799,6 +799,23 @@ let is_atomic = function
let is_imm_apply = function MLapp (MLrel 1, _) -> true | _ -> false
+(** Program creates a let-in named "program_branch_NN" for each branch of match.
+ Unfolding them leads to more natural code (and more dummy removal) *)
+
+let is_program_branch = function
+ | Id id ->
+ let s = string_of_id id in
+ let br = "program_branch_" in
+ let n = String.length br in
+ (try
+ ignore (int_of_string (String.sub s n (String.length s - n)));
+ String.sub s 0 n = br
+ with _ -> false)
+ | Tmp _ | Dummy -> false
+
+let expand_linear_let o id e =
+ o.opt_lin_let || is_tmp id || is_program_branch id || is_imm_apply e
+
(*S The main simplification function. *)
(* Some beta-iota reductions + simplifications. *)
@@ -815,7 +832,7 @@ let rec simpl o = function
if
(is_atomic c) || (is_atomic e) ||
(let n = nb_occur_match e in
- (n = 0 || (n=1 && (is_tmp id || is_imm_apply e || o.opt_lin_let))))
+ (n = 0 || (n=1 && expand_linear_let o id e)))
then
simpl o (ast_subst c e)
else
diff --git a/plugins/subtac/subtac_cases.ml b/plugins/subtac/subtac_cases.ml
index 4f8344745e..cd4400f186 100644
--- a/plugins/subtac/subtac_cases.ml
+++ b/plugins/subtac/subtac_cases.ml
@@ -1738,7 +1738,7 @@ let constrs_of_pats typing_fun env isevars eqns tomatchs sign neqs arity =
let j = typing_fun (mk_tycon tycon) rhs_env eqn.rhs.it in
let bbody = it_mkLambda_or_LetIn j.uj_val rhs_rels'
and btype = it_mkProd_or_LetIn j.uj_type rhs_rels' in
- let branch_name = id_of_string ("branch_" ^ (string_of_int !i)) in
+ let branch_name = id_of_string ("program_branch_" ^ (string_of_int !i)) in
let branch_decl = (Name branch_name, Some (lift !i bbody), (lift !i btype)) in
let branch =
let bref = GVar (dummy_loc, branch_name) in