Skip to content

Commit bd26419

Browse files
committed
remove return_expression which is not used
1 parent c7dbf6c commit bd26419

9 files changed

+51
-60
lines changed

jscomp/core/j.ml

+10-11
Original file line numberDiff line numberDiff line change
@@ -290,27 +290,26 @@ and statement_desc =
290290
* Js_closure.t
291291
| Continue of label
292292
| Break (* only used when inline a fucntion *)
293-
| Return of return_expression (* Here we need track back a bit ?, move Return to Function ...
293+
| Return of expression (* Here we need track back a bit ?, move Return to Function ...
294294
Then we can only have one Return, which is not good *)
295-
| Int_switch of expression * int case_clause list * block option
296-
| String_switch of expression * string case_clause list * block option
297-
| Throw of expression
298-
| Try of block * (exception_ident * block) option * block option
299-
| Debugger
300-
and return_expression = {
301-
(* since in ocaml, it's expression oriented langauge, [return] in
295+
(* since in ocaml, it's expression oriented langauge, [return] in
302296
general has no jumps, it only happens when we do
303297
tailcall conversion, in that case there is a jump.
304298
However, currently a single [break] is good to cover
305299
our compilation strategy
306-
307300
Attention: we should not insert [break] arbitrarily, otherwise
308301
it would break the semantics
309302
A more robust signature would be
310303
{[ goto : label option ; ]}
311304
*)
312-
return_value : expression
313-
}
305+
306+
| Int_switch of expression * int case_clause list * block option
307+
| String_switch of expression * string case_clause list * block option
308+
| Throw of expression
309+
| Try of block * (exception_ident * block) option * block option
310+
| Debugger
311+
312+
314313

315314
and expression = {
316315
expression_desc : expression_desc;

jscomp/core/js_analyzer.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ and eq_statement
296296
| Exp b -> eq_expression a b
297297
| _ -> false
298298
end
299-
| Return { return_value = a ; _} ->
299+
| Return a ->
300300
begin match y0 with
301-
| Return { return_value = b; _} ->
301+
| Return b ->
302302
eq_expression a b
303303
| _ -> false
304304
end

jscomp/core/js_dump.ml

+5-5
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,14 @@ and pp_function ~is_method
373373
(l : Ident.t list) (b : J.block) (env : Js_fun_env.t ) : cxt =
374374
match b with
375375
| [ {statement_desc =
376-
Return {return_value =
376+
Return
377377
{expression_desc =
378378
Call(({expression_desc = Var v ; _} as function_id),
379379
ls ,
380380
{arity = ( Full | NA as arity(* see #234*));
381381
(* TODO: need a case to justify it*)
382382
call_info =
383-
(Call_builtin_runtime | Call_ml )})}}}]
383+
(Call_builtin_runtime | Call_ml )})}}]
384384
when
385385
(* match such case:
386386
{[ function(x,y){ return u(x,y) } ]}
@@ -1243,7 +1243,7 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
12431243
| Debugger -> debugger_nl f ; cxt
12441244
| Break -> break_nl f; cxt
12451245

1246-
| Return {return_value = e} ->
1246+
| Return e ->
12471247
begin match e.expression_desc with
12481248
| Fun (is_method, l, b, env) ->
12491249
let cxt =
@@ -1340,10 +1340,10 @@ and function_body (cxt : cxt) f (b : J.block) : unit =
13401340
then_,
13411341
[{
13421342
statement_desc =
1343-
Return {return_value = {expression_desc = Undefined}} }])
1343+
Return {expression_desc = Undefined}} ])
13441344
->
13451345
ignore (statement false cxt f {s with statement_desc = If(bool,then_, [])} : cxt)
1346-
| Return {return_value = {expression_desc = Undefined }} -> ()
1346+
| Return {expression_desc = Undefined } -> ()
13471347
| _ ->
13481348
ignore (statement false cxt f s : cxt)
13491349
end

jscomp/core/js_exp_make.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ let of_block ?comment ?e block : t =
13181318
| None -> block
13191319
| Some e ->
13201320
Ext_list.append block
1321-
[{J.statement_desc = Return {return_value = e } ;
1321+
[{J.statement_desc = Return e ;
13221322
comment}]
13231323
end
13241324
, Js_fun_env.make 0)

jscomp/core/js_fold.ml

+12-15
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class virtual fold =
6868
let o = o#block _x_i4 in let o = o#unknown _x_i5 in o
6969
| Continue _x -> let o = o#label _x in o
7070
| Break -> o
71-
| Return _x -> let o = o#return_expression _x in o
71+
| Return _x -> let o = o#expression _x in o
7272
| Int_switch (_x, _x_i1, _x_i2) ->
7373
let o = o#expression _x in
7474
let o =
@@ -265,6 +265,16 @@ class virtual fold =
265265
(* only used when inline a fucntion *)
266266
(* Here we need track back a bit ?, move Return to Function ...
267267
Then we can only have one Return, which is not good *)
268+
(* since in ocaml, it's expression oriented langauge, [return] in
269+
general has no jumps, it only happens when we do
270+
tailcall conversion, in that case there is a jump.
271+
However, currently a single [break] is good to cover
272+
our compilation strategy
273+
Attention: we should not insert [break] arbitrarily, otherwise
274+
it would break the semantics
275+
A more robust signature would be
276+
{[ goto : label option ; ]}
277+
*)
268278
o#case_clause (fun o -> o#int))
269279
_x_i1 in
270280
let o = o#option (fun o -> o#block) _x_i2 in o
@@ -287,8 +297,6 @@ class virtual fold =
287297
fun { statement_desc = _x; comment = _x_i1 } ->
288298
let o = o#statement_desc _x in
289299
let o = o#option (fun o -> o#string) _x_i1 in o
290-
method return_expression : return_expression -> 'self_type =
291-
fun { return_value = _x } -> let o = o#expression _x in o
292300
method required_modules : required_modules -> 'self_type = o#unknown
293301
method property_name : property_name -> 'self_type = o#unknown
294302
method property_map : property_map -> 'self_type =
@@ -387,18 +395,7 @@ class virtual fold =
387395
let o = o#required_modules _x_i1 in
388396
let o = o#option (fun o -> o#string) _x_i2 in o
389397
method case_clause :
390-
(* since in ocaml, it's expression oriented langauge, [return] in
391-
general has no jumps, it only happens when we do
392-
tailcall conversion, in that case there is a jump.
393-
However, currently a single [break] is good to cover
394-
our compilation strategy
395-
396-
Attention: we should not insert [break] arbitrarily, otherwise
397-
it would break the semantics
398-
A more robust signature would be
399-
{[ goto : label option ; ]}
400-
*)
401-
'a. ('self_type -> 'a -> 'self_type) -> 'a case_clause -> 'self_type =
398+
'a. ('self_type -> 'a -> 'self_type) -> 'a case_clause -> 'self_type =
402399
fun _f_a
403400
{
404401
switch_case = _x;

jscomp/core/js_map.ml

+12-16
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class virtual map =
8181
in ForRange (_x, _x_i1, _x_i2, _x_i3, _x_i4, _x_i5)
8282
| Continue _x -> let _x = o#label _x in Continue _x
8383
| Break -> Break
84-
| Return _x -> let _x = o#return_expression _x in Return _x
84+
| Return _x -> let _x = o#expression _x in Return _x
8585
| Int_switch (_x, _x_i1, _x_i2) ->
8686
let _x = o#expression _x in
8787
let _x_i1 =
@@ -278,6 +278,16 @@ class virtual map =
278278
(* only used when inline a fucntion *)
279279
(* Here we need track back a bit ?, move Return to Function ...
280280
Then we can only have one Return, which is not good *)
281+
(* since in ocaml, it's expression oriented langauge, [return] in
282+
general has no jumps, it only happens when we do
283+
tailcall conversion, in that case there is a jump.
284+
However, currently a single [break] is good to cover
285+
our compilation strategy
286+
Attention: we should not insert [break] arbitrarily, otherwise
287+
it would break the semantics
288+
A more robust signature would be
289+
{[ goto : label option ; ]}
290+
*)
281291
o#case_clause (fun o -> o#int))
282292
_x_i1 in
283293
let _x_i2 = o#option (fun o -> o#block) _x_i2
@@ -305,9 +315,6 @@ class virtual map =
305315
let _x = o#statement_desc _x in
306316
let _x_i1 = o#option (fun o -> o#string) _x_i1
307317
in { statement_desc = _x; comment = _x_i1; }
308-
method return_expression : return_expression -> return_expression =
309-
fun { return_value = _x } ->
310-
let _x = o#expression _x in { return_value = _x; }
311318
method required_modules : required_modules -> required_modules =
312319
o#unknown
313320
method property_name : property_name -> property_name = o#unknown
@@ -428,18 +435,7 @@ class virtual map =
428435
let _x_i2 = o#option (fun o -> o#string) _x_i2
429436
in { program = _x; modules = _x_i1; side_effect = _x_i2; }
430437
method case_clause :
431-
(* since in ocaml, it's expression oriented langauge, [return] in
432-
general has no jumps, it only happens when we do
433-
tailcall conversion, in that case there is a jump.
434-
However, currently a single [break] is good to cover
435-
our compilation strategy
436-
437-
Attention: we should not insert [break] arbitrarily, otherwise
438-
it would break the semantics
439-
A more robust signature would be
440-
{[ goto : label option ; ]}
441-
*)
442-
'a 'a_out.
438+
'a 'a_out.
443439
('self_type -> 'a -> 'a_out) -> 'a case_clause -> 'a_out case_clause =
444440
fun _f_a
445441
{

jscomp/core/js_pass_flatten.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ let flatten_map =
6464
| _ ->
6565
assert false
6666
end
67-
| Return ( {return_value = {expression_desc = Cond (a,b,c); comment}})
67+
| Return {expression_desc = Cond (a,b,c); comment}
6868
->
6969
{ statement_desc = If (a, [self#statement (S.return_stmt b)],
7070
[ self#statement (S.return_stmt c)]); comment}
7171

72-
| Return ({return_value = {expression_desc = Seq _; _} as v}) ->
72+
| Return ({expression_desc = Seq _; _} as v) ->
7373
let block = Js_analyzer.rev_flatten_seq v in
7474
begin match block with
7575
| {statement_desc = Exp last_one ; _} :: rest_rev

jscomp/core/js_pass_tailcall_inline.ml

+4-5
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ let subst (export_set : Set_ident.t) stats =
163163
end
164164

165165
| [{statement_desc =
166-
Return {return_value =
166+
Return
167167
{expression_desc =
168-
Call({expression_desc = Var (Id id)},args,_info)}} } as st ]
168+
Call({expression_desc = Var (Id id)},args,_info)} } as st ]
169169
->
170170
begin match Hash_ident.find_opt stats id with
171171

@@ -197,9 +197,8 @@ let subst (export_set : Set_ident.t) stats =
197197
end
198198

199199
| [{statement_desc =
200-
Return {return_value =
201-
{expression_desc =
202-
Call({expression_desc = Fun (false, params, block, env)},args,_info)}} } ]
200+
Return {expression_desc =
201+
Call({expression_desc = Fun (false, params, block, env)},args,_info)}} ]
203202

204203
when Ext_list.same_length params args
205204
->

jscomp/core/js_stmt_make.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module E = Js_exp_make
3232
type t = J.statement
3333

3434
let return_stmt ?comment e : t =
35-
{statement_desc = Return {return_value = e; } ; comment}
35+
{statement_desc = Return e; comment}
3636

3737

3838
let empty_stmt : t =
@@ -231,8 +231,8 @@ let if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block) : t
231231
| [], [] -> exp e
232232
| [], _ ->
233233
aux ?comment (E.not e) ifnot [] (*Make sure no infinite loop*)
234-
| [ {statement_desc = Return {return_value = ret_ifso; _}; _}],
235-
[ {statement_desc = Return {return_value = ret_ifnot; _}; _}]
234+
| [ {statement_desc = Return ret_ifso; _}],
235+
[ {statement_desc = Return ret_ifnot; _}]
236236
->
237237
return_stmt (E.econd e ret_ifso ret_ifnot )
238238
| _, [{statement_desc = Return _ }]

0 commit comments

Comments
 (0)