Skip to content

Commit 6b075c0

Browse files
committed
Don't pass untyped ast, simple flag is sufficient.
1 parent ab32462 commit 6b075c0

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

0 commit comments

Comments
 (0)