Skip to content

Commit

Permalink
Remove redundant space after continue in generated file (#6743)
Browse files Browse the repository at this point in the history
* Remove continue label

* Recompile tests

* Update changelog
  • Loading branch information
DZakh committed May 13, 2024
1 parent cfed01f commit aee06c0
Show file tree
Hide file tree
Showing 218 changed files with 1,917 additions and 1,969 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Make the `--help` arg be prioritized in the CLI, so correctly prints help message and skip other commands. https://github.com/rescript-lang/rescript-compiler/pull/6667
- Remove redundant space for empty return in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6745
- Remove redundant space for export in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6560
- Remove redundant space after continue in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6743
- Remove empty export blocks in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6744
- Fix indent for returned/thrown/wrapped in parentheses objects in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6746
- Fix indent in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6747
Expand Down
5 changes: 2 additions & 3 deletions jscomp/core/j.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type exports = Js_op.exports
type tag_info = Js_op.tag_info
type property_name = Js_op.property_name

type label = string
and ident = Ident.t
(* we override `method ident` *)

Expand Down Expand Up @@ -254,15 +253,15 @@ and statement_desc =
(* Function declaration and Variable declaration *)
| Exp of expression
| If of expression * block * block
| While of label option * expression * block
| While of expression * block
(* check if it contains loop mutable values, happens in nested loop *)
| ForRange of
for_ident_expression option
* finish_ident_expression
* for_ident
* for_direction
* block
| Continue of label
| Continue
| Break (* only used when inline a fucntion *)
| Return of expression
(* Here we need track back a bit ?, move Return to Function ...
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/js_analyzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ let no_side_effect_obj =
statement =
(fun self s ->
match s.statement_desc with
| Throw _ | Debugger | Break | Variable _ | Continue _ ->
| Throw _ | Debugger | Break | Variable _ | Continue ->
raise_notrace Not_found
| Exp e -> self.expression self e
| Int_switch _ | String_switch _ | ForRange _ | If _ | While _ | Block _
Expand Down Expand Up @@ -226,7 +226,7 @@ and eq_statement ({ statement_desc = x0 } : J.statement)
| Debugger -> y0 = Debugger
| Break -> y0 = Break
| Block xs0 -> ( match y0 with Block ys0 -> eq_block xs0 ys0 | _ -> false)
| Variable _ | If _ | While _ | ForRange _ | Continue _ | Int_switch _
| Variable _ | If _ | While _ | ForRange _ | Continue | Int_switch _
| String_switch _ | Throw _ | Try _ ->
false

Expand Down
16 changes: 4 additions & 12 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,8 @@ let break_nl f =
semi f;
P.newline f

let continue f s =
let continue f =
P.string f L.continue;
P.space f;
P.string f s;
semi f

let formal_parameter_list cxt f l = iter_lst cxt f l Ext_pp_scope.ident comma_sp
Expand Down Expand Up @@ -1020,14 +1018,8 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
P.string f L.else_;
P.space f;
brace_block cxt f s2)
| While (label, e, s) ->
| While (e, s) ->
(* FIXME: print scope as well *)
(match label with
| Some i ->
P.string f i;
P.string f L.colon;
P.newline f
| None -> ());
let cxt =
match e.expression_desc with
| Number (Int { i = 1l }) ->
Expand Down Expand Up @@ -1120,8 +1112,8 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
brace_block cxt f s)
in
action cxt
| Continue s ->
continue f s;
| Continue ->
continue f;
cxt
(* P.newline f; #2642 *)
| Debugger ->
Expand Down
13 changes: 4 additions & 9 deletions jscomp/core/js_fold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class fold =
let _self = _self#list _f_a _x_i1 in
_self

method label : label -> 'self_type = unknown _self

method ident : ident -> 'self_type = unknown _self

method module_id : module_id -> 'self_type =
Expand Down Expand Up @@ -217,10 +215,9 @@ class fold =
let _self = _self#block _x1 in
let _self = _self#block _x2 in
_self
| While (_x0, _x1, _x2) ->
let _self = option (fun _self -> _self#label) _self _x0 in
let _self = _self#expression _x1 in
let _self = _self#block _x2 in
| While (_x0, _x1) ->
let _self = _self#expression _x0 in
let _self = _self#block _x1 in
_self
| ForRange (_x0, _x1, _x2, _x3, _x4) ->
let _self =
Expand All @@ -231,9 +228,7 @@ class fold =
let _self = _self#for_direction _x3 in
let _self = _self#block _x4 in
_self
| Continue _x0 ->
let _self = _self#label _x0 in
_self
| Continue -> _self
| Break -> _self
| Return _x0 ->
let _self = _self#expression _x0 in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_pass_scope.ml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ let record_scope_pass =
closured_idents =
Set_ident.union state.closured_idents lexical_scope;
}
| While (_label, pred, body) ->
| While (pred, body) ->
with_in_loop
(self.block self
(with_in_loop (self.expression self state pred) true)
Expand Down
13 changes: 4 additions & 9 deletions jscomp/core/js_record_fold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ type 'state iter = {

and ('state, 'a) fn = 'state iter -> 'state -> 'a -> 'state

let label : 'a. ('a, label) fn = unknown

let ident : 'a. ('a, ident) fn = unknown

let module_id : 'a. ('a, module_id) fn =
Expand Down Expand Up @@ -223,10 +221,9 @@ let statement_desc : 'a. ('a, statement_desc) fn =
let st = _self.block _self st _x1 in
let st = _self.block _self st _x2 in
st
| While (_x0, _x1, _x2) ->
let st = option label _self st _x0 in
let st = _self.expression _self st _x1 in
let st = _self.block _self st _x2 in
| While (_x0, _x1) ->
let st = _self.expression _self st _x0 in
let st = _self.block _self st _x1 in
st
| ForRange (_x0, _x1, _x2, _x3, _x4) ->
let st = option for_ident_expression _self st _x0 in
Expand All @@ -235,9 +232,7 @@ let statement_desc : 'a. ('a, statement_desc) fn =
let st = for_direction _self st _x3 in
let st = _self.block _self st _x4 in
st
| Continue _x0 ->
let st = label _self st _x0 in
st
| Continue -> st
| Break -> st
| Return _x0 ->
let st = _self.expression _self st _x0 in
Expand Down
11 changes: 4 additions & 7 deletions jscomp/core/js_record_iter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ type iter = {

and 'a fn = iter -> 'a -> unit

let label : label fn = unknown

let ident : ident fn = unknown

let module_id : module_id fn =
Expand Down Expand Up @@ -163,17 +161,16 @@ let statement_desc : statement_desc fn =
_self.expression _self _x0;
_self.block _self _x1;
_self.block _self _x2
| While (_x0, _x1, _x2) ->
option label _self _x0;
_self.expression _self _x1;
_self.block _self _x2
| While (_x0, _x1) ->
_self.expression _self _x0;
_self.block _self _x1
| ForRange (_x0, _x1, _x2, _x3, _x4) ->
option for_ident_expression _self _x0;
finish_ident_expression _self _x1;
_self.for_ident _self _x2;
for_direction _self _x3;
_self.block _self _x4
| Continue _x0 -> label _self _x0
| Continue -> ()
| Break -> ()
| Return _x0 -> _self.expression _self _x0
| Int_switch (_x0, _x1, _x2) ->
Expand Down
15 changes: 5 additions & 10 deletions jscomp/core/js_record_map.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ type iter = {

and 'a fn = iter -> 'a -> 'a

let label : label fn = unknown

let ident : ident fn = unknown

let module_id : module_id fn =
Expand Down Expand Up @@ -221,21 +219,18 @@ let statement_desc : statement_desc fn =
let _x1 = _self.block _self _x1 in
let _x2 = _self.block _self _x2 in
If (_x0, _x1, _x2)
| While (_x0, _x1, _x2) ->
let _x0 = option label _self _x0 in
let _x1 = _self.expression _self _x1 in
let _x2 = _self.block _self _x2 in
While (_x0, _x1, _x2)
| While (_x0, _x1) ->
let _x0 = _self.expression _self _x0 in
let _x1 = _self.block _self _x1 in
While (_x0, _x1)
| ForRange (_x0, _x1, _x2, _x3, _x4) ->
let _x0 = option for_ident_expression _self _x0 in
let _x1 = finish_ident_expression _self _x1 in
let _x2 = _self.for_ident _self _x2 in
let _x3 = for_direction _self _x3 in
let _x4 = _self.block _self _x4 in
ForRange (_x0, _x1, _x2, _x3, _x4)
| Continue _x0 ->
let _x0 = label _self _x0 in
Continue _x0
| Continue as v -> v
| Break as v -> v
| Return _x0 ->
let _x0 = _self.expression _self _x0 in
Expand Down
17 changes: 4 additions & 13 deletions jscomp/core/js_stmt_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ let rec block_last_is_return_throw_or_continue (x : J.block) =
| [] -> false
| [ x ] -> (
match x.statement_desc with
| Return _ | Throw _ | Continue _ -> true
| Return _ | Throw _ | Continue -> true
| _ -> false)
| _ :: rest -> block_last_is_return_throw_or_continue rest

Expand Down Expand Up @@ -318,8 +318,8 @@ let if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block) : t =
let assign ?comment id e : t =
{ statement_desc = J.Exp (E.assign (E.var id) e); comment }

let while_ ?comment ?label (e : E.t) (st : J.block) : t =
{ statement_desc = While (label, e, st); comment }
let while_ ?comment (e : E.t) (st : J.block) : t =
{ statement_desc = While (e, st); comment }

let for_ ?comment for_ident_expression finish_ident_expression id direction
(b : J.block) : t =
Expand All @@ -333,15 +333,6 @@ let for_ ?comment for_ident_expression finish_ident_expression id direction
let try_ ?comment ?with_ ?finally body : t =
{ statement_desc = Try (body, with_, finally); comment }

(* TODO:
actually, only loops can be labelled
*)
(* let continue_stmt ?comment ?(label="") () : t =
{
statement_desc = J.Continue label;
comment;
} *)

let continue_ : t = { statement_desc = Continue ""; comment = None }
let continue_ : t = { statement_desc = Continue; comment = None }

let debugger_block : t list = [ { statement_desc = Debugger; comment = None } ]
1 change: 0 additions & 1 deletion jscomp/core/js_stmt_make.mli
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ val assign : ?comment:string -> J.ident -> J.expression -> t

val while_ :
?comment:string ->
?label:J.label ->
J.expression ->
J.block ->
t
Expand Down
4 changes: 1 addition & 3 deletions jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t)
(id : Ident.t) (arg : Lam.t) : Js_output.t * initialization =
match arg with
| Lfunction { params; body; attr = { return_unit; async; oneUnitArg } } ->
let continue_label = Lam_util.generate_label ~name:id.name () in
(* TODO: Think about recursive value
{[
let rec v = ref (fun _ ...
Expand All @@ -331,7 +330,6 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t)
let ret : Lam_compile_context.return_label =
{
id;
label = continue_label;
params;
immutable_mask = Array.make (List.length params) true;
new_params = Map_ident.empty;
Expand Down Expand Up @@ -363,7 +361,7 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t)
(Ext_list.map params (fun x ->
Map_ident.find_default ret.new_params x x))
[
S.while_ (* ~label:continue_label *) E.true_
S.while_ E.true_
(Map_ident.fold ret.new_params body_block
(fun old new_param acc ->
S.define_variable ~kind:Alias old (E.var new_param) :: acc));
Expand Down
1 change: 0 additions & 1 deletion jscomp/core/lam_compile_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type value = { exit_id : Ident.t; bindings : Ident.t list; order_id : int }
*)
type return_label = {
id : Ident.t;
label : J.label;
params : Ident.t list;
immutable_mask : bool array;
mutable new_params : Ident.t Map_ident.t;
Expand Down
1 change: 0 additions & 1 deletion jscomp/core/lam_compile_context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type jbl_label = int

type return_label = {
id : Ident.t;
label : J.label;
params : Ident.t list;
immutable_mask : bool array;
mutable new_params : Ident.t Map_ident.t;
Expand Down
10 changes: 0 additions & 10 deletions jscomp/core/lam_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,6 @@ let field_flatten_get
| Some _
| None -> lam ()


(* TODO: check that if label belongs to a different
namesape
*)
let count = ref 0

let generate_label ?(name="") () =
incr count;
Printf.sprintf "%s_tailcall_%04d" name !count

#if (defined BROWSER || defined RELEASE)
let dump ext lam =
()
Expand Down
2 changes: 0 additions & 2 deletions jscomp/core/lam_util.mli
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ val alias_ident_or_global :

val refine_let : kind:Lam_compat.let_kind -> Ident.t -> Lam.t -> Lam.t -> Lam.t

val generate_label : ?name:string -> unit -> J.label

val dump : string -> Lam.t -> unit
(** [dump] when {!Js_config.is_same_file}*)

Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/a_scope_bug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions jscomp/test/and_or_tailcall_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions jscomp/test/arith_lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aee06c0

Please sign in to comment.