Skip to content

Commit 0b2c845

Browse files
committed
compress external names when all are dummy
1 parent 8dbd65e commit 0b2c845

14 files changed

+4586
-4230
lines changed

jscomp/core/lam_convert.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
456456
let args = Ext_list.map args convert_aux in
457457
prim ~primitive:(Pjs_object_create labels) ~args loc
458458
| Ffi_bs(arg_types, result_type, ffi) ->
459+
let arg_types =
460+
match arg_types with
461+
| Params ls -> ls
462+
| Param_number i -> Ext_list.init i (fun _ -> External_arg_spec.dummy ) in
459463
let args = Ext_list.map args convert_aux in
460464
Lam.handle_bs_non_obj_ffi arg_types result_type ffi args loc prim_name
461465
| Ffi_inline_const i -> Lam.const i

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 162 additions & 162 deletions
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 27 additions & 27 deletions
Large diffs are not rendered by default.

jscomp/syntax/ast_derive_abstract.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,12 @@ let handleTdcl
145145
{pld_name with txt = pld_name.txt ^ "Get"}
146146
) ~attrs:get_attrs
147147
~prim:(
148-
["" ; (* Not needed actually*)
149-
External_ffi_types.to_string
150-
(Ffi_bs (
151-
[{arg_type = Nothing; arg_label = Arg_empty}],
152-
Return_identity,
153-
Js_get {js_get_name = prim_as_name; js_get_scopes = []}
154-
))] )
148+
(* Not needed actually*)
149+
External_ffi_types.ffi_bs_as_prims
150+
[External_arg_spec.dummy]
151+
Return_identity
152+
(Js_get {js_get_name = prim_as_name; js_get_scopes = []})
153+
)
155154
(Ast_compatible.arrow ~loc core_type pld_type))
156155
:: acc
157156
)

jscomp/syntax/ast_external_process.ml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ let process_obj
503503
(* result type can not be labeled *)
504504
in
505505
Ast_compatible.mk_fn_type new_arg_types_ty result,
506-
External_ffi_types.Ffi_obj_create arg_kinds
506+
External_ffi_types.ffi_obj_create arg_kinds
507507
| _ -> Location.raise_errorf ~loc "Attribute found that conflicts with [@@bs.obj]"
508508

509509

@@ -938,7 +938,7 @@ let handle_attributes
938938
return type, in the future we may *)
939939
let return_wrapper = check_return_wrapper loc external_desc.return_wrapper result_type in
940940
Ast_compatible.mk_fn_type new_arg_types_ty result_type,
941-
Ffi_bs (arg_type_specs, return_wrapper, ffi),
941+
External_ffi_types.ffi_bs arg_type_specs return_wrapper ffi,
942942
unused_attrs,
943943
relative
944944

@@ -972,9 +972,8 @@ let pval_prim_of_labels (labels : string Asttypes.loc list) =
972972
{obj_arg_type = Nothing ;
973973
obj_arg_label } :: arg_kinds
974974
) in
975-
let encoding =
976-
External_ffi_types.to_string (Ffi_obj_create arg_kinds) in
977-
[""; encoding]
975+
External_ffi_types.ffi_obj_as_prims arg_kinds
976+
978977

979978
let pval_prim_of_option_labels
980979
(labels : (bool * string Asttypes.loc) list)
@@ -995,7 +994,6 @@ let pval_prim_of_option_labels
995994
in
996995
{obj_arg_type = Nothing ;
997996
obj_arg_label } :: arg_kinds) in
998-
let encoding =
999-
External_ffi_types.to_string (Ffi_obj_create arg_kinds) in
1000-
[""; encoding]
997+
External_ffi_types.ffi_obj_as_prims arg_kinds
998+
1001999

jscomp/syntax/external_arg_spec.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ let obj_label name =
113113
let optional name = Obj_optional {name}
114114

115115
let empty_kind obj_arg_type = { obj_arg_label = empty_label ; obj_arg_type }
116+
let dummy =
117+
{arg_type = Nothing; arg_label = Arg_empty}

jscomp/syntax/external_arg_spec.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ val empty_label : label
8080
val obj_label : string -> label
8181
val optional : string -> label
8282
val empty_kind : attr -> obj_param
83+
val dummy : param

jscomp/syntax/external_ffi_types.ml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ type return_wrapper =
119119
| Return_null_undefined_to_opt
120120
| Return_replaced_with_unit
121121

122+
type params =
123+
| Params of External_arg_spec.params
124+
| Param_number of int
125+
122126
type t =
123-
| Ffi_bs of External_arg_spec.params *
127+
| Ffi_bs of params *
124128
return_wrapper * external_spec
125129
(** [Ffi_bs(args,return,attr) ]
126130
[return] means return value is unit or not,
@@ -301,5 +305,29 @@ let inline_int_primitive i : string list =
301305
["";
302306
to_string
303307
(Ffi_inline_const
304-
(Lam_constant.Const_int32 (Int32.of_int i)))
305-
]
308+
(Const_int32 (Int32.of_int i)))
309+
]
310+
311+
312+
let rec ffi_bs_aux acc (params : External_arg_spec.params) =
313+
match params with
314+
| {arg_type = Nothing; arg_label = Arg_empty}
315+
(* same as External_arg_spec.dummy*)
316+
:: rest ->
317+
ffi_bs_aux (acc + 1) rest
318+
| _ :: _ -> -1
319+
| [] -> acc
320+
321+
let ffi_bs (params : External_arg_spec.params) return attr =
322+
let n = ffi_bs_aux 0 params in
323+
if n < 0 then Ffi_bs (Params params,return,attr)
324+
else Ffi_bs (Param_number n, return, attr)
325+
326+
let ffi_bs_as_prims params return attr =
327+
[""; to_string (ffi_bs params return attr)]
328+
329+
let ffi_obj_create obj_params =
330+
Ffi_obj_create obj_params
331+
332+
let ffi_obj_as_prims obj_params =
333+
["";to_string (Ffi_obj_create obj_params)]

jscomp/syntax/external_ffi_types.mli

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ type return_wrapper =
100100
| Return_null_undefined_to_opt
101101
| Return_replaced_with_unit
102102

103-
type t =
103+
type params =
104+
| Params of External_arg_spec.params
105+
| Param_number of int
106+
107+
type t = private
104108
| Ffi_bs of
105-
External_arg_spec.params *
109+
params *
106110
return_wrapper *
107111
external_spec
108112
| Ffi_obj_create of External_arg_spec.obj_params
@@ -131,4 +135,24 @@ val inline_bool_primitive :
131135

132136
val inline_int_primitive :
133137
int ->
138+
string list
139+
140+
val ffi_bs:
141+
External_arg_spec.params ->
142+
return_wrapper ->
143+
external_spec ->
144+
t
145+
146+
val ffi_bs_as_prims:
147+
External_arg_spec.params ->
148+
return_wrapper ->
149+
external_spec ->
150+
string list
151+
152+
val ffi_obj_create:
153+
External_arg_spec.obj_params ->
154+
t
155+
156+
val ffi_obj_as_prims:
157+
External_arg_spec.obj_params ->
134158
string list

lib/4.06.1/bsdep.ml

Lines changed: 248 additions & 188 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)