Skip to content

Commit 66d9910

Browse files
committed
Address review comments
1 parent f336bda commit 66d9910

File tree

4 files changed

+45
-43
lines changed

4 files changed

+45
-43
lines changed

compiler/core/lam_util.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ let refine_let ~kind param (arg : Lam.t) (l : Lam.t) : Lam.t =
4545
| Lam_primitive.Pmakeblock _ -> true
4646
| _ -> false
4747
in
48-
(* Helper for spotting RHS expressions that are safe to inline everywhere.
49-
These are the obviously pure shapes where substituting the original value
50-
cannot introduce extra work or side effects. *)
51-
let is_alias_candidate (lam : Lam.t) =
48+
let is_safe_to_inline (lam : Lam.t) =
5249
match lam with
5350
| Lvar _ | Lconst _ -> true
54-
| Lprim { primitive = Psome_not_nest; _ } -> true
51+
| Lprim { primitive = Psome_not_nest; args = [inner]; _ } ->
52+
Lam_analysis.no_side_effects inner
5553
| Lprim { primitive = Pfield (_, Fld_module _); args = [ (Lglobal_module _ | Lvar _) ]; _ } -> true
5654
| _ -> false
5755
in
@@ -74,7 +72,7 @@ let refine_let ~kind param (arg : Lam.t) (l : Lam.t) : Lam.t =
7472
rewrite to `someFn(value)` as long as the callee does not capture `x`.
7573
This removes the temporary binding while preserving the call semantics. *)
7674
Lam.apply fn [arg] ap_info ~ap_transformed_jsx
77-
| (Strict | StrictOpt), arg, _ when is_alias_candidate arg ->
75+
| (Strict | StrictOpt), arg, _ when is_safe_to_inline arg ->
7876
(* `Strict` and `StrictOpt` bindings both evaluate the RHS immediately
7977
(with `StrictOpt` allowing later elimination if unused). When that RHS
8078
is pure — `{ let x = Some(value); ... }`, `{ let x = 3; ... }`, or a module

packages/@rescript/runtime/lib/es6/Belt_internalAVLset.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,15 @@ function rotateWithRightChild(k1) {
741741

742742
function doubleWithLeftChild(k3) {
743743
let k3l = k3.l;
744-
k3.l = rotateWithRightChild(k3l);
744+
let v = rotateWithRightChild(k3l);
745+
k3.l = v;
745746
return rotateWithLeftChild(k3);
746747
}
747748

748749
function doubleWithRightChild(k2) {
749750
let k2r = k2.r;
750-
k2.r = rotateWithLeftChild(k2r);
751+
let v = rotateWithLeftChild(k2r);
752+
k2.r = v;
751753
return rotateWithRightChild(k2);
752754
}
753755

packages/@rescript/runtime/lib/js/Belt_internalAVLset.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,15 @@ function rotateWithRightChild(k1) {
741741

742742
function doubleWithLeftChild(k3) {
743743
let k3l = k3.l;
744-
k3.l = rotateWithRightChild(k3l);
744+
let v = rotateWithRightChild(k3l);
745+
k3.l = v;
745746
return rotateWithLeftChild(k3);
746747
}
747748

748749
function doubleWithRightChild(k2) {
749750
let k2r = k2.r;
750-
k2.r = rotateWithLeftChild(k2r);
751+
let v = rotateWithLeftChild(k2r);
752+
k2.r = v;
751753
return rotateWithRightChild(k2);
752754
}
753755

tests/tests/src/option_wrapping_test.mjs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,10 @@ let x10 = null;
1212

1313
let x11 = Primitive_option.some(undefined);
1414

15-
let x1 = "hello";
16-
17-
let x2 = 1;
18-
19-
let x3 = {
20-
TAG: "Ok",
21-
_0: "hi"
22-
};
23-
24-
let x4 = "polyvar";
25-
26-
let x5 = {
27-
x: 42
28-
};
29-
30-
let x7 = [
31-
1,
32-
2,
33-
3
34-
];
35-
36-
let x8 = () => {};
37-
38-
let x12 = "test";
39-
4015
let x20 = null;
4116

4217
let x21 = new Date();
4318

44-
let x22 = /test/;
45-
4619
let x23 = new Map();
4720

4821
let x24 = new Set();
@@ -75,8 +48,6 @@ let x37 = new Intl.DateTimeFormat();
7548

7649
let x38 = new Intl.NumberFormat();
7750

78-
let x39 = true;
79-
8051
let x40 = new Intl.Collator();
8152

8253
let x41 = new Intl.RelativeTimeFormat();
@@ -85,19 +56,48 @@ let x42 = new Intl.PluralRules();
8556

8657
let x43 = new Intl.Locale("en");
8758

59+
let x45 = Promise.resolve(true);
60+
61+
let x48 = Stdlib_Lazy.make(() => true);
62+
63+
let x1 = "hello";
64+
65+
let x2 = 1;
66+
67+
let x3 = {
68+
TAG: "Ok",
69+
_0: "hi"
70+
};
71+
72+
let x4 = "polyvar";
73+
74+
let x5 = {
75+
x: 42
76+
};
77+
78+
let x7 = [
79+
1,
80+
2,
81+
3
82+
];
83+
84+
let x8 = () => {};
85+
86+
let x12 = "test";
87+
88+
let x22 = /test/;
89+
90+
let x39 = true;
91+
8892
let x44 = [
8993
1,
9094
2
9195
];
9296

93-
let x45 = Promise.resolve(true);
94-
9597
let x46 = /* [] */0;
9698

9799
let x47 = {};
98100

99-
let x48 = Stdlib_Lazy.make(() => true);
100-
101101
export {
102102
x1,
103103
x2,

0 commit comments

Comments
 (0)