Skip to content

Commit 1184a40

Browse files
authored
Merge pull request #3780 from BuckleScript/tweak_beltId
Tweak codegen to merge if branches
2 parents 7c4225c + 6103685 commit 1184a40

15 files changed

+1972
-2288
lines changed

jscomp/core/js_stmt_make.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,16 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
213213
let common_prefix_blocks = ref [] in
214214
let add_prefix b = common_prefix_blocks := b :: !common_prefix_blocks in
215215
let rec aux ?comment (e : J.expression) (ifso : J.block) (ifnot : J.block ): t =
216-
match e.expression_desc with
217-
| Bool boolean ->
216+
match e.expression_desc,ifnot with
217+
| Bool boolean, _ ->
218218
block (if boolean then ifso else ifnot)
219-
| Js_not pred_not
219+
| Js_not pred_not, (_::_)
220220
-> aux ?comment pred_not ifnot ifso
221221
| _ ->
222222
match ifso, ifnot with
223223
| [], [] -> exp e
224224
| [], _ ->
225-
{
226-
statement_desc = If ( E.not e, ifnot, []); comment
227-
}
225+
aux ?comment (E.not e) ifnot [] (*Make sure no infinite loop*)
228226
| [ {statement_desc = Return {return_value = ret_ifso; _}; _}],
229227
[ {statement_desc = Return {return_value = ret_ifnot; _}; _} as _ifnot_stmt]
230228
->

jscomp/others/belt_Id.ml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ module MakeComparableU (M : sig
4949
end) =
5050
struct
5151
type identity
52-
type t = M.t
53-
let cmp = M.cmp
52+
include M
5453
end
5554

5655
module MakeComparable (M : sig
@@ -69,11 +68,11 @@ let comparableU
6968
(type key)
7069
~cmp
7170
=
72-
let module N = MakeComparableU(struct
71+
(module MakeComparableU(struct
7372
type t = key
7473
let cmp = cmp
75-
end) in
76-
(module N : Comparable with type t = key)
74+
end)
75+
: Comparable with type t = key)
7776

7877
let comparable
7978
(type key)
@@ -101,9 +100,7 @@ module MakeHashableU (M : sig
101100
end) =
102101
struct
103102
type identity
104-
type t = M.t
105-
let hash = M.hash
106-
let eq = M.eq
103+
include M
107104
end
108105

109106
module MakeHashable (M : sig
@@ -121,12 +118,11 @@ struct
121118
end
122119

123120
let hashableU (type key) ~hash ~eq =
124-
let module N = MakeHashableU(struct
125-
type t = key
126-
let hash = hash
127-
let eq = eq
128-
end) in
129-
(module N : Hashable with type t = key)
121+
(module MakeHashableU(struct
122+
type t = key
123+
let hash = hash
124+
let eq = eq
125+
end) : Hashable with type t = key)
130126

131127
let hashable (type key) ~hash ~eq =
132128
let module N = MakeHashable(struct

0 commit comments

Comments
 (0)