Skip to content

Commit 7598a49

Browse files
committed
Remove processing of objects expressions, which don't exist in .res syntax
1 parent 470feb2 commit 7598a49

26 files changed

+489
-2179
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ These are only breaking changes for unformatted code.
4848
- Syntax: process uncurried types explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5784 https://github.com/rescript-lang/rescript-compiler/pull/5822
4949
- Syntax: process uncurried function declarations explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5794
5050
- PPX V4: allow uncurried `make` function and treat it like a curried one [#5802](https://github.com/rescript-lang/rescript-compiler/pull/5802) [#5808](https://github.com/rescript-lang/rescript-compiler/pull/5808) [#5812](https://github.com/rescript-lang/rescript-compiler/pull/5812)
51+
- Remove processing of objects expressions, which don't exist in `.res` syntax (`Pexp_object`).
5152

5253
# 10.1.0-rc.6
5354

jscomp/frontend/ast_util.ml

Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -22,172 +22,11 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
open Ast_helper
26-
2725
type label_exprs = (Longident.t Asttypes.loc * Parsetree.expression) list
2826

2927
let js_property loc obj (name : string) =
3028
Parsetree.Pexp_send (obj, { loc; txt = name })
3129

32-
let ocaml_obj_as_js_object loc (mapper : Bs_ast_mapper.mapper)
33-
(self_pat : Parsetree.pattern) (clfs : Parsetree.class_field list) =
34-
(* Attention: we should avoid type variable conflict for each method
35-
Since the method name is unique, there would be no conflict
36-
OCaml does not allow duplicate instance variable and duplicate methods,
37-
but it does allow duplicates between instance variable and method name,
38-
we should enforce such rules
39-
{[
40-
object [@bs]
41-
val x = 3
42-
method x = 3
43-
end
44-
]} should not compile with a meaningful error message
45-
*)
46-
let generate_val_method_pair loc (mapper : Bs_ast_mapper.mapper)
47-
(val_name : string Asttypes.loc) is_mutable =
48-
let result = Typ.var ~loc val_name.txt in
49-
( result,
50-
Parsetree.Otag (val_name, [], result)
51-
::
52-
(if is_mutable then
53-
[
54-
Otag
55-
( { val_name with txt = val_name.txt ^ Literals.setter_suffix },
56-
[],
57-
Ast_typ_uncurry.to_method_type loc mapper Nolabel result
58-
(Ast_literal.type_unit ~loc ()) );
59-
]
60-
else []) )
61-
in
62-
63-
(* Note mapper is only for API compatible
64-
* TODO: we should check label name to avoid conflict
65-
*)
66-
67-
(* we need calculate the real object type
68-
and exposed object type, in some cases there are equivalent
69-
70-
for public object type its [@meth] it does not depend on itself
71-
while for label argument it is [@this] which depends internal object
72-
*)
73-
let ( (internal_label_attr_types : Parsetree.object_field list),
74-
(public_label_attr_types : Parsetree.object_field list) ) =
75-
Ext_list.fold_right clfs ([], [])
76-
(fun
77-
({ pcf_loc = loc } as x : Parsetree.class_field)
78-
(label_attr_types, public_label_attr_types)
79-
->
80-
match x.pcf_desc with
81-
| Pcf_method (label, public_flag, Cfk_concrete (Fresh, e)) -> (
82-
match e.pexp_desc with
83-
| Pexp_poly ({ pexp_desc = Pexp_fun (lbl, _, pat, e) }, None) ->
84-
let method_type =
85-
Ast_typ_uncurry.generate_arg_type x.pcf_loc mapper label.txt
86-
lbl pat e
87-
in
88-
( Parsetree.Otag (label, [], method_type) :: label_attr_types,
89-
if public_flag = Public then
90-
Parsetree.Otag (label, [], method_type)
91-
:: public_label_attr_types
92-
else public_label_attr_types )
93-
| Pexp_poly (_, Some _) ->
94-
Location.raise_errorf ~loc
95-
"polymorphic type annotation not supported yet"
96-
| Pexp_poly (_, None) ->
97-
Location.raise_errorf ~loc
98-
"Unsupported syntax, expect syntax like `method x () = x ` "
99-
| _ -> Location.raise_errorf ~loc "Unsupported syntax in js object")
100-
| Pcf_val (label, mutable_flag, Cfk_concrete (Fresh, _)) ->
101-
let _, label_attr =
102-
generate_val_method_pair x.pcf_loc mapper label
103-
(mutable_flag = Mutable)
104-
in
105-
( Ext_list.append label_attr label_attr_types,
106-
public_label_attr_types )
107-
| Pcf_val (_, _, Cfk_concrete (Override, _)) ->
108-
Location.raise_errorf ~loc "override flag not support currently"
109-
| Pcf_val (_, _, Cfk_virtual _) ->
110-
Location.raise_errorf ~loc "virtual flag not support currently"
111-
| Pcf_method (_, _, Cfk_concrete (Override, _)) ->
112-
Location.raise_errorf ~loc "override flag not supported"
113-
| Pcf_method (_, _, Cfk_virtual _) ->
114-
Location.raise_errorf ~loc "virtural method not supported"
115-
| Pcf_inherit _ | Pcf_initializer _ | Pcf_attribute _ | Pcf_extension _
116-
| Pcf_constraint _ ->
117-
Location.raise_errorf ~loc "Only method support currently")
118-
in
119-
let internal_obj_type =
120-
Ast_core_type.make_obj ~loc internal_label_attr_types
121-
in
122-
let public_obj_type = Ast_core_type.make_obj ~loc public_label_attr_types in
123-
let labels, label_types, exprs, _ =
124-
Ext_list.fold_right clfs ([], [], [], false)
125-
(fun (x : Parsetree.class_field) (labels, label_types, exprs, aliased) ->
126-
match x.pcf_desc with
127-
| Pcf_method (label, _public_flag, Cfk_concrete (Fresh, e)) -> (
128-
match e.pexp_desc with
129-
| Pexp_poly
130-
(({ pexp_desc = Pexp_fun (ll, None, pat, e) } as f), None) ->
131-
let alias_type =
132-
if aliased then None else Some internal_obj_type
133-
in
134-
let label_type =
135-
Ast_typ_uncurry.generate_method_type ?alias_type x.pcf_loc
136-
mapper label.txt ll pat e
137-
in
138-
( label :: labels,
139-
label_type :: label_types,
140-
{
141-
f with
142-
pexp_desc =
143-
(let f = Ast_pat.is_unit_cont pat ~yes:e ~no:f in
144-
Ast_uncurry_gen.to_method_callback loc mapper Nolabel
145-
self_pat f)
146-
(* the first argument is this*);
147-
}
148-
:: exprs,
149-
true )
150-
| Pexp_poly (_, Some _) ->
151-
Location.raise_errorf ~loc
152-
"polymorphic type annotation not supported yet"
153-
| Pexp_poly (_, None) ->
154-
Location.raise_errorf ~loc
155-
"Unsupported syntax, expect syntax like `method x () = x ` "
156-
| _ -> Location.raise_errorf ~loc "Unsupported syntax in js object")
157-
| Pcf_val (label, mutable_flag, Cfk_concrete (Fresh, val_exp)) ->
158-
let label_type, _ =
159-
generate_val_method_pair x.pcf_loc mapper label
160-
(mutable_flag = Mutable)
161-
in
162-
( label :: labels,
163-
label_type :: label_types,
164-
mapper.expr mapper val_exp :: exprs,
165-
aliased )
166-
| Pcf_val (_, _, Cfk_concrete (Override, _)) ->
167-
Location.raise_errorf ~loc "override flag not support currently"
168-
| Pcf_val (_, _, Cfk_virtual _) ->
169-
Location.raise_errorf ~loc "virtual flag not support currently"
170-
| Pcf_method (_, _, Cfk_concrete (Override, _)) ->
171-
Location.raise_errorf ~loc "override flag not supported"
172-
| Pcf_method (_, _, Cfk_virtual _) ->
173-
Location.raise_errorf ~loc "virtural method not supported"
174-
| Pcf_inherit _ | Pcf_initializer _ | Pcf_attribute _ | Pcf_extension _
175-
| Pcf_constraint _ ->
176-
Location.raise_errorf ~loc "Only method support currently")
177-
in
178-
let pval_type =
179-
Ext_list.fold_right2 labels label_types public_obj_type
180-
(fun label label_type acc ->
181-
Ast_compatible.label_arrow ~loc:label.Asttypes.loc label.Asttypes.txt
182-
label_type acc)
183-
in
184-
Ast_external_mk.local_extern_cont_to_obj loc
185-
~pval_prim:(Ast_external_process.pval_prim_of_labels labels)
186-
(fun e ->
187-
Ast_compatible.apply_labels ~loc e
188-
(Ext_list.map2 labels exprs (fun l expr -> (l.txt, expr))))
189-
~pval_type
190-
19130
let record_as_js_object loc (self : Bs_ast_mapper.mapper)
19231
(label_exprs : label_exprs) : Parsetree.expression_desc =
19332
let labels, args, arity =

jscomp/frontend/ast_util.mli

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,3 @@ val record_as_js_object :
3535

3636
val js_property :
3737
Location.t -> Parsetree.expression -> string -> Parsetree.expression_desc
38-
39-
val ocaml_obj_as_js_object :
40-
Location.t ->
41-
Bs_ast_mapper.mapper ->
42-
Parsetree.pattern ->
43-
Parsetree.class_field list ->
44-
Parsetree.expression_desc

jscomp/frontend/bs_builtin_ppx.ml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,6 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
155155
pexp_attributes;
156156
})
157157
| Pexp_apply (fn, args) -> Ast_exp_apply.app_exp_mapper e self fn args
158-
| Pexp_object { pcstr_self; pcstr_fields } ->
159-
let pexp_attributes =
160-
match Ast_attributes.process_bs e.pexp_attributes with
161-
| true, pexp_attributes ->
162-
Location.prerr_warning e.pexp_loc
163-
(Bs_ffi_warning "Here @bs attribute not needed any more");
164-
pexp_attributes
165-
| false, e -> e
166-
in
167-
{
168-
e with
169-
pexp_desc =
170-
Ast_util.ocaml_obj_as_js_object e.pexp_loc self pcstr_self
171-
pcstr_fields;
172-
pexp_attributes;
173-
}
174158
| Pexp_match
175159
( b,
176160
[

jscomp/test/arity_ml.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

jscomp/test/arity_ml.ml

Lines changed: 0 additions & 36 deletions
This file was deleted.

jscomp/test/build.ninja

Lines changed: 1 addition & 7 deletions
Large diffs are not rendered by default.

jscomp/test/class_type_ffi_test.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,6 @@ function mk_f(param) {
6666
};
6767
}
6868

69-
function omk_f(param) {
70-
return {
71-
huge_methdo: (function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) {
72-
return Curry.app(a0, [
73-
a1,
74-
a2,
75-
a3,
76-
a4,
77-
a5,
78-
a6,
79-
a7,
80-
a8,
81-
a9,
82-
a10,
83-
a11,
84-
a12
85-
]);
86-
})
87-
};
88-
}
89-
9069
exports.sum_float_array = sum_float_array;
9170
exports.sum_int_array = sum_int_array;
9271
exports.sum_poly = sum_poly;
@@ -96,5 +75,4 @@ exports.ff = ff;
9675
exports.ff2 = ff2;
9776
exports.off2 = off2;
9877
exports.mk_f = mk_f;
99-
exports.omk_f = omk_f;
10078
/* No side effect */

jscomp/test/class_type_ffi_test.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,3 @@ let off2 o a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
6868
let mk_f () =
6969
fun [@bs] a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 ->
7070
a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12
71-
72-
(* Test [fn_method] *)
73-
let omk_f ()=
74-
object
75-
method huge_methdo a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
76-
a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12
77-
end

jscomp/test/ffi_js_test.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,16 @@ var same_type = [
8080
same_type_1
8181
];
8282

83-
var v_obj = {
84-
hi: (function () {
85-
console.log("hei");
86-
})
87-
};
88-
89-
eq("File \"ffi_js_test.ml\", line 44, characters 5-12", [
83+
eq("File \"ffi_js_test.ml\", line 41, characters 5-12", [
9084
Object.keys(int_config).length,
9185
2
9286
]);
9387

94-
eq("File \"ffi_js_test.ml\", line 45, characters 5-12", [
88+
eq("File \"ffi_js_test.ml\", line 42, characters 5-12", [
9589
Object.keys(string_config).length,
9690
2
9791
]);
9892

99-
eq("File \"ffi_js_test.ml\", line 46, characters 5-12", [
100-
Object.keys(v_obj).indexOf("hi_x"),
101-
-1
102-
]);
103-
104-
eq("File \"ffi_js_test.ml\", line 47, characters 5-12", [
105-
Object.keys(v_obj).indexOf("hi"),
106-
0
107-
]);
108-
10993
var u = {
11094
contents: 3
11195
};
@@ -115,7 +99,7 @@ var side_effect_config = (u.contents = u.contents + 1 | 0, {
11599
low: 32
116100
});
117101

118-
eq("File \"ffi_js_test.ml\", line 54, characters 5-12", [
102+
eq("File \"ffi_js_test.ml\", line 49, characters 5-12", [
119103
u.contents,
120104
4
121105
]);
@@ -183,7 +167,6 @@ exports.eq = eq;
183167
exports.int_config = int_config;
184168
exports.string_config = string_config;
185169
exports.same_type = same_type;
186-
exports.v_obj = v_obj;
187170
exports.u = u;
188171
exports.side_effect_config = side_effect_config;
189172
exports.vv = vv;

jscomp/test/ffi_js_test.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,9 @@ let same_type =
3737
[string_config ; [%obj{hi = 3 ; low = "32"}]]
3838
)
3939

40-
let v_obj = object method hi__x () = Js.log "hei" end
41-
42-
4340
let () =
4441
eq __LOC__ (Array.length (Js_obj.keys int_config), 2 );
45-
eq __LOC__ (Array.length (Js_obj.keys string_config), 2 );
46-
eq __LOC__ (Js_obj.keys v_obj |. Js.Array2.indexOf "hi_x" , -1 );
47-
eq __LOC__ (Js_obj.keys v_obj |. Js.Array2.indexOf "hi", 0 )
42+
eq __LOC__ (Array.length (Js_obj.keys string_config), 2 )
4843

4944
let u = ref 3
5045

0 commit comments

Comments
 (0)