Skip to content

Commit c530c33

Browse files
committed
make module_id a separate type
Note we can not move its definition out of sources of J.ml which will break the code generation for o#ident
1 parent 77c02d7 commit c530c33

14 files changed

+867
-851
lines changed

jscomp/core/j.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ and exports = Js_op.exports
6363

6464
and tag_info = Js_op.tag_info
6565

66-
and required_modules = Js_op.required_modules
66+
and required_modules = module_id list
6767

6868

6969

@@ -75,10 +75,12 @@ and required_modules = Js_op.required_modules
7575
and property_name = Js_op.property_name
7676
and jsint = Js_op.jsint
7777
and ident = Ident.t
78-
78+
and module_id = {
79+
id : ident; kind : Js_op.kind
80+
}
7981
and vident =
8082
| Id of ident
81-
| Qualified of ident * kind * string option
83+
| Qualified of module_id * string option
8284
(* Since camldot is only available for toplevel module accessors,
8385
we don't need print `A.length$2`
8486
just print `A.length` - it's guarateed to be unique

jscomp/core/js_dump.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,14 @@ and loop_case_clauses : 'a . cxt ->
526526

527527
and vident cxt f (v : J.vident) =
528528
match v with
529-
| Id v | Qualified(v, _, None) ->
529+
| Id v | Qualified({id = v }, None) ->
530530
Ext_pp_scope.ident cxt f v
531-
| Qualified (id, (Ml | Runtime), Some name) ->
531+
| Qualified ({id; kind = Ml | Runtime}, Some name) ->
532532
let cxt = Ext_pp_scope.ident cxt f id in
533533
P.string f L.dot;
534534
P.string f (Ext_ident.convert name);
535535
cxt
536-
| Qualified (id, External _, Some name) ->
536+
| Qualified ({id; kind = External _}, Some name) ->
537537
let cxt = Ext_pp_scope.ident cxt f id in
538538
Js_dump_property.property_access f name ;
539539
cxt
@@ -958,7 +958,7 @@ and expression_desc cxt ~(level:int) f x : cxt =
958958
and property_name_and_value_list cxt f (l : J.property_map) =
959959
iter_lst cxt f l (fun cxt f (pn,e) ->
960960
match e.expression_desc with
961-
| Var (Id v | Qualified (v,_,None)) ->
961+
| Var (Id v | Qualified ({id =v; _},None)) ->
962962
let key = Js_dump_property.property_key pn in
963963
let str, cxt = Ext_pp_scope.str_of_ident cxt v in
964964
let content =

jscomp/core/js_exp_make.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ let flat_call ?comment e0 es : t =
8989

9090
let runtime_var_dot ?comment (x : string) (e1 : string) : J.expression =
9191
{ expression_desc =
92-
Var (Qualified(Ident.create_persistent x,Runtime, Some e1));
92+
Var (Qualified({id = Ident.create_persistent x; kind = Runtime}, Some e1));
9393
comment }
9494

9595

9696
let ml_var_dot ?comment ( id : Ident.t) e : J.expression =
97-
{expression_desc = Var (Qualified(id, Ml, Some e)); comment }
97+
{expression_desc = Var (Qualified({id; kind = Ml}, Some e)); comment }
9898

9999
(**
100100
module as a value
@@ -103,15 +103,15 @@ let ml_var_dot ?comment ( id : Ident.t) e : J.expression =
103103
]}
104104
*)
105105
let external_var_field ?comment ~external_name:name (id : Ident.t) ~dot : t =
106-
{expression_desc = Var (Qualified(id, External name, Some dot)); comment }
106+
{expression_desc = Var (Qualified({id; kind = External name}, Some dot)); comment }
107107

108108

109109
let external_var ?comment ~external_name (id : Ident.t) : t =
110110
{expression_desc =
111-
Var (Qualified(id, External external_name, None)); comment }
111+
Var (Qualified({id; kind = External external_name}, None)); comment }
112112

113113
let ml_module_as_var ?comment (id : Ident.t) : t =
114-
{expression_desc = Var (Qualified (id, Ml, None)); comment}
114+
{expression_desc = Var (Qualified ({id; kind = Ml}, None)); comment}
115115

116116
(* Static_index .....................**)
117117
let runtime_call ?comment module_name fn_name args =
@@ -971,23 +971,23 @@ let rec int_comp (cmp : Lam_compat.comparison) ?comment (e0 : t) (e1 : t) =
971971
| _, Call ({
972972
expression_desc =
973973
Var (Qualified
974-
(_, Runtime,
974+
({kind = Runtime},
975975
Some ("caml_int_compare" | "caml_int32_compare"))); _},
976976
[l;r], _),
977977
Number (Int {i = 0l})
978978
-> int_comp cmp l r (* = 0 > 0 < 0 *)
979979
| Ceq, Call ({
980980
expression_desc =
981981
Var (Qualified
982-
(ident, Runtime,
982+
({id = _; kind = Runtime} as iid,
983983
Some ("caml_compare"))); _} as fn,
984984
([_;_] as args), call_info),
985985
Number (Int {i = 0l})
986986
->
987987
{e0 with expression_desc =
988988
Call(
989989
{fn with expression_desc =
990-
Var(Qualified (ident,Runtime, Some "caml_equal"))
990+
Var(Qualified (iid, Some "caml_equal"))
991991
} , args, call_info)}
992992
| Ceq, Optional_block _, Undefined
993993
| Ceq, Undefined, Optional_block _

jscomp/core/js_fold.ml

+8-5
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ class virtual fold =
3737
method vident : vident -> 'self_type =
3838
function
3939
| Id _x -> let o = o#ident _x in o
40-
| Qualified (_x, _x_i1, _x_i2) ->
41-
let o = o#ident _x in
42-
let o = o#kind _x_i1 in
43-
let o = o#option (fun o -> o#string) _x_i2 in o
40+
| Qualified (_x, _x_i1) ->
41+
let o = o#module_id _x in
42+
let o = o#option (fun o -> o#string) _x_i1 in o
4443
method variable_declaration : variable_declaration -> 'self_type =
4544
fun { ident = _x; value = _x_i1; property = _x_i2; ident_info = _x_i3 }
4645
->
@@ -297,7 +296,8 @@ class virtual fold =
297296
fun { statement_desc = _x; comment = _x_i1 } ->
298297
let o = o#statement_desc _x in
299298
let o = o#option (fun o -> o#string) _x_i1 in o
300-
method required_modules : required_modules -> 'self_type = o#unknown
299+
method required_modules : required_modules -> 'self_type =
300+
o#list (fun o -> o#module_id)
301301
method property_name : property_name -> 'self_type = o#unknown
302302
method property_map : property_map -> 'self_type =
303303
o#list
@@ -310,6 +310,9 @@ class virtual fold =
310310
let o = o#exports _x_i1 in let o = o#unknown _x_i2 in o
311311
method number : number -> 'self_type = o#unknown
312312
method mutable_flag : mutable_flag -> 'self_type = o#unknown
313+
method module_id : module_id -> 'self_type =
314+
fun { id = _x; kind = _x_i1 } ->
315+
let o = o#ident _x in let o = o#unknown _x_i1 in o
313316
method length_object : length_object -> 'self_type = o#unknown
314317
method label : label -> 'self_type = o#string
315318
method kind : kind -> 'self_type = o#unknown

jscomp/core/js_fold_basic.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class count_hard_dependencies =
5656
val hard_dependencies = create 17
5757
method! vident vid =
5858
match vid with
59-
| Qualified (id,kind,_) ->
60-
add_lam_module_ident hard_dependencies (Lam_module_ident.mk kind id); self
59+
| Qualified (vid,_) ->
60+
add_lam_module_ident hard_dependencies vid; self
6161
| Id _ ->
6262
self
6363
method! expression x : 'self_type =

jscomp/core/js_map.ml

+9-6
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ class virtual map =
4040
method vident : vident -> vident =
4141
function
4242
| Id _x -> let _x = o#ident _x in Id _x
43-
| Qualified (_x, _x_i1, _x_i2) ->
44-
let _x = o#ident _x in
45-
let _x_i1 = o#kind _x_i1 in
46-
let _x_i2 = o#option (fun o -> o#string) _x_i2
47-
in Qualified (_x, _x_i1, _x_i2)
43+
| Qualified (_x, _x_i1) ->
44+
let _x = o#module_id _x in
45+
let _x_i1 = o#option (fun o -> o#string) _x_i1
46+
in Qualified (_x, _x_i1)
4847
method variable_declaration :
4948
variable_declaration -> variable_declaration =
5049
fun { ident = _x; value = _x_i1; property = _x_i2; ident_info = _x_i3 }
@@ -316,7 +315,7 @@ class virtual map =
316315
let _x_i1 = o#option (fun o -> o#string) _x_i1
317316
in { statement_desc = _x; comment = _x_i1; }
318317
method required_modules : required_modules -> required_modules =
319-
o#unknown
318+
o#list (fun o -> o#module_id)
320319
method property_name : property_name -> property_name = o#unknown
321320
method property_map : property_map -> property_map =
322321
o#list
@@ -332,6 +331,10 @@ class virtual map =
332331
in { block = _x; exports = _x_i1; export_set = _x_i2; }
333332
method number : number -> number = o#unknown
334333
method mutable_flag : mutable_flag -> mutable_flag = o#unknown
334+
method module_id : module_id -> module_id =
335+
fun { id = _x; kind = _x_i1 } ->
336+
let _x = o#ident _x in
337+
let _x_i1 = o#unknown _x_i1 in { id = _x; kind = _x_i1; }
335338
method length_object : length_object -> length_object = o#unknown
336339
method label : label -> label = o#string
337340
method kind : kind -> kind = o#unknown

jscomp/core/js_op.ml

-2
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ type ident_info = {
229229

230230
type exports = Ident.t list
231231

232-
type module_id = { id : Ident.t; kind : kind}
233232

234-
type required_modules = module_id list
235233

236234

237235
type tag_info = Lam_tag_info.t

jscomp/core/js_op_util.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ let same_str_opt ( x : string option ) (y : string option) =
136136
let same_vident (x : J.vident) (y : J.vident) =
137137
match x, y with
138138
| Id x0, Id y0 -> Ident.same x0 y0
139-
| Qualified(x0,k0,str_opt0), Qualified(y0,k1,str_opt1) ->
139+
| Qualified({id = x0; kind = k0},str_opt0), Qualified({id = y0; kind = k1},str_opt1) ->
140140
Ident.same x0 y0 && same_kind k0 k1 && same_str_opt str_opt0 str_opt1
141141
| Id _, Qualified _
142142
| Qualified _, Id _ -> false

jscomp/core/lam_module_ident.ml

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232

33-
type t = Js_op.module_id =
33+
type t = J.module_id =
3434
{ id : Ident.t ; kind : Js_op.kind }
3535

3636

@@ -43,8 +43,6 @@ let of_external id name = {id ; kind = External name}
4343

4444
let of_runtime id = { id ; kind = Runtime }
4545

46-
let mk kind id = {id; kind}
47-
4846
let name (x : t) : string =
4947
match x.kind with
5048
| Ml | Runtime -> x.id.name

jscomp/core/lam_module_ident.mli

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
(** A type for qualified identifiers in Lambda IR
3636
*)
3737

38-
type t = Js_op.module_id =
39-
private {
38+
39+
type t = J.module_id =
40+
(*private*) {
4041
id : Ident.t ;
4142
kind : Js_op.kind
4243
}
@@ -46,7 +47,7 @@ val id : t -> Ident.t
4647

4748
val name : t -> string
4849

49-
val mk : Js_op.kind -> Ident.t -> t
50+
5051

5152
val of_ml : Ident.t -> t
5253

0 commit comments

Comments
 (0)