Skip to content

Commit 01d1098

Browse files
authored
Remove more "bs." (rescript-lang#6635)
* @bs.obj -> @obj * @bs.optional -> @optional * @bs.return -> @return * @bs.send -> @send * @bs.scope -> @scope * @bs.splice, @bs.variadic -> variadic
1 parent cfd4eb9 commit 01d1098

Some content is hidden

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

55 files changed

+301
-265
lines changed

jscomp/core/design.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ Lalias-bound variables are never assigned, so it can only
134134
appear in `Lvar`, then it is easy to eliminate it
135135

136136

137-
# interaction between `bs.splice` and `|>`
137+
# interaction between `variadic` and `|>`
138138

139139
Note in general, it is fine whether we do beta reduction or not, it is just optimization.
140140

141-
However, since we introduced `bs.splice` which does require the `spliced argument` to be captured
141+
However, since we introduced `variadic` which does require the `spliced argument` to be captured
142142

143143
```ocaml
144144
spliced_external a0 a1 [|b0;b1|]
@@ -157,7 +157,7 @@ spliced_external a0 a1 [|b0;b1|] x
157157
```
158158

159159
So our optimizer needs to handle this case to make sure `spliced_external` not escaped,
160-
also becaues the interaction of `[@bs.splice]` and `[@bs.send]`, the spliced argument
160+
also becaues the interaction of `[@variadic]` and `[@send]`, the spliced argument
161161
is no longer in tail position, so that people can write such code
162162

163163
```ocaml
@@ -171,15 +171,15 @@ Internally in lambda layer it would be
171171

172172
We can simply do inlining, it may have side efffect in `b0`, `b1`, our optimizer also need handle such case.
173173

174-
Maybe in the future, we should lift the restriction about `bs.splice` (delegate to `slow` mode when we can not resolve it statically, my personal expereince is that people will complain about why it fails to compile more than why it is slow in some corner cases)
174+
Maybe in the future, we should lift the restriction about `variadic` (delegate to `slow` mode when we can not resolve it statically, my personal expereince is that people will complain about why it fails to compile more than why it is slow in some corner cases)
175175

176176
Note this also interacts with `[@bs.uncurry]`
177177

178178
for example
179179

180180
```ocaml
181181
external filter : 'a array -> ('a -> bool [@bs.uncurry]) -> 'a array = "filter"
182-
[@@bs.send]
182+
[@@send]
183183
184184
let f xs =
185185
xs |. filter (fun x -> x > 2)

jscomp/frontend/ast_attributes.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ let process_send_pipe (attrs : t) : (Parsetree.core_type * t) option =
199199
"This attribute is deprecated, use @send instead.");
200200

201201
ty := Some (Ast_payload.as_core_type loc payload);
202-
({Asttypes.txt = "bs.send"; loc}, Parsetree.PStr []) :: acc
202+
({Asttypes.txt = "send"; loc}, Parsetree.PStr []) :: acc
203203
| Some _ -> Location.raise_errorf ~loc "Duplicated bs.send.pipe")
204204
| _ -> attr :: acc)
205205
in
@@ -247,7 +247,7 @@ let iter_process_bs_string_as (attrs : t) : string option =
247247
let has_bs_optional (attrs : t) : bool =
248248
Ext_list.exists attrs (fun (({txt}, _) as attr) ->
249249
match txt with
250-
| "bs.optional" | "optional" ->
250+
| "optional" ->
251251
Bs_ast_invariant.mark_used_bs_attribute attr;
252252
true
253253
| _ -> false)
@@ -349,7 +349,7 @@ let internal_expansive : attr =
349349
({txt = "internal.expansive"; loc = locg}, Ast_payload.empty)
350350

351351
let bs_return_undefined : attr =
352-
( {txt = "bs.return"; loc = locg},
352+
( {txt = "return"; loc = locg},
353353
PStr
354354
[
355355
{

jscomp/frontend/ast_derive_js_mapper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ let init () =
181181
let exp =
182182
coerceResultToNewType
183183
(Exp.extension
184-
( {Asttypes.loc; txt = "bs.obj"},
184+
( {Asttypes.loc; txt = "obj"},
185185
PStr
186186
[
187187
Str.eval

jscomp/frontend/ast_exp_extension.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper)
7171
Location.raise_errorf ~loc "expect a boolean expression in the payload")
7272
| "bs.debugger" | "debugger" ->
7373
{e with pexp_desc = Ast_exp_handle_external.handle_debugger loc payload}
74-
| "bs.obj" | "obj" -> (
74+
| "obj" -> (
7575
match payload with
7676
| PStr
7777
[

jscomp/frontend/ast_external_process.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,16 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
376376
};
377377
}
378378
| _ -> Bs_syntaxerr.err loc Illegal_attribute))
379-
| "bs.scope" | "scope" -> (
379+
| "scope" -> (
380380
match Ast_payload.assert_strings loc payload with
381381
| [] -> Bs_syntaxerr.err loc Illegal_attribute
382382
(* We need err on empty scope, so we can tell the difference
383383
between unset/set
384384
*)
385385
| scopes -> {st with scopes})
386386
| "taggedTemplate" -> {st with splice = true; tagged_template = true}
387-
| "bs.splice" | "bs.variadic" | "variadic" -> {st with splice = true}
388-
| "bs.send" | "send" ->
387+
| "variadic" -> {st with splice = true}
388+
| "send" ->
389389
{st with val_send = Some (name_from_payload_or_prim ~loc payload)}
390390
| "set" ->
391391
{st with set_name = Some (name_from_payload_or_prim ~loc payload)}
@@ -405,8 +405,8 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
405405
"%@get_index this particular external's name needs to be a \
406406
placeholder empty string";
407407
{st with get_index = true}
408-
| "bs.obj" | "obj" -> {st with mk_obj = true}
409-
| "bs.return" | "return" -> (
408+
| "obj" -> {st with mk_obj = true}
409+
| "return" -> (
410410
let actions = Ast_payload.ident_or_record_as_config loc payload in
411411
match actions with
412412
| [({txt; _}, None)] ->

jscomp/ml/oprint.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ and print_out_sig_item ppf =
562562
fprintf ppf "@ = \"%s\"" s;
563563
List.iter (fun s ->
564564
(* TODO: in general, we should print bs attributes, some attributes like
565-
bs.splice does need it *)
565+
variadic do need it *)
566566
fprintf ppf "@ \"%s\"" (!map_primitive_name s)
567567
) sl
568568
in

jscomp/others/js.ml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
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-
[@@@bs.config { flags = [| "-unboxed-types"; "-w"; "-49" |] }]
25+
[@@@bs.config {flags = [|"-unboxed-types"; "-w"; "-49"|]}]
2626
(* DESIGN:
2727
- It does not have any code, all its code will be inlined so that
2828
there will never be
@@ -82,29 +82,23 @@ module Internal = struct
8282
external opaqueFullApply : 'a -> 'a = "%uncurried_apply"
8383

8484
(* Use opaque instead of [._n] to prevent some optimizations happening *)
85-
external run : (unit -> 'a [@bs]) -> 'a = "#run"
85+
external run : ((unit -> 'a)[@bs]) -> 'a = "#run"
8686
external opaque : 'a -> 'a = "%opaque"
8787
end
8888

8989
(**/**)
9090

91-
type +'a null =
92-
| Value of 'a
93-
| Null [@as null]
94-
[@@unboxed]
9591
(**
9692
Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t.
9793
*)
94+
type +'a null = Value of 'a | Null [@as null] [@@unboxed]
9895

9996
type +'a undefined
10097
(**
10198
A value of this type can be either undefined or 'a. This type is equivalent to Js.Undefined.t.
10299
*)
103100

104-
type +'a nullable =
105-
| Value of 'a
106-
| Null [@as null]
107-
| Undefined [@as undefined]
101+
type +'a nullable = Value of 'a | Null [@as null] | Undefined [@as undefined]
108102
[@@unboxed]
109103

110104
(**
@@ -144,17 +138,17 @@ external typeof : 'a -> string = "#typeof"
144138
*)
145139

146140
external log : 'a -> unit = "log"
147-
[@@val] [@@scope "console"]
141+
[@@val] [@@scope "console"]
148142
(** Equivalent to console.log any value. *)
149143

150-
external log2 : 'a -> 'b -> unit = "log" [@@bs.val] [@@bs.scope "console"]
151-
external log3 : 'a -> 'b -> 'c -> unit = "log" [@@bs.val] [@@bs.scope "console"]
144+
external log2 : 'a -> 'b -> unit = "log" [@@bs.val] [@@scope "console"]
145+
external log3 : 'a -> 'b -> 'c -> unit = "log" [@@bs.val] [@@scope "console"]
152146

153147
external log4 : 'a -> 'b -> 'c -> 'd -> unit = "log"
154-
[@@bs.val] [@@bs.scope "console"]
148+
[@@bs.val] [@@scope "console"]
155149

156150
external logMany : 'a array -> unit = "log"
157-
[@@bs.val] [@@bs.scope "console"] [@@bs.splice]
151+
[@@bs.val] [@@scope "console"] [@@variadic]
158152
(** A convenience function to console.log more than 4 arguments *)
159153

160154
external eqNull : 'a -> 'a null -> bool = "%bs_equal_null"
@@ -199,8 +193,9 @@ module Undefined = Js_undefined
199193
module Nullable = Js_null_undefined
200194
(** Provide utilities for `Js.null_undefined` *)
201195

202-
module Null_undefined = Js_null_undefined
203-
[@deprecated "Please use `Js.Nullable`"]
196+
module Null_undefined =
197+
Js_null_undefined
198+
[@deprecated "Please use `Js.Nullable`"]
204199

205200
module Exn = Js_exn
206201
(** Provide utilities for dealing with Js exceptions *)

jscomp/others/js_array2.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ external toLocaleString: t<'a> => string = "toLocaleString"
720720
/* Iteration functions
721721
*/
722722
/* commented out until bs has a plan for iterators
723-
external entries : 'a t -> (int * 'a) array_iter = "" [@@bs.send] (* ES2015 *)
723+
external entries : 'a t -> (int * 'a) array_iter = "" [@@send] (* ES2015 *)
724724
*/
725725

726726
@send
@@ -925,7 +925,7 @@ Js.Array2.forEachi(["a", "b", "c"], (item, index) => Js.log2(index + 1, item)) =
925925
external forEachi: (t<'a>, @uncurry ('a, int) => unit) => unit = "forEach"
926926

927927
/* commented out until bs has a plan for iterators
928-
external keys : 'a t -> int array_iter = "" [@@bs.send] (* ES2015 *)
928+
external keys : 'a t -> int array_iter = "" [@@send] (* ES2015 *)
929929
*/
930930

931931
@send
@@ -1142,7 +1142,7 @@ Js.Array2.somei(["a", "bc", "def", "gh"], sameLength) == false
11421142
external somei: (t<'a>, @uncurry ('a, int) => bool) => bool = "some"
11431143

11441144
/* commented out until bs has a plan for iterators
1145-
external values : 'a t -> 'a array_iter = "" [@@bs.send] (* ES2015 *)
1145+
external values : 'a t -> 'a array_iter = "" [@@send] (* ES2015 *)
11461146
*/
11471147

11481148
/**

jscomp/others/js_json.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ let decodeNull = (json): option<Js.null<_>> =>
131131
}
132132

133133
/* external parse : string -> t = "parse"
134-
[@@bs.val][@@bs.scope "JSON"] */
134+
[@@bs.val][@@scope "JSON"] */
135135

136136
@val @scope("JSON") external parseExn: string => t = "parse"
137137

0 commit comments

Comments
 (0)