Skip to content

Commit ed2cd45

Browse files
committed
fix #1692
1 parent fcc4831 commit ed2cd45

File tree

257 files changed

+42818
-42786
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

257 files changed

+42818
-42786
lines changed

jscomp/bin/whole_compiler.ml

+22-15
Original file line numberDiff line numberDiff line change
@@ -85253,7 +85253,7 @@ let pp_string f (* ?(utf=false)*) s =
8525385253
P.string f (Array.unsafe_get array_conv (c land 0xf))
8525485254
| '\"' -> P.string f "\\\"" (* quote*)
8525585255
| _ ->
85256-
P.string f (Array.unsafe_get array_str1 (Char.code c))
85256+
P.string f (Array.unsafe_get array_str1 (Char.code c))
8525785257
done
8525885258
in
8525985259
P.string f "\"";
@@ -85362,13 +85362,13 @@ type name =
8536285362
*)
8536385363
let rec
8536485364

85365-
try_optimize_curry cxt f len function_ =
85365+
try_optimize_curry cxt f len function_id =
8536685366
begin
8536785367
P.string f Js_config.curry;
8536885368
P.string f L.dot;
8536985369
P.string f "__";
8537085370
P.string f (Printf.sprintf "%d" len);
85371-
P.paren_group f 1 (fun _ -> expression 1 cxt f function_ )
85371+
P.paren_group f 1 (fun _ -> expression 1 cxt f function_id )
8537285372
end
8537385373

8537485374
and pp_function method_
@@ -85378,21 +85378,25 @@ and pp_function method_
8537885378
| [ {statement_desc =
8537985379
Return {return_value =
8538085380
{expression_desc =
85381-
Call(({expression_desc = Var v ; _} as function_),
85381+
Call(({expression_desc = Var v ; _} as function_id),
8538285382
ls ,
8538385383
{arity = ( Full | NA as arity(* see #234*));
8538485384
(* TODO: need a case to justify it*)
8538585385
call_info =
8538685386
(Call_builtin_runtime | Call_ml )})}}}],
8538785387
((_, false) | (No_name, true))
85388-
when
85388+
when
85389+
(* match such case:
85390+
{[ function(x,y){ return u(x,y) } ]}
85391+
it can be optimized in to either [u] or [Curry.__n(u)]
85392+
*)
8538985393
not method_ &&
85390-
Ext_list.for_all2_no_exn (fun a b ->
85391-
match b.J.expression_desc with
85394+
Ext_list.for_all2_no_exn (fun a (b : J.expression) ->
85395+
match b.expression_desc with
8539285396
| Var (Id i) -> Ident.same a i
8539385397
| _ -> false) l ls ->
8539485398
let optimize len p cxt f v =
85395-
if p then try_optimize_curry cxt f len function_
85399+
if p then try_optimize_curry cxt f len function_id
8539685400
else
8539785401
vident cxt f v
8539885402
in
@@ -85412,9 +85416,10 @@ and pp_function method_
8541285416
if return then
8541385417
begin
8541485418
P.string f L.return ;
85415-
P.space f;
85419+
P.space f
8541685420
end;
8541785421
optimize len (arity = NA && len <=8) cxt f v
85422+
8541885423
end
8541985424
| _, _ ->
8542085425

@@ -85475,7 +85480,7 @@ and pp_function method_
8547585480
ignore @@ P.brace_vgroup f 1 (fun _ -> statement_list false cxt f b );
8547685481
end
8547785482
in
85478-
let lexical = Js_fun_env.get_lexical_scope env in
85483+
let lexical : Ident_set.t = Js_fun_env.get_lexical_scope env in
8547985484
let enclose lexical return =
8548085485
let handle lexical =
8548185486
if Ident_set.is_empty lexical
@@ -85489,10 +85494,12 @@ and pp_function method_
8548985494

8549085495
begin match name with
8549185496
| No_name ->
85492-
P.string f L.function_;
85493-
P.space f ;
85494-
param_body ();
85495-
(* semi f ; *)
85497+
(* see # 1692, add a paren for annoymous function for safety *)
85498+
P.paren_group f 1 begin fun _ ->
85499+
P.string f L.function_;
85500+
P.space f ;
85501+
param_body ()
85502+
end
8549685503
| Name_non_top x ->
8549785504
P.string f L.var ;
8549885505
P.space f ;
@@ -86757,7 +86764,7 @@ let imports cxt f (modules : (Ident.t * string) list ) =
8675786764
(cxt, [], 0) modules in
8675886765
P.force_newline f ;
8675986766
Ext_list.rev_iter (fun (s,file) ->
86760-
86767+
8676186768
P.string f L.import;
8676286769
P.space f ;
8676386770
P.string f L.star ;

jscomp/core/js_dump.ml

+22-15
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ let pp_string f (* ?(utf=false)*) s =
230230
P.string f (Array.unsafe_get array_conv (c land 0xf))
231231
| '\"' -> P.string f "\\\"" (* quote*)
232232
| _ ->
233-
P.string f (Array.unsafe_get array_str1 (Char.code c))
233+
P.string f (Array.unsafe_get array_str1 (Char.code c))
234234
done
235235
in
236236
P.string f "\"";
@@ -339,13 +339,13 @@ type name =
339339
*)
340340
let rec
341341

342-
try_optimize_curry cxt f len function_ =
342+
try_optimize_curry cxt f len function_id =
343343
begin
344344
P.string f Js_config.curry;
345345
P.string f L.dot;
346346
P.string f "__";
347347
P.string f (Printf.sprintf "%d" len);
348-
P.paren_group f 1 (fun _ -> expression 1 cxt f function_ )
348+
P.paren_group f 1 (fun _ -> expression 1 cxt f function_id )
349349
end
350350

351351
and pp_function method_
@@ -355,21 +355,25 @@ and pp_function method_
355355
| [ {statement_desc =
356356
Return {return_value =
357357
{expression_desc =
358-
Call(({expression_desc = Var v ; _} as function_),
358+
Call(({expression_desc = Var v ; _} as function_id),
359359
ls ,
360360
{arity = ( Full | NA as arity(* see #234*));
361361
(* TODO: need a case to justify it*)
362362
call_info =
363363
(Call_builtin_runtime | Call_ml )})}}}],
364364
((_, false) | (No_name, true))
365-
when
365+
when
366+
(* match such case:
367+
{[ function(x,y){ return u(x,y) } ]}
368+
it can be optimized in to either [u] or [Curry.__n(u)]
369+
*)
366370
not method_ &&
367-
Ext_list.for_all2_no_exn (fun a b ->
368-
match b.J.expression_desc with
371+
Ext_list.for_all2_no_exn (fun a (b : J.expression) ->
372+
match b.expression_desc with
369373
| Var (Id i) -> Ident.same a i
370374
| _ -> false) l ls ->
371375
let optimize len p cxt f v =
372-
if p then try_optimize_curry cxt f len function_
376+
if p then try_optimize_curry cxt f len function_id
373377
else
374378
vident cxt f v
375379
in
@@ -389,9 +393,10 @@ and pp_function method_
389393
if return then
390394
begin
391395
P.string f L.return ;
392-
P.space f;
396+
P.space f
393397
end;
394398
optimize len (arity = NA && len <=8) cxt f v
399+
395400
end
396401
| _, _ ->
397402

@@ -452,7 +457,7 @@ and pp_function method_
452457
ignore @@ P.brace_vgroup f 1 (fun _ -> statement_list false cxt f b );
453458
end
454459
in
455-
let lexical = Js_fun_env.get_lexical_scope env in
460+
let lexical : Ident_set.t = Js_fun_env.get_lexical_scope env in
456461
let enclose lexical return =
457462
let handle lexical =
458463
if Ident_set.is_empty lexical
@@ -466,10 +471,12 @@ and pp_function method_
466471

467472
begin match name with
468473
| No_name ->
469-
P.string f L.function_;
470-
P.space f ;
471-
param_body ();
472-
(* semi f ; *)
474+
(* see # 1692, add a paren for annoymous function for safety *)
475+
P.paren_group f 1 begin fun _ ->
476+
P.string f L.function_;
477+
P.space f ;
478+
param_body ()
479+
end
473480
| Name_non_top x ->
474481
P.string f L.var ;
475482
P.space f ;
@@ -1734,7 +1741,7 @@ let imports cxt f (modules : (Ident.t * string) list ) =
17341741
(cxt, [], 0) modules in
17351742
P.force_newline f ;
17361743
Ext_list.rev_iter (fun (s,file) ->
1737-
1744+
17381745
P.string f L.import;
17391746
P.space f ;
17401747
P.string f L.star ;

jscomp/test/.depend

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ gpr_1539_test.cmj :
226226
gpr_1600_test.cmj : ../runtime/js.cmj ../stdlib/array.cmj
227227
gpr_1658_test.cmj : mt.cmj ../runtime/js.cmj
228228
gpr_1667_test.cmj : mt.cmj
229+
gpr_1692_test.cmj :
229230
gpr_405_test.cmj : ../stdlib/hashtbl.cmj gpr_405_test.cmi
230231
gpr_441.cmj :
231232
gpr_459_test.cmj : mt.cmj

jscomp/test/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
159159
js_list_test\
160160
js_option_test\
161161
gpr_1658_test\
162-
gpr_1667_test
162+
gpr_1667_test\
163+
gpr_1692_test
163164

164165
# bs_uncurry_test
165166
# needs Lam to get rid of Uncurry arity first

jscomp/test/a_filename_test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ function eq(loc, x, y) {
1414
suites[0] = /* :: */[
1515
/* tuple */[
1616
loc + (" id " + test_id[0]),
17-
function () {
18-
return /* Eq */Block.__(0, [
19-
x,
20-
y
21-
]);
22-
}
17+
(function () {
18+
return /* Eq */Block.__(0, [
19+
x,
20+
y
21+
]);
22+
})
2323
],
2424
suites[0]
2525
];

jscomp/test/a_list_test.js

+61-61
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,9 @@ var Ext_list = require("./ext_list.js");
66

77
var suites_000 = /* tuple */[
88
"drop",
9-
function () {
10-
return /* Eq */Block.__(0, [
11-
Ext_list.drop(3, /* :: */[
12-
0,
13-
/* :: */[
14-
1,
15-
/* :: */[
16-
2,
17-
/* [] */0
18-
]
19-
]
20-
]),
21-
/* [] */0
22-
]);
23-
}
24-
];
25-
26-
var suites_001 = /* :: */[
27-
/* tuple */[
28-
"drop1",
29-
function () {
9+
(function () {
3010
return /* Eq */Block.__(0, [
31-
Ext_list.drop(2, /* :: */[
11+
Ext_list.drop(3, /* :: */[
3212
0,
3313
/* :: */[
3414
1,
@@ -38,64 +18,84 @@ var suites_001 = /* :: */[
3818
]
3919
]
4020
]),
41-
/* :: */[
42-
2,
43-
/* [] */0
44-
]
21+
/* [] */0
4522
]);
46-
}
23+
})
24+
];
25+
26+
var suites_001 = /* :: */[
27+
/* tuple */[
28+
"drop1",
29+
(function () {
30+
return /* Eq */Block.__(0, [
31+
Ext_list.drop(2, /* :: */[
32+
0,
33+
/* :: */[
34+
1,
35+
/* :: */[
36+
2,
37+
/* [] */0
38+
]
39+
]
40+
]),
41+
/* :: */[
42+
2,
43+
/* [] */0
44+
]
45+
]);
46+
})
4747
],
4848
/* :: */[
4949
/* tuple */[
5050
"flat_map",
51-
function () {
52-
return /* Eq */Block.__(0, [
53-
/* :: */[
54-
0,
51+
(function () {
52+
return /* Eq */Block.__(0, [
5553
/* :: */[
5654
0,
5755
/* :: */[
58-
1,
56+
0,
5957
/* :: */[
6058
1,
6159
/* :: */[
62-
0,
63-
/* [] */0
60+
1,
61+
/* :: */[
62+
0,
63+
/* [] */0
64+
]
6465
]
6566
]
6667
]
67-
]
68-
],
69-
Ext_list.flat_map(function (x) {
70-
if (x % 2) {
71-
return /* :: */[
72-
1,
73-
/* :: */[
74-
1,
75-
/* [] */0
76-
]
77-
];
78-
} else {
79-
return /* :: */[
80-
0,
81-
/* [] */0
82-
];
83-
}
84-
}, /* :: */[
85-
0,
86-
/* :: */[
68+
],
69+
Ext_list.flat_map((function (x) {
70+
if (x % 2) {
71+
return /* :: */[
72+
1,
73+
/* :: */[
74+
1,
75+
/* [] */0
76+
]
77+
];
78+
} else {
79+
return /* :: */[
80+
0,
81+
/* [] */0
82+
];
83+
}
84+
}), /* :: */[
8785
0,
8886
/* :: */[
89-
3,
87+
0,
9088
/* :: */[
91-
0,
92-
/* [] */0
89+
3,
90+
/* :: */[
91+
0,
92+
/* [] */0
93+
]
9394
]
9495
]
95-
]
96-
])
97-
]);
98-
}
96+
])
97+
]);
98+
})
9999
],
100100
/* [] */0
101101
]

0 commit comments

Comments
 (0)