Skip to content

Commit 75bf0fb

Browse files
authored
Merge pull request rescript-lang#5053 from rescript-lang/add_one_more_test
clean up; fix rescript-lang#5050
2 parents ce218cf + f270569 commit 75bf0fb

Some content is hidden

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

75 files changed

+1047
-2830
lines changed

jscomp/frontend/bs_builtin_ppx.ml

+37-31
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,20 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
115115
| Pexp_apply (fn, args ) ->
116116
Ast_exp_apply.app_exp_mapper e self fn args
117117
| Pexp_object {pcstr_self; pcstr_fields} ->
118-
(match Ast_attributes.process_bs e.pexp_attributes with
119-
| true, pexp_attributes
120-
->
121-
{e with
122-
pexp_desc =
123-
Ast_util.ocaml_obj_as_js_object
124-
e.pexp_loc self pcstr_self pcstr_fields;
125-
pexp_attributes
126-
}
127-
| false , _ ->
128-
default_expr_mapper self e)
118+
let pexp_attributes =
119+
match Ast_attributes.process_bs e.pexp_attributes with
120+
| true, pexp_attributes
121+
->
122+
Location.prerr_warning e.pexp_loc (Bs_ffi_warning "Here @bs attribute not needed any more");
123+
pexp_attributes
124+
| false, e -> e in
125+
{e with
126+
pexp_desc =
127+
Ast_util.ocaml_obj_as_js_object
128+
e.pexp_loc self pcstr_self pcstr_fields;
129+
pexp_attributes
130+
}
131+
129132
| Pexp_match(b,
130133
[
131134
{pc_lhs= {ppat_desc = Ppat_construct ({txt = Lident "true"},None)};pc_guard=None;pc_rhs=t_exp};
@@ -171,26 +174,29 @@ let typ_mapper (self : mapper) (typ : Parsetree.core_type) =
171174
Ast_core_type_class_type.typ_mapper self typ
172175

173176
let class_type_mapper (self : mapper) ({pcty_attributes; pcty_loc} as ctd : Parsetree.class_type) =
174-
match Ast_attributes.process_bs pcty_attributes with
175-
| false, _ ->
176-
default_mapper.class_type self ctd
177-
| true, pcty_attributes ->
178-
(match ctd.pcty_desc with
179-
| Pcty_signature ({pcsig_self; pcsig_fields })
180-
->
181-
let pcsig_self = self.typ self pcsig_self in
182-
{ctd with
183-
pcty_desc = Pcty_signature {
184-
pcsig_self ;
185-
pcsig_fields = Ast_core_type_class_type.handle_class_type_fields self pcsig_fields
186-
};
187-
pcty_attributes
188-
}
189-
| Pcty_open _ (* let open M in CT *)
190-
| Pcty_constr _
191-
| Pcty_extension _
192-
| Pcty_arrow _ ->
193-
Location.raise_errorf ~loc:pcty_loc "invalid or unused attribute `bs`")
177+
let pcty_attributes =
178+
match Ast_attributes.process_bs pcty_attributes with
179+
| false, _ ->
180+
pcty_attributes
181+
| true, pcty_attributes ->
182+
Location.prerr_warning pcty_loc (Bs_ffi_warning "Here @bs attribute is not needed any more.");
183+
pcty_attributes in
184+
(match ctd.pcty_desc with
185+
| Pcty_signature ({pcsig_self; pcsig_fields })
186+
->
187+
let pcsig_self = self.typ self pcsig_self in
188+
{ctd with
189+
pcty_desc = Pcty_signature {
190+
pcsig_self ;
191+
pcsig_fields = Ast_core_type_class_type.handle_class_type_fields self pcsig_fields
192+
};
193+
pcty_attributes
194+
}
195+
| Pcty_open _ (* let open M in CT *)
196+
| Pcty_constr _
197+
| Pcty_extension _
198+
| Pcty_arrow _ ->
199+
default_mapper.class_type self ctd)
194200
(* {[class x : int -> object
195201
end [@bs]
196202
]}

jscomp/main/builtin_cmi_datasets.ml

+3-3
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* f41d749a6102f58618a170a9c386c77a *)
1+
(* 73944a82990d2855f017f11f495934c8 *)
22
let module_names : string array = Obj.magic (
33
"Js" (* 23 *),
44
"Arg" (* 217 *),
@@ -55,7 +55,7 @@ let module_names : string array = Obj.magic (
5555
"Js_array" (* 23 *),
5656
"Js_float" (* 23 *),
5757
"Js_types" (* 53 *),
58-
"Printexc" (* 525 *),
58+
"Printexc" (* 94 *),
5959
"Std_exit" (* 23 *),
6060
"Belt_List" (* 1571 *),
6161
"Js_array2" (* 23 *),
@@ -184,7 +184,7 @@ let module_data : string array = Obj.magic (
184184
(* Js_array *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
185185
(* Js_float *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
186186
(* Js_types *)"\132\149\166\190\000\000\000!\000\000\000\012\000\000\000%\000\000\000#\160\160\176$test\144\160\160B@@@\176(classify\144\160\160A@@@A",
187-
(* Printexc *)"\132\149\166\190\000\000\001\249\000\000\000h\000\000\001\127\000\000\001V\160\b\000\000L\000\176$Slot\145\192\160\160A@@\160\160A@@\160\160A@@\160\160B@@@\176%catch\144\160\160B@@@\176%print\144\160\160B@@@\176)to_string\144\160\160A@@@\176-get_backtrace\144\160\160A@@@\176-get_callstack\144\160\160A@@@\176/backtrace_slots\144\160\160A@@@\176/print_backtrace\144\160\160A@@@\1760backtrace_status\144\160\160A@@@\1760record_backtrace\144\160\160A@@@\1760register_printer\144\160\160A@@@\1761get_raw_backtrace\144\160\160A@@@\1763print_raw_backtrace\144\160\160B@@@\1764raw_backtrace_length\144\160\160A@@@\1766get_raw_backtrace_slot\144\160\160B@@@\1767raw_backtrace_to_string\144\160\160A@@@\176:convert_raw_backtrace_slot\144\160\160A@A@\176;get_raw_backtrace_next_slot\144\160\160A@@@\176>set_uncaught_exception_handler\144\160\160A@@@A",
187+
(* Printexc *)"\132\149\166\190\000\000\000J\000\000\000\022\000\000\000H\000\000\000C\160\192\176%catch\144\160\160B@@@\176%print\144\160\160B@@@\176)to_string\144\160\160A@@@\1760register_printer\144\160\160A@@@A",
188188
(* Std_exit *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128@",
189189
(* Belt_List *)"\132\149\166\190\000\000\006\015\000\000\001\203\000\000\005\236\000\000\005\138\160\b\000\001`\000\176\"eq\144\160\160C@@@\176#add\144\160\160B@@\144\148\192B\160\176\001\003\251\"xs@\160\176\001\003\252!x@@\151\176\176@\165\"::A@\160\144\004\t\160\144\004\014@\176\1923others/belt_List.ml\000l\001\011y\001\011\137\192\004\002\000l\001\011y\001\011\144@\160BA\176#cmp\144\160\160C@@@\176#eqU\144\160\160C@@@\176#get\144\160\160B@@@\176#has\144\160\160C@@@\176#map\144\160\160B@@@\176#zip\144\160\160B@@@\176$cmpU\144\160\160C@@@\176$drop\144\160\160B@@@\176$hasU\144\160\160C@@@\176$head\144\160\160A@@@\176$keep\144\160\160B@@@\176$make\144\160\160B@@@\176$mapU\144\160\160B@@@\176$size\144\160\160A@@@\176$some\144\160\160B@@@\176$sort\144\160\160B@@@\176$tail\144\160\160A@@@\176$take\144\160\160B@@@\176%every\144\160\160B@@@\176%getBy\144\160\160B@@@\176%keepU\144\160\160B@@@\176%some2\144\160\160C@@@\176%someU\144\160\160B@@@\176%sortU\144\160\160B@@@\176%unzip\144\160\160A@@@\176%zipBy\144\160\160C@@@\176&concat\144\160\160B@@@\176&every2\144\160\160C@@@\176&everyU\144\160\160B@@@\176&filter\144\004_@\176&getByU\144\160\160B@@@\176&getExn\144\160\160B@@@\176&length\144\004]@\176&makeBy\144\160\160B@@@\176&reduce\144\160\160C@@@\176&some2U\144\160\160C@@@\176&zipByU\144\160\160C@@@\176'every2U\144\160\160C@@@\176'flatten\144\160\160A@@@\176'forEach\144\160\160B@@@\176'headExn\144\160\160A@@@\176'keepMap\144\160\160B@@@\176'makeByU\144\160\160B@@@\176'reduce2\144\160\160D@@@\176'reduceU\144\160\160C@@@\176'reverse\144\160\160A@@@\176'shuffle\144\160\160A@@@\176'splitAt\144\160\160B@@@\176'tailExn\144\160\160A@@@\176'toArray\144\160\160A@@@\176(forEach2\144\160\160C@@@\176(forEachU\144\160\160B@@@\176(getAssoc\144\160\160C@@@\176(hasAssoc\144\160\160C@@@\176(keepMapU\144\160\160B@@@\176(reduce2U\144\160\160D@@@\176(setAssoc\144\160\160D@@@\176)forEach2U\144\160\160C@@@\176)fromArray\144\160\160A@@@\176)getAssocU\144\160\160C@@@\176)hasAssocU\144\160\160C@@@\176)partition\144\160\160B@@@\176)setAssocU\144\160\160D@@@\176*concatMany\144\160\160A@@@\176*mapReverse\144\160\160B@@@\176*partitionU\144\160\160B@@@\176+cmpByLength\144\160\160B@@@\176+mapReverse2\144\160\160C@@@\176+mapReverseU\144\160\160B@@@\176+removeAssoc\144\160\160C@@@\176,mapReverse2U\144\160\160C@@@\176,mapWithIndex\144\160\160B@@@\176,removeAssocU\144\160\160C@@@\176-keepWithIndex\144\160\160B@@@\176-mapWithIndexU\144\160\160B@@@\176-reduceReverse\144\160\160C@@@\176-reverseConcat\144\160\160B@@@\176.keepWithIndexU\144\160\160B@@@\176.reduceReverse2\144\160\160D@@@\176.reduceReverseU\144\160\160C@@@\176/filterWithIndex\144\004#@\176/reduceReverse2U\144\160\160D@@@\176/reduceWithIndex\144\160\160C@@@\1760forEachWithIndex\144\160\160B@@@\1760reduceWithIndexU\144\160\160C@@@\1761forEachWithIndexU\144\160\160B@@@A",
190190
(* Js_array2 *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",

jscomp/stdlib-406/filename.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ let prng = lazy(Random.State.make_self_init ())
232232

233233
let temp_file_name temp_dir prefix suffix =
234234
let rnd = (Random.State.bits (Lazy.force prng)) land 0xFFFFFF in
235-
concat temp_dir (Printf.sprintf "%s%06x%s" prefix rnd suffix)
235+
concat temp_dir {j|$(prefix)$(rnd)$(suffix)|j}
236236

237237

238238
let current_temp_dir_name = ref temp_dir_name

jscomp/stdlib-406/printexc.ml

+8-242
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
(* *)
1414
(**************************************************************************)
1515
[@@@bs.config { flags = [|"-bs-no-cross-module-opt" |]}]
16-
open Printf
16+
1717

1818
let printers = ref []
1919

20-
let locfmt = format_of_string "File \"%s\", line %d, characters %d-%d: %s"
20+
let locfmt s (linum : int) (start : int) (finish : int) msg =
21+
{j|File "$(s)", line $(linum), characters $(start)-$(finish): $(msg)|j}
2122

2223

2324
let fields : exn -> string = [%raw{|function(x){
@@ -51,11 +52,11 @@ let to_string x =
5152
| Out_of_memory -> "Out of memory"
5253
| Stack_overflow -> "Stack overflow"
5354
| Match_failure(file, line, char) ->
54-
sprintf locfmt file line char (char+5) "Pattern matching failed"
55+
locfmt file line char (char+5) "Pattern matching failed"
5556
| Assert_failure(file, line, char) ->
56-
sprintf locfmt file line char (char+6) "Assertion failed"
57+
locfmt file line char (char+6) "Assertion failed"
5758
| Undefined_recursive_module(file, line, char) ->
58-
sprintf locfmt file line char (char+6) "Undefined recursive module"
59+
locfmt file line char (char+6) "Undefined recursive module"
5960
| _ ->
6061
let constructor =
6162
exn_slot_name x in
@@ -66,251 +67,16 @@ let print fct arg =
6667
try
6768
fct arg
6869
with x ->
69-
eprintf "Uncaught exception: %s\n" (to_string x);
70-
flush stderr;
70+
Js.log ("Uncaught exception: " ^ to_string x);
7171
raise x
7272

7373
let catch fct arg =
7474
try
7575
fct arg
7676
with x ->
7777
flush stdout;
78-
eprintf "Uncaught exception: %s\n" (to_string x);
78+
Js.log ("Uncaught exception: " ^ to_string x);
7979
exit 2
8080

81-
type raw_backtrace_slot
82-
type raw_backtrace
83-
84-
external get_raw_backtrace:
85-
unit -> raw_backtrace = "caml_get_exception_raw_backtrace"
86-
87-
external raise_with_backtrace: exn -> raw_backtrace -> 'a
88-
= "%raise_with_backtrace"
89-
90-
type backtrace_slot =
91-
| Known_location of {
92-
is_raise : bool;
93-
filename : string;
94-
line_number : int;
95-
start_char : int;
96-
end_char : int;
97-
is_inline : bool;
98-
}
99-
| Unknown_location of {
100-
is_raise : bool
101-
}
102-
103-
(* to avoid warning *)
104-
let _ = [Known_location { is_raise = false; filename = "";
105-
line_number = 0; start_char = 0; end_char = 0;
106-
is_inline = false };
107-
Unknown_location { is_raise = false }]
108-
109-
#if BS
110-
let convert_raw_backtrace_slot:
111-
raw_backtrace_slot -> backtrace_slot =
112-
fun _ -> failwith "convert_raw_backtrace_slot not implemented"
113-
#else
114-
external convert_raw_backtrace_slot:
115-
raw_backtrace_slot -> backtrace_slot = "caml_convert_raw_backtrace_slot"
116-
#end
117-
external convert_raw_backtrace:
118-
raw_backtrace -> backtrace_slot array = "caml_convert_raw_backtrace"
119-
120-
let convert_raw_backtrace bt =
121-
try Some (convert_raw_backtrace bt)
122-
with Failure _ -> None
123-
124-
let format_backtrace_slot pos slot =
125-
let info is_raise =
126-
if is_raise then
127-
if pos = 0 then "Raised at" else "Re-raised at"
128-
else
129-
if pos = 0 then "Raised by primitive operation at" else "Called from"
130-
in
131-
match slot with
132-
| Unknown_location l ->
133-
if l.is_raise then
134-
(* compiler-inserted re-raise, skipped *) None
135-
else
136-
Some (sprintf "%s unknown location" (info false))
137-
| Known_location l ->
138-
Some (sprintf "%s file \"%s\"%s, line %d, characters %d-%d"
139-
(info l.is_raise) l.filename
140-
(if l.is_inline then " (inlined)" else "")
141-
l.line_number l.start_char l.end_char)
142-
143-
let print_exception_backtrace outchan backtrace =
144-
match backtrace with
145-
| None ->
146-
fprintf outchan
147-
"(Program not linked with -g, cannot print stack backtrace)\n"
148-
| Some a ->
149-
for i = 0 to Array.length a - 1 do
150-
match format_backtrace_slot i a.(i) with
151-
| None -> ()
152-
| Some str -> fprintf outchan "%s\n" str
153-
done
154-
155-
let print_raw_backtrace outchan raw_backtrace =
156-
print_exception_backtrace outchan (convert_raw_backtrace raw_backtrace)
157-
158-
(* confusingly named: prints the global current backtrace *)
159-
let print_backtrace outchan =
160-
print_raw_backtrace outchan (get_raw_backtrace ())
161-
162-
let backtrace_to_string backtrace =
163-
match backtrace with
164-
| None ->
165-
"(Program not linked with -g, cannot print stack backtrace)\n"
166-
| Some a ->
167-
let b = Buffer.create 1024 in
168-
for i = 0 to Array.length a - 1 do
169-
match format_backtrace_slot i a.(i) with
170-
| None -> ()
171-
| Some str -> bprintf b "%s\n" str
172-
done;
173-
Buffer.contents b
174-
175-
let raw_backtrace_to_string raw_backtrace =
176-
backtrace_to_string (convert_raw_backtrace raw_backtrace)
177-
178-
let backtrace_slot_is_raise = function
179-
| Known_location l -> l.is_raise
180-
| Unknown_location l -> l.is_raise
181-
182-
let backtrace_slot_is_inline = function
183-
| Known_location l -> l.is_inline
184-
| Unknown_location _ -> false
185-
186-
type location = {
187-
filename : string;
188-
line_number : int;
189-
start_char : int;
190-
end_char : int;
191-
}
192-
193-
let backtrace_slot_location = function
194-
| Unknown_location _ -> None
195-
| Known_location l ->
196-
Some {
197-
filename = l.filename;
198-
line_number = l.line_number;
199-
start_char = l.start_char;
200-
end_char = l.end_char;
201-
}
202-
203-
let backtrace_slots raw_backtrace =
204-
(* The documentation of this function guarantees that Some is
205-
returned only if a part of the trace is usable. This gives us
206-
a bit more work than just convert_raw_backtrace, but it makes the
207-
API more user-friendly -- otherwise most users would have to
208-
reimplement the "Program not linked with -g, sorry" logic
209-
themselves. *)
210-
match convert_raw_backtrace raw_backtrace with
211-
| None -> None
212-
| Some backtrace ->
213-
let usable_slot = function
214-
| Unknown_location _ -> false
215-
| Known_location _ -> true in
216-
let rec exists_usable = function
217-
| (-1) -> false
218-
| i -> usable_slot backtrace.(i) || exists_usable (i - 1) in
219-
if exists_usable (Array.length backtrace - 1)
220-
then Some backtrace
221-
else None
222-
223-
module Slot = struct
224-
type t = backtrace_slot
225-
let format = format_backtrace_slot
226-
let is_raise = backtrace_slot_is_raise
227-
let is_inline = backtrace_slot_is_inline
228-
let location = backtrace_slot_location
229-
end
230-
231-
external raw_backtrace_length :
232-
raw_backtrace -> int = "caml_raw_backtrace_length" [@@noalloc]
233-
234-
external get_raw_backtrace_slot :
235-
raw_backtrace -> int -> raw_backtrace_slot = "caml_raw_backtrace_slot"
236-
237-
external get_raw_backtrace_next_slot :
238-
raw_backtrace_slot -> raw_backtrace_slot option
239-
= "caml_raw_backtrace_next_slot"
240-
241-
(* confusingly named:
242-
returns the *string* corresponding to the global current backtrace *)
243-
let get_backtrace () = raw_backtrace_to_string (get_raw_backtrace ())
244-
245-
external record_backtrace: bool -> unit = "caml_record_backtrace"
246-
external backtrace_status: unit -> bool = "caml_backtrace_status"
247-
24881
let register_printer fn =
24982
printers := fn :: !printers
250-
251-
external get_callstack: int -> raw_backtrace = "caml_get_current_callstack"
252-
253-
254-
#if BS
255-
let set_uncaught_exception_handler _ = ()
256-
#else
257-
let uncaught_exception_handler = ref None
258-
259-
let set_uncaught_exception_handler fn = uncaught_exception_handler := Some fn
260-
261-
let empty_backtrace : raw_backtrace = Obj.obj (Obj.new_block Obj.abstract_tag 0)
262-
263-
let try_get_raw_backtrace () =
264-
try
265-
get_raw_backtrace ()
266-
with _ (* Out_of_memory? *) ->
267-
empty_backtrace
268-
269-
let handle_uncaught_exception' exn debugger_in_use =
270-
try
271-
(* Get the backtrace now, in case one of the [at_exit] function
272-
destroys it. *)
273-
let raw_backtrace =
274-
if debugger_in_use (* Same test as in [byterun/printexc.c] *) then
275-
empty_backtrace
276-
else
277-
try_get_raw_backtrace ()
278-
in
279-
(try Pervasives.do_at_exit () with _ -> ());
280-
match !uncaught_exception_handler with
281-
| None ->
282-
eprintf "Fatal error: exception %s\n" (to_string exn);
283-
print_raw_backtrace stderr raw_backtrace;
284-
flush stderr
285-
| Some handler ->
286-
try
287-
handler exn raw_backtrace
288-
with exn' ->
289-
let raw_backtrace' = try_get_raw_backtrace () in
290-
eprintf "Fatal error: exception %s\n" (to_string exn);
291-
print_raw_backtrace stderr raw_backtrace;
292-
eprintf "Fatal error in uncaught exception handler: exception %s\n"
293-
(to_string exn');
294-
print_raw_backtrace stderr raw_backtrace';
295-
flush stderr
296-
with
297-
| Out_of_memory ->
298-
prerr_endline
299-
"Fatal error: out of memory in uncaught exception handler"
300-
301-
(* This function is called by [caml_fatal_uncaught_exception] in
302-
[byterun/printexc.c] which expects no exception is raised. *)
303-
let handle_uncaught_exception exn debugger_in_use =
304-
try
305-
handle_uncaught_exception' exn debugger_in_use
306-
with _ ->
307-
(* There is not much we can do at this point *)
308-
()
309-
310-
external register_named_value : string -> 'a -> unit
311-
= "caml_register_named_value"
312-
313-
let () =
314-
register_named_value "Printexc.handle_uncaught_exception"
315-
handle_uncaught_exception
316-
#end

0 commit comments

Comments
 (0)