Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jscomp/ext_pervasives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

(* Author: Hongbo Zhang *)


external reraise: exn -> 'a = "%reraise"

let finally v f action =
match f v with
| exception e ->
action v ;
raise e
reraise e
| e -> action v ; e

let with_file_as_chan filename f =
Expand Down
1 change: 1 addition & 0 deletions jscomp/ext_pervasives.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
(** Extension to standard library [Pervavives] module, safe to open
*)

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

val with_file_as_chan : string -> (out_channel -> 'a) -> 'a
Expand Down
15 changes: 13 additions & 2 deletions jscomp/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,20 @@ let implementation ppf sourcefile outputprefix =
|> Translmod.transl_implementation modulename
|> print_if ppf Clflags.dump_rawlambda Printlambda.lambda
|> (fun lambda ->
Lam_compile_group.lambda_as_module true
match
Lam_compile_group.lambda_as_module
finalenv current_signature
sourcefile lambda);
sourcefile lambda with
| e -> e
| exception e ->
(* Save to a file instead so that it will not scare user *)
let file = "osc.dump" in
Ext_pervasives.with_file_as_chan file
(fun ch -> output_string ch @@
Printexc.raw_backtrace_to_string (Printexc.get_raw_backtrace ()));
Ext_log.err __LOC__ "Compilation fatal error, stacktrace saved into %s" file ;
raise e
);
end;
Stypes.dump (Some (outputprefix ^ ".annot"));
with x ->
Expand Down
24 changes: 21 additions & 3 deletions jscomp/js_pass_flatten_and_mark_dead.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,16 @@ let mark_dead_code js =

Take away, it is really hard to change the code while collecting some information..
we should always collect info in a single pass

Note that, we should avoid reuse object, i.e,
{[
let v =
object
end
]}
Since user may use `osc -c xx.ml xy.ml xz.ml` and we need clean up state
*)
let subst_map = object (self)
let subst_map name = object (self)
inherit Js_map.map as super

val mutable substitution = Hashtbl.create 17
Expand Down Expand Up @@ -213,9 +221,19 @@ let subst_map = object (self)
begin match Hashtbl.find self#get_substitution id with
| {expression_desc = Array (ls, Immutable) }
->
(* user program can be wrong, we should not
turn a runtime crash into compile time crash : )
*)
begin match List.nth ls i with
| {expression_desc = J.Var _ | Number _ | Str _ } as x
-> x
| exception _ ->
begin
Ext_log.err __LOC__ "suspcious code %s when compiling %s@."
(Printf.sprintf "%s/%d" id.name id.stamp)
name ;
super#expression x ;
end
| _ ->
(** we can do here, however, we should
be careful that it can only be done
Expand Down Expand Up @@ -266,9 +284,9 @@ end
there is no need to add another pass
*)

let program js =
let program (js : J.program) =
js
|> subst_map#program
|> (subst_map js.name )#program
|> mark_dead_code
(* |> mark_dead_code *)
(* mark dead code twice does have effect in some cases, however, we disabled it
Expand Down
1 change: 0 additions & 1 deletion jscomp/lam_compile_group.ml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ let compile ~filename env sigs lam : J.program =
let current_file_name : string option ref = ref None;;

let lambda_as_module
(raw : bool)
env
(sigs : Types.signature)
(filename : string)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/lam_compile_group.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ val compile :
Lambda.lambda ->
J.program

val lambda_as_module : bool -> Env.t -> Types.signature -> string -> Lambda.lambda -> unit
val lambda_as_module : Env.t -> Types.signature -> string -> Lambda.lambda -> unit
2 changes: 1 addition & 1 deletion jscomp/lam_register.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
let () =
Printlambda.serialize_raw_js := Lam_compile_group.lambda_as_module true;
Printlambda.serialize_raw_js := Lam_compile_group.lambda_as_module;
;;
1 change: 1 addition & 0 deletions jscomp/lam_register.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(** *)