Skip to content

Commit 09860f5

Browse files
committed
tweak
1 parent 1b61dfb commit 09860f5

File tree

5 files changed

+117
-41
lines changed

5 files changed

+117
-41
lines changed

jscomp/core/js_dump.ml

+41-37
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,59 @@ module L = Js_dump_lit
7272
}
7373
There are no sane way to easy detect it ahead of time, we should be
7474
conservative here.
75+
(our call Js_fun_env.get_unbounded env) is not precise
7576
*)
77+
78+
7679
module Curry_gen = struct
77-
78-
let pp_optimize_curry (f : P.t) (len : int) =
80+
let pp_curry_dot f =
7981
P.string f Js_runtime_modules.curry;
80-
P.string f L.dot ;
82+
P.string f L.dot
83+
let pp_optimize_curry (f : P.t) (len : int) =
84+
pp_curry_dot f;
8185
P.string f "__";
8286
P.string f (Printf.sprintf "%d" len)
8387

8488
let pp_app_any (f : P.t) =
85-
P.string f Js_runtime_modules.curry;
86-
P.string f L.dot ;
89+
pp_curry_dot f;
8790
P.string f "app"
8891

8992
let pp_app (f : P.t) (len : int) =
90-
P.string f Js_runtime_modules.curry;
91-
P.string f L.dot;
93+
pp_curry_dot f;
9294
P.string f "_";
9395
P.string f (Printf.sprintf "%d" len)
9496
end
9597

98+
let pp_block_dot f =
99+
P.string f Js_runtime_modules.block;
100+
P.string f L.dot
101+
102+
let pp_block_create f =
103+
pp_block_dot f ;
104+
P.string f L.caml_block_create
105+
106+
let pp_block_record f =
107+
pp_block_dot f ;
108+
P.string f L.block_record
109+
110+
let pp_block_local_module f =
111+
pp_block_dot f;
112+
P.string f L.block_local_module
113+
114+
let pp_block_poly_var f =
115+
pp_block_dot f;
116+
P.string f L.block_poly_var
117+
118+
let pp_block_simple_variant f =
119+
pp_block_dot f ;
120+
P.string f L.block_simple_variant
121+
122+
let pp_block_variant f =
123+
pp_block_dot f ;
124+
P.string f L.block_variant
125+
126+
127+
96128
let return_indent = String.length L.return / Ext_pp.indent_length
97129

98130
let throw_indent = String.length L.throw / Ext_pp.indent_length
@@ -232,34 +264,6 @@ let pp_direction f (direction : J.for_direction) =
232264
| Upto -> P.string f L.plus_plus
233265
| Downto -> P.string f L.minus_minus
234266

235-
let pp_block_dot f =
236-
P.string f L.caml_block;
237-
P.string f L.dot
238-
239-
let pp_block_create f =
240-
pp_block_dot f ;
241-
P.string f L.caml_block_create
242-
243-
let pp_block_record f =
244-
pp_block_dot f ;
245-
P.string f L.block_record
246-
247-
let pp_block_local_module f =
248-
pp_block_dot f;
249-
P.string f L.block_local_module
250-
251-
let pp_block_poly_var f =
252-
pp_block_dot f;
253-
P.string f L.block_poly_var
254-
255-
let pp_block_simple_variant f =
256-
pp_block_dot f ;
257-
P.string f L.block_simple_variant
258-
259-
let pp_block_variant f =
260-
pp_block_dot f ;
261-
P.string f L.block_variant
262-
263267
let return_sp f =
264268
P.string f L.return ; P.space f
265269

@@ -383,7 +387,7 @@ and pp_function is_method
383387
| Name_top id | Name_non_top id ->
384388
Ident_set.add (Js_fun_env.get_unbounded env ) id in
385389
(* the context will be continued after this function *)
386-
let outer_cxt = Ext_pp_scope.merge set_env cxt in
390+
let outer_cxt = Ext_pp_scope.merge cxt set_env in
387391

388392
(* the context used to be printed inside this function
389393
@@ -1203,7 +1207,7 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
12031207
[print for loop] has side effect,
12041208
we should take it out
12051209
*)
1206-
let inner_cxt = Ext_pp_scope.merge lexical cxt in
1210+
let inner_cxt = Ext_pp_scope.merge cxt lexical in
12071211
let lexical = Ident_set.elements lexical in
12081212
P.vgroup f 0
12091213
(fun _ ->

jscomp/ext/ext_pp_scope.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type t =
3434
(**
3535
-- "name" --> int map -- stamp --> index suffix
3636
*)
37-
let empty =
37+
let empty : t =
3838
String_map.empty
3939

4040
let rec print fmt v =
@@ -48,7 +48,7 @@ and print_int_map fmt m =
4848
Format.fprintf fmt "%d - %d" k v
4949
)
5050

51-
let add_ident ~mangled:name stamp (cxt : t) : int * t =
51+
let add_ident ~mangled:name (stamp : int) (cxt : t) : int * t =
5252
match String_map.find_opt cxt name with
5353
| None ->
5454
(0, String_map.add cxt name (Int_map.add Int_map.empty stamp 0 ) )
@@ -116,7 +116,7 @@ let ident (cxt : t) f (id : Ident.t) : t =
116116
cxt
117117

118118

119-
let merge set cxt =
119+
let merge (cxt : t) (set : Ident_set.t) =
120120
Ident_set.fold set cxt (fun ident acc ->
121121
snd (add_ident ~mangled:(Ext_ident.convert ident.name) ident.stamp acc))
122122

jscomp/ext/ext_pp_scope.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ val print : Format.formatter -> t -> unit
4444

4545
val sub_scope : t -> Ident_set.t -> t
4646

47-
val merge : Ident_set.t -> t -> t
47+
val merge : t -> Ident_set.t -> t
4848

4949

5050

jscomp/test/gpr_3566_drive_test.ml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let suites : Mt.pair_suites ref = ref []
2+
3+
let test_id = ref 0
4+
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
5+
6+
module H = Gpr_3566_test.Test ()
7+
let () =
8+
eq __LOC__ H.b true
9+
10+
let () = Mt.from_pair_suites __FILE__ !suites

jscomp/test/gpr_3566_test.ml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
type t = A of int | B of string
3+
let eq_A (x :t) y =
4+
match x with
5+
| A x ->
6+
(match y with A x1 -> x = x1 | _ -> false)
7+
| _ -> false
8+
9+
module Test() =
10+
struct
11+
let () = Js.log "no inline"
12+
let u = A 3
13+
module Block = struct end
14+
let y = 32
15+
let b = eq_A (A 3) u
16+
end
17+
18+
19+
module Test2() =
20+
struct
21+
let () = Js.log "no inline"
22+
23+
module Block = struct end
24+
let y = 32
25+
let b = eq_A (A 3) (A 3)
26+
end
27+
28+
29+
let x = 3
30+
31+
let f i y =
32+
let x = A i in
33+
eq_A x y
34+
35+
module Test3 () = struct
36+
let f x y = x = y
37+
module Caml_obj = struct
38+
end
39+
end
40+
module Test4 () = struct
41+
module Caml_obj = struct
42+
end
43+
let f x y = x = y
44+
end
45+
46+
47+
module Test5 () = struct
48+
let f x = Some x
49+
module Caml_option = struct
50+
end
51+
end
52+
53+
module Test6 () = struct
54+
module Caml_option = struct
55+
end
56+
let f x = Some x
57+
end
58+
59+
module Test7 () = struct
60+
module Caml_option = struct
61+
end
62+
end

0 commit comments

Comments
 (0)