Skip to content

Commit b692f6b

Browse files
authored
Merge pull request rescript-lang#4028 from BuckleScript/self_document_code
[refactor] self-document code
2 parents 619f645 + e93c5be commit b692f6b

26 files changed

+246
-326
lines changed

jscomp/core/lam.ml

+14-20
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,16 @@ module Types = struct
8080
loc : Location.t;
8181
status : apply_status
8282
}
83-
and function_info =
84-
{ arity : int ;
85-
params : ident list ;
86-
body : t
87-
}
83+
8884
and t =
8985
| Lvar of ident
9086
| Lglobal_module of ident
9187
| Lconst of Lam_constant.t
9288
| Lapply of apply_info
93-
| Lfunction of function_info
89+
| Lfunction of { arity : int ;
90+
params : ident list ;
91+
body : t
92+
}
9493
| Llet of Lam_compat.let_kind * ident * t * t
9594
| Lletrec of (ident * t) list * t
9695
| Lprim of prim_info
@@ -133,22 +132,17 @@ module X = struct
133132
loc : Location.t;
134133
status : apply_status
135134
}
136-
137-
and function_info
138-
= Types.function_info
139-
=
140-
{ arity : int ;
141-
params : ident list ;
142-
body : t
143-
}
144135
and t
145136
= Types.t
146137
=
147138
| Lvar of ident
148139
| Lglobal_module of ident
149140
| Lconst of Lam_constant.t
150141
| Lapply of apply_info
151-
| Lfunction of function_info
142+
| Lfunction of { arity : int ;
143+
params : ident list ;
144+
body : t
145+
}
152146
| Llet of Lam_compat.let_kind * ident * t * t
153147
| Lletrec of (ident * t) list * t
154148
| Lprim of prim_info
@@ -839,12 +833,12 @@ let handle_bs_non_obj_ffi
839833
loc
840834
prim_name =
841835
if no_auto_uncurried_arg_types arg_types then
842-
result_wrap loc result_type @@ prim ~primitive:(Pjs_call(prim_name, arg_types, ffi))
843-
~args loc
836+
result_wrap loc result_type (prim ~primitive:(Pjs_call {prim_name; arg_types; ffi})
837+
~args loc)
844838
else
845839
let n_arg_types, n_args =
846840
transform_uncurried_arg_type loc arg_types args in
847-
result_wrap loc result_type @@
848-
prim ~primitive:(Pjs_call (prim_name, n_arg_types, ffi))
849-
~args:n_args loc
841+
result_wrap loc result_type (
842+
prim ~primitive:(Pjs_call {prim_name; arg_types = n_arg_types; ffi})
843+
~args:n_args loc)
850844

jscomp/core/lam.mli

+4-6
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,15 @@ and prim_info = private
5151
args : t list ;
5252
loc : Location.t
5353
}
54-
and function_info = private
55-
{ arity : int ;
56-
params : ident list ;
57-
body : t
58-
}
5954
and t = private
6055
| Lvar of ident
6156
| Lglobal_module of ident
6257
| Lconst of Lam_constant.t
6358
| Lapply of apply_info
64-
| Lfunction of function_info
59+
| Lfunction of { arity : int ;
60+
params : ident list ;
61+
body : t
62+
}
6563
| Llet of Lam_compat.let_kind * ident * t * t
6664
| Lletrec of (ident * t) list * t
6765
| Lprim of prim_info

jscomp/core/lam_compile_primitive.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ let translate loc
576576
->
577577
assert false
578578

579-
| Pjs_call (_, arg_types, ffi) ->
579+
| Pjs_call {arg_types; ffi} ->
580580
Lam_compile_external_call.translate_ffi
581581
loc cxt arg_types ffi args
582582
(** FIXME, this can be removed later *)

jscomp/core/lam_id_kind.ml

+8-10
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ type rec_flag =
3737
*)
3838

3939

40-
type function_id = {
41-
42-
mutable arity : Lam_arity.t;
43-
(* TODO: This may contain some closure environment,
44-
check how it will interact with dead code elimination
45-
*)
46-
lambda : (Lam.t * rec_flag) option ;
47-
48-
}
4940

5041
type element =
5142
| NA
@@ -66,7 +57,14 @@ type t =
6657
| Constant of Lam_constant.t
6758
| Module of Ident.t
6859
(** TODO: static module vs first class module *)
69-
| FunctionId of function_id
60+
| FunctionId of {
61+
mutable arity : Lam_arity.t;
62+
(* TODO: This may contain some closure environment,
63+
check how it will interact with dead code elimination
64+
*)
65+
lambda : (Lam.t * rec_flag) option ;
66+
}
67+
7068
| Exception
7169
| Parameter
7270
(** For this case, it can help us determine whether it should be inlined or not *)

jscomp/core/lam_id_kind.mli

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ type rec_flag =
3232
*)
3333
| Lam_self_rec
3434
(* not inlining in this case *)
35-
type function_id = {
36-
mutable arity : Lam_arity.t;
37-
lambda : (Lam.t * rec_flag) option ;
38-
}
3935

4036
type element =
4137
| NA
@@ -56,7 +52,10 @@ type t =
5652
| Constant of Lam_constant.t
5753
| Module of Ident.t
5854
(** TODO: static module vs first class module *)
59-
| FunctionId of function_id
55+
| FunctionId of {
56+
mutable arity : Lam_arity.t;
57+
lambda : (Lam.t * rec_flag) option;
58+
}
6059
| Exception
6160
| Parameter
6261
(** For this case, it can help us determine whether it should be inlined or not *)

jscomp/core/lam_primitive.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ type t =
4848
(* External call *)
4949
| Pccall of Primitive_compat.t
5050
| Pjs_call of
51-
string * (* prim_name *)
52-
External_arg_spec.t list * (* arg_types *)
53-
External_ffi_types.external_spec (* ffi *)
51+
{ prim_name : string ;
52+
arg_types : External_arg_spec.t list ;
53+
ffi : External_ffi_types.external_spec }
5454
| Pjs_object_create of External_ffi_types.obj_create
5555
(* Exceptions *)
5656
| Praise
@@ -188,10 +188,10 @@ let eq_record_representation ( p : record_representation) ( p1 : record_represen
188188
match p with
189189
| Record_regular -> p1 = Record_regular
190190
#if OCAML_VERSION =~ ">4.03.0" then
191-
| Record_inlined {tag = a0; name = a1; num_nonconsts = a2 } ->
191+
| Record_inlined {tag ; name ; num_nonconsts} ->
192192
(match p1 with
193-
|Record_inlined {tag = b0; name = b1; num_nonconsts = b2} ->
194-
a0 = b0 && a1 = b1 && a2 = b2
193+
|Record_inlined rhs ->
194+
tag = rhs.tag && name = rhs.name && num_nonconsts = rhs.num_nonconsts
195195
| _ -> false)
196196
| Record_extension ->
197197
p1 = Record_extension
@@ -277,7 +277,7 @@ let eq_primitive_approx ( lhs : t) (rhs : t) =
277277

278278
| Pglobal_exception ident -> (match rhs with Pglobal_exception ident2 -> Ident.same ident ident2 | _ -> false )
279279
| Pduprecord record_repesentation0 -> (match rhs with Pduprecord record_repesentation1 -> eq_record_representation record_repesentation0 record_repesentation1 | _ -> false)
280-
| Pjs_call (prim_name, arg_types, ffi) -> ( match rhs with Pjs_call(prim_name1, arg_types1,ffi1) -> prim_name = prim_name1 && arg_types = arg_types1 && ffi = ffi1 | _ -> false)
280+
| Pjs_call {prim_name; arg_types; ffi} -> ( match rhs with Pjs_call rhs -> prim_name = rhs.prim_name && arg_types = rhs.arg_types && ffi = rhs.ffi | _ -> false)
281281
| Pjs_object_create obj_create -> (match rhs with Pjs_object_create obj_create1 -> obj_create = obj_create1 | _ -> false )
282282
| Pintcomp comparison -> (match rhs with Pintcomp comparison1 -> Lam_compat.eq_comparison comparison comparison1 | _ -> false )
283283
| Pfloatcomp comparison -> (match rhs with Pfloatcomp comparison1 -> Lam_compat.eq_comparison comparison comparison1 | _ -> false)

jscomp/core/lam_primitive.mli

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ type t =
4646
| Pccall of Primitive_compat.t
4747
| Pjs_call of
4848
(* Location.t * [loc] is passed down *)
49-
string * (* prim_name *)
50-
External_arg_spec.t list * (* arg_types *)
51-
External_ffi_types.external_spec (* ffi *)
49+
{ prim_name : string;
50+
arg_types : External_arg_spec.t list ;
51+
ffi : External_ffi_types.external_spec}
5252
| Pjs_object_create of External_ffi_types.obj_create
5353

5454
| Praise

jscomp/core/lam_print.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ let primitive ppf (prim : Lam_primitive.t) = match prim with
166166
| Pduprecord rep -> fprintf ppf "duprecord %a" record_rep rep
167167
| Plazyforce -> fprintf ppf "force"
168168
| Pccall p -> fprintf ppf "%s" p.prim_name
169-
| Pjs_call (prim_name, _, _) ->
169+
| Pjs_call {prim_name} ->
170170
fprintf ppf "%s[js]" prim_name
171171
| Pjs_object_create obj_create ->
172172
fprintf ppf "[js.obj]"

jscomp/core/lam_stats_export.ml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ let values_of_export
4747
match Ident_hashtbl.find_opt meta.ident_tbl x with
4848
| Some (FunctionId {arity ; _}) -> Single arity
4949
| Some (ImmutableBlock(elems)) ->
50+
(* FIXME: field name for dumping*)
5051
Submodule(Ext_array.map elems (fun x ->
5152
match x with
5253
| NA -> Lam_arity.na

jscomp/ext/hash_set.cppo.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type 'a t = 'a Hash_set_gen.t
6464
let create = Hash_set_gen.create
6565
let clear = Hash_set_gen.clear
6666
let reset = Hash_set_gen.reset
67-
let copy = Hash_set_gen.copy
67+
(* let copy = Hash_set_gen.copy *)
6868
let iter = Hash_set_gen.iter
6969
let fold = Hash_set_gen.fold
7070
let length = Hash_set_gen.length

jscomp/ext/hash_set_gen.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let reset h =
5555
h.data <- Array.make h.initial_size Empty
5656

5757

58-
let copy h = { h with data = Array.copy h.data }
58+
(* let copy h = { h with data = Array.copy h.data } *)
5959

6060
let length h = h.size
6161

@@ -145,7 +145,7 @@ sig
145145
val create: int -> t
146146
val clear : t -> unit
147147
val reset : t -> unit
148-
val copy: t -> t
148+
(* val copy: t -> t *)
149149
val remove: t -> key -> unit
150150
val add : t -> key -> unit
151151
val of_array : key array -> t

jscomp/ext/hash_set_poly.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ val clear : 'a t -> unit
3131

3232
val reset : 'a t -> unit
3333

34-
val copy : 'a t -> 'a t
34+
(* val copy : 'a t -> 'a t *)
3535

3636
val add : 'a t -> 'a -> unit
3737
val remove : 'a t -> 'a -> unit

jscomp/ext/hashtbl.cppo.ml

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type ('a, 'b) bucketlist = ('a,'b) Hashtbl_gen.bucketlist
3434
let create = Hashtbl_gen.create
3535
let clear = Hashtbl_gen.clear
3636
let reset = Hashtbl_gen.reset
37-
let copy = Hashtbl_gen.copy
3837
let iter = Hashtbl_gen.iter
3938
let to_list = Hashtbl_gen.to_list
4039
let fold = Hashtbl_gen.fold

jscomp/ext/hashtbl_gen.ml

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ let reset h =
4747
h.data <- Array.make h.initial_size Empty
4848

4949

50-
let copy h = { h with data = Array.copy h.data }
51-
5250
let length h = h.size
5351

5452
let resize indexfun h =
@@ -176,7 +174,7 @@ module type S = sig
176174
val create: int -> 'a t
177175
val clear: 'a t -> unit
178176
val reset: 'a t -> unit
179-
val copy: 'a t -> 'a t
177+
180178
val add: 'a t -> key -> 'a -> unit
181179
val modify_or_init: 'a t -> key -> ('a -> unit) -> (unit -> 'a) -> unit
182180
val remove: 'a t -> key -> unit

jscomp/main/cmjdump_main.ml

+1-6
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
(* open Printf *)
26-
27-
28-
29-
3025

3126
let () =
3227
match Sys.argv with
3328
| [|_; file |]
3429
->
35-
let cmj,digest = (Js_cmj_format.from_file_with_digest file) in
30+
let cmj,digest = Js_cmj_format.from_file_with_digest file in
3631
Format.fprintf Format.std_formatter "@[Digest: %s@]@." (Digest.to_hex digest);
3732
Js_cmj_format.pp_cmj cmj
3833
| _ -> failwith "expect one argument"

lib/4.06.1/bsb.ml

+5-9
Original file line numberDiff line numberDiff line change
@@ -7410,7 +7410,7 @@ let reset h =
74107410
h.data <- Array.make h.initial_size Empty
74117411

74127412

7413-
let copy h = { h with data = Array.copy h.data }
7413+
(* let copy h = { h with data = Array.copy h.data } *)
74147414

74157415
let length h = h.size
74167416

@@ -7500,7 +7500,7 @@ sig
75007500
val create: int -> t
75017501
val clear : t -> unit
75027502
val reset : t -> unit
7503-
val copy: t -> t
7503+
(* val copy: t -> t *)
75047504
val remove: t -> key -> unit
75057505
val add : t -> key -> unit
75067506
val of_array : key array -> t
@@ -7583,7 +7583,7 @@ type t = key Hash_set_gen.t
75837583
let create = Hash_set_gen.create
75847584
let clear = Hash_set_gen.clear
75857585
let reset = Hash_set_gen.reset
7586-
let copy = Hash_set_gen.copy
7586+
(* let copy = Hash_set_gen.copy *)
75877587
let iter = Hash_set_gen.iter
75887588
let fold = Hash_set_gen.fold
75897589
let length = Hash_set_gen.length
@@ -8089,8 +8089,6 @@ let reset h =
80898089
h.data <- Array.make h.initial_size Empty
80908090

80918091

8092-
let copy h = { h with data = Array.copy h.data }
8093-
80948092
let length h = h.size
80958093

80968094
let resize indexfun h =
@@ -8218,7 +8216,7 @@ module type S = sig
82188216
val create: int -> 'a t
82198217
val clear: 'a t -> unit
82208218
val reset: 'a t -> unit
8221-
val copy: 'a t -> 'a t
8219+
82228220
val add: 'a t -> key -> 'a -> unit
82238221
val modify_or_init: 'a t -> key -> ('a -> unit) -> (unit -> 'a) -> unit
82248222
val remove: 'a t -> key -> unit
@@ -8274,7 +8272,6 @@ type ('a, 'b) bucketlist = ('a,'b) Hashtbl_gen.bucketlist
82748272
let create = Hashtbl_gen.create
82758273
let clear = Hashtbl_gen.clear
82768274
let reset = Hashtbl_gen.reset
8277-
let copy = Hashtbl_gen.copy
82788275
let iter = Hashtbl_gen.iter
82798276
let to_list = Hashtbl_gen.to_list
82808277
let fold = Hashtbl_gen.fold
@@ -8398,7 +8395,7 @@ let of_list2 ks vs =
83988395
List.iter2 (fun k v -> add map k v) ks vs ;
83998396
map
84008397

8401-
# 162 "ext/hashtbl.cppo.ml"
8398+
# 161 "ext/hashtbl.cppo.ml"
84028399
end
84038400

84048401
end
@@ -9423,7 +9420,6 @@ type ('a, 'b) bucketlist = ('a,'b) Hashtbl_gen.bucketlist
94239420
let create = Hashtbl_gen.create
94249421
let clear = Hashtbl_gen.clear
94259422
let reset = Hashtbl_gen.reset
9426-
let copy = Hashtbl_gen.copy
94279423
let iter = Hashtbl_gen.iter
94289424
let to_list = Hashtbl_gen.to_list
94299425
let fold = Hashtbl_gen.fold

0 commit comments

Comments
 (0)