Skip to content

Commit d67be05

Browse files
author
Hongbo Zhang
committed
fix a compilation error
1 parent a1d6488 commit d67be05

File tree

8 files changed

+40
-10
lines changed

8 files changed

+40
-10
lines changed

jscomp/ext_pervasives.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919
(* Author: Hongbo Zhang *)
2020

21-
21+
external reraise: exn -> 'a = "%reraise"
2222

2323
let finally v f action =
2424
match f v with
2525
| exception e ->
2626
action v ;
27-
raise e
27+
reraise e
2828
| e -> action v ; e
2929

3030
let with_file_as_chan filename f =

jscomp/ext_pervasives.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
(** Extension to standard library [Pervavives] module, safe to open
2424
*)
2525

26+
external reraise: exn -> 'a = "%reraise"
2627
val finally : 'a -> ('a -> 'b) -> ('a -> 'c) -> 'b
2728

2829
val with_file_as_chan : string -> (out_channel -> 'a) -> 'a

jscomp/js_implementation.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,20 @@ let implementation ppf sourcefile outputprefix =
4949
|> Translmod.transl_implementation modulename
5050
|> print_if ppf Clflags.dump_rawlambda Printlambda.lambda
5151
|> (fun lambda ->
52-
Lam_compile_group.lambda_as_module true
52+
match
53+
Lam_compile_group.lambda_as_module
5354
finalenv current_signature
54-
sourcefile lambda);
55+
sourcefile lambda with
56+
| e -> e
57+
| exception e ->
58+
(* Save to a file instead so that it will not scare user *)
59+
let file = "osc.dump" in
60+
Ext_pervasives.with_file_as_chan file
61+
(fun ch -> output_string ch @@
62+
Printexc.raw_backtrace_to_string (Printexc.get_raw_backtrace ()));
63+
Ext_log.err __LOC__ "Compilation fatal error, stacktrace saved into %s" file ;
64+
raise e
65+
);
5566
end;
5667
Stypes.dump (Some (outputprefix ^ ".annot"));
5768
with x ->

jscomp/js_pass_flatten_and_mark_dead.ml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,16 @@ let mark_dead_code js =
143143
144144
Take away, it is really hard to change the code while collecting some information..
145145
we should always collect info in a single pass
146+
147+
Note that, we should avoid reuse object, i.e,
148+
{[
149+
let v =
150+
object
151+
end
152+
]}
153+
Since user may use `osc -c xx.ml xy.ml xz.ml` and we need clean up state
146154
*)
147-
let subst_map = object (self)
155+
let subst_map name = object (self)
148156
inherit Js_map.map as super
149157

150158
val mutable substitution = Hashtbl.create 17
@@ -213,9 +221,19 @@ let subst_map = object (self)
213221
begin match Hashtbl.find self#get_substitution id with
214222
| {expression_desc = Array (ls, Immutable) }
215223
->
224+
(* user program can be wrong, we should not
225+
turn a runtime crash into compile time crash : )
226+
*)
216227
begin match List.nth ls i with
217228
| {expression_desc = J.Var _ | Number _ | Str _ } as x
218229
-> x
230+
| exception _ ->
231+
begin
232+
Ext_log.err __LOC__ "suspcious code %s when compiling %s@."
233+
(Printf.sprintf "%s/%d" id.name id.stamp)
234+
name ;
235+
super#expression x ;
236+
end
219237
| _ ->
220238
(** we can do here, however, we should
221239
be careful that it can only be done
@@ -266,9 +284,9 @@ end
266284
there is no need to add another pass
267285
*)
268286

269-
let program js =
287+
let program (js : J.program) =
270288
js
271-
|> subst_map#program
289+
|> (subst_map js.name )#program
272290
|> mark_dead_code
273291
(* |> mark_dead_code *)
274292
(* mark dead code twice does have effect in some cases, however, we disabled it

jscomp/lam_compile_group.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ let compile ~filename env sigs lam : J.program =
297297
let current_file_name : string option ref = ref None;;
298298

299299
let lambda_as_module
300-
(raw : bool)
301300
env
302301
(sigs : Types.signature)
303302
(filename : string)

jscomp/lam_compile_group.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ val compile :
3535
Lambda.lambda ->
3636
J.program
3737

38-
val lambda_as_module : bool -> Env.t -> Types.signature -> string -> Lambda.lambda -> unit
38+
val lambda_as_module : Env.t -> Types.signature -> string -> Lambda.lambda -> unit

jscomp/lam_register.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
let () =
2-
Printlambda.serialize_raw_js := Lam_compile_group.lambda_as_module true;
2+
Printlambda.serialize_raw_js := Lam_compile_group.lambda_as_module;
33
;;

jscomp/lam_register.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(** *)

0 commit comments

Comments
 (0)