Skip to content

Commit f39a4a6

Browse files
mshinwellpoechsel
authored andcommitted
Ensure that Lifthenelse has a boolean-valued condition (#63)
1 parent 0d8a593 commit f39a4a6

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

lambda/matching.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,9 +2744,10 @@ let combine_constructor loc arg pat_env cstr partial ctx def
27442744
match
27452745
(cstr.cstr_consts, cstr.cstr_nonconsts, consts, nonconsts)
27462746
with
2747-
| 1, 1, [ (0, act1) ], [ (0, act2) ] ->
2747+
| 1, 1, [ (0, act1) ], [ (0, act2) ]
2748+
when not (Clflags.is_flambda2 ()) ->
27482749
(* Typically, match on lists, will avoid isint primitive in that
2749-
case *)
2750+
case *)
27502751
Lifthenelse (arg, act2, act1)
27512752
| n, 0, _, [] ->
27522753
(* The type defines constant constructors only *)

lambda/simplif.ml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,22 @@ and list_emit_tail_infos is_tail =
706706
let split_default_wrapper ~id:fun_id ~kind ~params ~return ~body ~attr ~loc =
707707
let rec aux map = function
708708
| Llet(Strict, k, id, (Lifthenelse(Lvar optparam, _, _) as def), rest) when
709-
Ident.name optparam = "*opt*" && List.mem_assoc optparam params
709+
(not (Clflags.is_flambda2 ()))
710+
&& Ident.name optparam = "*opt*" && List.mem_assoc optparam params
711+
&& not (List.mem_assoc optparam map)
712+
->
713+
let wrapper_body, inner = aux ((optparam, id) :: map) rest in
714+
Llet(Strict, k, id, def, wrapper_body), inner
715+
| Llet(Strict, k, id,
716+
(Lswitch(Lvar optparam,
717+
{sw_numconsts = 1;
718+
sw_consts = [_];
719+
sw_numblocks = 1;
720+
sw_blocks = [_];
721+
sw_failaction = None}, _dbg)
722+
as def), rest) when
723+
Clflags.is_flambda2 ()
724+
&& Ident.name optparam = "*opt*" && List.mem_assoc optparam params
710725
&& not (List.mem_assoc optparam map)
711726
->
712727
let wrapper_body, inner = aux ((optparam, id) :: map) rest in

lambda/switch.ml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ let prerr_inter i = Printf.fprintf stderr
187187
and get_low cases i =
188188
let r,_,_ = cases.(i) in
189189
r
190+
and get_high cases i =
191+
let _,r,_ = cases.(i) in
192+
r
190193

191194
type ctests = {
192195
mutable n : int ;
@@ -660,9 +663,14 @@ let rec pkey chan = function
660663
and right = {s with cases=right} in
661664

662665
if i=1 && (lim+ctx.off)=1 && get_low cases 0+ctx.off=0 then
663-
Arg.make_if
664-
ctx.arg
665-
(c_test ctx right) (c_test ctx left)
666+
if lcases = 2 && get_high cases 1+ctx.off = 1 then
667+
Arg.make_if
668+
ctx.arg
669+
(c_test ctx right) (c_test ctx left)
670+
else
671+
make_if_ne
672+
ctx.arg 0
673+
(c_test ctx right) (c_test ctx left)
666674
else if less_tests cright cleft then
667675
make_if_lt
668676
ctx.arg (lim+ctx.off)

0 commit comments

Comments
 (0)