Skip to content

Commit 0799242

Browse files
committed
avoid late bindings in callback
the object already had a late binding for methods TODO: we may do eta-expansion here to avoid the cost of currying
1 parent 77bb5d2 commit 0799242

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

jscomp/core/js_iter.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
class iter =
99
object ((_self : 'self_type))
1010
method list :
11-
'a. ('self_type -> 'a -> unit) -> 'a list -> unit =
11+
'a. ('a -> unit) -> 'a list -> unit =
1212
fun _f_a ->
1313
function
1414
| [] -> ()
15-
| _x :: _x_i1 -> _f_a _self _x ; _self#list _f_a _x_i1
15+
| _x :: _x_i1 -> _f_a _x ; _self#list _f_a _x_i1
1616
method label : label -> unit = ignore
17-
method required_modules : required_modules -> unit = _self#list (fun _self -> _self#module_id)
17+
method required_modules : required_modules -> unit = _self#list _self#module_id
1818
method ident : ident -> unit = ignore
1919
method module_id : module_id -> unit = fun { id = _x0;kind = _x1} -> begin _self#ident _x0 end
2020
method vident : vident -> unit = function
@@ -25,7 +25,7 @@ method vident : vident -> unit = function
2525
method exception_ident : exception_ident -> unit = _self#ident
2626
method for_ident : for_ident -> unit = _self#ident
2727
method for_direction : for_direction -> unit = ignore
28-
method property_map : property_map -> unit = _self#list (fun _self -> fun ( _x0,_x1) -> begin _self#expression _x1 end)
28+
method property_map : property_map -> unit = _self#list (fun ( _x0,_x1) -> begin _self#expression _x1 end)
2929
method length_object : length_object -> unit = ignore
3030
method expression_desc : expression_desc -> unit = function
3131
| Length ( _x0,_x1) ->
@@ -52,28 +52,28 @@ method expression_desc : expression_desc -> unit = function
5252
|FlatCall ( _x0,_x1) ->
5353
begin _self#expression _x0;_self#expression _x1 end
5454
|Call ( _x0,_x1,_x2) ->
55-
begin _self#expression _x0;_self#list (fun _self -> _self#expression) _x1 end
55+
begin _self#expression _x0;_self#list _self#expression _x1 end
5656
|String_index ( _x0,_x1) ->
5757
begin _self#expression _x0;_self#expression _x1 end
5858
|Array_index ( _x0,_x1) ->
5959
begin _self#expression _x0;_self#expression _x1 end
6060
|Static_index ( _x0,_x1,_x2) ->
6161
begin _self#expression _x0 end
6262
|New ( _x0,_x1) ->
63-
begin _self#expression _x0;option (_self#list (fun _self -> _self#expression)) _x1 end
63+
begin _self#expression _x0;option (_self#list _self#expression) _x1 end
6464
|Var ( _x0) ->
6565
begin _self#vident _x0 end
6666
|Fun ( _x0,_x1,_x2,_x3) ->
67-
begin _self#list (fun _self -> _self#ident) _x1;_self#block _x2 end
67+
begin _self#list _self#ident _x1;_self#block _x2 end
6868
|Str _ -> ()
6969
|Unicode _ -> ()
7070
|Raw_js_code _ -> ()
7171
|Array ( _x0,_x1) ->
72-
begin _self#list (fun _self -> _self#expression) _x0 end
72+
begin _self#list _self#expression _x0 end
7373
|Optional_block ( _x0,_x1) ->
7474
begin _self#expression _x0 end
7575
|Caml_block ( _x0,_x1,_x2,_x3) ->
76-
begin _self#list (fun _self -> _self#expression) _x0;_self#expression _x2 end
76+
begin _self#list _self#expression _x0;_self#expression _x2 end
7777
|Caml_block_tag ( _x0) ->
7878
begin _self#expression _x0 end
7979
|Number _ -> ()
@@ -102,21 +102,21 @@ method statement_desc : statement_desc -> unit = function
102102
|Return ( _x0) ->
103103
begin _self#expression _x0 end
104104
|Int_switch ( _x0,_x1,_x2) ->
105-
begin _self#expression _x0;_self#list (fun _self -> _self#int_clause) _x1;option (_self#block) _x2 end
105+
begin _self#expression _x0;_self#list _self#int_clause _x1;option (_self#block) _x2 end
106106
|String_switch ( _x0,_x1,_x2) ->
107-
begin _self#expression _x0;_self#list (fun _self -> _self#string_clause) _x1;option (_self#block) _x2 end
107+
begin _self#expression _x0;_self#list _self#string_clause _x1;option (_self#block) _x2 end
108108
|Throw ( _x0) ->
109109
begin _self#expression _x0 end
110110
|Try ( _x0,_x1,_x2) ->
111-
begin _self#block _x0;option (fun ( _x0,_x1) -> begin _self#exception_ident _x0;_self#block _x1 end) _x1;option (_self#block) _x2 end
111+
begin _self#block _x0;option ((fun ( _x0,_x1) -> begin _self#exception_ident _x0;_self#block _x1 end)) _x1;option (_self#block) _x2 end
112112
|Debugger -> ()
113113
method expression : expression -> unit = fun { expression_desc = _x0;comment = _x1} -> begin _self#expression_desc _x0 end
114114
method statement : statement -> unit = fun { statement_desc = _x0;comment = _x1} -> begin _self#statement_desc _x0 end
115115
method variable_declaration : variable_declaration -> unit = fun { ident = _x0;value = _x1;property = _x2;ident_info = _x3} -> begin _self#ident _x0;option (_self#expression) _x1 end
116-
method string_clause : string_clause -> unit = fun ( _x0,_x1) -> begin _self#case_clause _x1 end
117-
method int_clause : int_clause -> unit = fun ( _x0,_x1) -> begin _self#case_clause _x1 end
116+
method string_clause : string_clause -> unit = (fun ( _x0,_x1) -> begin _self#case_clause _x1 end)
117+
method int_clause : int_clause -> unit = (fun ( _x0,_x1) -> begin _self#case_clause _x1 end)
118118
method case_clause : case_clause -> unit = fun { switch_body = _x0;should_break = _x1;comment = _x2} -> begin _self#block _x0 end
119-
method block : block -> unit = _self#list (fun _self -> _self#statement)
119+
method block : block -> unit = _self#list _self#statement
120120
method program : program -> unit = fun { block = _x0;exports = _x1;export_set = _x2} -> begin _self#block _x0 end
121121
method deps_program : deps_program -> unit = fun { program = _x0;modules = _x1;side_effect = _x2} -> begin _self#program _x0;_self#required_modules _x1 end
122122
end

ocaml-tree/iter_maker.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ function mkBody(def, allNames) {
4646
return `option (${inner})`;
4747
case "list":
4848
// there are list and other
49-
return `${mkBody(list, allNames)} (fun _self -> ${mkBody(
50-
base,
51-
allNames
52-
)})`;
49+
return `${mkBody(list, allNames)} ${mkBody(base, allNames)}`;
5350
default:
5451
throw new Error(`not supported high order types ${list.text}`);
5552
}
@@ -81,7 +78,7 @@ function mkBody(def, allNames) {
8178
var body = args
8279
.map((x, i) => mkBodyApply(def.children[i], allNames, x))
8380
.filter(Boolean);
84-
return `fun ( ${args.join(",")}) -> begin ${body.join(";")} end`;
81+
return `(fun ( ${args.join(",")}) -> begin ${body.join(";")} end)`;
8582
default:
8683
throw new Error(`unkonwn ${def.type}`);
8784
}
@@ -149,11 +146,11 @@ function make(typedefs) {
149146
class iter =
150147
object ((_self : 'self_type))
151148
method list :
152-
'a. ('self_type -> 'a -> unit) -> 'a list -> unit =
149+
'a. ('a -> unit) -> 'a list -> unit =
153150
fun _f_a ->
154151
function
155152
| [] -> ()
156-
| _x :: _x_i1 -> _f_a _self _x ; _self#list _f_a _x_i1
153+
| _x :: _x_i1 -> _f_a _x ; _self#list _f_a _x_i1
157154
${output.join("\n")}
158155
end
159156
`;

0 commit comments

Comments
 (0)