Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove processing of objects expressions, which don't exist in .res #5841

Merged
merged 2 commits into from
Nov 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ These are only breaking changes for unformatted code.
- 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
- Syntax: process uncurried function declarations explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5794
- 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)
- Remove processing of objects expressions, which don't exist in `.res` syntax (`Pexp_object`) https://github.com/rescript-lang/rescript-compiler/pull/5841

# 10.1.0-rc.6

161 changes: 0 additions & 161 deletions jscomp/frontend/ast_util.ml
Original file line number Diff line number Diff line change
@@ -22,172 +22,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

open Ast_helper

type label_exprs = (Longident.t Asttypes.loc * Parsetree.expression) list

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

let ocaml_obj_as_js_object loc (mapper : Bs_ast_mapper.mapper)
(self_pat : Parsetree.pattern) (clfs : Parsetree.class_field list) =
(* Attention: we should avoid type variable conflict for each method
Since the method name is unique, there would be no conflict
OCaml does not allow duplicate instance variable and duplicate methods,
but it does allow duplicates between instance variable and method name,
we should enforce such rules
{[
object [@bs]
val x = 3
method x = 3
end
]} should not compile with a meaningful error message
*)
let generate_val_method_pair loc (mapper : Bs_ast_mapper.mapper)
(val_name : string Asttypes.loc) is_mutable =
let result = Typ.var ~loc val_name.txt in
( result,
Parsetree.Otag (val_name, [], result)
::
(if is_mutable then
[
Otag
( { val_name with txt = val_name.txt ^ Literals.setter_suffix },
[],
Ast_typ_uncurry.to_method_type loc mapper Nolabel result
(Ast_literal.type_unit ~loc ()) );
]
else []) )
in

(* Note mapper is only for API compatible
* TODO: we should check label name to avoid conflict
*)

(* we need calculate the real object type
and exposed object type, in some cases there are equivalent
for public object type its [@meth] it does not depend on itself
while for label argument it is [@this] which depends internal object
*)
let ( (internal_label_attr_types : Parsetree.object_field list),
(public_label_attr_types : Parsetree.object_field list) ) =
Ext_list.fold_right clfs ([], [])
(fun
({ pcf_loc = loc } as x : Parsetree.class_field)
(label_attr_types, public_label_attr_types)
->
match x.pcf_desc with
| Pcf_method (label, public_flag, Cfk_concrete (Fresh, e)) -> (
match e.pexp_desc with
| Pexp_poly ({ pexp_desc = Pexp_fun (lbl, _, pat, e) }, None) ->
let method_type =
Ast_typ_uncurry.generate_arg_type x.pcf_loc mapper label.txt
lbl pat e
in
( Parsetree.Otag (label, [], method_type) :: label_attr_types,
if public_flag = Public then
Parsetree.Otag (label, [], method_type)
:: public_label_attr_types
else public_label_attr_types )
| Pexp_poly (_, Some _) ->
Location.raise_errorf ~loc
"polymorphic type annotation not supported yet"
| Pexp_poly (_, None) ->
Location.raise_errorf ~loc
"Unsupported syntax, expect syntax like `method x () = x ` "
| _ -> Location.raise_errorf ~loc "Unsupported syntax in js object")
| Pcf_val (label, mutable_flag, Cfk_concrete (Fresh, _)) ->
let _, label_attr =
generate_val_method_pair x.pcf_loc mapper label
(mutable_flag = Mutable)
in
( Ext_list.append label_attr label_attr_types,
public_label_attr_types )
| Pcf_val (_, _, Cfk_concrete (Override, _)) ->
Location.raise_errorf ~loc "override flag not support currently"
| Pcf_val (_, _, Cfk_virtual _) ->
Location.raise_errorf ~loc "virtual flag not support currently"
| Pcf_method (_, _, Cfk_concrete (Override, _)) ->
Location.raise_errorf ~loc "override flag not supported"
| Pcf_method (_, _, Cfk_virtual _) ->
Location.raise_errorf ~loc "virtural method not supported"
| Pcf_inherit _ | Pcf_initializer _ | Pcf_attribute _ | Pcf_extension _
| Pcf_constraint _ ->
Location.raise_errorf ~loc "Only method support currently")
in
let internal_obj_type =
Ast_core_type.make_obj ~loc internal_label_attr_types
in
let public_obj_type = Ast_core_type.make_obj ~loc public_label_attr_types in
let labels, label_types, exprs, _ =
Ext_list.fold_right clfs ([], [], [], false)
(fun (x : Parsetree.class_field) (labels, label_types, exprs, aliased) ->
match x.pcf_desc with
| Pcf_method (label, _public_flag, Cfk_concrete (Fresh, e)) -> (
match e.pexp_desc with
| Pexp_poly
(({ pexp_desc = Pexp_fun (ll, None, pat, e) } as f), None) ->
let alias_type =
if aliased then None else Some internal_obj_type
in
let label_type =
Ast_typ_uncurry.generate_method_type ?alias_type x.pcf_loc
mapper label.txt ll pat e
in
( label :: labels,
label_type :: label_types,
{
f with
pexp_desc =
(let f = Ast_pat.is_unit_cont pat ~yes:e ~no:f in
Ast_uncurry_gen.to_method_callback loc mapper Nolabel
self_pat f)
(* the first argument is this*);
}
:: exprs,
true )
| Pexp_poly (_, Some _) ->
Location.raise_errorf ~loc
"polymorphic type annotation not supported yet"
| Pexp_poly (_, None) ->
Location.raise_errorf ~loc
"Unsupported syntax, expect syntax like `method x () = x ` "
| _ -> Location.raise_errorf ~loc "Unsupported syntax in js object")
| Pcf_val (label, mutable_flag, Cfk_concrete (Fresh, val_exp)) ->
let label_type, _ =
generate_val_method_pair x.pcf_loc mapper label
(mutable_flag = Mutable)
in
( label :: labels,
label_type :: label_types,
mapper.expr mapper val_exp :: exprs,
aliased )
| Pcf_val (_, _, Cfk_concrete (Override, _)) ->
Location.raise_errorf ~loc "override flag not support currently"
| Pcf_val (_, _, Cfk_virtual _) ->
Location.raise_errorf ~loc "virtual flag not support currently"
| Pcf_method (_, _, Cfk_concrete (Override, _)) ->
Location.raise_errorf ~loc "override flag not supported"
| Pcf_method (_, _, Cfk_virtual _) ->
Location.raise_errorf ~loc "virtural method not supported"
| Pcf_inherit _ | Pcf_initializer _ | Pcf_attribute _ | Pcf_extension _
| Pcf_constraint _ ->
Location.raise_errorf ~loc "Only method support currently")
in
let pval_type =
Ext_list.fold_right2 labels label_types public_obj_type
(fun label label_type acc ->
Ast_compatible.label_arrow ~loc:label.Asttypes.loc label.Asttypes.txt
label_type acc)
in
Ast_external_mk.local_extern_cont_to_obj loc
~pval_prim:(Ast_external_process.pval_prim_of_labels labels)
(fun e ->
Ast_compatible.apply_labels ~loc e
(Ext_list.map2 labels exprs (fun l expr -> (l.txt, expr))))
~pval_type

let record_as_js_object loc (self : Bs_ast_mapper.mapper)
(label_exprs : label_exprs) : Parsetree.expression_desc =
let labels, args, arity =
7 changes: 0 additions & 7 deletions jscomp/frontend/ast_util.mli
Original file line number Diff line number Diff line change
@@ -35,10 +35,3 @@ val record_as_js_object :

val js_property :
Location.t -> Parsetree.expression -> string -> Parsetree.expression_desc

val ocaml_obj_as_js_object :
Location.t ->
Bs_ast_mapper.mapper ->
Parsetree.pattern ->
Parsetree.class_field list ->
Parsetree.expression_desc
16 changes: 0 additions & 16 deletions jscomp/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
@@ -155,22 +155,6 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
pexp_attributes;
})
| Pexp_apply (fn, args) -> Ast_exp_apply.app_exp_mapper e self fn args
| Pexp_object { pcstr_self; pcstr_fields } ->
let pexp_attributes =
match Ast_attributes.process_bs e.pexp_attributes with
| true, pexp_attributes ->
Location.prerr_warning e.pexp_loc
(Bs_ffi_warning "Here @bs attribute not needed any more");
pexp_attributes
| false, e -> e
in
{
e with
pexp_desc =
Ast_util.ocaml_obj_as_js_object e.pexp_loc self pcstr_self
pcstr_fields;
pexp_attributes;
}
| Pexp_match
( b,
[
11 changes: 0 additions & 11 deletions jscomp/test/arity_ml.js

This file was deleted.

36 changes: 0 additions & 36 deletions jscomp/test/arity_ml.ml

This file was deleted.

8 changes: 1 addition & 7 deletions jscomp/test/build.ninja

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions jscomp/test/class_type_ffi_test.js
Original file line number Diff line number Diff line change
@@ -66,27 +66,6 @@ function mk_f(param) {
};
}

function omk_f(param) {
return {
huge_methdo: (function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) {
return Curry.app(a0, [
a1,
a2,
a3,
a4,
a5,
a6,
a7,
a8,
a9,
a10,
a11,
a12
]);
})
};
}

exports.sum_float_array = sum_float_array;
exports.sum_int_array = sum_int_array;
exports.sum_poly = sum_poly;
@@ -96,5 +75,4 @@ exports.ff = ff;
exports.ff2 = ff2;
exports.off2 = off2;
exports.mk_f = mk_f;
exports.omk_f = omk_f;
/* No side effect */
7 changes: 0 additions & 7 deletions jscomp/test/class_type_ffi_test.ml
Original file line number Diff line number Diff line change
@@ -68,10 +68,3 @@ let off2 o a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
let mk_f () =
fun [@bs] a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 ->
a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12

(* Test [fn_method] *)
let omk_f ()=
object
method huge_methdo a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12
end
23 changes: 3 additions & 20 deletions jscomp/test/ffi_js_test.js
Original file line number Diff line number Diff line change
@@ -80,32 +80,16 @@ var same_type = [
same_type_1
];

var v_obj = {
hi: (function () {
console.log("hei");
})
};

eq("File \"ffi_js_test.ml\", line 44, characters 5-12", [
eq("File \"ffi_js_test.ml\", line 41, characters 5-12", [
Object.keys(int_config).length,
2
]);

eq("File \"ffi_js_test.ml\", line 45, characters 5-12", [
eq("File \"ffi_js_test.ml\", line 42, characters 5-12", [
Object.keys(string_config).length,
2
]);

eq("File \"ffi_js_test.ml\", line 46, characters 5-12", [
Object.keys(v_obj).indexOf("hi_x"),
-1
]);

eq("File \"ffi_js_test.ml\", line 47, characters 5-12", [
Object.keys(v_obj).indexOf("hi"),
0
]);

var u = {
contents: 3
};
@@ -115,7 +99,7 @@ var side_effect_config = (u.contents = u.contents + 1 | 0, {
low: 32
});

eq("File \"ffi_js_test.ml\", line 54, characters 5-12", [
eq("File \"ffi_js_test.ml\", line 49, characters 5-12", [
u.contents,
4
]);
@@ -183,7 +167,6 @@ exports.eq = eq;
exports.int_config = int_config;
exports.string_config = string_config;
exports.same_type = same_type;
exports.v_obj = v_obj;
exports.u = u;
exports.side_effect_config = side_effect_config;
exports.vv = vv;
7 changes: 1 addition & 6 deletions jscomp/test/ffi_js_test.ml
Original file line number Diff line number Diff line change
@@ -37,14 +37,9 @@ let same_type =
[string_config ; [%obj{hi = 3 ; low = "32"}]]
)

let v_obj = object method hi__x () = Js.log "hei" end


let () =
eq __LOC__ (Array.length (Js_obj.keys int_config), 2 );
eq __LOC__ (Array.length (Js_obj.keys string_config), 2 );
eq __LOC__ (Js_obj.keys v_obj |. Js.Array2.indexOf "hi_x" , -1 );
eq __LOC__ (Js_obj.keys v_obj |. Js.Array2.indexOf "hi", 0 )
eq __LOC__ (Array.length (Js_obj.keys string_config), 2 )

let u = ref 3

36 changes: 0 additions & 36 deletions jscomp/test/gpr_1600_test.js

This file was deleted.

33 changes: 0 additions & 33 deletions jscomp/test/gpr_1600_test.ml

This file was deleted.

76 changes: 0 additions & 76 deletions jscomp/test/gpr_627_test.js

This file was deleted.

31 changes: 0 additions & 31 deletions jscomp/test/gpr_627_test.ml

This file was deleted.

24 changes: 3 additions & 21 deletions jscomp/test/mutable_uncurry_test.js
Original file line number Diff line number Diff line change
@@ -39,22 +39,6 @@ eqs("File \"mutable_uncurry_test.ml\", line 16, characters 7-14", true, eq({
contents: 2
}));

var u = {
hi: (function (param, param$1) {
var x = param.contents;
var y = param$1.contents;
return x === y;
})
};

var h = u.hi({
contents: 1
}, {
contents: 2
});

eqs("File \"mutable_uncurry_test.ml\", line 26, characters 7-14", h, false);

function ut3(param, param$1, param$2) {
var x0 = param.contents;
var x1 = param$1.contents;
@@ -195,7 +179,7 @@ function nested1(param) {
};
}

eqs("File \"mutable_uncurry_test.ml\", line 56, characters 9-16", ut3({
eqs("File \"mutable_uncurry_test.ml\", line 46, characters 9-16", ut3({
contents: 1
}, {
contents: 2
@@ -207,7 +191,7 @@ eqs("File \"mutable_uncurry_test.ml\", line 56, characters 9-16", ut3({
3
]);

eqs("File \"mutable_uncurry_test.ml\", line 57, characters 7-14", Curry._1(t3({
eqs("File \"mutable_uncurry_test.ml\", line 47, characters 7-14", Curry._1(t3({
contents: 1
})({
contents: 2
@@ -219,7 +203,7 @@ eqs("File \"mutable_uncurry_test.ml\", line 57, characters 7-14", Curry._1(t3({
3
]);

eqs("File \"mutable_uncurry_test.ml\", line 59, characters 7-14", ut5({
eqs("File \"mutable_uncurry_test.ml\", line 49, characters 7-14", ut5({
contents: 1
}, {
contents: 2
@@ -244,8 +228,6 @@ exports.test_id = test_id;
exports.eqs = eqs;
exports.eq = eq;
exports.eq2 = eq2;
exports.u = u;
exports.h = h;
exports.ut3 = ut3;
exports.t3 = t3;
exports.ut4 = ut4;
10 changes: 0 additions & 10 deletions jscomp/test/mutable_uncurry_test.ml
Original file line number Diff line number Diff line change
@@ -15,16 +15,6 @@ let eq2 =fun [@bs] x {contents = y} -> x.contents = y
;; eqs __LOC__ false (eq (ref 1) (ref 2) [@bs])
;; eqs __LOC__ true (eq (ref 2) (ref 2) [@bs])

let u = object
method hi {contents = x} {contents = y} =
(x : int) = y
end;;


let h = u##hi (ref 1) (ref 2)

;; eqs __LOC__ h false


let ut3 = fun [@bs] {contents = x0} {contents = x1} {contents = x2} ->
(x0,x1,x2)
230 changes: 0 additions & 230 deletions jscomp/test/ppx_this_obj_field.js

This file was deleted.

115 changes: 0 additions & 115 deletions jscomp/test/ppx_this_obj_field.ml

This file was deleted.

116 changes: 0 additions & 116 deletions jscomp/test/ppx_this_obj_test.js

This file was deleted.

62 changes: 0 additions & 62 deletions jscomp/test/ppx_this_obj_test.ml

This file was deleted.

62 changes: 0 additions & 62 deletions jscomp/test/uncurry_method.js

This file was deleted.

62 changes: 0 additions & 62 deletions jscomp/test/uncurry_method.ml

This file was deleted.

504 changes: 160 additions & 344 deletions lib/4.06.1/unstable/js_compiler.ml

Large diffs are not rendered by default.

504 changes: 160 additions & 344 deletions lib/4.06.1/unstable/js_playground_compiler.ml

Large diffs are not rendered by default.

504 changes: 160 additions & 344 deletions lib/4.06.1/whole_compiler.ml

Large diffs are not rendered by default.