Skip to content

Commit

Permalink
check predef exception in the begininng
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbo Zhang committed Aug 8, 2016
1 parent 6b59211 commit 2ac578c
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
9 changes: 7 additions & 2 deletions jscomp/lam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type primitive =
(* Globals *)
| Pgetglobal of ident
| Psetglobal of ident
| Pglobal_exception of ident
(* Operations on heap blocks *)
| Pmakeblock of int * tag_info * mutable_flag
| Pfield of int * field_dbg_info
Expand Down Expand Up @@ -553,7 +554,11 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args : t =
| _ -> assert false
end
| Ploc loc -> assert false (* already compiled away here*)
| Pgetglobal id -> prim ~primitive:(Pgetglobal id) ~args
| Pgetglobal id ->
if Ident.is_predef_exn id then
prim ~primitive:(Pglobal_exception id) ~args
else
prim ~primitive:(Pgetglobal id) ~args
| Psetglobal id -> prim ~primitive:(Psetglobal id) ~args
| Pmakeblock (tag,info, mutable_flag)
-> prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args
Expand Down Expand Up @@ -592,7 +597,7 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args : t =
begin match args with
| [Lprim {primitive = Pmakeblock (0, _, _) ;
args = [
Lprim {primitive = Pgetglobal ({name = "Assert_failure"} as id); args = []};
Lprim {primitive = Pglobal_exception ({name = "Assert_failure"} as id); args = []};
_
]
} ] when Ident.global id
Expand Down
1 change: 1 addition & 0 deletions jscomp/lam.mli
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type primitive =
| Pbytes_of_string
| Pgetglobal of ident
| Psetglobal of ident
| Pglobal_exception of ident
| Pmakeblock of int * Lambda.tag_info * Asttypes.mutable_flag
| Pfield of int * Lambda.field_dbg_info
| Psetfield of int * bool * Lambda.set_field_dbg_info
Expand Down
5 changes: 3 additions & 2 deletions jscomp/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ let rec no_side_effects (lam : Lam.t) : bool =



| Pgetglobal _
| Pgetglobal _
| Pglobal_exception _
| Pmakeblock _ (* whether it's mutable or not *)
| Pfield _
| Pfloatfield _
Expand Down Expand Up @@ -188,7 +189,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
args = [Lconst _]; _},exn,
Lifthenelse(Lprim{args =
[Lvar exn1;
Lprim {primitive = Pgetglobal ({name="Not_found"}); args = []; _}]
Lprim {primitive = Pglobal_exception ({name="Not_found"}); args = []; _}]
; _},
then_, _)) when Ident.same exn1 exn
(** we might put this in an optimization pass
Expand Down
4 changes: 2 additions & 2 deletions jscomp/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ and
Lifthenelse
(Lprim{primitive = Pintcomp(Ceq);
args = [Lvar id2 ;
Lprim{primitive = Pgetglobal {name = "Not_found"}; _}]},
Lprim{primitive = Pglobal_exception {name = "Not_found"}; _}]},
cont, _reraise )
)
| Ltrywith(
Expand All @@ -1473,7 +1473,7 @@ and
id,
Lifthenelse(Lprim{primitive = Pintcomp(Ceq);
args = [
Lprim { primitive = Pgetglobal {name = "Not_found"; _}; _}; Lvar id2 ]},
Lprim { primitive = Pglobal_exception {name = "Not_found"; _}; _}; Lvar id2 ]},
cont, _reraise )
)) when Ident.same id id2
->
Expand Down
5 changes: 1 addition & 4 deletions jscomp/lam_compile_global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ let query_lambda id env =
let get_exp (key : Lam_compile_env.key) : J.expression =
match key with
(id, env, expand) ->
if Ident.is_predef_exn id
then Js_of_lam_exception.get_builtin_by_name id.name
else
Lam_compile_env.query_and_add_if_not_exist
Lam_compile_env.query_and_add_if_not_exist
(Lam_module_ident.of_ml id)
(Has_env env)
~not_found:(fun id -> assert false)
Expand Down
2 changes: 2 additions & 0 deletions jscomp/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ let translate
| Pjs_fn_runmethod _
-> assert false (* already handled by {!Lam_compile} *)
| Pjs_fn_method _ -> assert false
| Pglobal_exception id ->
Js_of_lam_exception.get_builtin_by_name id.name
| Pstringadd ->
begin match args with
| [a;b] ->
Expand Down
5 changes: 1 addition & 4 deletions jscomp/lam_pass_collect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ let collect_helper (meta : Lam_stats.meta) (lam : Lam.t) =

and collect (lam : Lam.t) =
match lam with
(* | Lprim (Pgetglobal ident,[]) *)
(* -> *)
(* if not @@ Ident.is_predef_exn ident then *)
(* Lam_util.add_required_module ident meta *)

(** TODO:
how about module aliases..
record dependency
Expand Down
2 changes: 2 additions & 0 deletions jscomp/lam_print.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ let primitive ppf (prim : Lam.primitive) = match prim with
| Pjs_fn_runmethod i -> fprintf ppf "js_fn_runmethod_%i" i
| Pdebugger -> fprintf ppf "debugger"
| Pgetglobal id -> fprintf ppf "global %a" Ident.print id
| Pglobal_exception id ->
fprintf ppf "global exception %a" Ident.print id
| Psetglobal id -> fprintf ppf "setglobal %a" Ident.print id
| Pmakeblock(tag, _, Immutable) -> fprintf ppf "makeblock %i" tag
| Pmakeblock(tag, _, Mutable) -> fprintf ppf "makemutable %i" tag
Expand Down
10 changes: 3 additions & 7 deletions jscomp/lam_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,12 @@ let sort_dag_args param_args =


let add_required_module (x : Ident.t) (meta : Lam_stats.meta) =
if not @@ Ident.is_predef_exn x then
meta.required_modules <- Lam_module_ident.of_ml x :: meta.required_modules
meta.required_modules <- Lam_module_ident.of_ml x :: meta.required_modules

let add_required_modules ( x : Ident.t list) (meta : Lam_stats.meta) =
let required_modules =
Ext_list.filter_map
(fun x ->
if Ident.is_predef_exn x then
None
else Some ( Lam_module_ident.of_ml x)) x
List.map
(fun x -> Lam_module_ident.of_ml x) x
@ meta.required_modules in
meta.required_modules <- required_modules

Expand Down

0 comments on commit 2ac578c

Please sign in to comment.