Skip to content

Commit 5aa9826

Browse files
committed
Merge pull request #430 from bloomberg/ppx_global_config
[refact] remove lam_current_unit and add a test case for format
2 parents eeb86db + 1055c05 commit 5aa9826

18 files changed

+134
-126
lines changed

jscomp/common/ext_log.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let iwarn b str f =
5555

5656
(* TODO: add {[@.]} later for all *)
5757
let dwarn str f =
58-
if Lam_current_unit.is_same_file () then
58+
if Js_config.is_same_file () then
5959
Format.fprintf Format.err_formatter ("WARN: %s " ^^ f ^^ "@.") str
6060
else
6161
Format.ifprintf Format.err_formatter ("WARN: %s " ^^ f ^^ "@.") str

jscomp/common/js_config.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,19 @@ let runtime_set =
241241
md5 ;
242242
weak ] |>
243243
List.fold_left (fun acc x -> String_set.add (String.uncapitalize x) acc ) String_set.empty
244+
245+
let current_file = ref ""
246+
let debug_file = ref ""
247+
248+
let set_current_file f = current_file := f
249+
let get_current_file () = !current_file
250+
let get_module_name () =
251+
Filename.chop_extension (String.uncapitalize !current_file)
252+
253+
let iset_debug_file _ = ()
254+
let set_debug_file f = debug_file := f
255+
let get_debug_file () = !debug_file
256+
257+
258+
let is_same_file () =
259+
!debug_file <> "" && !debug_file = !current_file

jscomp/common/js_config.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,15 @@ val md5 : string
8888
val hash : string
8989
val weak : string
9090
val js_primitive : string
91+
92+
93+
(** Debugging utilies *)
94+
val set_current_file : string -> unit
95+
val get_current_file : unit -> string
96+
val get_module_name : unit -> string
97+
98+
val iset_debug_file : string -> unit
99+
val set_debug_file : string -> unit
100+
val get_debug_file : unit -> string
101+
102+
val is_same_file : unit -> bool

jscomp/config_util.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ let find_cmj file =
5757
| exception _
5858
->
5959
Ext_log.warn __LOC__
60-
"@[%s corrupted in database, when looking %s while compiling %s please update @]" file target (Lam_current_unit.get_current_file ()) ;
60+
"@[%s corrupted in database, when looking %s while compiling %s please update @]" file target (Js_config.get_current_file ()) ;
6161
Js_cmj_format.no_pure_dummy; (* FIXME *)
6262
| v -> v
6363
end

jscomp/idents_analysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let calculate_used_idents
5555
begin match Hashtbl.find ident_free_vars id with
5656
| exception Not_found ->
5757
Ext_log.err __LOC__ "%s/%d when compiling %s"
58-
id.name id.stamp (Lam_current_unit.get_current_file ());
58+
id.name id.stamp (Js_config.get_current_file ());
5959
assert false
6060
| e -> e
6161
end

jscomp/js_dump.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ let pp_deps_program ( program : J.deps_program) (f : Ext_pp.t) =
16201620
end
16211621
| Goog opt ->
16221622
let goog_package =
1623-
let v = Lam_current_unit.get_module_name () in
1623+
let v = Js_config.get_module_name () in
16241624
match opt with
16251625
| None
16261626
| Some ""

jscomp/js_pass_debug.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ let dump name (prog : J.program) =
3434
let () =
3535
if Js_config.get_env () <> Browser
3636
(* TODO: when no [Browser] detection, it will go through.. bug in js_of_ocaml? *)
37-
&& Lam_current_unit.is_same_file ()
37+
&& Js_config.is_same_file ()
3838
then
3939
begin
4040
incr log_counter ;
4141
Ext_pervasives.with_file_as_chan
42-
(Ext_filename.chop_extension ~loc:__LOC__ (Lam_current_unit.get_current_file()) ^
42+
(Ext_filename.chop_extension ~loc:__LOC__ (Js_config.get_current_file()) ^
4343
(Printf.sprintf ".%02d.%s.jsx" !log_counter name)
4444
) (fun chan -> Js_dump.dump_program prog chan )
4545
end in

jscomp/lam_compile_group.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ let compile ~filename output_prefix non_export env _sigs lam =
318318

319319
(* TODO: turn in on debug mode later*)
320320
let () =
321-
if Lam_current_unit.is_same_file () then
321+
if Js_config.is_same_file () then
322322
let f =
323323
Ext_filename.chop_extension ~loc:__LOC__ filename ^ ".lambda" in
324324
Ext_pervasives.with_file_as_pp f @@ fun fmt ->
@@ -418,8 +418,8 @@ let lambda_as_module
418418
(output_prefix : string)
419419
(lam : Lambda.lambda) =
420420
begin
421-
Lam_current_unit.set_current_file filename ;
422-
Lam_current_unit.iset_debug_file "tuple_alloc.ml";
421+
Js_config.set_current_file filename ;
422+
Js_config.iset_debug_file "tuple_alloc.ml";
423423
Ext_pervasives.with_file_as_chan
424424
(Js_config.get_output_file filename)
425425
(fun chan -> Js_dump.dump_deps_program

jscomp/lam_dispatch_primitive.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ let query (prim : Lam_compile_env.primitive_description)
944944
| _ ->
945945
Ext_log.err __LOC__
946946
"JS.unsafe_js_expr is applied to an non literal string in %s"
947-
(Lam_current_unit.get_current_file ())
947+
(Js_config.get_current_file ())
948948
;
949949
assert false
950950
end
@@ -955,7 +955,7 @@ let query (prim : Lam_compile_env.primitive_description)
955955
| _ ->
956956
Ext_log.err __LOC__
957957
"JS.unsafe_js_expr is applied to an non literal string in %s"
958-
(Lam_current_unit.get_current_file ())
958+
(Js_config.get_current_file ())
959959
;
960960
assert false
961961
end
@@ -1015,7 +1015,7 @@ let query (prim : Lam_compile_env.primitive_description)
10151015

10161016
let comment = "Missing primitve" in
10171017
Ext_log.warn __LOC__ "%s: %s when compiling %s\n" comment prim_name
1018-
(Lam_current_unit.get_current_file ()) ;
1018+
(Js_config.get_current_file ()) ;
10191019
E.not_implemented prim_name
10201020
(*we dont use [throw] here, since [throw] is an statement
10211021
so we wrap in IIFE

jscomp/lam_util.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,12 @@ let dump env ext lam =
306306
incr log_counter ;
307307
if Js_config.get_env () <> Browser
308308
(* TODO: when no [Browser] detection, it will go through.. bug in js_of_ocaml? *)
309-
&& Lam_current_unit.is_same_file ()
309+
&& Js_config.is_same_file ()
310310
then
311311
Printlambda.seriaize env
312312
(Ext_filename.chop_extension
313313
~loc:__LOC__
314-
(Lam_current_unit.get_current_file ()) ^
314+
(Js_config.get_current_file ()) ^
315315
(Printf.sprintf ".%02d%s.lam" !log_counter ext)
316316
) lam;
317317
lam

jscomp/lam_util.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ val sort_dag_args : J.expression Ident_map.t -> Ident.t list option
5959
*)
6060

6161

62-
(** [dump] when {!Lam_current_unit.is_same_file}*)
62+
(** [dump] when {!Js_config.is_same_file}*)
6363
val dump : Env.t -> string -> Lambda.lambda -> Lambda.lambda
6464

6565
val ident_set_of_list : Ident.t list -> Ident_set.t

jscomp/test/.depend

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ ext_filename.cmx : ../stdlib/sys.cmx ../stdlib/string.cmx ../stdlib/list.cmx \
163163
ext_pervasives.cmx
164164
ext_list.cmj : ../stdlib/list.cmi ../stdlib/array.cmi
165165
ext_list.cmx : ../stdlib/list.cmx ../stdlib/array.cmx
166-
ext_log.cmj : lam_current_unit.cmj ../stdlib/format.cmi
167-
ext_log.cmx : lam_current_unit.cmx ../stdlib/format.cmx
166+
ext_log.cmj : ../stdlib/format.cmi
167+
ext_log.cmx : ../stdlib/format.cmx
168168
ext_pervasives.cmj : ../stdlib/int32.cmi ../stdlib/format.cmi \
169169
../stdlib/arg.cmi ext_pervasives.cmi
170170
ext_pervasives.cmx : ../stdlib/int32.cmx ../stdlib/format.cmx \
@@ -205,6 +205,8 @@ for_side_effect_test.cmj : mt.cmi
205205
for_side_effect_test.cmx : mt.cmx
206206
format_regression.cmj :
207207
format_regression.cmx :
208+
format_test.cmj : mt.cmi ../stdlib/format.cmi
209+
format_test.cmx : mt.cmx ../stdlib/format.cmx
208210
genlex_test.cmj : ../stdlib/stream.cmi mt.cmi ../stdlib/list.cmi \
209211
../stdlib/genlex.cmi
210212
genlex_test.cmx : ../stdlib/stream.cmx mt.cmx ../stdlib/list.cmx \
@@ -279,8 +281,6 @@ js_obj_test.cmj : mt.cmi ../runtime/js.cmj
279281
js_obj_test.cmx : mt.cmx ../runtime/js.cmx
280282
js_val.cmj :
281283
js_val.cmx :
282-
lam_current_unit.cmj : ../stdlib/string.cmi ../stdlib/filename.cmi
283-
lam_current_unit.cmx : ../stdlib/string.cmx ../stdlib/filename.cmx
284284
lazy_test.cmj : mt.cmi ../stdlib/lazy.cmi
285285
lazy_test.cmx : mt.cmx ../stdlib/lazy.cmx
286286
lexer_test.cmj : number_lexer.cmj mt.cmi ../stdlib/list.cmi \
@@ -817,8 +817,8 @@ ext_filename.cmj : ../stdlib/sys.cmj ../stdlib/string.cmj ../stdlib/list.cmj \
817817
ext_pervasives.cmj
818818
ext_list.cmo : ../stdlib/list.cmi ../stdlib/array.cmi
819819
ext_list.cmj : ../stdlib/list.cmj ../stdlib/array.cmj
820-
ext_log.cmo : lam_current_unit.cmo ../stdlib/format.cmi
821-
ext_log.cmj : lam_current_unit.cmj ../stdlib/format.cmj
820+
ext_log.cmo : ../stdlib/format.cmi
821+
ext_log.cmj : ../stdlib/format.cmj
822822
ext_pervasives.cmo : ../stdlib/int32.cmi ../stdlib/format.cmi \
823823
../stdlib/arg.cmi ext_pervasives.cmi
824824
ext_pervasives.cmj : ../stdlib/int32.cmj ../stdlib/format.cmj \
@@ -859,6 +859,8 @@ for_side_effect_test.cmo : mt.cmi
859859
for_side_effect_test.cmj : mt.cmj
860860
format_regression.cmo :
861861
format_regression.cmj :
862+
format_test.cmo : mt.cmi ../stdlib/format.cmi
863+
format_test.cmj : mt.cmj ../stdlib/format.cmj
862864
genlex_test.cmo : ../stdlib/stream.cmi mt.cmi ../stdlib/list.cmi \
863865
../stdlib/genlex.cmi
864866
genlex_test.cmj : ../stdlib/stream.cmj mt.cmj ../stdlib/list.cmj \
@@ -933,8 +935,6 @@ js_obj_test.cmo : mt.cmi ../runtime/js.cmo
933935
js_obj_test.cmj : mt.cmj ../runtime/js.cmj
934936
js_val.cmo :
935937
js_val.cmj :
936-
lam_current_unit.cmo : ../stdlib/string.cmi ../stdlib/filename.cmi
937-
lam_current_unit.cmj : ../stdlib/string.cmj ../stdlib/filename.cmj
938938
lazy_test.cmo : mt.cmi ../stdlib/lazy.cmi
939939
lazy_test.cmj : mt.cmj ../stdlib/lazy.cmj
940940
lexer_test.cmo : number_lexer.cmo mt.cmi ../stdlib/list.cmi \

jscomp/test/ext_log.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ let iwarn b str f =
5454
Format.ifprintf Format.err_formatter ("WARN: %s " ^^ f) str
5555

5656
(* TODO: add {[@.]} later for all *)
57-
let dwarn str f =
58-
if Lam_current_unit.is_same_file () then
59-
Format.fprintf Format.err_formatter ("WARN: %s " ^^ f ^^ "@.") str
60-
else
61-
Format.ifprintf Format.err_formatter ("WARN: %s " ^^ f ^^ "@.") str
57+
(* let dwarn str f = *)
58+
(* if Js_config.is_same_file () then *)
59+
(* Format.fprintf Format.err_formatter ("WARN: %s " ^^ f ^^ "@.") str *)
60+
(* else *)
61+
(* Format.ifprintf Format.err_formatter ("WARN: %s " ^^ f ^^ "@.") str *)
6262

6363
let info str f =
6464
Format.fprintf Format.err_formatter ("INFO: %s " ^^ f) str

jscomp/test/format_test.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
let suites : Mt.pair_suites ref = ref []
2+
let test_id = ref 0
3+
let eq loc x y =
4+
incr test_id ;
5+
suites :=
6+
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
7+
8+
9+
let u () = "xx %s" ^^ "yy"
10+
11+
let () =
12+
eq __LOC__ (Format.asprintf (u ()) "x") ("xx x" ^ "yy")
13+
14+
let () = Mt.from_pair_suites __FILE__ !suites

jscomp/test/lam_current_unit.ml

Lines changed: 0 additions & 45 deletions
This file was deleted.

jscomp/test/test.mllib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ nested_obj_test
316316
nested_obj_literal
317317

318318
method_name_test
319-
319+
format_test
320320
# sig
321321
# delaunay
322322
# rand

lib/js/test/ext_log.js

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.5.0 , PLEASE EDIT WITH CARE
22
'use strict';
33

4-
var Pervasives = require("../pervasives");
5-
var Block = require("../block");
6-
var Curry = require("../curry");
7-
var Lam_current_unit = require("./lam_current_unit");
8-
var Format = require("../format");
4+
var Pervasives = require("../pervasives");
5+
var Block = require("../block");
6+
var Curry = require("../curry");
7+
var Format = require("../format");
98

109
function err(str, f) {
1110
return Curry._1(Format.fprintf(Format.err_formatter, Pervasives.$caret$caret(/* Format */[
@@ -108,51 +107,6 @@ function iwarn(b, str, f) {
108107
}
109108
}
110109

111-
function dwarn(str, f) {
112-
if (Lam_current_unit.is_same_file(/* () */0)) {
113-
return Curry._1(Format.fprintf(Format.err_formatter, Pervasives.$caret$caret(/* Format */[
114-
/* String_literal */Block.__(11, [
115-
"WARN: ",
116-
/* String */Block.__(2, [
117-
/* No_padding */0,
118-
/* Char_literal */Block.__(12, [
119-
/* " " */32,
120-
/* End_of_format */0
121-
])
122-
])
123-
]),
124-
"WARN: %s "
125-
], Pervasives.$caret$caret(f, /* Format */[
126-
/* Formatting_lit */Block.__(17, [
127-
/* Flush_newline */4,
128-
/* End_of_format */0
129-
]),
130-
"@."
131-
]))), str);
132-
}
133-
else {
134-
return Curry._1(Format.ifprintf(Format.err_formatter, Pervasives.$caret$caret(/* Format */[
135-
/* String_literal */Block.__(11, [
136-
"WARN: ",
137-
/* String */Block.__(2, [
138-
/* No_padding */0,
139-
/* Char_literal */Block.__(12, [
140-
/* " " */32,
141-
/* End_of_format */0
142-
])
143-
])
144-
]),
145-
"WARN: %s "
146-
], Pervasives.$caret$caret(f, /* Format */[
147-
/* Formatting_lit */Block.__(17, [
148-
/* Flush_newline */4,
149-
/* End_of_format */0
150-
]),
151-
"@."
152-
]))), str);
153-
}
154-
}
155-
156110
function info(str, f) {
157111
return Curry._1(Format.fprintf(Format.err_formatter, Pervasives.$caret$caret(/* Format */[
158112
/* String_literal */Block.__(11, [
@@ -206,7 +160,6 @@ exports.err = err;
206160
exports.ierr = ierr;
207161
exports.warn = warn;
208162
exports.iwarn = iwarn;
209-
exports.dwarn = dwarn;
210163
exports.info = info;
211164
exports.iinfo = iinfo;
212-
/* Lam_current_unit Not a pure module */
165+
/* Format Not a pure module */

0 commit comments

Comments
 (0)