Skip to content

Commit 43d07f7

Browse files
committed
Remove class type processing from compiler ppx.
There's no class type in `.res` syntax.
1 parent 9d585cd commit 43d07f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+7
-1629
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ These are only breaking changes for unformatted code.
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)
5151
- Remove processing of objects expressions, which don't exist in `.res` syntax (`Pexp_object`) https://github.com/rescript-lang/rescript-compiler/pull/5841
52+
- Remove class type processing from compiler ppx
5253

5354
# 10.1.0-rc.6
5455

jscomp/frontend/ast_core_type_class_type.ml

-57
Original file line numberDiff line numberDiff line change
@@ -56,60 +56,6 @@ let process_getter_setter ~not_getter_setter
5656
pctf_attributes
5757
:: get_acc
5858

59-
let handle_class_type_field self
60-
({ pctf_loc = loc } as ctf : Parsetree.class_type_field) acc =
61-
match ctf.pctf_desc with
62-
| Pctf_method (name, private_flag, virtual_flag, ty) ->
63-
let not_getter_setter (ty : Parsetree.core_type) =
64-
let ty =
65-
match ty.ptyp_desc with
66-
| Ptyp_arrow (label, args, body) ->
67-
Ast_typ_uncurry.to_method_type ty.ptyp_loc self label args body
68-
| Ptyp_poly
69-
(strs, { ptyp_desc = Ptyp_arrow (label, args, body); ptyp_loc })
70-
->
71-
{
72-
ty with
73-
ptyp_desc =
74-
Ptyp_poly
75-
( strs,
76-
Ast_typ_uncurry.to_method_type ptyp_loc self label args
77-
body );
78-
}
79-
| _ -> self.typ self ty
80-
in
81-
{
82-
ctf with
83-
pctf_desc = Pctf_method (name, private_flag, virtual_flag, ty);
84-
}
85-
in
86-
let get ty name pctf_attributes =
87-
{
88-
ctf with
89-
pctf_desc =
90-
Pctf_method (name, private_flag, virtual_flag, self.typ self ty);
91-
pctf_attributes;
92-
}
93-
in
94-
let set ty name pctf_attributes =
95-
{
96-
ctf with
97-
pctf_desc =
98-
Pctf_method
99-
( name,
100-
private_flag,
101-
virtual_flag,
102-
Ast_typ_uncurry.to_method_type loc self Nolabel ty
103-
(Ast_literal.type_unit ~loc ()) );
104-
pctf_attributes;
105-
}
106-
in
107-
process_getter_setter ~not_getter_setter ~get ~set loc name
108-
ctf.pctf_attributes ty acc
109-
| Pctf_inherit _ | Pctf_val _ | Pctf_constraint _ | Pctf_attribute _
110-
| Pctf_extension _ ->
111-
Bs_ast_mapper.default_mapper.class_type_field self ctf :: acc
112-
11359
let default_typ_mapper = Bs_ast_mapper.default_mapper.typ
11460
(*
11561
Attributes are very hard to attribute
@@ -191,6 +137,3 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
191137
in
192138
{ ty with ptyp_desc = Ptyp_object (new_methods, closed_flag) }
193139
| _ -> default_typ_mapper self ty
194-
195-
let handle_class_type_fields self fields =
196-
Ext_list.fold_right fields [] (handle_class_type_field self)

jscomp/frontend/ast_core_type_class_type.mli

-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,5 @@
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-
val handle_class_type_fields :
26-
Bs_ast_mapper.mapper ->
27-
Parsetree.class_type_field list ->
28-
Parsetree.class_type_field list
29-
3025
val typ_mapper :
3126
Bs_ast_mapper.mapper -> Parsetree.core_type -> Parsetree.core_type

jscomp/frontend/bs_builtin_ppx.ml

-37
Original file line numberDiff line numberDiff line change
@@ -238,42 +238,6 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
238238
let typ_mapper (self : mapper) (typ : Parsetree.core_type) =
239239
Ast_core_type_class_type.typ_mapper self typ
240240

241-
let class_type_mapper (self : mapper)
242-
({ pcty_attributes; pcty_loc } as ctd : Parsetree.class_type) =
243-
let pcty_attributes =
244-
match Ast_attributes.process_bs pcty_attributes with
245-
| false, _ -> pcty_attributes
246-
| true, pcty_attributes ->
247-
Location.prerr_warning pcty_loc
248-
(Bs_ffi_warning "Here @bs attribute is not needed any more.");
249-
pcty_attributes
250-
in
251-
match ctd.pcty_desc with
252-
| Pcty_signature { pcsig_self; pcsig_fields } ->
253-
let pcsig_self = self.typ self pcsig_self in
254-
{
255-
ctd with
256-
pcty_desc =
257-
Pcty_signature
258-
{
259-
pcsig_self;
260-
pcsig_fields =
261-
Ast_core_type_class_type.handle_class_type_fields self
262-
pcsig_fields;
263-
};
264-
pcty_attributes;
265-
}
266-
| Pcty_open _ (* let open M in CT *) | Pcty_constr _ | Pcty_extension _
267-
| Pcty_arrow _ ->
268-
default_mapper.class_type self ctd
269-
(* {[class x : int -> object
270-
end [@bs]
271-
]}
272-
Actually this is not going to happpen as below is an invalid syntax
273-
{[class type x = int -> object
274-
end[@bs]]}
275-
*)
276-
277241
let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) :
278242
Parsetree.signature_item =
279243
match sigi.psig_desc with
@@ -544,7 +508,6 @@ let mapper : mapper =
544508
expr = expr_mapper ~async_context:(ref false) ~in_function_def:(ref false);
545509
pat = pat_mapper;
546510
typ = typ_mapper;
547-
class_type = class_type_mapper;
548511
signature_item = signature_item_mapper;
549512
value_bindings = Ast_tuple_pattern_flatten.value_bindings_mapper;
550513
structure_item = structure_item_mapper;

jscomp/test/build.ninja

+1-15
Large diffs are not rendered by default.

jscomp/test/class_setter_getter.js

-20
This file was deleted.

jscomp/test/class_setter_getter.ml

-39
This file was deleted.

jscomp/test/class_setter_getter.mli

-63
This file was deleted.

jscomp/test/class_type_ffi_test.js

-27
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,6 @@
22

33
var Curry = require("../../lib/js/curry.js");
44

5-
function sum_float_array(arr) {
6-
var v = 0;
7-
for(var i = 0 ,i_finish = arr.length; i < i_finish; ++i){
8-
v = v + arr.case(i);
9-
}
10-
return v;
11-
}
12-
13-
function sum_int_array(arr) {
14-
var v = 0;
15-
for(var i = 0 ,i_finish = arr.length; i < i_finish; ++i){
16-
v = v + arr.case(i) | 0;
17-
}
18-
return v;
19-
}
20-
21-
function sum_poly(zero, add, arr) {
22-
var v = zero;
23-
for(var i = 0 ,i_finish = arr.length; i < i_finish; ++i){
24-
v = add(v, arr.case(i));
25-
}
26-
return v;
27-
}
28-
295
function test_set(x) {
306
x.length = 3;
317
}
@@ -66,9 +42,6 @@ function mk_f(param) {
6642
};
6743
}
6844

69-
exports.sum_float_array = sum_float_array;
70-
exports.sum_int_array = sum_int_array;
71-
exports.sum_poly = sum_poly;
7245
exports.test_set = test_set;
7346
exports.f = f;
7447
exports.ff = ff;

jscomp/test/class_type_ffi_test.ml

-35
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,8 @@
11

2-
class type ['k,'v] arrayLike =
3-
object
4-
method case : 'k -> 'v Js.Null.t
5-
method caseSet : 'k * 'v -> unit
6-
method case__unsafe : 'k -> 'v
7-
method length : int
8-
end
92

10-
class type floatArray = [int, float] arrayLike
11-
(** here we can see [@bs] is really attached to `object end` instead of `class type` *)
123

134

145

15-
class type intArray = [int, int] arrayLike
16-
17-
18-
let sum_float_array (arr : floatArray ) =
19-
let v = ref 0. in
20-
for i = 0 to arr##length - 1 do
21-
v := !v +. arr##case__unsafe i
22-
done;
23-
!v
24-
25-
let sum_int_array (arr : intArray ) =
26-
let v = ref 0 in
27-
for i = 0 to arr##length - 1 do
28-
v := !v + arr## case__unsafe i
29-
done;
30-
!v
31-
32-
(* TODO: warning about unprocessed attributes *)
33-
let sum_poly zero add (arr : _ arrayLike ) =
34-
let v = ref zero in
35-
for i = 0 to arr##length - 1 do
36-
v := add !v (arr##case__unsafe i ) [@bs]
37-
done;
38-
!v
39-
40-
416
(* TODO: create a special type
427
['a Js.prop_set] for better error message
438
*)

jscomp/test/config2_test.js

-15
This file was deleted.

jscomp/test/config2_test.ml

-34
This file was deleted.

0 commit comments

Comments
 (0)