Skip to content

Commit b0a7894

Browse files
committed
tidy up the pipe line
1 parent 3e28de9 commit b0a7894

File tree

3 files changed

+78
-60
lines changed

3 files changed

+78
-60
lines changed

jscomp/core/js_implementation.ml

+30-28
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ let fprintf = Format.fprintf
2222

2323

2424

25-
let print_if ppf flag printer arg =
25+
let print_if_pipe ppf flag printer arg =
2626
if !flag then fprintf ppf "%a@." printer arg;
2727
arg
2828

29+
let print_if ppf flag printer arg =
30+
if !flag then fprintf ppf "%a@." printer arg
31+
32+
2933

3034
let process_with_gentype filename =
3135
match !Clflags.bs_gentype with
@@ -103,15 +107,15 @@ let interface ppf fname outputprefix =
103107
Compmisc.init_path false;
104108
Pparse.parse_interface ~tool_name:Js_config.tool_name ppf fname
105109
|> Ppx_entry.rewrite_signature
106-
|> print_if ppf Clflags.dump_parsetree Printast.interface
107-
|> print_if ppf Clflags.dump_source Pprintast.signature
110+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.interface
111+
|> print_if_pipe ppf Clflags.dump_source Pprintast.signature
108112
|> after_parsing_sig ppf outputprefix
109113

110114
let interface_mliast ppf fname outputprefix =
111115
Compmisc.init_path false;
112116
Binary_ast.read_ast Mli fname
113-
|> print_if ppf Clflags.dump_parsetree Printast.interface
114-
|> print_if ppf Clflags.dump_source Pprintast.signature
117+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.interface
118+
|> print_if_pipe ppf Clflags.dump_source Pprintast.signature
115119
|> after_parsing_sig ppf outputprefix
116120

117121

@@ -140,43 +144,41 @@ let after_parsing_impl ppf outputprefix ast =
140144
Lam_compile_env.reset () ;
141145
let env = Compmisc.initial_env() in
142146
Env.set_unit_name modulename;
143-
144147
let (typedtree, coercion, _, _) =
145-
ast
146-
|> Typemod.type_implementation_more ?check_exists:(if !Js_config.force_cmi then None else Some ()) !Location.input_name outputprefix modulename env
147-
|> print_if ppf Clflags.dump_typedtree
148-
(fun fmt (ty,co,_,_) -> Printtyped.implementation_with_coercion fmt (ty,co))
149-
in
148+
Typemod.type_implementation_more
149+
?check_exists:(if !Js_config.force_cmi then None else Some ())
150+
!Location.input_name outputprefix modulename env ast in
151+
let typedtree_coercion = (typedtree, coercion) in
152+
print_if ppf Clflags.dump_typedtree
153+
Printtyped.implementation_with_coercion typedtree_coercion ;
150154
if !Clflags.print_types || !Js_config.cmi_only then begin
151155
Warnings.check_fatal ();
152156
end else begin
153-
(typedtree, coercion)
154-
|> Translmod.transl_implementation modulename
155-
|> (fun lambda ->
156-
let js_program =
157-
print_if ppf Clflags.dump_rawlambda Printlambda.lambda (get_lambda lambda)
158-
|> Lam_compile_main.compile outputprefix in
159-
if not !Js_config.cmj_only then
160-
Lam_compile_main.lambda_as_module
161-
js_program
162-
outputprefix
163-
);
157+
let lambda = Translmod.transl_implementation modulename typedtree_coercion in
158+
let js_program =
159+
print_if_pipe ppf Clflags.dump_rawlambda Printlambda.lambda (get_lambda lambda)
160+
|> Lam_compile_main.compile outputprefix in
161+
if not !Js_config.cmj_only then
162+
Lam_compile_main.lambda_as_module
163+
js_program
164+
outputprefix
165+
;
164166
end;
165167
process_with_gentype (outputprefix ^ ".cmt")
166168
end
167169
let implementation ppf fname outputprefix =
168170
Compmisc.init_path false;
169171
Pparse.parse_implementation ~tool_name:Js_config.tool_name ppf fname
170172
|> Ppx_entry.rewrite_implementation
171-
|> print_if ppf Clflags.dump_parsetree Printast.implementation
172-
|> print_if ppf Clflags.dump_source Pprintast.structure
173+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
174+
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
173175
|> after_parsing_impl ppf outputprefix
174176

175177
let implementation_mlast ppf fname outputprefix =
176178
Compmisc.init_path false;
177179
Binary_ast.read_ast Ml fname
178-
|> print_if ppf Clflags.dump_parsetree Printast.implementation
179-
|> print_if ppf Clflags.dump_source Pprintast.structure
180+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
181+
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
180182
|> after_parsing_impl ppf outputprefix
181183

182184

@@ -212,7 +214,7 @@ let implementation_map ppf sourcefile outputprefix =
212214
) in
213215
Compmisc.init_path false;
214216
ml_ast
215-
|> print_if ppf Clflags.dump_parsetree Printast.implementation
216-
|> print_if ppf Clflags.dump_source Pprintast.structure
217+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
218+
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
217219
|> after_parsing_impl ppf outputprefix
218220

lib/4.02.3/unstable/js_compiler.ml

+9-2
Original file line numberDiff line numberDiff line change
@@ -81014,10 +81014,17 @@ class virtual fold =
8101481014
{[ goto : label option ; ]}
8101581015
*)
8101681016
'a. ('self_type -> 'a -> 'self_type) -> 'a case_clause -> 'self_type =
81017-
fun _f_a { switch_case = _x; switch_body = _x_i1; should_break = _x_i2
81017+
fun _f_a
81018+
{
81019+
switch_case = _x;
81020+
switch_body = _x_i1;
81021+
should_break = _x_i2;
81022+
comment = _x_i3
8101881023
} ->
8101981024
let o = _f_a o _x in
81020-
let o = o#block _x_i1 in let o = o#bool _x_i2 in o
81025+
let o = o#block _x_i1 in
81026+
let o = o#bool _x_i2 in
81027+
let o = o#option (fun o -> o#string) _x_i3 in o
8102181028
method block : block -> 'self_type = (* true means break *)
8102281029
(* TODO: For efficency: block should not be a list, it should be able to
8102381030
be concatenated in both ways

lib/4.02.3/whole_compiler.ml

+39-30
Original file line numberDiff line numberDiff line change
@@ -71158,10 +71158,17 @@ class virtual fold =
7115871158
{[ goto : label option ; ]}
7115971159
*)
7116071160
'a. ('self_type -> 'a -> 'self_type) -> 'a case_clause -> 'self_type =
71161-
fun _f_a { switch_case = _x; switch_body = _x_i1; should_break = _x_i2
71161+
fun _f_a
71162+
{
71163+
switch_case = _x;
71164+
switch_body = _x_i1;
71165+
should_break = _x_i2;
71166+
comment = _x_i3
7116271167
} ->
7116371168
let o = _f_a o _x in
71164-
let o = o#block _x_i1 in let o = o#bool _x_i2 in o
71169+
let o = o#block _x_i1 in
71170+
let o = o#bool _x_i2 in
71171+
let o = o#option (fun o -> o#string) _x_i3 in o
7116571172
method block : block -> 'self_type = (* true means break *)
7116671173
(* TODO: For efficency: block should not be a list, it should be able to
7116771174
be concatenated in both ways
@@ -123058,10 +123065,14 @@ let fprintf = Format.fprintf
123058123065

123059123066

123060123067

123061-
let print_if ppf flag printer arg =
123068+
let print_if_pipe ppf flag printer arg =
123062123069
if !flag then fprintf ppf "%a@." printer arg;
123063123070
arg
123064123071

123072+
let print_if ppf flag printer arg =
123073+
if !flag then fprintf ppf "%a@." printer arg
123074+
123075+
123065123076

123066123077
let process_with_gentype filename =
123067123078
match !Clflags.bs_gentype with
@@ -123132,15 +123143,15 @@ let interface ppf fname outputprefix =
123132123143
Compmisc.init_path false;
123133123144
Pparse.parse_interface ~tool_name:Js_config.tool_name ppf fname
123134123145
|> Ppx_entry.rewrite_signature
123135-
|> print_if ppf Clflags.dump_parsetree Printast.interface
123136-
|> print_if ppf Clflags.dump_source Pprintast.signature
123146+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.interface
123147+
|> print_if_pipe ppf Clflags.dump_source Pprintast.signature
123137123148
|> after_parsing_sig ppf outputprefix
123138123149

123139123150
let interface_mliast ppf fname outputprefix =
123140123151
Compmisc.init_path false;
123141123152
Binary_ast.read_ast Mli fname
123142-
|> print_if ppf Clflags.dump_parsetree Printast.interface
123143-
|> print_if ppf Clflags.dump_source Pprintast.signature
123153+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.interface
123154+
|> print_if_pipe ppf Clflags.dump_source Pprintast.signature
123144123155
|> after_parsing_sig ppf outputprefix
123145123156

123146123157

@@ -123167,43 +123178,41 @@ let after_parsing_impl ppf outputprefix ast =
123167123178
Lam_compile_env.reset () ;
123168123179
let env = Compmisc.initial_env() in
123169123180
Env.set_unit_name modulename;
123170-
123171123181
let (typedtree, coercion, _, _) =
123172-
ast
123173-
|> Typemod.type_implementation_more ?check_exists:(if !Js_config.force_cmi then None else Some ()) !Location.input_name outputprefix modulename env
123174-
|> print_if ppf Clflags.dump_typedtree
123175-
(fun fmt (ty,co,_,_) -> Printtyped.implementation_with_coercion fmt (ty,co))
123176-
in
123182+
Typemod.type_implementation_more
123183+
?check_exists:(if !Js_config.force_cmi then None else Some ())
123184+
!Location.input_name outputprefix modulename env ast in
123185+
let typedtree_coercion = (typedtree, coercion) in
123186+
print_if ppf Clflags.dump_typedtree
123187+
Printtyped.implementation_with_coercion typedtree_coercion ;
123177123188
if !Clflags.print_types || !Js_config.cmi_only then begin
123178123189
Warnings.check_fatal ();
123179123190
end else begin
123180-
(typedtree, coercion)
123181-
|> Translmod.transl_implementation modulename
123182-
|> (fun lambda ->
123183-
let js_program =
123184-
print_if ppf Clflags.dump_rawlambda Printlambda.lambda (get_lambda lambda)
123185-
|> Lam_compile_main.compile outputprefix in
123186-
if not !Js_config.cmj_only then
123187-
Lam_compile_main.lambda_as_module
123188-
js_program
123189-
outputprefix
123190-
);
123191+
let lambda = Translmod.transl_implementation modulename typedtree_coercion in
123192+
let js_program =
123193+
print_if_pipe ppf Clflags.dump_rawlambda Printlambda.lambda (get_lambda lambda)
123194+
|> Lam_compile_main.compile outputprefix in
123195+
if not !Js_config.cmj_only then
123196+
Lam_compile_main.lambda_as_module
123197+
js_program
123198+
outputprefix
123199+
;
123191123200
end;
123192123201
process_with_gentype (outputprefix ^ ".cmt")
123193123202
end
123194123203
let implementation ppf fname outputprefix =
123195123204
Compmisc.init_path false;
123196123205
Pparse.parse_implementation ~tool_name:Js_config.tool_name ppf fname
123197123206
|> Ppx_entry.rewrite_implementation
123198-
|> print_if ppf Clflags.dump_parsetree Printast.implementation
123199-
|> print_if ppf Clflags.dump_source Pprintast.structure
123207+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
123208+
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
123200123209
|> after_parsing_impl ppf outputprefix
123201123210

123202123211
let implementation_mlast ppf fname outputprefix =
123203123212
Compmisc.init_path false;
123204123213
Binary_ast.read_ast Ml fname
123205-
|> print_if ppf Clflags.dump_parsetree Printast.implementation
123206-
|> print_if ppf Clflags.dump_source Pprintast.structure
123214+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
123215+
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
123207123216
|> after_parsing_impl ppf outputprefix
123208123217

123209123218

@@ -123239,8 +123248,8 @@ let implementation_map ppf sourcefile outputprefix =
123239123248
) in
123240123249
Compmisc.init_path false;
123241123250
ml_ast
123242-
|> print_if ppf Clflags.dump_parsetree Printast.implementation
123243-
|> print_if ppf Clflags.dump_source Pprintast.structure
123251+
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
123252+
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
123244123253
|> after_parsing_impl ppf outputprefix
123245123254

123246123255

0 commit comments

Comments
 (0)