Skip to content

Commit 627f27f

Browse files
committed
snapshot, add a test case
1 parent 92b47cb commit 627f27f

File tree

9 files changed

+540
-500
lines changed

9 files changed

+540
-500
lines changed

jscomp/core/lam_compile_external_obj.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
4646
: (Js_op.property_name * E.t ) list * J.expression list * _ =
4747
match labels, args with
4848
| [] , [] -> [], [], []
49-
| {obj_arg_label = Obj_labelCst {name = label; cst }} :: labels , args ->
49+
| {obj_arg_label = Obj_label {name = label; }; obj_arg_type = Arg_cst cst } :: labels , args ->
5050
let accs, eff, assign = aux labels args in
5151
(label, Lam_compile_const.translate_arg_cst cst )::accs, eff, assign
5252
(* | {obj_arg_label = EmptyCst _ } :: rest , args -> assert false *)

jscomp/main/builtin_cmj_datasets.ml

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

jscomp/test/record_name_test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ function f4(param) {
3434
return (((param.EXACT_MAPPING_TO_JS_LABEL + param.EXACT_2 | 0) + param.z.hello | 0) << 1);
3535
}
3636

37+
function u(param) {
38+
return {
39+
x: 22,
40+
h: 3
41+
};
42+
}
43+
3744
exports.f = f;
3845
exports.set = set;
3946
exports.f1 = f1;
4047
exports.f2 = f2;
4148
exports.f3 = f3;
4249
exports.f4 = f4;
50+
exports.u = u;
4351
/* No side effect */

jscomp/test/record_name_test.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,11 @@ type t6 = {
8080
x : int [@bs.as "x"];
8181
y : int [@bs.as "y"]
8282
}
83-
(* allow this case *)
83+
(* allow this case *)
84+
85+
86+
external ff : x:int -> h:(_[@bs.as 3]) -> _ = "" [@@bs.obj]
87+
external ff2 : x:int -> h:(_[@bs.as 3]) -> <x:int> Js.t = "" [@@bs.obj]
88+
let u () =
89+
ignore (ff ~x:3 );
90+
ff2 ~x:22

lib/4.06.1/bsdep.ml

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

lib/4.06.1/unstable/js_compiler.ml

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

lib/4.06.1/unstable/js_refmt_compiler.ml

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

lib/4.06.1/unstable/native_ppx.ml

Lines changed: 72 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17051,10 +17051,11 @@ type cst = private
1705117051

1705217052

1705317053
type label = private
17054-
| Label of {name : string ; cst : cst option }
17055-
| Empty
17056-
| EmptyCst of cst
17057-
| Optional of {name : string}
17054+
| Obj_label of {name : string}
17055+
(* | Obj_labelCst of {name : string ; cst : cst} *)
17056+
| Obj_empty
17057+
17058+
| Obj_optional of {name : string}
1705817059
(* it will be ignored , side effect will be recorded *)
1705917060

1706017061
type attr =
@@ -17071,31 +17072,33 @@ type attr =
1707117072

1707217073

1707317074
type label_noname =
17074-
| Label
17075-
| Empty
17076-
| Optional
17075+
| Arg_label
17076+
| Arg_empty
17077+
| Arg_optional
1707717078

17078-
type t =
17079+
type obj_param =
1707917080
{
17080-
arg_type : attr;
17081-
arg_label :label
17081+
obj_arg_type : attr;
17082+
obj_arg_label :label
1708217083
}
1708317084

17084-
type t_noname = {
17085+
type param = {
1708517086
arg_type : attr;
1708617087
arg_label : label_noname
1708717088
}
17088-
type params = t_noname list
17089+
17090+
type obj_params = obj_param list
17091+
type params = param list
1708917092

1709017093
val cst_json : Location.t -> string -> cst
1709117094
val cst_int : int -> cst
1709217095
val cst_string : string -> cst
1709317096

1709417097
val empty_label : label
17095-
val empty_lit : cst -> label
17096-
val label : string -> cst option -> label
17098+
(* val empty_lit : cst -> label *)
17099+
val obj_label : string -> label
1709717100
val optional : string -> label
17098-
val empty_kind : attr -> t
17101+
val empty_kind : attr -> obj_param
1709917102

1710017103
end = struct
1710117104
#1 "external_arg_spec.ml"
@@ -17135,15 +17138,15 @@ type cst =
1713517138
| Arg_js_json of string
1713617139

1713717140
type label_noname =
17138-
| Label
17139-
| Empty
17140-
| Optional
17141+
| Arg_label
17142+
| Arg_empty
17143+
| Arg_optional
1714117144

1714217145
type label =
17143-
| Label of {name : string ; cst : cst option }
17144-
| Empty
17145-
| EmptyCst of cst
17146-
| Optional of {name : string }
17146+
| Obj_label of {name : string }
17147+
(* | Obj_labelCst of {name : string} *)
17148+
| Obj_empty
17149+
| Obj_optional of {name : string }
1714717150
(* it will be ignored , side effect will be recorded *)
1714817151

1714917152
type attr =
@@ -17158,20 +17161,20 @@ type attr =
1715817161
| Ignore
1715917162
| Unwrap
1716017163

17161-
type t_noname = {
17164+
type param = {
1716217165
arg_type : attr;
1716317166
arg_label : label_noname
1716417167
}
1716517168

17166-
type t =
17169+
type obj_param =
1716717170
{
17168-
arg_type : attr;
17169-
arg_label : label
17171+
obj_arg_type : attr;
17172+
obj_arg_label : label
1717017173
}
1717117174

1717217175

17173-
17174-
type params = t_noname list
17176+
type obj_params = obj_param list
17177+
type params = param list
1717517178

1717617179
exception Error of Location.t * Ext_json_parse.error
1717717180

@@ -17206,12 +17209,14 @@ let cst_json (loc : Location.t) s : cst =
1720617209

1720717210
let cst_int i = Arg_int_lit i
1720817211
let cst_string s = Arg_string_lit s
17209-
let empty_label = Empty
17210-
let empty_lit s = EmptyCst s
17211-
let label name cst = Label {name ; cst}
17212-
let optional name = Optional {name}
17212+
let empty_label = Obj_empty
1721317213

17214-
let empty_kind arg_type = { arg_label = empty_label ; arg_type }
17214+
let obj_label name =
17215+
Obj_label {name }
17216+
17217+
let optional name = Obj_optional {name}
17218+
17219+
let empty_kind obj_arg_type = { obj_arg_label = empty_label ; obj_arg_type }
1721517220

1721617221
end
1721717222
module Ast_polyvar : sig
@@ -18128,7 +18133,7 @@ type t =
1812818133
External_arg_spec.params *
1812918134
return_wrapper *
1813018135
external_spec
18131-
| Ffi_obj_create of External_arg_spec.t list
18136+
| Ffi_obj_create of External_arg_spec.obj_params
1813218137
| Ffi_inline_const of Lam_constant.t
1813318138
| Ffi_normal
1813418139
(* When it's normal, it is handled as normal c functional ffi call *)
@@ -18285,7 +18290,7 @@ type t =
1828518290
[return] means return value is unit or not,
1828618291
[true] means is [unit]
1828718292
*)
18288-
| Ffi_obj_create of External_arg_spec.t list
18293+
| Ffi_obj_create of External_arg_spec.obj_params
1828918294
| Ffi_inline_const of Lam_constant.t
1829018295
| Ffi_normal
1829118296
(* When it's normal, it is handled as normal c functional ffi call *)
@@ -19274,30 +19279,30 @@ let process_obj
1927419279
else
1927519280
Location.raise_errorf ~loc "expect label, optional, or unit here"
1927619281
| Labelled name ->
19277-
let new_ty, arg_type = refine_arg_type ~nolabel:false ty in
19278-
begin match arg_type with
19282+
let new_ty, obj_arg_type = refine_arg_type ~nolabel:false ty in
19283+
begin match obj_arg_type with
1927919284
| Ignore ->
19280-
External_arg_spec.empty_kind arg_type,
19285+
External_arg_spec.empty_kind obj_arg_type,
1928119286
{param_type with ty = new_ty}::arg_types, result_types
19282-
| Arg_cst i ->
19287+
| Arg_cst _ ->
1928319288
let s = Lam_methname.translate name in
19284-
{arg_label = External_arg_spec.label s (Some i);
19285-
arg_type },
19289+
{obj_arg_label = External_arg_spec.obj_label s;
19290+
obj_arg_type },
1928619291
arg_types, (* ignored in [arg_types], reserved in [result_types] *)
1928719292
(({Asttypes.txt = name; loc} , [], new_ty) :: result_types)
1928819293
| Nothing ->
1928919294
let s = (Lam_methname.translate name) in
19290-
{arg_label = External_arg_spec.label s None ; arg_type },
19295+
{obj_arg_label = External_arg_spec.obj_label s ; obj_arg_type },
1929119296
{param_type with ty = new_ty}::arg_types,
1929219297
(({Asttypes.txt = name; loc} , [], new_ty) :: result_types)
1929319298
| Int _ ->
1929419299
let s = Lam_methname.translate name in
19295-
{arg_label = External_arg_spec.label s None; arg_type},
19300+
{obj_arg_label = External_arg_spec.obj_label s; obj_arg_type},
1929619301
{param_type with ty = new_ty}::arg_types,
1929719302
(({Asttypes.txt = name; loc}, [], Ast_literal.type_int ~loc ()) :: result_types)
1929819303
| NullString _ ->
1929919304
let s = Lam_methname.translate name in
19300-
{arg_label = External_arg_spec.label s None; arg_type},
19305+
{obj_arg_label = External_arg_spec.obj_label s; obj_arg_type},
1930119306
{param_type with ty = new_ty }::arg_types,
1930219307
(({Asttypes.txt = name; loc}, [], Ast_literal.type_string ~loc ()) :: result_types)
1930319308
| Fn_uncurry_arity _ ->
@@ -19313,24 +19318,24 @@ let process_obj
1931319318
"bs.obj label %s does not support [@bs.unwrap] arguments" name
1931419319
end
1931519320
| Optional name ->
19316-
let arg_type = get_opt_arg_type ~nolabel:false ty in
19317-
begin match arg_type with
19321+
let obj_arg_type = get_opt_arg_type ~nolabel:false ty in
19322+
begin match obj_arg_type with
1931819323
| Ignore ->
19319-
External_arg_spec.empty_kind arg_type,
19324+
External_arg_spec.empty_kind obj_arg_type,
1932019325
param_type::arg_types, result_types
1932119326
| Nothing ->
1932219327
let s = (Lam_methname.translate name) in
19323-
{arg_label = External_arg_spec.optional s; arg_type},
19328+
{obj_arg_label = External_arg_spec.optional s; obj_arg_type},
1932419329
param_type :: arg_types,
1932519330
( ({Asttypes.txt = name; loc}, [], Ast_comb.to_undefined_type loc ty) :: result_types)
1932619331
| Int _ ->
1932719332
let s = Lam_methname.translate name in
19328-
{arg_label = External_arg_spec.optional s ; arg_type },
19333+
{obj_arg_label = External_arg_spec.optional s ; obj_arg_type },
1932919334
param_type :: arg_types,
1933019335
(({Asttypes.txt = name; loc}, [], Ast_comb.to_undefined_type loc @@ Ast_literal.type_int ~loc ()) :: result_types)
1933119336
| NullString _ ->
1933219337
let s = Lam_methname.translate name in
19333-
{arg_label = External_arg_spec.optional s ; arg_type },
19338+
{obj_arg_label = External_arg_spec.optional s ; obj_arg_type },
1933419339
param_type::arg_types,
1933519340
(({Asttypes.txt = name; loc}, [], Ast_comb.to_undefined_type loc @@ Ast_literal.type_string ~loc ()) :: result_types)
1933619341
| Arg_cst _
@@ -19722,7 +19727,7 @@ let handle_attributes
1972219727
Location.raise_errorf ~loc:obj.ptyp_loc "[@bs.as] is not supported in bs.send type "
1972319728
| _ ->
1972419729
(* more error checking *)
19725-
[{arg_label = Empty; arg_type}],
19730+
[{arg_label = Arg_empty; arg_type}],
1972619731
[{label = Nolabel;
1972719732
ty = new_ty;
1972819733
attr = [];
@@ -19760,22 +19765,22 @@ let handle_attributes
1976019765
~loc
1976119766
"[@@bs.string] does not work with optional when it has arities in label %s" s
1976219767
| _ ->
19763-
Optional, arg_type,
19768+
Arg_optional, arg_type,
1976419769
param_type :: arg_types end
1976519770
| Labelled s ->
1976619771
begin match refine_arg_type ~nolabel:false ty with
1976719772
| new_ty, (Arg_cst _ as arg_type) ->
19768-
Label , arg_type, arg_types
19773+
Arg_label , arg_type, arg_types
1976919774
| new_ty, arg_type ->
19770-
Label , arg_type,
19775+
Arg_label , arg_type,
1977119776
{param_type with ty = new_ty} :: arg_types
1977219777
end
1977319778
| Nolabel ->
1977419779
begin match refine_arg_type ~nolabel:true ty with
1977519780
| new_ty , (Arg_cst _ as arg_type) ->
19776-
Empty , arg_type, arg_types
19781+
Arg_empty , arg_type, arg_types
1977719782
| new_ty , arg_type ->
19778-
Empty, arg_type, {param_type with ty = new_ty} :: arg_types
19783+
Arg_empty, arg_type, {param_type with ty = new_ty} :: arg_types
1977919784
end
1978019785
in
1978119786
({ arg_label ;
@@ -19821,14 +19826,14 @@ let handle_attributes_as_string
1982119826

1982219827
let pval_prim_of_labels (labels : string Asttypes.loc list) =
1982319828
let arg_kinds =
19824-
Ext_list.fold_right labels ([] : External_arg_spec.t list )
19829+
Ext_list.fold_right labels ([] : External_arg_spec.obj_params )
1982519830
(fun {loc ; txt } arg_kinds
1982619831
->
19827-
let arg_label =
19828-
External_arg_spec.label
19829-
(Lam_methname.translate txt) None in
19830-
{arg_type = Nothing ;
19831-
arg_label } :: arg_kinds
19832+
let obj_arg_label =
19833+
External_arg_spec.obj_label
19834+
(Lam_methname.translate txt) in
19835+
{obj_arg_type = Nothing ;
19836+
obj_arg_label } :: arg_kinds
1983219837
) in
1983319838
let encoding =
1983419839
External_ffi_types.to_string (Ffi_obj_create arg_kinds) in
@@ -19846,13 +19851,13 @@ let pval_prim_of_option_labels
1984619851
(fun (is_option,{loc ; txt }) arg_kinds
1984719852
->
1984819853
let label_name = Lam_methname.translate txt in
19849-
let arg_label =
19854+
let obj_arg_label =
1985019855
if is_option then
1985119856
External_arg_spec.optional label_name
19852-
else External_arg_spec.label label_name None
19857+
else External_arg_spec.obj_label label_name
1985319858
in
19854-
{arg_type = Nothing ;
19855-
arg_label } :: arg_kinds) in
19859+
{obj_arg_type = Nothing ;
19860+
obj_arg_label } :: arg_kinds) in
1985619861
let encoding =
1985719862
External_ffi_types.to_string (Ffi_obj_create arg_kinds) in
1985819863
[""; encoding]
@@ -22513,7 +22518,7 @@ let handleTdcl
2251322518
["" ; (* Not needed actually*)
2251422519
External_ffi_types.to_string
2251522520
(Ffi_bs (
22516-
[{arg_type = Nothing; arg_label = Empty}],
22521+
[{arg_type = Nothing; arg_label = Arg_empty}],
2251722522
Return_identity,
2251822523
Js_get {js_get_name = prim_as_name; js_get_scopes = []}
2251922524
))] )

lib/4.06.1/whole_compiler.ml

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

0 commit comments

Comments
 (0)