Skip to content

Commit 61f75df

Browse files
committed
Don't use Lam_analysis.no_side_effects here
1 parent 66d9910 commit 61f75df

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

compiler/core/lam_util.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ let refine_let ~kind param (arg : Lam.t) (l : Lam.t) : Lam.t =
4545
| Lam_primitive.Pmakeblock _ -> true
4646
| _ -> false
4747
in
48-
let is_safe_to_inline (lam : Lam.t) =
48+
let rec is_safe_to_alias (lam : Lam.t) =
4949
match lam with
5050
| Lvar _ | Lconst _ -> true
51-
| Lprim { primitive = Psome_not_nest; args = [inner]; _ } ->
52-
Lam_analysis.no_side_effects inner
5351
| Lprim { primitive = Pfield (_, Fld_module _); args = [ (Lglobal_module _ | Lvar _) ]; _ } -> true
52+
| Lprim { primitive = Psome_not_nest; args = [inner]; _ } ->
53+
is_safe_to_alias inner
5454
| _ -> false
5555
in
5656
match (kind : Lam_compat.let_kind), arg, l with
@@ -72,7 +72,7 @@ let refine_let ~kind param (arg : Lam.t) (l : Lam.t) : Lam.t =
7272
rewrite to `someFn(value)` as long as the callee does not capture `x`.
7373
This removes the temporary binding while preserving the call semantics. *)
7474
Lam.apply fn [arg] ap_info ~ap_transformed_jsx
75-
| (Strict | StrictOpt), arg, _ when is_safe_to_inline arg ->
75+
| (Strict | StrictOpt), arg, _ when is_safe_to_alias arg ->
7676
(* `Strict` and `StrictOpt` bindings both evaluate the RHS immediately
7777
(with `StrictOpt` allowing later elimination if unused). When that RHS
7878
is pure — `{ let x = Some(value); ... }`, `{ let x = 3; ... }`, or a module

tests/gentype_tests/typescript-react-example/src/nested/Types.res.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/src/option_wrapping_test.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ let x6 = {
88
x: 42
99
};
1010

11+
let x7 = [
12+
1,
13+
2,
14+
3
15+
];
16+
17+
let x8 = () => {};
18+
1119
let x10 = null;
1220

1321
let x11 = Primitive_option.some(undefined);
@@ -16,6 +24,8 @@ let x20 = null;
1624

1725
let x21 = new Date();
1826

27+
let x22 = /test/;
28+
1929
let x23 = new Map();
2030

2131
let x24 = new Set();
@@ -58,6 +68,8 @@ let x43 = new Intl.Locale("en");
5868

5969
let x45 = Promise.resolve(true);
6070

71+
let x47 = {};
72+
6173
let x48 = Stdlib_Lazy.make(() => true);
6274

6375
let x1 = "hello";
@@ -75,18 +87,8 @@ let x5 = {
7587
x: 42
7688
};
7789

78-
let x7 = [
79-
1,
80-
2,
81-
3
82-
];
83-
84-
let x8 = () => {};
85-
8690
let x12 = "test";
8791

88-
let x22 = /test/;
89-
9092
let x39 = true;
9193

9294
let x44 = [
@@ -96,8 +98,6 @@ let x44 = [
9698

9799
let x46 = /* [] */0;
98100

99-
let x47 = {};
100-
101101
export {
102102
x1,
103103
x2,

tests/tests/src/reasonReact.mjs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ function wrapReasonForJs(component, jsPropsToReason) {
9292
let dummyInteropComponent = basicComponent("interop");
9393

9494
function wrapJsForReason(reactClass, props, children) {
95+
let jsElementWrapped = (extra, extra$1) => {
96+
let props$1 = Object.assign(Object.assign({}, props), {
97+
ref: extra$1,
98+
key: extra
99+
});
100+
let varargs = Js_array.concat(children, [
101+
reactClass,
102+
props$1
103+
]);
104+
return React.createElement.apply(null, varargs);
105+
};
95106
return {
96107
debugName: dummyInteropComponent.debugName,
97108
reactClassInternal: dummyInteropComponent.reactClassInternal,
@@ -106,17 +117,7 @@ function wrapJsForReason(reactClass, props, children) {
106117
initialState: dummyInteropComponent.initialState,
107118
retainedProps: dummyInteropComponent.retainedProps,
108119
reducer: dummyInteropComponent.reducer,
109-
jsElementWrapped: (extra, extra$1) => {
110-
let props$1 = Object.assign(Object.assign({}, props), {
111-
ref: extra$1,
112-
key: extra
113-
});
114-
let varargs = Js_array.concat(children, [
115-
reactClass,
116-
props$1
117-
]);
118-
return React.createElement.apply(null, varargs);
119-
}
120+
jsElementWrapped: jsElementWrapped
120121
};
121122
}
122123

0 commit comments

Comments
 (0)