Skip to content

Commit 99945f0

Browse files
committed
Don't pass untyped ast, simple flag is sufficient.
1 parent f1b4687 commit 99945f0

32 files changed

+139
-177
lines changed

compiler/core/js_call_info.ml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ type call_info =
3333
{[ fun x y -> (f x y) === f ]} when [f] is an atom
3434
*)
3535

36-
type t = {
37-
call_info: call_info;
38-
arity: arity;
39-
call_transformed_jsx: Parsetree.jsx_element option;
40-
}
36+
type t = {call_info: call_info; arity: arity; call_transformed_jsx: bool}
4137

42-
let dummy = {arity = NA; call_info = Call_na; call_transformed_jsx = None}
38+
let dummy = {arity = NA; call_info = Call_na; call_transformed_jsx = false}
4339

4440
let builtin_runtime_call =
45-
{arity = Full; call_info = Call_builtin_runtime; call_transformed_jsx = None}
41+
{arity = Full; call_info = Call_builtin_runtime; call_transformed_jsx = false}
4642

4743
let ml_full_call =
48-
{arity = Full; call_info = Call_ml; call_transformed_jsx = None}
44+
{arity = Full; call_info = Call_ml; call_transformed_jsx = false}

compiler/core/js_call_info.mli

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ type call_info =
3535
{[ fun x y -> f x y === f ]} when [f] is an atom
3636
*)
3737

38-
type t = {
39-
call_info: call_info;
40-
arity: arity;
41-
call_transformed_jsx: Parsetree.jsx_element option;
42-
}
38+
type t = {call_info: call_info; arity: arity; call_transformed_jsx: bool}
4339

4440
val dummy : t
4541

compiler/core/js_dump.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
524524
when Ext_list.length_equal el i
525525
]}
526526
*)
527-
| Call (e, el, {call_transformed_jsx = Some jsx_element}) -> (
527+
| Call (e, el, {call_transformed_jsx = true}) -> (
528528
match el with
529529
| [
530530
tag;
@@ -561,11 +561,9 @@ and expression_desc cxt ~(level : int) f x : cxt =
561561
(Call
562562
( e,
563563
el,
564-
{call_transformed_jsx = None; arity = Full; call_info = Call_ml} ))
565-
)
564+
{call_transformed_jsx = false; arity = Full; call_info = Call_ml}
565+
)))
566566
| Call (e, el, info) ->
567-
Format.fprintf Format.err_formatter "Js_dump Has transformed_jsx %b\n"
568-
(Option.is_some info.call_transformed_jsx);
569567
P.cond_paren_group f (level > 15) (fun _ ->
570568
P.group f 0 (fun _ ->
571569
match (info, el) with
@@ -1080,7 +1078,7 @@ and print_jsx cxt ~(level : int) f (tag : J.expression)
10801078
| Some children ->
10811079
let child_is_jsx =
10821080
match children.expression_desc with
1083-
| J.Call (_, _, {call_transformed_jsx = Some _}) -> true
1081+
| J.Call (_, _, {call_transformed_jsx = is_jsx}) -> is_jsx
10841082
| _ -> false
10851083
in
10861084

compiler/core/lam.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module Types = struct
8585
ap_func: t;
8686
ap_args: t list;
8787
ap_info: ap_info;
88-
ap_transformed_jsx: Parsetree.jsx_element option;
88+
ap_transformed_jsx: bool;
8989
}
9090

9191
and t =
@@ -130,7 +130,7 @@ module X = struct
130130
ap_func: t;
131131
ap_args: t list;
132132
ap_info: ap_info;
133-
ap_transformed_jsx: Parsetree.jsx_element option;
133+
ap_transformed_jsx: bool;
134134
}
135135

136136
and lfunction = Types.lfunction = {
@@ -289,7 +289,7 @@ let rec is_eta_conversion_exn params inner_args outer_args : t list =
289289
| _, _, _ -> raise_notrace Not_simple_form
290290

291291
(** FIXME: more robust inlining check later, we should inline it before we add stub code*)
292-
let rec apply ?(ap_transformed_jsx = None) fn args (ap_info : ap_info) : t =
292+
let rec apply ?(ap_transformed_jsx = false) fn args (ap_info : ap_info) : t =
293293
match fn with
294294
| Lfunction
295295
{
@@ -723,7 +723,7 @@ let result_wrap loc (result_type : External_ffi_types.return_wrapper) result =
723723
prim ~primitive:Pundefined_to_opt ~args:[result] loc
724724
| Return_unset | Return_identity -> result
725725

726-
let handle_bs_non_obj_ffi ?transformed_jsx
726+
let handle_bs_non_obj_ffi ?(transformed_jsx = false)
727727
(arg_types : External_arg_spec.params)
728728
(result_type : External_ffi_types.return_wrapper) ffi args loc prim_name
729729
~dynamic_import =

compiler/core/lam.mli

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ and apply = private {
4545
ap_func: t;
4646
ap_args: t list;
4747
ap_info: ap_info;
48-
ap_transformed_jsx: Parsetree.jsx_element option;
48+
ap_transformed_jsx: bool;
4949
}
5050

5151
and lfunction = {
@@ -90,7 +90,7 @@ and t = private
9090
val inner_map : t -> (t -> t) -> t
9191

9292
val handle_bs_non_obj_ffi :
93-
?transformed_jsx:Parsetree.jsx_element ->
93+
?transformed_jsx:bool ->
9494
External_arg_spec.params ->
9595
External_ffi_types.return_wrapper ->
9696
External_ffi_types.external_spec ->
@@ -109,12 +109,7 @@ val global_module : ?dynamic_import:bool -> ident -> t
109109

110110
val const : Lam_constant.t -> t
111111

112-
val apply :
113-
?ap_transformed_jsx:Parsetree.jsx_element option ->
114-
t ->
115-
t list ->
116-
ap_info ->
117-
t
112+
val apply : ?ap_transformed_jsx:bool -> t -> t list -> ap_info -> t
118113

119114
val function_ :
120115
attr:Lambda.function_attribute ->

compiler/core/lam_compile.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let rec apply_with_arity_aux (fn : J.expression) (arity : int list)
5555
{
5656
arity = Full;
5757
call_info = Call_ml;
58-
(* no clue if this is correct *) call_transformed_jsx = None;
58+
(* no clue if this is correct *) call_transformed_jsx = false;
5959
}
6060
fn first_part)
6161
rest continue (len - x)
@@ -76,7 +76,7 @@ let rec apply_with_arity_aux (fn : J.expression) (arity : int list)
7676
arity = Full;
7777
call_info = Call_ml;
7878
(* no clue if this is correct *) call_transformed_jsx =
79-
None;
79+
false;
8080
}
8181
fn
8282
(Ext_list.append args @@ Ext_list.map params E.var));

compiler/core/lam_compile_external_call.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,9 @@ let translate_scoped_access scopes obj =
267267
| [] -> obj
268268
| x :: xs -> Ext_list.fold_left xs (E.dot obj x) E.dot
269269

270-
let translate_ffi ?(transformed_jsx : Parsetree.jsx_element option)
271-
(cxt : Lam_compile_context.t) arg_types
272-
(ffi : External_ffi_types.external_spec) (args : J.expression list)
273-
~dynamic_import =
270+
let translate_ffi ?(transformed_jsx = false) (cxt : Lam_compile_context.t)
271+
arg_types (ffi : External_ffi_types.external_spec)
272+
(args : J.expression list) ~dynamic_import =
274273
match ffi with
275274
| Js_call
276275
{external_module_name; name; splice : _; scopes; tagged_template = true}

compiler/core/lam_compile_external_call.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ val ocaml_to_js_eff :
3030
(** Compile ocaml external function call to JS IR. *)
3131

3232
val translate_ffi :
33-
?transformed_jsx:Parsetree.jsx_element ->
33+
?transformed_jsx:bool ->
3434
Lam_compile_context.t ->
3535
External_arg_spec.params ->
3636
External_ffi_types.external_spec ->

compiler/core/lam_compile_primitive.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ let get_module_system () =
5656

5757
let import_of_path path =
5858
E.call
59-
~info:{arity = Full; call_info = Call_na; call_transformed_jsx = None}
59+
~info:{arity = Full; call_info = Call_na; call_transformed_jsx = false}
6060
(E.js_global "import")
6161
[E.str path]
6262

6363
let wrap_then import value =
6464
let arg = Ident.create "m" in
6565
E.call
66-
~info:{arity = Full; call_info = Call_na; call_transformed_jsx = None}
66+
~info:{arity = Full; call_info = Call_na; call_transformed_jsx = false}
6767
(E.dot import "then")
6868
[
6969
E.ocaml_fun ~return_unit:false ~async:false ~one_unit_arg:false [arg]
@@ -90,7 +90,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
9090
match args with
9191
| fn :: rest ->
9292
E.call
93-
~info:{arity = Full; call_info = Call_na; call_transformed_jsx = None}
93+
~info:{arity = Full; call_info = Call_na; call_transformed_jsx = false}
9494
fn rest
9595
| _ -> assert false)
9696
| Pnull_to_opt -> (
@@ -599,7 +599,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
599599
| Pjs_object_create _ -> assert false
600600
| Pjs_call {arg_types; ffi; dynamic_import; transformed_jsx} ->
601601
Lam_compile_external_call.translate_ffi cxt arg_types ffi args
602-
~dynamic_import ?transformed_jsx
602+
~dynamic_import ~transformed_jsx
603603
(* FIXME, this can be removed later *)
604604
| Pisint -> E.is_type_number (Ext_list.singleton_exn args)
605605
| Pis_poly_var_block -> E.is_type_object (Ext_list.singleton_exn args)

compiler/core/lam_convert.ml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
373373
let exit_map = Hash_int.create 0 in
374374
let may_depends = Lam_module_ident.Hash_set.create 0 in
375375

376-
let rec convert_ccall ?(transformed_jsx = None)
376+
let rec convert_ccall ?(transformed_jsx = false)
377377
(a_prim : Primitive.description) (args : Lambda.lambda list) loc
378378
~dynamic_import : Lam.t =
379379
let prim_name = a_prim.prim_name in
@@ -382,14 +382,13 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
382382
let args = Ext_list.map args convert_aux in
383383
prim ~primitive:(Pjs_object_create labels) ~args loc
384384
| Ffi_bs (arg_types, result_type, ffi) ->
385-
Format.fprintf Format.err_formatter "Ffi_bs\n";
386385
let arg_types =
387386
match arg_types with
388387
| Params ls -> ls
389388
| Param_number i -> Ext_list.init i (fun _ -> External_arg_spec.dummy)
390389
in
391390
let args = Ext_list.map args convert_aux in
392-
Lam.handle_bs_non_obj_ffi ?transformed_jsx arg_types result_type ffi args
391+
Lam.handle_bs_non_obj_ffi ~transformed_jsx arg_types result_type ffi args
393392
loc prim_name ~dynamic_import
394393
| Ffi_inline_const i -> Lam.const i
395394
| Ffi_normal ->
@@ -455,9 +454,6 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
455454
| Lprim (Prevapply, _, _, _) -> assert false
456455
| Lprim (Pdirapply, _, _, _) -> assert false
457456
| Lprim (Pccall a, args, loc, transformed_jsx) ->
458-
Format.fprintf Format.err_formatter
459-
"lam convert Pccall Has transformed_jsx %b\n"
460-
(Option.is_some transformed_jsx);
461457
convert_ccall ~transformed_jsx a args loc ~dynamic_import
462458
| Lprim (Pjs_raw_expr, args, loc, _) -> (
463459
match args with

compiler/core/lam_pass_alpha_conversion.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
let alpha_conversion (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
26-
let rec populate_apply_info ?(ap_transformed_jsx = None)
26+
let rec populate_apply_info ?(ap_transformed_jsx = false)
2727
(args_arity : int list) (len : int) (fn : Lam.t) (args : Lam.t list)
2828
ap_info : Lam.t =
2929
match args_arity with

compiler/core/lam_primitive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type t =
4646
arg_types: External_arg_spec.params;
4747
ffi: External_ffi_types.external_spec;
4848
dynamic_import: bool;
49-
transformed_jsx: Parsetree.jsx_element option;
49+
transformed_jsx: bool;
5050
}
5151
| Pjs_object_create of External_arg_spec.obj_params
5252
(* Exceptions *)

compiler/core/lam_primitive.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type t =
4242
arg_types: External_arg_spec.params;
4343
ffi: External_ffi_types.external_spec;
4444
dynamic_import: bool;
45-
transformed_jsx: Parsetree.jsx_element option;
45+
transformed_jsx: bool;
4646
}
4747
| Pjs_object_create of External_arg_spec.obj_params
4848
| Praise

compiler/core/polyvar_pattern_match.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let or_list (arg : lam) (hash_names : (int * string) list) =
6666
( Pintcomp Ceq,
6767
[arg; Lconst (Const_pointer (hash, Pt_variant {name}))],
6868
Location.none,
69-
None )
69+
false )
7070
in
7171
Ext_list.fold_left rest init (fun acc (hash, name) ->
7272
Lambda.Lprim
@@ -77,10 +77,10 @@ let or_list (arg : lam) (hash_names : (int * string) list) =
7777
( Pintcomp Ceq,
7878
[arg; Lconst (Const_pointer (hash, Pt_variant {name}))],
7979
Location.none,
80-
None );
80+
false );
8181
],
8282
Location.none,
83-
None ))
83+
false ))
8484
| _ -> assert false
8585

8686
let make_test_sequence_variant_constant (fail : lam option) (arg : lam)
@@ -114,5 +114,5 @@ let call_switcher_variant_constr (loc : Location.t) (fail : lam option)
114114
( Alias,
115115
Pgenval,
116116
v,
117-
Lprim (Pfield (0, Fld_poly_var_tag), [arg], loc, None),
117+
Lprim (Pfield (0, Fld_poly_var_tag), [arg], loc, false),
118118
call_switcher_variant_constant loc fail (Lvar v) int_lambda_list names )

compiler/frontend/ast_compatible.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let apply_simple ?(loc = default_loc) ?(attrs = []) (fn : expression)
4444
funct = fn;
4545
args = Ext_list.map args (fun x -> (Asttypes.Nolabel, x));
4646
partial = false;
47-
transformed_jsx = None;
47+
transformed_jsx = false;
4848
};
4949
}
5050

@@ -58,7 +58,7 @@ let app1 ?(loc = default_loc) ?(attrs = []) fn arg1 : expression =
5858
funct = fn;
5959
args = [(Nolabel, arg1)];
6060
partial = false;
61-
transformed_jsx = None;
61+
transformed_jsx = false;
6262
};
6363
}
6464

@@ -72,7 +72,7 @@ let app2 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 : expression =
7272
funct = fn;
7373
args = [(Nolabel, arg1); (Nolabel, arg2)];
7474
partial = false;
75-
transformed_jsx = None;
75+
transformed_jsx = false;
7676
};
7777
}
7878

@@ -86,7 +86,7 @@ let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
8686
funct = fn;
8787
args = [(Nolabel, arg1); (Nolabel, arg2); (Nolabel, arg3)];
8888
partial = false;
89-
transformed_jsx = None;
89+
transformed_jsx = false;
9090
};
9191
}
9292

@@ -134,7 +134,7 @@ let apply_labels ?(loc = default_loc) ?(attrs = []) fn
134134
Ext_list.map args (fun (l, a) ->
135135
(Asttypes.Labelled {txt = l; loc = Location.none}, a));
136136
partial = false;
137-
transformed_jsx = None;
137+
transformed_jsx = false;
138138
};
139139
}
140140

compiler/frontend/ast_uncurry_gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ let to_method_callback loc (self : Bs_ast_mapper.mapper) label
7575
[Typ.any ~loc ()]) );
7676
];
7777
partial = false;
78-
transformed_jsx = None;
78+
transformed_jsx = false;
7979
}

compiler/frontend/bs_ast_mapper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ module E = struct
331331
(map_opt (sub.expr sub) def)
332332
(sub.pat sub p) (sub.expr sub e)
333333
| Pexp_apply {funct = e; args = l; partial; transformed_jsx} ->
334-
apply ~loc ~attrs ~partial ?transformed_jsx (sub.expr sub e)
334+
apply ~loc ~attrs ~partial ~transformed_jsx (sub.expr sub e)
335335
(List.map (map_snd (sub.expr sub)) l)
336336
| Pexp_match (e, pel) ->
337337
match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)

compiler/ml/ast_helper.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ module Exp = struct
154154
let fun_ ?loc ?attrs ?(async = false) ~arity a b c d =
155155
mk ?loc ?attrs
156156
(Pexp_fun {arg_label = a; default = b; lhs = c; rhs = d; arity; async})
157-
let apply ?loc ?attrs ?(partial = false) ?transformed_jsx funct args =
157+
let apply ?loc ?attrs ?(partial = false) ?(transformed_jsx = false) funct args
158+
=
158159
mk ?loc ?attrs (Pexp_apply {funct; args; partial; transformed_jsx})
159160
let match_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_match (a, b))
160161
let try_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_try (a, b))

compiler/ml/ast_helper.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ module Exp : sig
149149
?loc:loc ->
150150
?attrs:attrs ->
151151
?partial:bool ->
152-
?transformed_jsx:jsx_element ->
152+
?transformed_jsx:bool ->
153153
expression ->
154154
(arg_label * expression) list ->
155155
expression

compiler/ml/ast_mapper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ module E = struct
294294
(map_opt (sub.expr sub) def)
295295
(sub.pat sub p) (sub.expr sub e)
296296
| Pexp_apply {funct = e; args = l; partial; transformed_jsx} ->
297-
apply ~loc ~attrs ~partial ?transformed_jsx (sub.expr sub e)
297+
apply ~loc ~attrs ~partial ~transformed_jsx (sub.expr sub e)
298298
(List.map (map_snd (sub.expr sub)) l)
299299
| Pexp_match (e, pel) ->
300300
match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)

0 commit comments

Comments
 (0)