Skip to content

Commit 5d308e7

Browse files
committed
unparen shift ops
1 parent 1308af2 commit 5d308e7

37 files changed

+105
-117
lines changed

compiler/core/js_dump.ml

+2-14
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
717717
expression_desc cxt ~level:(level : int) f (Is_null_or_undefined e1)
718718
| Bin (op, e1, e2) ->
719719
let out, lft, rght = Js_op_util.op_prec op in
720-
let need_paren =
721-
level > out
722-
||
723-
match op with
724-
| Lsl | Lsr | Asr -> true
725-
| _ -> false
726-
in
720+
let need_paren = level > out in
727721
(* We are more conservative here, to make the generated code more readable
728722
to the user *)
729723
P.cond_paren_group f need_paren (fun _ ->
@@ -735,13 +729,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
735729
| String_append (e1, e2) ->
736730
let op : Js_op.binop = Plus in
737731
let out, lft, rght = Js_op_util.op_prec op in
738-
let need_paren =
739-
level > out
740-
||
741-
match op with
742-
| Lsl | Lsr | Asr -> true
743-
| _ -> false
744-
in
732+
let need_paren = level > out in
745733
P.cond_paren_group f need_paren (fun _ ->
746734
let cxt = expression ~level:lft cxt f e1 in
747735
P.space f;

lib/es6/Belt_HashMap.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ function set0(h, key, value, eq, hash) {
6666
};
6767
h.size = h.size + 1 | 0;
6868
}
69-
if (h.size > (buckets_len << 1)) {
69+
if (h.size > buckets_len << 1) {
7070
let odata = h.buckets;
7171
let osize = odata.length;
72-
let nsize = (osize << 1);
72+
let nsize = osize << 1;
7373
if (nsize < osize) {
7474
return;
7575
}

lib/es6/Belt_HashMapInt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ function set(h, key, value) {
6363
};
6464
h.size = h.size + 1 | 0;
6565
}
66-
if (h.size > (buckets_len << 1)) {
66+
if (h.size > buckets_len << 1) {
6767
let odata = h.buckets;
6868
let osize = odata.length;
69-
let nsize = (osize << 1);
69+
let nsize = osize << 1;
7070
if (nsize < osize) {
7171
return;
7272
}

lib/es6/Belt_HashMapString.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ function set(h, key, value) {
6363
};
6464
h.size = h.size + 1 | 0;
6565
}
66-
if (h.size > (buckets_len << 1)) {
66+
if (h.size > buckets_len << 1) {
6767
let odata = h.buckets;
6868
let osize = odata.length;
69-
let nsize = (osize << 1);
69+
let nsize = osize << 1;
7070
if (nsize < osize) {
7171
return;
7272
}

lib/es6/Belt_HashSet.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ function add0(h, key, hash, eq) {
9393
next: undefined
9494
};
9595
}
96-
if (h.size > (buckets_len << 1)) {
96+
if (h.size > buckets_len << 1) {
9797
let odata = h.buckets;
9898
let osize = odata.length;
99-
let nsize = (osize << 1);
99+
let nsize = osize << 1;
100100
if (nsize < osize) {
101101
return;
102102
}

lib/es6/Belt_HashSetInt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ function add(h, key) {
9393
};
9494
h.size = h.size + 1 | 0;
9595
}
96-
if (h.size > (buckets_len << 1)) {
96+
if (h.size > buckets_len << 1) {
9797
let odata = h.buckets;
9898
let osize = odata.length;
99-
let nsize = (osize << 1);
99+
let nsize = osize << 1;
100100
if (nsize < osize) {
101101
return;
102102
}

lib/es6/Belt_HashSetString.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ function add(h, key) {
9393
};
9494
h.size = h.size + 1 | 0;
9595
}
96-
if (h.size > (buckets_len << 1)) {
96+
if (h.size > buckets_len << 1) {
9797
let odata = h.buckets;
9898
let osize = odata.length;
99-
let nsize = (osize << 1);
99+
let nsize = osize << 1;
100100
if (nsize < osize) {
101101
return;
102102
}

lib/es6/Belt_internalBucketsType.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ function power_2_above(_x, n) {
77
if (x >= n) {
88
return x;
99
}
10-
if ((x << 1) < x) {
10+
if (x << 1 < x) {
1111
return x;
1212
}
13-
_x = (x << 1);
13+
_x = x << 1;
1414
continue;
1515
};
1616
}

lib/es6/Primitive_hash.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function unsafe_pop(q) {
4444
}
4545

4646
function rotl32(x, n) {
47-
return (x << n) | (x >>> (32 - n | 0)) | 0;
47+
return x << n | x >>> (32 - n | 0) | 0;
4848
}
4949

5050
function hash_mix_int(h, d) {
@@ -58,26 +58,26 @@ function hash_mix_int(h, d) {
5858
}
5959

6060
function hash_final_mix(h) {
61-
let h$1 = h ^ (h >>> 16);
61+
let h$1 = h ^ h >>> 16;
6262
h$1 = Math.imul(h$1, -2048144789);
63-
h$1 = h$1 ^ (h$1 >>> 13);
63+
h$1 = h$1 ^ h$1 >>> 13;
6464
h$1 = Math.imul(h$1, -1028477387);
65-
return h$1 ^ (h$1 >>> 16);
65+
return h$1 ^ h$1 >>> 16;
6666
}
6767

6868
function hash_mix_string(h, s) {
6969
let len = s.length;
7070
let block = (len / 4 | 0) - 1 | 0;
7171
let hash = h;
7272
for (let i = 0; i <= block; ++i) {
73-
let j = (i << 2);
74-
let w = s.charCodeAt(j) | (s.charCodeAt(j + 1 | 0) << 8) | (s.charCodeAt(j + 2 | 0) << 16) | (s.charCodeAt(j + 3 | 0) << 24);
73+
let j = i << 2;
74+
let w = s.charCodeAt(j) | s.charCodeAt(j + 1 | 0) << 8 | s.charCodeAt(j + 2 | 0) << 16 | s.charCodeAt(j + 3 | 0) << 24;
7575
hash = hash_mix_int(hash, w);
7676
}
7777
let modulo = len & 3;
7878
if (modulo !== 0) {
79-
let w$1 = modulo === 3 ? (s.charCodeAt(len - 1 | 0) << 16) | (s.charCodeAt(len - 2 | 0) << 8) | s.charCodeAt(len - 3 | 0) : (
80-
modulo === 2 ? (s.charCodeAt(len - 1 | 0) << 8) | s.charCodeAt(len - 2 | 0) : s.charCodeAt(len - 1 | 0)
79+
let w$1 = modulo === 3 ? s.charCodeAt(len - 1 | 0) << 16 | s.charCodeAt(len - 2 | 0) << 8 | s.charCodeAt(len - 3 | 0) : (
80+
modulo === 2 ? s.charCodeAt(len - 1 | 0) << 8 | s.charCodeAt(len - 2 | 0) : s.charCodeAt(len - 1 | 0)
8181
);
8282
hash = hash_mix_int(hash, w$1);
8383
}
@@ -117,7 +117,7 @@ function hash(count, _limit, seed, obj) {
117117
let size = obj$1.length | 0;
118118
if (size !== 0) {
119119
let obj_tag = obj$1.TAG;
120-
let tag = (size << 10) | obj_tag;
120+
let tag = size << 10 | obj_tag;
121121
s = hash_mix_int(s, tag);
122122
let v = size - 1 | 0;
123123
let block = v < num ? v : num;
@@ -133,7 +133,7 @@ function hash(count, _limit, seed, obj) {
133133
}
134134
return size
135135
})(obj$1, v => push_back(queue, v));
136-
s = hash_mix_int(s, (size$1 << 10) | 0);
136+
s = hash_mix_int(s, size$1 << 10 | 0);
137137
}
138138
}
139139

lib/js/Belt_HashMap.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ function set0(h, key, value, eq, hash) {
6666
};
6767
h.size = h.size + 1 | 0;
6868
}
69-
if (h.size > (buckets_len << 1)) {
69+
if (h.size > buckets_len << 1) {
7070
let odata = h.buckets;
7171
let osize = odata.length;
72-
let nsize = (osize << 1);
72+
let nsize = osize << 1;
7373
if (nsize < osize) {
7474
return;
7575
}

lib/js/Belt_HashMapInt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ function set(h, key, value) {
6363
};
6464
h.size = h.size + 1 | 0;
6565
}
66-
if (h.size > (buckets_len << 1)) {
66+
if (h.size > buckets_len << 1) {
6767
let odata = h.buckets;
6868
let osize = odata.length;
69-
let nsize = (osize << 1);
69+
let nsize = osize << 1;
7070
if (nsize < osize) {
7171
return;
7272
}

lib/js/Belt_HashMapString.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ function set(h, key, value) {
6363
};
6464
h.size = h.size + 1 | 0;
6565
}
66-
if (h.size > (buckets_len << 1)) {
66+
if (h.size > buckets_len << 1) {
6767
let odata = h.buckets;
6868
let osize = odata.length;
69-
let nsize = (osize << 1);
69+
let nsize = osize << 1;
7070
if (nsize < osize) {
7171
return;
7272
}

lib/js/Belt_HashSet.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ function add0(h, key, hash, eq) {
9393
next: undefined
9494
};
9595
}
96-
if (h.size > (buckets_len << 1)) {
96+
if (h.size > buckets_len << 1) {
9797
let odata = h.buckets;
9898
let osize = odata.length;
99-
let nsize = (osize << 1);
99+
let nsize = osize << 1;
100100
if (nsize < osize) {
101101
return;
102102
}

lib/js/Belt_HashSetInt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ function add(h, key) {
9393
};
9494
h.size = h.size + 1 | 0;
9595
}
96-
if (h.size > (buckets_len << 1)) {
96+
if (h.size > buckets_len << 1) {
9797
let odata = h.buckets;
9898
let osize = odata.length;
99-
let nsize = (osize << 1);
99+
let nsize = osize << 1;
100100
if (nsize < osize) {
101101
return;
102102
}

lib/js/Belt_HashSetString.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ function add(h, key) {
9393
};
9494
h.size = h.size + 1 | 0;
9595
}
96-
if (h.size > (buckets_len << 1)) {
96+
if (h.size > buckets_len << 1) {
9797
let odata = h.buckets;
9898
let osize = odata.length;
99-
let nsize = (osize << 1);
99+
let nsize = osize << 1;
100100
if (nsize < osize) {
101101
return;
102102
}

lib/js/Belt_internalBucketsType.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ function power_2_above(_x, n) {
77
if (x >= n) {
88
return x;
99
}
10-
if ((x << 1) < x) {
10+
if (x << 1 < x) {
1111
return x;
1212
}
13-
_x = (x << 1);
13+
_x = x << 1;
1414
continue;
1515
};
1616
}

lib/js/Primitive_hash.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function unsafe_pop(q) {
4444
}
4545

4646
function rotl32(x, n) {
47-
return (x << n) | (x >>> (32 - n | 0)) | 0;
47+
return x << n | x >>> (32 - n | 0) | 0;
4848
}
4949

5050
function hash_mix_int(h, d) {
@@ -58,26 +58,26 @@ function hash_mix_int(h, d) {
5858
}
5959

6060
function hash_final_mix(h) {
61-
let h$1 = h ^ (h >>> 16);
61+
let h$1 = h ^ h >>> 16;
6262
h$1 = Math.imul(h$1, -2048144789);
63-
h$1 = h$1 ^ (h$1 >>> 13);
63+
h$1 = h$1 ^ h$1 >>> 13;
6464
h$1 = Math.imul(h$1, -1028477387);
65-
return h$1 ^ (h$1 >>> 16);
65+
return h$1 ^ h$1 >>> 16;
6666
}
6767

6868
function hash_mix_string(h, s) {
6969
let len = s.length;
7070
let block = (len / 4 | 0) - 1 | 0;
7171
let hash = h;
7272
for (let i = 0; i <= block; ++i) {
73-
let j = (i << 2);
74-
let w = s.charCodeAt(j) | (s.charCodeAt(j + 1 | 0) << 8) | (s.charCodeAt(j + 2 | 0) << 16) | (s.charCodeAt(j + 3 | 0) << 24);
73+
let j = i << 2;
74+
let w = s.charCodeAt(j) | s.charCodeAt(j + 1 | 0) << 8 | s.charCodeAt(j + 2 | 0) << 16 | s.charCodeAt(j + 3 | 0) << 24;
7575
hash = hash_mix_int(hash, w);
7676
}
7777
let modulo = len & 3;
7878
if (modulo !== 0) {
79-
let w$1 = modulo === 3 ? (s.charCodeAt(len - 1 | 0) << 16) | (s.charCodeAt(len - 2 | 0) << 8) | s.charCodeAt(len - 3 | 0) : (
80-
modulo === 2 ? (s.charCodeAt(len - 1 | 0) << 8) | s.charCodeAt(len - 2 | 0) : s.charCodeAt(len - 1 | 0)
79+
let w$1 = modulo === 3 ? s.charCodeAt(len - 1 | 0) << 16 | s.charCodeAt(len - 2 | 0) << 8 | s.charCodeAt(len - 3 | 0) : (
80+
modulo === 2 ? s.charCodeAt(len - 1 | 0) << 8 | s.charCodeAt(len - 2 | 0) : s.charCodeAt(len - 1 | 0)
8181
);
8282
hash = hash_mix_int(hash, w$1);
8383
}
@@ -117,7 +117,7 @@ function hash(count, _limit, seed, obj) {
117117
let size = obj$1.length | 0;
118118
if (size !== 0) {
119119
let obj_tag = obj$1.TAG;
120-
let tag = (size << 10) | obj_tag;
120+
let tag = size << 10 | obj_tag;
121121
s = hash_mix_int(s, tag);
122122
let v = size - 1 | 0;
123123
let block = v < num ? v : num;
@@ -133,7 +133,7 @@ function hash(count, _limit, seed, obj) {
133133
}
134134
return size
135135
})(obj$1, v => push_back(queue, v));
136-
s = hash_mix_int(s, (size$1 << 10) | 0);
136+
s = hash_mix_int(s, size$1 << 10 | 0);
137137
}
138138
}
139139

tests/tests/src/alias_default_value_test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function Alias_default_value_test$C0(props) {
55
let __b = props.b;
66
let __a = props.a;
77
let a = __a !== undefined ? __a : 2;
8-
let b = __b !== undefined ? __b : (a << 1);
8+
let b = __b !== undefined ? __b : a << 1;
99
return a + b | 0;
1010
}
1111

tests/tests/src/belt_list_test.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ Mocha.describe("Belt_list_test", () => {
657657
});
658658
let id = x => x;
659659
Mocha.test("map", () => {
660-
Test_utils.eq("File \"belt_list_test.res\", line 109, characters 7-14", Belt_List.map(Belt_List.makeBy(5, id), x => (x << 1)), {
660+
Test_utils.eq("File \"belt_list_test.res\", line 109, characters 7-14", Belt_List.map(Belt_List.makeBy(5, id), x => x << 1), {
661661
hd: 0,
662662
tl: {
663663
hd: 2,
@@ -686,7 +686,7 @@ Mocha.describe("Belt_list_test", () => {
686686
let length_10_id = Belt_List.makeBy(10, id);
687687
let length_8_id = Belt_List.makeBy(8, id);
688688
Mocha.test("mapWithIndex etc.", () => {
689-
let d = Belt_List.makeBy(10, x => (x << 1));
689+
let d = Belt_List.makeBy(10, x => x << 1);
690690
Test_utils.eq("File \"belt_list_test.res\", line 124, characters 7-14", Belt_List.zipBy(length_10_id, length_10_id, add), d);
691691
Test_utils.eq("File \"belt_list_test.res\", line 125, characters 7-14", Belt_List.zipBy(/* [] */0, {
692692
hd: 1,
@@ -697,15 +697,15 @@ Mocha.describe("Belt_list_test", () => {
697697
tl: /* [] */0
698698
}, /* [] */0, add), /* [] */0);
699699
Test_utils.eq("File \"belt_list_test.res\", line 127, characters 7-14", Belt_List.zipBy(/* [] */0, /* [] */0, add), /* [] */0);
700-
Test_utils.eq("File \"belt_list_test.res\", line 128, characters 7-14", Belt_List.zipBy(length_10_id, length_10_id, add), Belt_List.concat(Belt_List.map(length_8_id, x => (x << 1)), {
700+
Test_utils.eq("File \"belt_list_test.res\", line 128, characters 7-14", Belt_List.zipBy(length_10_id, length_10_id, add), Belt_List.concat(Belt_List.map(length_8_id, x => x << 1), {
701701
hd: 16,
702702
tl: {
703703
hd: 18,
704704
tl: /* [] */0
705705
}
706706
}));
707707
Test_utils.eq("File \"belt_list_test.res\", line 129, characters 7-14", Belt_List.zipBy(length_10_id, length_8_id, add), Belt_List.mapWithIndex(length_8_id, (i, x) => i + x | 0));
708-
Test_utils.eq("File \"belt_list_test.res\", line 131, characters 6-13", Belt_List.reverse(Belt_List.mapReverse2(length_10_id, length_10_id, add)), Belt_List.map(length_10_id, x => (x << 1)));
708+
Test_utils.eq("File \"belt_list_test.res\", line 131, characters 6-13", Belt_List.reverse(Belt_List.mapReverse2(length_10_id, length_10_id, add)), Belt_List.map(length_10_id, x => x << 1));
709709
let xs = Belt_List.reverse(Belt_List.mapReverse2(length_8_id, length_10_id, add));
710710
Test_utils.eq("File \"belt_list_test.res\", line 136, characters 7-14", Belt_List.length(xs), 8);
711711
Test_utils.eq("File \"belt_list_test.res\", line 137, characters 7-14", xs, Belt_List.zipBy(length_10_id, length_8_id, add));

tests/tests/src/belt_sortarray_test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Mocha.describe("Belt_sortarray_test", () => {
268268
], 4, cmp), 3);
269269
let aa = Array_data_util.range(0, 1000);
270270
Test_utils.ok("File \"belt_sortarray_test.res\", line 115, characters 7-14", Belt_Range.every(0, 1000, i => Belt_SortArray.binarySearchBy(aa, i, cmp) === i));
271-
let cc = Belt_Array.map(Array_data_util.range(0, 2000), x => (x << 1));
271+
let cc = Belt_Array.map(Array_data_util.range(0, 2000), x => x << 1);
272272
Test_utils.eq("File \"belt_sortarray_test.res\", line 118, characters 7-14", Pervasives.lnot(Belt_SortArray.binarySearchBy(cc, 5000, cmp)), 2001);
273273
Test_utils.eq("File \"belt_sortarray_test.res\", line 119, characters 7-14", Pervasives.lnot(Belt_SortArray.binarySearchBy(cc, -1, cmp)), 0);
274274
Test_utils.eq("File \"belt_sortarray_test.res\", line 120, characters 7-14", Belt_SortArray.binarySearchBy(cc, 0, cmp), 0);

0 commit comments

Comments
 (0)