Skip to content

Commit 85dba3d

Browse files
authored
Merge pull request #449 from bloomberg/no_assert
-bs-rest-files option
2 parents 199041a + c2cacd7 commit 85dba3d

28 files changed

+23690
-21844
lines changed

jscomp/bin/compiler.ml

Lines changed: 22349 additions & 21231 deletions
Large diffs are not rendered by default.

jscomp/bin/ocaml_pack.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(** Bundled by ocaml_pack 05/23-09:55 *)
1+
(** Bundled by ocaml_pack 06/20-16:36 *)
22
module Ext_bytes : sig
33
#1 "ext_bytes.mli"
44
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -446,7 +446,7 @@ val with_file_as_pp : string -> (Format.formatter -> 'a) -> 'a
446446

447447
val is_pos_pow : Int32.t -> int
448448

449-
val failwithf : ('a, unit, string, 'b) format4 -> 'a
449+
val failwithf : loc:string -> ('a, unit, string, 'b) format4 -> 'a
450450

451451
val invalid_argf : ('a, unit, string, 'b) format4 -> 'a
452452

@@ -517,8 +517,9 @@ let is_pos_pow n =
517517
else raise M.E in
518518
try aux 0 n with M.E -> -1
519519

520-
let failwithf fmt = Format.ksprintf failwith fmt
521-
520+
let failwithf ~loc fmt = Format.ksprintf (fun s -> failwith (loc ^ s))
521+
fmt
522+
522523
let invalid_argf fmt = Format.ksprintf invalid_arg fmt
523524

524525
let bad_argf fmt = Format.ksprintf (fun x -> raise (Arg.Bad x ) ) fmt
@@ -612,7 +613,7 @@ let rec process_line cwd filedir line =
612613
(ml_exists, ml) @> (mli_exists , mli) @> []
613614

614615
| _
615-
-> Ext_pervasives.failwithf "invalid line %s" line
616+
-> Ext_pervasives.failwithf ~loc:__LOC__ "invalid line %s" line
616617
end
617618

618619
(* example

jscomp/common/js_config.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,5 @@ let get_debug_file () = !debug_file
257257

258258
let is_same_file () =
259259
!debug_file <> "" && !debug_file = !current_file
260+
261+
let tool_name = "BuckleScript"

jscomp/common/js_config.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@ val set_debug_file : string -> unit
100100
val get_debug_file : unit -> string
101101

102102
val is_same_file : unit -> bool
103+
104+
val tool_name : string

jscomp/core.mllib

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ idents_analysis
66
config_util
77

88

9+
ocaml_options
10+
ocaml_batch_compile
11+
ocaml_parse
912

1013
lam
1114
lam_iter

jscomp/ext/ext_list.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,24 @@ let reduce_from_right fn lst =
306306
| _ -> invalid_arg "Ext_list.reduce"
307307
end
308308

309+
type 'a t = 'a list ref
309310

311+
let create_ref_empty () = ref []
312+
313+
let ref_top x =
314+
match !x with
315+
| y::_ -> y
316+
| _ -> invalid_arg "Ext_list.ref_top"
317+
318+
let ref_empty x =
319+
match !x with [] -> true | _ -> false
320+
321+
let ref_push x refs =
322+
refs := x :: !refs
323+
324+
let ref_pop refs =
325+
match !refs with
326+
| [] -> invalid_arg "Ext_list.ref_pop"
327+
| x::rest ->
328+
refs := rest ;
329+
x

jscomp/ext/ext_list.mli

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,18 @@ val find_opt : ('a -> 'b option) -> 'a list -> 'b option
9191
(** [f] is applied follow the list order *)
9292
val split_map : ('a -> 'b * 'c) -> 'a list -> 'b list * 'c list
9393

94+
9495
val reduce_from_right : ('a -> 'a -> 'a) -> 'a list -> 'a
96+
97+
98+
type 'a t = 'a list ref
99+
100+
val create_ref_empty : unit -> 'a t
101+
102+
val ref_top : 'a t -> 'a
103+
104+
val ref_empty : 'a t -> bool
105+
106+
val ref_push : 'a -> 'a t -> unit
107+
108+
val ref_pop : 'a t -> 'a

jscomp/ext/hash_set.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ val mem : 'a hashset -> 'a -> bool
4848
val iter : ('a -> unit) -> 'a hashset -> unit
4949

5050
val elements : 'a hashset -> 'a list
51+
52+
val length : 'a hashset -> int

jscomp/js_implementation.ml

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,16 @@ open Compenv
2020

2121
let fprintf = Format.fprintf
2222

23-
let tool_name = "BuckleScript"
23+
2424

2525
let print_if ppf flag printer arg =
2626
if !flag then fprintf ppf "%a@." printer arg;
2727
arg
2828

29-
let interface ppf sourcefile outputprefix =
30-
Compmisc.init_path false;
29+
let after_parsing_sig ppf sourcefile outputprefix ast =
3130
let modulename = module_of_filename ppf sourcefile outputprefix in
32-
Env.set_unit_name modulename;
3331
let initial_env = Compmisc.initial_env () in
34-
let ast = Pparse.parse_interface ~tool_name ppf sourcefile in
35-
let ast = if !Js_config.no_builtin_ppx_mli then ast else !Ppx_entry.rewrite_signature ast in
36-
if !Clflags.dump_parsetree then fprintf ppf "%a@." Printast.interface ast;
37-
if !Clflags.dump_source then fprintf ppf "%a@." Pprintast.signature ast;
32+
Env.set_unit_name modulename;
3833
let tsg = Typemod.type_interface initial_env ast in
3934
if !Clflags.dump_typedtree then fprintf ppf "%a@." Printtyped.interface tsg;
4035
let sg = tsg.sig_type in
@@ -51,20 +46,23 @@ let interface ppf sourcefile outputprefix =
5146
initial_env sg ;
5247
end
5348

54-
let implementation ppf sourcefile outputprefix =
49+
let interface ppf sourcefile outputprefix =
5550
Compmisc.init_path false;
51+
Ocaml_parse.parse_interface ppf sourcefile
52+
|> print_if ppf Clflags.dump_parsetree Printast.interface
53+
|> print_if ppf Clflags.dump_source Pprintast.signature
54+
|> after_parsing_sig ppf sourcefile outputprefix
55+
56+
let after_parsing_impl ppf sourcefile outputprefix ast =
5657
let modulename = Compenv.module_of_filename ppf sourcefile outputprefix in
57-
Env.set_unit_name modulename;
5858
let env = Compmisc.initial_env() in
59+
Env.set_unit_name modulename;
5960
try
6061
let (typedtree, coercion, finalenv, current_signature) =
61-
Pparse.parse_implementation ~tool_name ppf sourcefile
62-
|> print_if ppf Clflags.dump_parsetree Printast.implementation
63-
|> (fun x -> if !Js_config.no_builtin_ppx_ml then x else !Ppx_entry.rewrite_implementation x )
64-
|> print_if ppf Clflags.dump_source Pprintast.structure
62+
ast
6563
|> Typemod.type_implementation_more sourcefile outputprefix modulename env
6664
|> print_if ppf Clflags.dump_typedtree
67-
(fun fmt (ty,co,_,_) -> Printtyped.implementation_with_coercion fmt (ty,co))
65+
(fun fmt (ty,co,_,_) -> Printtyped.implementation_with_coercion fmt (ty,co))
6866
in
6967
if !Clflags.print_types then begin
7068
Warnings.check_fatal ();
@@ -74,9 +72,9 @@ let implementation ppf sourcefile outputprefix =
7472
|> print_if ppf Clflags.dump_rawlambda Printlambda.lambda
7573
|> (fun lambda ->
7674
match
77-
Lam_compile_group.lambda_as_module
78-
finalenv current_signature
79-
sourcefile outputprefix ((* Obj.magic *) lambda ) with
75+
Lam_compile_group.lambda_as_module
76+
finalenv current_signature
77+
sourcefile outputprefix lambda with
8078
| e -> e
8179
| exception e ->
8280
(* Save to a file instead so that it will not scare user *)
@@ -94,3 +92,10 @@ let implementation ppf sourcefile outputprefix =
9492
with x ->
9593
Stypes.dump (Some (outputprefix ^ ".annot"));
9694
raise x
95+
96+
let implementation ppf sourcefile outputprefix =
97+
Compmisc.init_path false;
98+
Ocaml_parse.parse_implementation ppf sourcefile
99+
|> print_if ppf Clflags.dump_parsetree Printast.implementation
100+
|> print_if ppf Clflags.dump_source Pprintast.structure
101+
|> after_parsing_impl ppf sourcefile outputprefix

jscomp/js_implementation.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
*)
3838
val interface : Format.formatter -> string -> string -> unit
3939

40+
val after_parsing_sig : Format.formatter -> string -> string -> Parsetree.signature -> unit
4041

4142
val implementation : Format.formatter -> string -> string -> unit
4243
(** [implementation ppf sourcefile outprefix] compiles to JS directly *)
44+
45+
val after_parsing_impl : Format.formatter -> string -> string -> Parsetree.structure -> unit

0 commit comments

Comments
 (0)