Skip to content

Commit 8bd1dfd

Browse files
committed
use tagged_template annotation in ffi instead
1 parent d7f48c7 commit 8bd1dfd

24 files changed

+55
-112
lines changed

jscomp/core/lam.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type apply_status = App_na | App_infer_full | App_uncurry
2828
type ap_info = {
2929
ap_loc : Location.t;
3030
ap_inlined : Lambda.inline_attribute;
31-
ap_tagged_template : bool;
3231
ap_status : apply_status;
3332
}
3433

jscomp/core/lam.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type apply_status = App_na | App_infer_full | App_uncurry
2727
type ap_info = {
2828
ap_loc : Location.t;
2929
ap_inlined : Lambda.inline_attribute;
30-
ap_tagged_template : bool;
3130
ap_status : apply_status;
3231
}
3332

jscomp/core/lam_analysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
9898
true
9999
| Pjs_apply | Pjs_runtime_apply | Pjs_call _ | Pinit_mod | Pupdate_mod
100100
| Pjs_unsafe_downgrade _ | Pdebugger | Pvoid_run | Pfull_apply
101-
| Pjs_fn_method | Pjs_tagged_template _
101+
| Pjs_fn_method
102102
(* TODO *)
103103
| Praw_js_code _ | Pbytessetu | Pbytessets
104104
(* Operations on boxed integers (Nativeint.t, Int32.t, Int64.t) *)

jscomp/core/lam_compile.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,6 @@ and compile_prim (prim_info : Lam.prim_info)
15991599
{
16001600
ap_loc = loc;
16011601
ap_inlined = Default_inline;
1602-
ap_tagged_template = false;
16031602
ap_status = App_uncurry;
16041603
})
16051604
(*FIXME: should pass info down: `f a [@bs][@inlined]`*)

jscomp/core/lam_compile_external_call.ml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,17 @@ let translate_scoped_access scopes obj =
252252
let translate_ffi (cxt : Lam_compile_context.t) arg_types
253253
(ffi : External_ffi_types.external_spec) (args : J.expression list) =
254254
match ffi with
255-
| Js_call { external_module_name = module_name; name = fn; splice; scopes } ->
255+
| Js_call { external_module_name; name; splice; scopes; tagged_template = true } ->
256+
let fn = translate_scoped_module_val external_module_name name scopes in
257+
(match args with
258+
| [ stringArgs; valueArgs ] -> (
259+
match (stringArgs, valueArgs) with
260+
| ({expression_desc = Array (strings, _); _}, {expression_desc = Array (values, _); _}) ->
261+
E.tagged_template fn strings values
262+
| _ -> assert false
263+
)
264+
| _ -> assert false)
265+
| Js_call { external_module_name = module_name; name = fn; splice; scopes; tagged_template = false } ->
256266
let fn = translate_scoped_module_val module_name fn scopes in
257267
if splice then
258268
let args, eff, dynamic = assemble_args_has_splice arg_types args in
@@ -381,19 +391,3 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
381391
| [ obj; v; value ] ->
382392
Js_arr.set_array (translate_scoped_access scopes obj) v value
383393
| _ -> assert false)
384-
385-
let translate_tagged_template (cxt : Lam_compile_context.t)
386-
(ffi : External_ffi_types.external_spec) (args : J.expression list) =
387-
let fn = match ffi with
388-
| Js_call { external_module_name; name; scopes; _ } ->
389-
translate_scoped_module_val external_module_name name scopes
390-
| _ -> assert false
391-
in
392-
match args with
393-
| [ stringArgs; valueArgs ] -> (
394-
match (stringArgs, valueArgs) with
395-
| ({expression_desc = Array (strings, _); _}, {expression_desc = Array (values, _); _}) ->
396-
E.tagged_template fn strings values
397-
| _ -> assert false
398-
)
399-
| _ -> assert false

jscomp/core/lam_compile_external_call.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ val translate_ffi :
3636
J.expression list ->
3737
J.expression
3838

39-
val translate_tagged_template :
40-
Lam_compile_context.t ->
41-
External_ffi_types.external_spec ->
42-
J.expression list ->
43-
J.expression
44-
4539
(** TODO: document supported attributes
4640
Attributes starting with `js` are reserved
4741
examples: "variadic"

jscomp/core/lam_compile_primitive.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
339339
| Pjs_object_create _ -> assert false
340340
| Pjs_call { arg_types; ffi } ->
341341
Lam_compile_external_call.translate_ffi cxt arg_types ffi args
342-
| Pjs_tagged_template { ffi } -> Lam_compile_external_call.translate_tagged_template cxt ffi args
343342
(* FIXME, this can be removed later *)
344343
| Pisint -> E.is_type_number (Ext_list.singleton_exn args)
345344
| Pis_poly_var_block -> E.is_type_object (Ext_list.singleton_exn args)

jscomp/core/lam_convert.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,11 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
512512
match lam with
513513
| Lvar x -> Lam.var (Hash_ident.find_default alias_tbl x x)
514514
| Lconst x -> Lam.const (Lam_constant_convert.convert_constant x)
515-
| Lapply { ap_func = fn; ap_args = args; ap_loc = loc; ap_inlined; ap_tagged_template } ->
515+
| Lapply { ap_func = fn; ap_args = args; ap_loc = loc; ap_inlined } ->
516516
(* we need do this eargly in case [aux fn] add some wrapper *)
517517
Lam.apply (convert_aux fn)
518518
(Ext_list.map args convert_aux)
519-
{ ap_loc = loc; ap_inlined; ap_tagged_template; ap_status = App_na }
519+
{ ap_loc = loc; ap_inlined; ap_status = App_na }
520520
| Lfunction { params; body; attr } ->
521521
let new_map, body =
522522
rename_optional_parameters Map_ident.empty params body
@@ -685,15 +685,13 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
685685
{
686686
ap_loc = outer_loc;
687687
ap_inlined = ap_info.ap_inlined;
688-
ap_tagged_template = ap_info.ap_tagged_template;
689688
ap_status = App_na;
690689
}
691690
| _ ->
692691
Lam.apply f [ x ]
693692
{
694693
ap_loc = outer_loc;
695694
ap_inlined = Default_inline;
696-
ap_tagged_template = false;
697695
ap_status = App_na;
698696
}
699697
and convert_switch (e : Lambda.lambda) (s : Lambda.lambda_switch) =

jscomp/core/lam_eta_conversion.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ let transform_under_supply n ap_info fn args =
111111
let unsafe_adjust_to_arity loc ~(to_ : int) ?(from : int option) (fn : Lam.t) :
112112
Lam.t =
113113
let ap_info : Lam.ap_info =
114-
{ ap_loc = loc; ap_inlined = Default_inline; ap_tagged_template = false; ap_status = App_na }
114+
{ ap_loc = loc; ap_inlined = Default_inline; ap_status = App_na }
115115
in
116116
let is_async_fn = match fn with
117117
| Lfunction { attr = {async}} -> async

jscomp/core/lam_pass_remove_alias.ml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
198198

199199
(* Ext_log.dwarn __LOC__ "%s/%d" v.name v.stamp; *)
200200
let ap_args = Ext_list.map ap_args simpl in
201-
let normal () = Lam.apply (simpl fn) ap_args ap_info in
201+
let[@local] normal () = Lam.apply (simpl fn) ap_args ap_info in
202202
match Hash_ident.find_opt meta.ident_tbl v with
203203
| Some
204204
(FunctionId
@@ -238,7 +238,7 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
238238
Lam_closure.is_closed_with_map meta.export_idents params body
239239
in
240240
let is_export_id = Set_ident.mem meta.export_idents v in
241-
let result = match (is_export_id, param_map) with
241+
match (is_export_id, param_map) with
242242
| false, (_, param_map) | true, (true, param_map) -> (
243243
match rec_flag with
244244
| Lam_rec ->
@@ -256,18 +256,6 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
256256
(Lam_beta_reduce.propagate_beta_reduce_with_map meta
257257
param_map params body ap_args))
258258
| _ -> normal ()
259-
in
260-
let result = (match result with
261-
| Lprim {primitive; args; loc} -> (match primitive with
262-
(* Converts Pjs_calls to Pjs_tagged_templates if ap_tagged_template is true *)
263-
| Pjs_call {prim_name; ffi} when ap_info.ap_tagged_template ->
264-
let prim = Lam_primitive.Pjs_tagged_template {prim_name; ffi} in
265-
Lam.prim ~primitive:prim ~args loc
266-
| _ -> result
267-
)
268-
| _ -> result)
269-
in
270-
result
271259
else normal ()
272260
else normal ()
273261
| Some _ | None -> normal ())

0 commit comments

Comments
 (0)