Skip to content

Commit 76c6273

Browse files
committed
better pattern match code generation, fix #4924
1 parent e492e89 commit 76c6273

18 files changed

+811
-958
lines changed

jscomp/core/lam.ml

+18
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,24 @@ let if_ (a : t) (b : t) (c : t) : t =
773773
{ body with sw_failaction = Some b; sw_consts_full = false; })
774774
| _ -> Lifthenelse(a,b,c)
775775
end
776+
| Lprim{primitive = Pisint; args = [Lvar i];_}
777+
->
778+
begin match b with
779+
| Lifthenelse(Lprim{primitive = Pintcomp Ceq ; args = [Lvar j; Lconst _]} , _, b_f)
780+
when Ident.same i j && eq_approx b_f c ->
781+
b
782+
| Lprim{primitive = Pintcomp Ceq ; args = [Lvar j; Lconst _]}
783+
when Ident.same i j && eq_approx false_ c -> b
784+
| Lifthenelse(Lprim({primitive = Pintcomp Cneq ; args = [Lvar j; Lconst _]} as b_pred) , b_t, b_f)
785+
when Ident.same i j && eq_approx b_t c ->
786+
Lifthenelse(Lprim{b_pred with primitive = Pintcomp Ceq}, b_f, b_t)
787+
| Lprim({primitive = Pintcomp Cneq ; args = [Lvar j; Lconst _] as args ; loc} )
788+
| Lprim(
789+
{primitive = Pnot ; args = [Lprim{primitive = Pintcomp Ceq ; args = [Lvar j; Lconst _] as args; loc}]})
790+
when Ident.same i j && eq_approx true_ c
791+
-> Lprim{primitive = Pintcomp Ceq; args; loc}
792+
| _ -> Lifthenelse(a,b,c)
793+
end
776794
| _ -> Lifthenelse (a,b,c))
777795

778796

jscomp/test/build.ninja

+1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ o test/gpr_4494_test.cmi test/gpr_4494_test.cmj : cc test/gpr_4494_test.ml | $st
333333
o test/gpr_4519_test.cmi test/gpr_4519_test.cmj : cc test/gpr_4519_test.ml | test/mt.cmj $stdlib
334334
o test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.ml | test/mt.cmj $stdlib
335335
o test/gpr_4639_test.cmi test/gpr_4639_test.cmj : cc test/gpr_4639_test.ml | $stdlib
336+
o test/gpr_4924_test.cmi test/gpr_4924_test.cmj : cc test/gpr_4924_test.ml | $stdlib
336337
o test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib
337338
o test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.ml | $stdlib
338339
o test/gpr_858_test.cmi test/gpr_858_test.cmj : cc test/gpr_858_test.ml | $stdlib

0 commit comments

Comments
 (0)