Skip to content

Commit 6f65a39

Browse files
committed
fix #5071
1 parent 8f9243a commit 6f65a39

Some content is hidden

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

48 files changed

+1364
-2252
lines changed

Changes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
`*` means potential break changes
22

33
# 9.1
4-
4+
- Remove depercated APIs Js.Re.exec, Js.Re.test, Node.Fs.on
55
- #5014 #5063 #5027 the new ReScript CLI interface
66
Thew new CLI is self explainatory:
77
```

jscomp/frontend/ast_external_process.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2-
*
1+
(* Copyright (C) 2015 - 2016 Bloomberg Finance L.P.
2+
* Copyright (C) 2017 - Hongbo Zhang, Authors of ReScript
33
* This program is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU Lesser General Public License as published by
55
* the Free Software Foundation, either version 3 of the License, or
@@ -330,6 +330,7 @@ let parse_external_attributes
330330
{ st with val_send = name_from_payload_or_prim ~loc payload}
331331
| "bs.send.pipe"
332332
->
333+
Location.prerr_warning loc (Warnings.Bs_ffi_warning "This attribute is deprecated, use @send instead.");
333334
{ st with val_send_pipe = Some (Ast_payload.as_core_type loc payload)}
334335
| "bs.set" | "set" ->
335336
{st with set_name = name_from_payload_or_prim ~loc payload}

jscomp/frontend/bs_builtin_ppx.ml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2-
*
1+
(* Copyright (C) 2015 - 2016 Bloomberg Finance L.P.
2+
* Copyright (C) 2017 - Hongbo Zhang, Authors of ReScript
33
* This program is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU Lesser General Public License as published by
55
* the Free Software Foundation, either version 3 of the License, or
@@ -206,7 +206,8 @@ let class_type_mapper (self : mapper) ({pcty_attributes; pcty_loc} as ctd : Pars
206206
*)
207207

208208

209-
let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
209+
let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item)
210+
: Parsetree.signature_item =
210211
match sigi.psig_desc with
211212
| Psig_type (
212213
rf,
@@ -284,13 +285,14 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
284285
| _ -> default_mapper.signature_item self sigi
285286

286287

287-
let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
288+
let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) : Parsetree.structure_item =
288289
match str.pstr_desc with
289290
| Pstr_type (
290291
rf,
291292
tdcls) (* [ {ptype_attributes} as tdcl ] *)->
292293
Ast_tdcls.handleTdclsInStru self str rf tdcls
293-
| Pstr_primitive prim when Ast_attributes.external_needs_to_be_encoded prim.pval_attributes
294+
| Pstr_primitive prim
295+
when Ast_attributes.external_needs_to_be_encoded prim.pval_attributes
294296
->
295297
Ast_external.handleExternalInStru self prim str
296298
| Pstr_value

jscomp/frontend/external_arg_spec.ml

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2-
*
1+
(* Copyright (C) 2015 - 2016 Bloomberg Finance L.P.
2+
* Copyright (C) 2017 - Hongbo Zhang, Authors of ReScript
33
* This program is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU Lesser General Public License as published by
55
* the Free Software Foundation, either version 3 of the License, or
@@ -35,9 +35,12 @@ type label_noname =
3535
| Arg_optional
3636

3737
type label =
38+
| Obj_empty
3839
| Obj_label of {name : string }
39-
| Obj_empty
40-
| Obj_optional of {name : string; for_sure_no_nested_option : bool }
40+
| Obj_optional of {
41+
name : string;
42+
for_sure_no_nested_option : bool
43+
}
4144

4245
(* it will be ignored , side effect will be recorded *)
4346

jscomp/frontend/external_arg_spec.mli

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2-
*
1+
(* Copyright (C) 2015 - 2016 Bloomberg Finance L.P.
2+
* Copyright (C) 2017 - Hongbo Zhang, Authors of ReScript
33
* This program is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU Lesser General Public License as published by
55
* the Free Software Foundation, either version 3 of the License, or
@@ -28,13 +28,6 @@ type cst = private
2828
| Arg_js_literal of string
2929

3030

31-
type label = private
32-
| Obj_label of {name : string}
33-
| Obj_empty
34-
35-
| Obj_optional of {name : string;
36-
for_sure_no_nested_option : bool}
37-
(* it will be ignored , side effect will be recorded *)
3831

3932

4033

@@ -62,8 +55,16 @@ type label_noname =
6255
| Arg_empty
6356
| Arg_optional
6457

65-
type obj_param =
66-
{
58+
type label = private
59+
| Obj_empty
60+
| Obj_label of {name : string}
61+
| Obj_optional of {
62+
name : string;
63+
for_sure_no_nested_option : bool
64+
}
65+
(* it will be ignored , side effect will be recorded *)
66+
67+
type obj_param = {
6768
obj_arg_type : attr;
6869
obj_arg_label :label
6970
}

jscomp/frontend/external_ffi_types.ml

+61-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2-
*
1+
(* Copyright (C) 2015 - 2016 Bloomberg Finance L.P.
2+
* Copyright (C) 2017 - Hongbo Zhang, Authors of ReScript
33
* This program is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU Lesser General Public License as published by
55
* the Free Software Foundation, either version 3 of the License, or
@@ -21,18 +21,17 @@
2121
* You should have received a copy of the GNU Lesser General Public License
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. *)
24-
24+
[@@@warning"+9"]
2525
type module_bind_name =
2626
| Phint_name of string
2727
(* explicit hint name *)
28-
2928
| Phint_nothing
3029

3130

32-
type external_module_name =
33-
{ bundle : string ;
34-
module_bind_name : module_bind_name
35-
}
31+
type external_module_name = {
32+
bundle : string ;
33+
module_bind_name : module_bind_name
34+
}
3635

3736
type pipe = bool
3837

@@ -52,9 +51,10 @@ type external_spec =
5251
scopes : string list
5352
}
5453
| Js_module_as_var of external_module_name
55-
| Js_module_as_fn of { external_module_name : external_module_name;
56-
splice : bool
57-
}
54+
| Js_module_as_fn of {
55+
external_module_name : external_module_name;
56+
splice : bool
57+
}
5858
| Js_module_as_class of external_module_name
5959
| Js_call of {
6060
name : string;
@@ -75,13 +75,14 @@ type external_spec =
7575
external_module_name : external_module_name option;
7676
scopes : string list;
7777
}
78-
| Js_set of
79-
{ js_set_name : string ;
80-
js_set_scopes : string list
81-
}
82-
| Js_get of { js_get_name : string ;
83-
js_get_scopes : string list;
84-
}
78+
| Js_set of {
79+
js_set_name : string ;
80+
js_set_scopes : string list
81+
}
82+
| Js_get of {
83+
js_get_name : string ;
84+
js_get_scopes : string list;
85+
}
8586
| Js_get_index of {
8687
js_get_index_scopes : string list
8788
}
@@ -137,6 +138,8 @@ type t =
137138

138139

139140

141+
142+
140143
let valid_js_char =
141144
let a = Array.init 256 (fun i ->
142145
let c = Char.chr i in
@@ -155,14 +158,14 @@ let valid_first_js_char =
155158
let valid_ident (s : string) =
156159
let len = String.length s in
157160
len > 0 && valid_js_char s.[0] && valid_first_js_char s.[0] &&
158-
(let module E = struct exception E end in
161+
(let exception E in
159162
try
160163
for i = 1 to len - 1 do
161164
if not (valid_js_char (String.unsafe_get s i)) then
162-
raise E.E
165+
raise_notrace E
163166
done ;
164167
true
165-
with E.E -> false )
168+
with E -> false )
166169

167170
let is_package_relative_path (x : string) =
168171
Ext_string.starts_with x "./" ||
@@ -192,7 +195,7 @@ let valid_method_name ?loc:_ _txt =
192195
let check_external_module_name ?loc x =
193196
match x with
194197
| {bundle = ""; _ }
195-
| { module_bind_name = Phint_name "" } ->
198+
| { module_bind_name = Phint_name ""; bundle = _ } ->
196199
Location.raise_errorf ?loc "empty name encountered"
197200
| _ -> ()
198201

@@ -203,14 +206,14 @@ let check_ffi ?loc ffi : bool =
203206
let upgrade bool =
204207
if not (!xrelative) then xrelative := bool in
205208
begin match ffi with
206-
| Js_var {name; external_module_name} ->
209+
| Js_var {name; external_module_name; scopes = _} ->
207210
upgrade (is_package_relative_path name);
208211
Ext_option.iter external_module_name (fun name ->
209212
upgrade (is_package_relative_path name.bundle));
210213
valid_global_name ?loc name
211-
| Js_send {name }
212-
| Js_set {js_set_name = name}
213-
| Js_get { js_get_name = name}
214+
| Js_send {name ; pipe = _; splice = _; js_send_scopes = _}
215+
| Js_set {js_set_name = name; js_set_scopes = _}
216+
| Js_get { js_get_name = name; js_get_scopes = _}
214217
-> valid_method_name ?loc name
215218
| Js_get_index _ (* TODO: check scopes *)
216219
| Js_set_index _
@@ -222,7 +225,7 @@ let check_ffi ?loc ffi : bool =
222225
->
223226
upgrade (is_package_relative_path external_module_name.bundle);
224227
check_external_module_name external_module_name
225-
| Js_new {external_module_name ; name}
228+
| Js_new {external_module_name ; name; scopes = _}
226229
| Js_call {external_module_name ; name ; splice = _; scopes = _ }
227230
->
228231
Ext_option.iter external_module_name (fun external_module_name ->
@@ -268,7 +271,7 @@ let () = Oprint.map_primitive_name :=
268271
if is_bs_primitive s then "BS:external"
269272
else s )
270273
#else
271-
(fun s -> String.escaped s) (* For debugging*)
274+
String.escaped
272275
#end
273276

274277
(* TODO: better error message when version mismatch *)
@@ -277,7 +280,36 @@ let from_string s : t =
277280
Ext_marshal.from_string_uncheck s
278281
else Ffi_normal
279282

280-
283+
let () =
284+
Primitive.coerce :=
285+
(fun
286+
({prim_name; prim_arity; prim_native_name;
287+
prim_alloc = _;
288+
prim_native_repr_args = _;
289+
prim_native_repr_res = _} : Primitive.description)
290+
(p2 : Primitive.description) ->
291+
let p2_native = p2.prim_native_name in
292+
prim_name = p2.prim_name &&
293+
prim_arity = p2.prim_arity &&
294+
prim_native_name = p2_native || (
295+
match from_string prim_native_name, from_string p2_native with
296+
| Ffi_obj_create obj_parms, Ffi_obj_create obj_parms2 ->
297+
Ext_list.for_all2_no_exn obj_parms obj_parms2 (fun {obj_arg_type; obj_arg_label} b ->
298+
let b_obj_arg_label = b.obj_arg_label in
299+
obj_arg_type = b.obj_arg_type &&
300+
(obj_arg_label = b_obj_arg_label ||
301+
match obj_arg_label, b_obj_arg_label with
302+
| Obj_optional {name; for_sure_no_nested_option}, Obj_optional p
303+
->
304+
name = p.name &&
305+
((Obj.magic for_sure_no_nested_option : int) <= (Obj.magic p.for_sure_no_nested_option))
306+
| _ -> false
307+
)
308+
)
309+
| Ffi_bs _, Ffi_bs _ -> false
310+
| _ -> false
311+
)
312+
)
281313
let inline_string_primitive (s : string) (op : string option) : string list =
282314
let lam : Lam_constant.t =
283315
match op with

0 commit comments

Comments
 (0)