Skip to content

Commit f04aa3f

Browse files
committed
Remove support for @bs.send.pipe from the compiler.
1 parent d22ec58 commit f04aa3f

File tree

7 files changed

+44
-169
lines changed

7 files changed

+44
-169
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- Remove ml parsing tests and conversion from `.ml` to `.res` via format. https://github.com/rescript-lang/rescript-compiler/pull/6848
3333
- Remove support for compiling `.ml` files, and general cleanup. https://github.com/rescript-lang/rescript-compiler/pull/6852
3434
- Remove `rescript convert` subcommand. https://github.com/rescript-lang/rescript-compiler/pull/6860
35+
- Remove support for `@bs.send.pipe`. https://github.com/rescript-lang/rescript-compiler/pull/6858
3536

3637
#### :bug: Bug Fix
3738

jscomp/frontend/ast_attributes.ml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -176,34 +176,6 @@ let process_derive_type (attrs : t) : derive_attr * t =
176176
| Some _ -> Bs_syntaxerr.err loc Duplicated_bs_deriving)
177177
| _ -> (st, attr :: acc))
178178

179-
let process_send_pipe (attrs : t) : (Parsetree.core_type * t) option =
180-
match attrs with
181-
| [] -> None
182-
| _ -> (
183-
if not (Ext_list.exists_fst attrs (fun {txt} -> txt = "bs.send.pipe")) then
184-
(* fast path *)
185-
None
186-
else
187-
let ty = ref None in
188-
let attrs =
189-
Ext_list.fold_left attrs [] (fun acc (({txt; loc}, payload) as attr) ->
190-
match txt with
191-
| "bs.send.pipe" -> (
192-
match !ty with
193-
| None ->
194-
Location.prerr_warning loc
195-
(Warnings.Bs_ffi_warning
196-
"This attribute is deprecated, use @send instead.");
197-
198-
ty := Some (Ast_payload.as_core_type loc payload);
199-
({Asttypes.txt = "send"; loc}, Parsetree.PStr []) :: acc
200-
| Some _ -> Location.raise_errorf ~loc "Duplicated bs.send.pipe")
201-
| _ -> attr :: acc)
202-
in
203-
match !ty with
204-
| None -> assert false
205-
| Some ty -> Some (ty, attrs))
206-
207179
(* duplicated @uncurry @string not allowed,
208180
it is worse in @uncurry since it will introduce
209181
inconsistency in arity

jscomp/frontend/ast_attributes.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ val internal_expansive : attr
8787

8888
val rs_externals : t -> string list -> bool
8989

90-
val process_send_pipe : t -> (Parsetree.core_type * t) option
91-
9290
val is_gentype : attr -> bool
9391

9492
val gentype : attr

jscomp/frontend/ast_core_type.ml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ let get_curry_arity (ty : t) =
129129
let arity, _ = Ast_uncurried.core_type_extract_uncurried_fun ty in
130130
arity
131131
else get_uncurry_arity_aux ty 0
132-
133-
(* add hoc for bs.send.pipe *)
134-
let rec get_curry_labels (ty : t) acc =
135-
match ty.ptyp_desc with
136-
| Ptyp_arrow (label, _, rest) -> get_curry_labels rest (label :: acc)
137-
| _ -> acc
138-
139-
let get_curry_labels ty = List.rev (get_curry_labels ty [])
140132
let is_arity_one ty = get_curry_arity ty = 1
141133

142134
type param_type = {

jscomp/frontend/ast_core_type.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ val get_uncurry_arity : t -> int option
4747
None -- means not a function
4848
*)
4949

50-
val get_curry_labels : t -> Asttypes.arg_label list
51-
5250
type param_type = {
5351
label: Asttypes.arg_label;
5452
ty: t;

jscomp/frontend/ast_external.ml

Lines changed: 43 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,35 @@ let handle_external_in_sig (self : Bs_ast_mapper.mapper)
2828
let loc = prim.pval_loc in
2929
let pval_type = self.typ self prim.pval_type in
3030
let pval_attributes = self.attributes self prim.pval_attributes in
31-
match Ast_attributes.process_send_pipe pval_attributes with
32-
| Some (obj, _) ->
33-
(*has bs.send.pipe: best effort *)
34-
{
35-
sigi with
36-
psig_desc =
37-
Psig_value
38-
{
39-
prim with
40-
pval_type = Ast_core_type.add_last_obj pval_type obj;
41-
pval_prim = [];
42-
pval_attributes = [];
43-
};
44-
}
45-
| None -> (
46-
match prim.pval_prim with
47-
| [] -> Location.raise_errorf ~loc "empty primitive string"
48-
| a :: b :: _ ->
49-
Location.raise_errorf ~loc
50-
"only a single string is allowed in bs external %S %S" a b
51-
| [v] -> (
52-
match
53-
Ast_external_process.encode_attributes_as_string loc pval_type
54-
pval_attributes v
55-
with
56-
| {pval_type; pval_prim; pval_attributes; no_inline_cross_module} ->
57-
{
58-
sigi with
59-
psig_desc =
60-
Psig_value
61-
{
62-
prim with
63-
pval_type;
64-
pval_prim = (if no_inline_cross_module then [] else pval_prim);
65-
pval_attributes;
66-
};
67-
}))
31+
match prim.pval_prim with
32+
| [] -> Location.raise_errorf ~loc "empty primitive string"
33+
| a :: b :: _ ->
34+
Location.raise_errorf ~loc
35+
"only a single string is allowed in bs external %S %S" a b
36+
| [v] -> (
37+
match
38+
Ast_external_process.encode_attributes_as_string loc pval_type
39+
pval_attributes v
40+
with
41+
| {pval_type; pval_prim; pval_attributes; no_inline_cross_module} ->
42+
{
43+
sigi with
44+
psig_desc =
45+
Psig_value
46+
{
47+
prim with
48+
pval_type;
49+
pval_prim = (if no_inline_cross_module then [] else pval_prim);
50+
pval_attributes;
51+
};
52+
})
6853

6954
let handle_external_in_stru (self : Bs_ast_mapper.mapper)
7055
(prim : Parsetree.value_description) (str : Parsetree.structure_item) :
7156
Parsetree.structure_item =
7257
let loc = prim.pval_loc in
7358
let pval_type = self.typ self prim.pval_type in
7459
let pval_attributes = self.attributes self prim.pval_attributes in
75-
let send_pipe = ref false in
76-
let pval_type, pval_attributes =
77-
match Ast_attributes.process_send_pipe pval_attributes with
78-
| Some (obj, attrs) ->
79-
send_pipe := true;
80-
(Ast_helper.Typ.arrow ~loc Nolabel obj pval_type, attrs)
81-
| None -> (pval_type, pval_attributes)
82-
in
8360
match prim.pval_prim with
8461
| [] -> Location.raise_errorf ~loc "empty primitive string"
8562
| a :: b :: _ ->
@@ -98,86 +75,24 @@ let handle_external_in_stru (self : Bs_ast_mapper.mapper)
9875
Pstr_primitive {prim with pval_type; pval_prim; pval_attributes};
9976
}
10077
in
101-
let normal () =
102-
if not no_inline_cross_module then external_result
103-
else
104-
let open Ast_helper in
105-
Str.include_ ~loc
106-
(Incl.mk ~loc
107-
(Mod.constraint_ ~loc
108-
(Mod.structure ~loc [external_result])
109-
(Mty.signature ~loc
110-
[
111-
{
112-
psig_desc =
113-
Psig_value
114-
{
115-
prim with
116-
pval_type;
117-
pval_prim = [];
118-
pval_attributes;
119-
};
120-
psig_loc = loc;
121-
};
122-
])))
123-
in
124-
if !send_pipe then
125-
let[@warning "-8"] (_ :: params as args) =
126-
Ast_core_type.get_curry_labels pval_type
127-
in
128-
let arity = List.length args in
129-
if arity = 1 then normal ()
130-
else
131-
let open Ast_helper in
132-
Str.include_ ~loc
133-
(Incl.mk ~loc
134-
(Mod.structure ~loc
135-
[
136-
external_result;
137-
Str.value ~loc Nonrecursive
138-
[
139-
Vb.mk ~loc
140-
(Pat.var ~loc prim.pval_name)
141-
(let body =
142-
Exp.apply ~loc
143-
(Exp.ident ~loc
144-
{txt = Lident prim.pval_name.txt; loc})
145-
(( Asttypes.Nolabel,
146-
Exp.ident ~loc {txt = Lident "obj"; loc} )
147-
:: Ext_list.mapi params (fun i x ->
148-
( x,
149-
match x with
150-
| Asttypes.Nolabel ->
151-
Exp.ident
152-
{
153-
txt =
154-
Lident
155-
("arg" ^ string_of_int (i + 1));
156-
loc;
157-
}
158-
| Labelled s | Optional s ->
159-
Exp.ident {txt = Lident s; loc} )))
160-
in
161-
snd
162-
@@ Ext_list.fold_right params
163-
( 0,
164-
Exp.fun_ Nolabel None
165-
(Pat.var ~loc {txt = "obj"; loc})
166-
body )
167-
(fun arg (i, obj) ->
168-
( i + 1,
169-
Exp.fun_ arg None
170-
(Pat.var ~loc
171-
{
172-
txt =
173-
(match arg with
174-
| Labelled s | Optional s -> s
175-
| Nolabel ->
176-
"arg"
177-
^ string_of_int (arity - i - 1));
178-
loc;
179-
})
180-
obj )));
181-
];
182-
]))
183-
else normal ())
78+
if not no_inline_cross_module then external_result
79+
else
80+
let open Ast_helper in
81+
Str.include_ ~loc
82+
(Incl.mk ~loc
83+
(Mod.constraint_ ~loc
84+
(Mod.structure ~loc [external_result])
85+
(Mty.signature ~loc
86+
[
87+
{
88+
psig_desc =
89+
Psig_value
90+
{
91+
prim with
92+
pval_type;
93+
pval_prim = [];
94+
pval_attributes;
95+
};
96+
psig_loc = loc;
97+
};
98+
]))))

jscomp/frontend/ast_external_process.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
222222
(prim_attributes : Ast_attributes.t) : Ast_attributes.t * external_desc =
223223
(* shared by `[@@val]`, `[@@send]`,
224224
`[@@set]`, `[@@get]` , `[@@new]`
225-
`[@@bs.send.pipe]` does not use it
226225
*)
227226
let name_from_payload_or_prim ~loc (payload : Parsetree.payload) :
228227
bundle_source =

0 commit comments

Comments
 (0)