Skip to content

Commit 09ee5e4

Browse files
committed
Fix issue with pattern matching empty list which interferes with boolean optimisations.
The pattern matching case for empty list `switch x { | list{} =>` used to compile to `if(x)`, which interferes with boolean optimisation. Now it compiles to `if(x ==0)` which is the same output as for `if(x == list{})`. Fixes #7235
1 parent feb85f2 commit 09ee5e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+727
-660
lines changed

compiler/ml/matching.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,8 @@ let combine_constructor sw_names loc arg ex_pat cstr partial ctx def
22452245
let arg =
22462246
if Datarepr.constructor_has_optional_shape cstr then
22472247
Lprim (Pis_not_none, [arg], loc)
2248-
else arg
2248+
else
2249+
Lprim (Pjscomp Cneq, [arg; Lconst (Const_base (Const_int 0))], loc)
22492250
in
22502251
Lifthenelse (arg, act2, act1)
22512252
| 2, 0, [(i1, act1); (_, act2)], []

0 commit comments

Comments
 (0)