Skip to content

Commit 7afe0d3

Browse files
committed
clean up
1 parent 6a6e047 commit 7afe0d3

File tree

8 files changed

+77
-71
lines changed

8 files changed

+77
-71
lines changed

jscomp/others/belt_internalAVLset.ml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let rec copy n =
5656
match toOpt n with
5757
| None -> n
5858
| Some n ->
59-
let l,r = left n, right n in
59+
let l,r = n |. (left , right) in
6060
return @@ node
6161
~left:(copy l) ~right:(copy r)
6262
~value:(value n) ~height:(height n)
@@ -86,23 +86,23 @@ let bal l v r =
8686
let hl = match toOpt l with None -> 0 | Some n -> height n in
8787
let hr = match toOpt r with None -> 0 | Some n -> height n in
8888
if hl > hr + 2 then begin
89-
let n = unsafeCoerce l in (* [l] could not be empty *)
90-
let ll,lv,lr = left n, value n, right n in
89+
(* [l] could not be empty *)
90+
let ll,lv,lr = l |. unsafeCoerce |. (left , value , right) in
9191
if heightGe ll lr then
9292
create ll lv (create lr v r)
9393
else begin
94-
let n = unsafeCoerce lr in (* [lr] could not be empty*)
95-
let lrl, lrv, lrr = left n, value n, right n in
94+
(* [lr] could not be empty*)
95+
let lrl, lrv, lrr = lr |. unsafeCoerce |. (left , value , right) in
9696
create (create ll lv lrl) lrv (create lrr v r)
9797
end
9898
end else if hr > hl + 2 then begin
99-
let n = unsafeCoerce r in (* [r] could not be empty *)
100-
let rl,rv,rr = left n, value n, right n in
99+
(* [r] could not be empty *)
100+
let rl,rv,rr = r |. unsafeCoerce |. (left , value , right) in
101101
if heightGe rr rl then
102102
create (create l v rl) rv rr
103103
else begin
104-
let n = unsafeCoerce rl in (* [rl] could not be empty *)
105-
let rll, rlv, rlr = left n, value n, right n in
104+
(* [rl] could not be empty *)
105+
let rll, rlv, rlr = rl |. unsafeCoerce |. (left , value , right) in
106106
create (create l v rll) rlv (create rlr rv rr)
107107
end
108108
end else
@@ -142,7 +142,7 @@ let maxUndefined n =
142142
| Some n -> Js.Undefined.return (max0Aux n)
143143

144144
let rec removeMinAuxWithRef n v =
145-
let ln, rn, kn = left n, right n, value n in
145+
let ln, rn, kn = n |. (left , right , value) in
146146
match toOpt ln with
147147
| None -> v:= kn ; rn
148148
| Some ln -> bal (removeMinAuxWithRef ln v) kn rn
@@ -186,8 +186,8 @@ let rec everyU n p =
186186
| None -> true
187187
| Some n ->
188188
p (value n) [@bs] &&
189-
everyU (left n) p &&
190-
everyU (right n) p
189+
n |. left |. everyU p &&
190+
n |. right |. everyU p
191191

192192
let every n p = everyU n (fun [@bs] a -> p a )
193193

@@ -196,8 +196,8 @@ let rec someU n p =
196196
| None -> false
197197
| Some n ->
198198
p (value n) [@bs] ||
199-
someU (left n) p ||
200-
someU (right n) p
199+
n |. left |. someU p ||
200+
n |. right |. someU p
201201

202202
let some n p = someU n (fun[@bs] a -> p a )
203203
(* [addMinElement v n] and [addMaxElement v n]
@@ -281,16 +281,17 @@ let size n =
281281
| Some n ->
282282
lengthNode n
283283

284-
let rec toListAux accu n =
284+
let rec toListAux n accu =
285285
match toOpt n with
286286
| None -> accu
287287
| Some n ->
288288
toListAux
289-
((value n) :: toListAux accu (right n))
290289
(left n)
290+
((value n) :: toListAux (right n) accu)
291+
291292

292293
let toList s =
293-
toListAux [] s
294+
toListAux s []
294295

295296
let rec checkInvariantInternal (v : _ t) =
296297
match toOpt v with

jscomp/others/belt_internalAVLtree.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ let rec mapU n f =
185185
None ->
186186
empty
187187
| Some n ->
188-
let newLeft = mapU (left n) f in
188+
let newLeft = n |. left |. mapU f in
189189
let newD = f (value n) [@bs] in
190-
let newRight = mapU (right n) f in
190+
let newRight = n |. right |. mapU f in
191191
return @@ node ~left:newLeft ~key:(key n) ~value:newD ~right:newRight ~height:(height n)
192192

193193
let map n f = mapU n (fun[@bs] a -> f a)
@@ -198,9 +198,9 @@ let rec mapWithKeyU n f =
198198
empty
199199
| Some n ->
200200
let key = key n in
201-
let newLeft = mapWithKeyU (left n) f in
201+
let newLeft = n |. left |. mapWithKeyU f in
202202
let newD = f key (value n) [@bs] in
203-
let newRight = mapWithKeyU (right n) f in
203+
let newRight = n |. right |. mapWithKeyU f in
204204
return @@ node ~left:newLeft ~key ~value:newD ~right:newRight ~height:(height n)
205205

206206
let mapWithKey n f = mapWithKeyU n (fun [@bs] a b -> f a b)
@@ -349,14 +349,15 @@ let size n =
349349
| Some n ->
350350
lengthNode n
351351

352-
let rec toListAux accu n =
352+
let rec toListAux n accu =
353353
match toOpt n with
354354
| None -> accu
355355
| Some n ->
356-
toListAux ((key n, value n) :: toListAux accu (right n)) (left n)
356+
let l, r , k, v = n |. (left, right, key, value ) in
357+
l |. toListAux ((k, v) :: ( r |. toListAux accu ))
357358

358359
let toList s =
359-
toListAux [] s
360+
toListAux s []
360361

361362

362363
let rec checkInvariantInternal (v : _ t) =
@@ -371,7 +372,7 @@ let rec checkInvariantInternal (v : _ t) =
371372

372373

373374
let rec fillArrayKey n i arr =
374-
let l,v,r = left n, key n, right n in
375+
let l,v,r = n |. (left, key, right) in
375376
let next =
376377
match toOpt l with
377378
| None -> i

jscomp/syntax/ast_exp_apply.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ let handle_exp_apply
7474
| [ "", obj_arg ;
7575
"", fn
7676
] ->
77-
let obj_arg = self.expr self obj_arg in
77+
let new_obj_arg = self.expr self obj_arg in
7878
begin match fn with
7979
| {pexp_desc = Pexp_apply (fn, args); pexp_loc; pexp_attributes} ->
8080
let fn = self.expr self fn in
8181
let args = Ext_list.map (fun (lab,exp) -> lab, self.expr self exp ) args in
8282
Bs_ast_invariant.warn_unused_attributes pexp_attributes;
83-
{ pexp_desc = Pexp_apply(fn, ("", obj_arg) :: args);
83+
{ pexp_desc = Pexp_apply(fn, ("", new_obj_arg) :: args);
8484
pexp_attributes = [];
8585
pexp_loc = pexp_loc}
8686
| _ ->
8787
let try_dispatch_by_tuple =
88-
Ast_tuple_pattern_flatten.map_open_tuple fn (fun xs attrs ->
89-
bound obj_arg @@ fun obj_arg ->
88+
Ast_tuple_pattern_flatten.map_open_tuple fn (fun xs tuple_attrs ->
89+
bound new_obj_arg @@ fun bounded_obj_arg ->
9090
{
9191
pexp_desc =
9292
Pexp_tuple (
@@ -97,22 +97,22 @@ let handle_exp_apply
9797
let fn = self.expr self fn in
9898
let args = Ext_list.map (fun (lab,exp) -> lab, self.expr self exp ) args in
9999
Bs_ast_invariant.warn_unused_attributes pexp_attributes;
100-
{ Parsetree.pexp_desc = Pexp_apply(fn, ("", obj_arg) :: args);
100+
{ Parsetree.pexp_desc = Pexp_apply(fn, ("", bounded_obj_arg) :: args);
101101
pexp_attributes = [];
102102
pexp_loc = pexp_loc}
103103
| _ ->
104104
Exp.apply ~loc:fn.pexp_loc
105105
(self.expr self fn )
106-
["", obj_arg]
106+
["", bounded_obj_arg]
107107
) xs );
108-
pexp_attributes = attrs;
108+
pexp_attributes = tuple_attrs;
109109
pexp_loc = fn.pexp_loc;
110110
}
111111
) in
112112
begin match try_dispatch_by_tuple with
113113
| Some x -> x
114114
| None ->
115-
Exp.apply ~loc (self.expr self fn) ["", obj_arg]
115+
Exp.apply ~loc (self.expr self fn) ["", new_obj_arg]
116116
end
117117
end
118118
| _ ->

lib/bsdep.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36152,19 +36152,19 @@ let handle_exp_apply
3615236152
| [ "", obj_arg ;
3615336153
"", fn
3615436154
] ->
36155-
let obj_arg = self.expr self obj_arg in
36155+
let new_obj_arg = self.expr self obj_arg in
3615636156
begin match fn with
3615736157
| {pexp_desc = Pexp_apply (fn, args); pexp_loc; pexp_attributes} ->
3615836158
let fn = self.expr self fn in
3615936159
let args = Ext_list.map (fun (lab,exp) -> lab, self.expr self exp ) args in
3616036160
Bs_ast_invariant.warn_unused_attributes pexp_attributes;
36161-
{ pexp_desc = Pexp_apply(fn, ("", obj_arg) :: args);
36161+
{ pexp_desc = Pexp_apply(fn, ("", new_obj_arg) :: args);
3616236162
pexp_attributes = [];
3616336163
pexp_loc = pexp_loc}
3616436164
| _ ->
3616536165
let try_dispatch_by_tuple =
36166-
Ast_tuple_pattern_flatten.map_open_tuple fn (fun xs attrs ->
36167-
bound obj_arg @@ fun obj_arg ->
36166+
Ast_tuple_pattern_flatten.map_open_tuple fn (fun xs tuple_attrs ->
36167+
bound new_obj_arg @@ fun bounded_obj_arg ->
3616836168
{
3616936169
pexp_desc =
3617036170
Pexp_tuple (
@@ -36175,22 +36175,22 @@ let handle_exp_apply
3617536175
let fn = self.expr self fn in
3617636176
let args = Ext_list.map (fun (lab,exp) -> lab, self.expr self exp ) args in
3617736177
Bs_ast_invariant.warn_unused_attributes pexp_attributes;
36178-
{ Parsetree.pexp_desc = Pexp_apply(fn, ("", obj_arg) :: args);
36178+
{ Parsetree.pexp_desc = Pexp_apply(fn, ("", bounded_obj_arg) :: args);
3617936179
pexp_attributes = [];
3618036180
pexp_loc = pexp_loc}
3618136181
| _ ->
3618236182
Exp.apply ~loc:fn.pexp_loc
3618336183
(self.expr self fn )
36184-
["", obj_arg]
36184+
["", bounded_obj_arg]
3618536185
) xs );
36186-
pexp_attributes = attrs;
36186+
pexp_attributes = tuple_attrs;
3618736187
pexp_loc = fn.pexp_loc;
3618836188
}
3618936189
) in
3619036190
begin match try_dispatch_by_tuple with
3619136191
| Some x -> x
3619236192
| None ->
36193-
Exp.apply ~loc (self.expr self fn) ["", obj_arg]
36193+
Exp.apply ~loc (self.expr self fn) ["", new_obj_arg]
3619436194
end
3619536195
end
3619636196
| _ ->

lib/bsppx.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18157,19 +18157,19 @@ let handle_exp_apply
1815718157
| [ "", obj_arg ;
1815818158
"", fn
1815918159
] ->
18160-
let obj_arg = self.expr self obj_arg in
18160+
let new_obj_arg = self.expr self obj_arg in
1816118161
begin match fn with
1816218162
| {pexp_desc = Pexp_apply (fn, args); pexp_loc; pexp_attributes} ->
1816318163
let fn = self.expr self fn in
1816418164
let args = Ext_list.map (fun (lab,exp) -> lab, self.expr self exp ) args in
1816518165
Bs_ast_invariant.warn_unused_attributes pexp_attributes;
18166-
{ pexp_desc = Pexp_apply(fn, ("", obj_arg) :: args);
18166+
{ pexp_desc = Pexp_apply(fn, ("", new_obj_arg) :: args);
1816718167
pexp_attributes = [];
1816818168
pexp_loc = pexp_loc}
1816918169
| _ ->
1817018170
let try_dispatch_by_tuple =
18171-
Ast_tuple_pattern_flatten.map_open_tuple fn (fun xs attrs ->
18172-
bound obj_arg @@ fun obj_arg ->
18171+
Ast_tuple_pattern_flatten.map_open_tuple fn (fun xs tuple_attrs ->
18172+
bound new_obj_arg @@ fun bounded_obj_arg ->
1817318173
{
1817418174
pexp_desc =
1817518175
Pexp_tuple (
@@ -18180,22 +18180,22 @@ let handle_exp_apply
1818018180
let fn = self.expr self fn in
1818118181
let args = Ext_list.map (fun (lab,exp) -> lab, self.expr self exp ) args in
1818218182
Bs_ast_invariant.warn_unused_attributes pexp_attributes;
18183-
{ Parsetree.pexp_desc = Pexp_apply(fn, ("", obj_arg) :: args);
18183+
{ Parsetree.pexp_desc = Pexp_apply(fn, ("", bounded_obj_arg) :: args);
1818418184
pexp_attributes = [];
1818518185
pexp_loc = pexp_loc}
1818618186
| _ ->
1818718187
Exp.apply ~loc:fn.pexp_loc
1818818188
(self.expr self fn )
18189-
["", obj_arg]
18189+
["", bounded_obj_arg]
1819018190
) xs );
18191-
pexp_attributes = attrs;
18191+
pexp_attributes = tuple_attrs;
1819218192
pexp_loc = fn.pexp_loc;
1819318193
}
1819418194
) in
1819518195
begin match try_dispatch_by_tuple with
1819618196
| Some x -> x
1819718197
| None ->
18198-
Exp.apply ~loc (self.expr self fn) ["", obj_arg]
18198+
Exp.apply ~loc (self.expr self fn) ["", new_obj_arg]
1819918199
end
1820018200
end
1820118201
| _ ->

lib/js/belt_internalAVLset.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,16 @@ function size(n) {
368368
}
369369
}
370370

371-
function toListAux(_accu, _n) {
371+
function toListAux(_n, _accu) {
372372
while(true) {
373-
var n = _n;
374373
var accu = _accu;
374+
var n = _n;
375375
if (n !== null) {
376-
_n = n.left;
377376
_accu = /* :: */[
378377
n.value,
379-
toListAux(accu, n.right)
378+
toListAux(n.right, accu)
380379
];
380+
_n = n.left;
381381
continue ;
382382
} else {
383383
return accu;
@@ -386,7 +386,7 @@ function toListAux(_accu, _n) {
386386
}
387387

388388
function toList(s) {
389-
return toListAux(/* [] */0, s);
389+
return toListAux(s, /* [] */0);
390390
}
391391

392392
function checkInvariantInternal(_v) {
@@ -397,7 +397,7 @@ function checkInvariantInternal(_v) {
397397
var r = v.right;
398398
var diff = treeHeight(l) - treeHeight(r) | 0;
399399
if (!(diff <= 2 && diff >= -2)) {
400-
throw new Error("File \"belt_internalAVLset.ml\", line 301, characters 6-12");
400+
throw new Error("File \"belt_internalAVLset.ml\", line 302, characters 6-12");
401401
}
402402
checkInvariantInternal(l);
403403
_v = r;

lib/js/belt_internalAVLtree.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,19 +560,23 @@ function size(n) {
560560
}
561561
}
562562

563-
function toListAux(_accu, _n) {
563+
function toListAux(_n, _accu) {
564564
while(true) {
565-
var n = _n;
566565
var accu = _accu;
566+
var n = _n;
567567
if (n !== null) {
568-
_n = n.left;
568+
var l = n.left;
569+
var r = n.right;
570+
var k = n.key;
571+
var v = n.value;
569572
_accu = /* :: */[
570573
/* tuple */[
571-
n.key,
572-
n.value
574+
k,
575+
v
573576
],
574-
toListAux(accu, n.right)
577+
toListAux(r, accu)
575578
];
579+
_n = l;
576580
continue ;
577581
} else {
578582
return accu;
@@ -581,7 +585,7 @@ function toListAux(_accu, _n) {
581585
}
582586

583587
function toList(s) {
584-
return toListAux(/* [] */0, s);
588+
return toListAux(s, /* [] */0);
585589
}
586590

587591
function checkInvariantInternal(_v) {
@@ -592,7 +596,7 @@ function checkInvariantInternal(_v) {
592596
var r = v.right;
593597
var diff = treeHeight(l) - treeHeight(r) | 0;
594598
if (!(diff <= 2 && diff >= -2)) {
595-
throw new Error("File \"belt_internalAVLtree.ml\", line 368, characters 6-12");
599+
throw new Error("File \"belt_internalAVLtree.ml\", line 369, characters 6-12");
596600
}
597601
checkInvariantInternal(l);
598602
_v = r;

0 commit comments

Comments
 (0)