Skip to content

Commit 63c0228

Browse files
committed
Experiment with emitting functors as 1 arg at a time
See #7245
1 parent c527775 commit 63c0228

File tree

5 files changed

+102
-25
lines changed

5 files changed

+102
-25
lines changed

compiler/ml/translmod.ml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ let merge_inline_attributes (attr1 : Lambda.inline_attribute)
220220
else raise (Error (loc, Conflicting_inline_attributes))
221221

222222
let merge_functors mexp coercion root_path =
223-
let rec merge mexp coercion path acc inline_attribute =
223+
let merge mexp coercion path acc inline_attribute =
224224
let finished = (acc, mexp, path, coercion, inline_attribute) in
225225
match mexp.mod_desc with
226226
| Tmod_functor (param, _, _, body) ->
@@ -239,9 +239,19 @@ let merge_functors mexp coercion root_path =
239239
let inline_attribute =
240240
merge_inline_attributes inline_attribute inline_attribute' loc
241241
in
242-
merge body res_coercion path
243-
((param, loc, arg_coercion) :: acc)
244-
inline_attribute
242+
let r =
243+
( (param, loc, arg_coercion) :: acc,
244+
body,
245+
path,
246+
res_coercion,
247+
inline_attribute )
248+
in
249+
(* let _ =
250+
merge body res_coercion path
251+
((param, loc, arg_coercion) :: acc)
252+
inline_attribute
253+
in *)
254+
r
245255
| _ -> finished
246256
in
247257
merge mexp coercion root_path [] Default_inline

tests/tests/src/functors.mjs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,42 @@ function O(X) {
1010
};
1111
}
1212

13-
function F(X, Y) {
14-
let cow = x => Y.foo(X.foo(x));
15-
let sheep = x => 1 + Y.foo(X.foo(x)) | 0;
16-
return {
17-
cow: cow,
18-
sheep: sheep
13+
function F(X) {
14+
return Y => {
15+
let cow = x => Y.foo(X.foo(x));
16+
let sheep = x => 1 + Y.foo(X.foo(x)) | 0;
17+
return {
18+
cow: cow,
19+
sheep: sheep
20+
};
1921
};
2022
}
2123

22-
function F1(X, Y) {
23-
let sheep = x => 1 + Y.foo(X.foo(x)) | 0;
24-
return {
25-
sheep: sheep
24+
function F1(X) {
25+
return Y => {
26+
let sheep = x => 1 + Y.foo(X.foo(x)) | 0;
27+
return {
28+
sheep: sheep
29+
};
2630
};
2731
}
2832

29-
function F2(X, Y) {
30-
let sheep = x => 1 + Y.foo(X.foo(x)) | 0;
31-
return {
32-
sheep: sheep
33+
function F2(X) {
34+
return Y => {
35+
let sheep = x => 1 + Y.foo(X.foo(x)) | 0;
36+
return {
37+
sheep: sheep
38+
};
3339
};
3440
}
3541

3642
let M = {
3743
F: (funarg, funarg$1) => {
38-
let sheep = x => 1 + funarg$1.foo(funarg.foo(x)) | 0;
44+
let Y = {
45+
foo: funarg$1.foo
46+
};
47+
let cow = x => Y.foo(funarg.foo(x));
48+
let sheep = x => 1 + cow(x) | 0;
3949
return {
4050
sheep: sheep
4151
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
4+
function Make(T) {
5+
return Q => {
6+
let Eq = E => (A => ({}));
7+
return {
8+
Eq: Eq
9+
};
10+
};
11+
}
12+
13+
function Eq(E) {
14+
return A => ({});
15+
}
16+
17+
let M = {
18+
Eq: Eq
19+
};
20+
21+
let EQ = Eq({})({});
22+
23+
let MF = {
24+
F: (funarg, funarg$1) => ({})
25+
};
26+
27+
function UseF(X) {
28+
return Y => MF.F(X)(Y);
29+
}
30+
31+
export {
32+
Make,
33+
M,
34+
EQ,
35+
MF,
36+
UseF,
37+
}
38+
/* EQ Not a pure module */
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Make = (T: {}, Q: {}) => {
2+
module Eq = (E: {}, A: {}) => {}
3+
}
4+
5+
module M = Make((), ())
6+
7+
module EQ = M.Eq((), ())
8+
9+
module MF: {
10+
module F: (X: {}, Y: {}) => {}
11+
} = {
12+
module F = (X: {}, Y: {}) => {
13+
let c = 12
14+
}
15+
}
16+
17+
module UseF = (X: {}, Y: {}) => MF.F(X, Y)

tests/tests/src/recmodule.mjs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ let UseCase = {
1818
MakeLayer: MakeLayer
1919
};
2020

21-
function MakeLayer$1(Deps, UC) {
22-
let presentLight = light => Deps.presentJson(light, 200);
23-
let handleGetLight = req => UC.getLight(req.params.id);
24-
return {
25-
handleGetLight: handleGetLight,
26-
presentLight: presentLight
21+
function MakeLayer$1(Deps) {
22+
return UC => {
23+
let presentLight = light => Deps.presentJson(light, 200);
24+
let handleGetLight = req => UC.getLight(req.params.id);
25+
return {
26+
handleGetLight: handleGetLight,
27+
presentLight: presentLight
28+
};
2729
};
2830
}
2931

0 commit comments

Comments
 (0)