Skip to content

Commit 25daf30

Browse files
committed
change params definition to not saving label names when it's not relevant
1 parent 4fcdb9f commit 25daf30

12 files changed

+57
-29
lines changed

jscomp/core/lam.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ let sequand l r = if_ l r false_
783783
if it does not we wrap it in a nomral way otherwise
784784
*)
785785
let rec no_auto_uncurried_arg_types
786-
(xs : External_arg_spec.t list) =
786+
(xs : External_arg_spec.params) =
787787
match xs with
788788
| [] -> true
789789
| {arg_type = Fn_uncurry_arity _ } :: _ ->
@@ -802,7 +802,7 @@ let result_wrap loc (result_type : External_ffi_types.return_wrapper) result =
802802
| Return_identity ->
803803
result
804804

805-
let rec transform_uncurried_arg_type loc (arg_types : External_arg_spec.t list)
805+
let rec transform_uncurried_arg_type loc (arg_types : External_arg_spec.params)
806806
(args : t list ) =
807807
match arg_types,args with
808808
| { arg_type = Fn_uncurry_arity n ; arg_label } :: xs,
@@ -826,7 +826,7 @@ let rec transform_uncurried_arg_type loc (arg_types : External_arg_spec.t list)
826826

827827

828828
let handle_bs_non_obj_ffi
829-
(arg_types : External_arg_spec.t list)
829+
(arg_types : External_arg_spec.params)
830830
(result_type : External_ffi_types.return_wrapper)
831831
ffi
832832
args

jscomp/core/lam.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ val inner_map : t -> (t -> t) -> t
8686

8787

8888
val handle_bs_non_obj_ffi:
89-
External_arg_spec.t list ->
89+
External_arg_spec.params ->
9090
External_ffi_types.return_wrapper ->
9191
External_ffi_types.external_spec ->
9292
t list ->

jscomp/core/lam_compile_external_call.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ let append_list x xs =
9191
This would not work with [NonNullString]
9292
*)
9393
let ocaml_to_js_eff
94-
({arg_label; arg_type }: External_arg_spec.t)
94+
({arg_label; arg_type }: External_arg_spec.t_noname)
9595
(raw_arg : E.t)
9696
: arg_expression * E.t list =
9797
let arg =
9898
match arg_label with
99-
| Optional label ->
99+
| Optional ->
100100
Js_of_lam_option.get_default_undefined_from_optional raw_arg
101101
| Label {cst = None;_} | Empty -> raw_arg
102102
| Label {cst = Some _;_}
@@ -107,7 +107,7 @@ let ocaml_to_js_eff
107107
| Fn_uncurry_arity _ -> assert false
108108
(* has to be preprocessed by {!Lam} module first *)
109109
| Extern_unit ->
110-
(if arg_label = External_arg_spec.empty_label then
110+
(if arg_label = Empty then
111111
Splice0 else Splice1 E.unit),
112112
(if Js_analyzer.no_side_effect_expression arg then
113113
[]
@@ -133,7 +133,7 @@ let ocaml_to_js_eff
133133
| Unwrap ->
134134
let single_arg =
135135
match arg_label with
136-
| Optional label ->
136+
| Optional ->
137137
(**
138138
If this is an optional arg (like `?arg`), we have to potentially do
139139
2 levels of unwrapping:
@@ -158,7 +158,7 @@ let add_eff eff e =
158158
| Some v -> E.seq v e
159159

160160

161-
type specs = External_arg_spec.t list
161+
type specs = External_arg_spec.params
162162

163163
type exprs = E.t list
164164
(* TODO: fix splice,
@@ -179,13 +179,13 @@ let assemble_args_no_splice call_loc ffi
179179
| { arg_label = Label {cst = Some cst;_}; _} :: labels, args ->
180180
let accs, eff = aux labels args in
181181
Lam_compile_const.translate_arg_cst cst :: accs, eff
182-
| ({arg_label = Empty | Label {cst = None;_} | Optional _ ;_ } as arg_kind) ::labels,
182+
| ({arg_label = Empty | Label {cst = None;_} | Optional ;_ } as arg_kind) ::labels,
183183
arg :: args
184184
->
185185
let accs, eff = aux labels args in
186186
let acc, new_eff = ocaml_to_js_eff arg_kind arg in
187187
append_list acc accs, Ext_list.append new_eff eff
188-
| { arg_label = Empty | Label {cst = None;_} | Optional _ ; _ } :: _ , []
188+
| { arg_label = Empty | Label {cst = None;_} | Optional ; _ } :: _ , []
189189
-> assert false
190190
in
191191
let args, eff = aux arg_types args in
@@ -205,7 +205,7 @@ let assemble_args_has_splice call_loc ffi (arg_types : specs) (args : exprs)
205205
| { arg_label = Label {cst = Some cst;_}; _} :: labels , args ->
206206
let accs, eff = aux labels args in
207207
Lam_compile_const.translate_arg_cst cst :: accs, eff
208-
| ({arg_label = Empty | Label {cst = None;_} | Optional _ ;_ } as arg_kind) ::labels,
208+
| ({arg_label = Empty | Label {cst = None;_} | Optional ;_ } as arg_kind) ::labels,
209209
arg :: args
210210
->
211211
let accs, eff = aux labels args in
@@ -217,7 +217,7 @@ let assemble_args_has_splice call_loc ffi (arg_types : specs) (args : exprs)
217217
let acc, new_eff = ocaml_to_js_eff arg_kind arg in
218218
append_list acc accs, Ext_list.append new_eff eff
219219
end
220-
| { arg_label = Empty | Label {cst = None;_} | Optional _ ; _ } :: _ , []
220+
| { arg_label = Empty | Label {cst = None;_} | Optional ; _ } :: _ , []
221221
-> assert false
222222
in
223223
let args, eff = aux arg_types args in

jscomp/core/lam_compile_external_call.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131

3232
(** Compile ocaml external function call to JS IR. *)
3333
val ocaml_to_js_eff :
34-
External_arg_spec.t ->
34+
External_arg_spec.t_noname ->
3535
J.expression ->
3636
Js_of_lam_variant.arg_expression * J.expression list
3737

3838
val translate_ffi :
3939
Location.t ->
4040
Lam_compile_context.t ->
41-
External_arg_spec.t list ->
41+
External_arg_spec.params ->
4242
External_ffi_types.external_spec ->
4343
J.expression list ->
4444
J.expression

jscomp/core/lam_primitive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type t =
4747
| Pccall of Primitive_compat.t
4848
| Pjs_call of
4949
{ prim_name : string ;
50-
arg_types : External_arg_spec.t list ;
50+
arg_types : External_arg_spec.params ;
5151
ffi : External_ffi_types.external_spec }
5252
| Pjs_object_create of External_arg_spec.t list
5353
(* Exceptions *)

jscomp/core/lam_primitive.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type t =
4646
| Pjs_call of
4747
(* Location.t * [loc] is passed down *)
4848
{ prim_name : string;
49-
arg_types : External_arg_spec.t list ;
49+
arg_types : External_arg_spec.params ;
5050
ffi : External_ffi_types.external_spec}
5151
| Pjs_object_create of External_arg_spec.t list
5252

jscomp/syntax/ast_derive_abstract.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ let handleTdcl
148148
["" ; (* Not needed actually*)
149149
External_ffi_types.to_string
150150
(Ffi_bs (
151-
[{arg_type = Nothing; arg_label = External_arg_spec.empty_label}],
151+
[{arg_type = Nothing; arg_label = Empty}],
152152
Return_identity,
153153
Js_get {js_get_name = prim_as_name; js_get_scopes = []}
154154
))] )

jscomp/syntax/ast_external_process.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ let external_desc_of_non_obj
513513
(prim_name_or_pval_prim : bundle_source)
514514
(arg_type_specs_length : int)
515515
arg_types_ty
516-
(arg_type_specs : External_arg_spec.t list) : External_ffi_types.external_spec =
516+
(arg_type_specs : External_arg_spec.params) : External_ffi_types.external_spec =
517517
match st with
518518
| {set_index = true;
519519
val_name = `Nm_na;
@@ -855,7 +855,7 @@ let handle_attributes
855855
else
856856
let splice = external_desc.splice in
857857
let arg_type_specs, new_arg_types_ty, arg_type_specs_length =
858-
let init : External_arg_spec.t list * Ast_compatible.param_type list * int =
858+
let init : External_arg_spec.params * Ast_compatible.param_type list * int =
859859
match external_desc.val_send_pipe with
860860
| Some obj ->
861861
let new_ty, arg_type = refine_arg_type ~nolabel:true obj in
@@ -864,7 +864,7 @@ let handle_attributes
864864
Location.raise_errorf ~loc:obj.ptyp_loc "[@bs.as] is not supported in bs.send type "
865865
| _ ->
866866
(* more error checking *)
867-
[External_arg_spec.empty_kind arg_type],
867+
[{arg_label = Empty; arg_type}],
868868
[{label = Nolabel;
869869
ty = new_ty;
870870
attr = [];
@@ -891,7 +891,7 @@ let handle_attributes
891891
-> ()
892892
| _ -> Location.raise_errorf ~loc "[@@@@bs.splice] expect the last type to be an array";
893893
end ;
894-
let arg_label, arg_type, new_arg_types =
894+
let (arg_label : External_arg_spec.label_noname), arg_type, new_arg_types =
895895
match arg_label with
896896
| Optional s ->
897897
let arg_type = get_opt_arg_type ~nolabel:false ty in
@@ -902,22 +902,22 @@ let handle_attributes
902902
~loc
903903
"[@@bs.string] does not work with optional when it has arities in label %s" s
904904
| _ ->
905-
External_arg_spec.optional s, arg_type,
905+
Optional, arg_type,
906906
param_type :: arg_types end
907907
| Labelled s ->
908908
begin match refine_arg_type ~nolabel:false ty with
909909
| new_ty, (Arg_cst i as arg_type) ->
910-
External_arg_spec.label s (Some i), arg_type, arg_types
910+
Label {cst = Some i}, arg_type, arg_types
911911
| new_ty, arg_type ->
912-
External_arg_spec.label s None, arg_type,
912+
Label {cst = None}, arg_type,
913913
{param_type with ty = new_ty} :: arg_types
914914
end
915915
| Nolabel ->
916916
begin match refine_arg_type ~nolabel:true ty with
917917
| new_ty , (Arg_cst i as arg_type) ->
918-
External_arg_spec.empty_lit i , arg_type, arg_types
918+
EmptyCst i , arg_type, arg_types
919919
| new_ty , arg_type ->
920-
External_arg_spec.empty_label, arg_type, {param_type with ty = new_ty} :: arg_types
920+
Empty, arg_type, {param_type with ty = new_ty} :: arg_types
921921
end
922922
in
923923
({ arg_label ;

jscomp/syntax/external_arg_spec.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ type cst =
3232
| Arg_js_true
3333
| Arg_js_false
3434
| Arg_js_json of string
35+
36+
type label_noname =
37+
| Label of { cst : cst option }
38+
| Empty
39+
| EmptyCst of cst
40+
| Optional
41+
3542
type label =
3643
| Label of {name : string ; cst : cst option }
3744
| Empty
@@ -51,13 +58,21 @@ type attr =
5158
| Ignore
5259
| Unwrap
5360

61+
type t_noname = {
62+
arg_type : attr;
63+
arg_label : label_noname
64+
}
65+
5466
type t =
5567
{
5668
arg_type : attr;
5769
arg_label : label
5870
}
5971

6072

73+
74+
type params = t_noname list
75+
6176
exception Error of Location.t * Ext_json_parse.error
6277

6378
let pp_invaild_json fmt err =

jscomp/syntax/external_arg_spec.mli

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,25 @@ type attr =
5050
| Ignore
5151
| Unwrap
5252

53+
54+
type label_noname =
55+
| Label of { cst : cst option }
56+
| Empty
57+
| EmptyCst of cst
58+
| Optional
59+
5360
type t =
5461
{
5562
arg_type : attr;
5663
arg_label :label
5764
}
5865

66+
type t_noname = {
67+
arg_type : attr;
68+
arg_label : label_noname
69+
}
70+
type params = t_noname list
71+
5972
val cst_json : Location.t -> string -> cst
6073
val cst_int : int -> cst
6174
val cst_string : string -> cst

0 commit comments

Comments
 (0)