Skip to content

Commit 6112b5b

Browse files
committed
use direct bindings instead of refs
1 parent 15bf8c8 commit 6112b5b

File tree

7 files changed

+117
-160
lines changed

7 files changed

+117
-160
lines changed

jscomp/core/bs_conditional_initial.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ let setup_env () =
4444
Builtin_attributes.check_bs_attributes_inclusion := Record_attributes_check.check_bs_attributes_inclusion;
4545
Builtin_attributes.check_duplicated_labels :=
4646
Record_attributes_check.check_duplicated_labels;
47-
Lambda.fld_record := Record_attributes_check.fld_record;
48-
Lambda.fld_record_set := Record_attributes_check.fld_record_set;
49-
Lambda.fld_record_inline := Record_attributes_check.fld_record_inline;
50-
Lambda.fld_record_inline_set := Record_attributes_check.fld_record_inline_set;
51-
Lambda.fld_record_extension := Record_attributes_check.fld_record_extension;
52-
Lambda.fld_record_extension_set := Record_attributes_check.fld_record_extension_set;
53-
Lambda.blk_record := Record_attributes_check.blk_record;
54-
Lambda.blk_record_inlined := Record_attributes_check.blk_record_inlined;
55-
Lambda.blk_record_ext := Record_attributes_check.blk_record_ext;
5647
Matching.names_from_construct_pattern :=
5748
Matching_polyfill.names_from_construct_pattern;
5849

jscomp/core/record_attributes_check.ml

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
type label = Types.label_description
2626

27-
let find_name = Matching.find_name
27+
let find_name = Lambda.find_name
2828

2929
let find_name_with_loc (attr : Parsetree.attribute) : string Asttypes.loc option
3030
=
@@ -40,59 +40,6 @@ let find_name_with_loc (attr : Parsetree.attribute) : string Asttypes.loc option
4040
Some { txt = s; loc }
4141
| _ -> None
4242

43-
let fld_record (lbl : label) =
44-
Lambda.Fld_record
45-
{
46-
name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name;
47-
mutable_flag = lbl.lbl_mut;
48-
}
49-
50-
let fld_record_set (lbl : label) =
51-
Lambda.Fld_record_set
52-
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
53-
54-
let fld_record_inline (lbl : label) =
55-
Lambda.Fld_record_inline
56-
{ name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name }
57-
58-
let fld_record_inline_set (lbl : label) =
59-
Lambda.Fld_record_inline_set
60-
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
61-
62-
let fld_record_extension (lbl : label) =
63-
Lambda.Fld_record_extension
64-
{ name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name }
65-
66-
let fld_record_extension_set (lbl : label) =
67-
Lambda.Fld_record_extension_set
68-
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
69-
70-
let blk_record (fields : (label * _) array) mut record_repr =
71-
let all_labels_info =
72-
Ext_array.map fields (fun (lbl, _) ->
73-
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
74-
in
75-
Lambda.Blk_record
76-
{ fields = all_labels_info; mutable_flag = mut; record_repr }
77-
78-
let blk_record_ext fields mutable_flag =
79-
let all_labels_info =
80-
Array.map
81-
(fun ((lbl : label), _) ->
82-
Ext_list.find_def lbl.Types.lbl_attributes find_name lbl.lbl_name)
83-
fields
84-
in
85-
Lambda.Blk_record_ext {fields = all_labels_info; mutable_flag }
86-
87-
let blk_record_inlined fields name num_nonconst optional_labels ~tag ~attrs mutable_flag =
88-
let fields =
89-
Array.map
90-
(fun ((lbl : label), _) ->
91-
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
92-
fields
93-
in
94-
Lambda.Blk_record_inlined {fields; name; num_nonconst; tag; mutable_flag; optional_labels; attrs }
95-
9643
let check_bs_attributes_inclusion (attrs1 : Parsetree.attributes)
9744
(attrs2 : Parsetree.attributes) lbl_name =
9845
let a = Ext_list.find_def attrs1 find_name lbl_name in

jscomp/ml/lambda.ml

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,47 @@ let mutable_flag_of_tag_info (tag : tag_info) =
8686
| Blk_some
8787
-> Immutable
8888

89+
type label = Types.label_description
90+
91+
let find_name (attr : Parsetree.attribute) =
92+
match attr with
93+
| ( { txt = "bs.as" | "as" },
94+
PStr
95+
[
96+
{
97+
pstr_desc =
98+
Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (s, _)) }, _);
99+
};
100+
] ) ->
101+
Some s
102+
| _ -> None
103+
104+
let blk_record (fields : (label * _) array) mut record_repr =
105+
let all_labels_info =
106+
Ext_array.map fields (fun (lbl, _) ->
107+
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
108+
in
109+
Blk_record
110+
{ fields = all_labels_info; mutable_flag = mut; record_repr }
89111

90-
let blk_record = ref (fun _ _ _ ->
91-
assert false
92-
)
93-
94-
95-
let blk_record_ext = ref (fun fields mutable_flag ->
96-
let all_labels_info = fields |> Array.map (fun (x,_) -> x.Types.lbl_name) in
97-
Blk_record_ext {fields = all_labels_info; mutable_flag }
98-
)
99112

100-
let blk_record_inlined = ref (fun fields name num_nonconst optional_labels ~tag ~attrs mutable_flag ->
101-
let fields = fields |> Array.map (fun (x,_) -> x.Types.lbl_name) in
113+
let blk_record_ext fields mutable_flag =
114+
let all_labels_info =
115+
Array.map
116+
(fun ((lbl : label), _) ->
117+
Ext_list.find_def lbl.Types.lbl_attributes find_name lbl.lbl_name)
118+
fields
119+
in
120+
Blk_record_ext {fields = all_labels_info; mutable_flag }
121+
122+
let blk_record_inlined fields name num_nonconst optional_labels ~tag ~attrs mutable_flag =
123+
let fields =
124+
Array.map
125+
(fun ((lbl : label), _) ->
126+
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
127+
fields
128+
in
102129
Blk_record_inlined {fields; name; num_nonconst; tag; mutable_flag; optional_labels; attrs }
103-
)
104130

105131
let ref_tag_info : tag_info =
106132
Blk_record {fields = [| "contents" |]; mutable_flag = Mutable; record_repr = Record_regular}
@@ -117,15 +143,17 @@ type field_dbg_info =
117143
| Fld_variant
118144
| Fld_cons
119145
| Fld_array
120-
121-
let fld_record = ref (fun (lbl : Types.label_description) ->
122-
Fld_record {name = lbl.lbl_name; mutable_flag = Mutable})
123146

124-
let fld_record_inline = ref (fun (lbl : Types.label_description) ->
125-
Fld_record_inline {name = lbl.lbl_name})
147+
let fld_record (lbl : label) =
148+
Fld_record
149+
{
150+
name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name;
151+
mutable_flag = lbl.lbl_mut;
152+
}
126153

127-
let fld_record_extension = ref (fun (lbl : Types.label_description) ->
128-
Fld_record_extension {name = lbl.lbl_name})
154+
let fld_record_extension (lbl : label) =
155+
Fld_record_extension
156+
{ name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name }
129157

130158
let ref_field_info : field_dbg_info =
131159
Fld_record { name = "contents"; mutable_flag = Mutable}
@@ -137,14 +165,21 @@ type set_field_dbg_info =
137165
| Fld_record_extension_set of string
138166

139167
let ref_field_set_info : set_field_dbg_info = Fld_record_set "contents"
140-
let fld_record_set = ref ( fun (lbl : Types.label_description) ->
141-
Fld_record_set lbl.lbl_name )
168+
let fld_record_set (lbl : label) =
169+
Fld_record_set
170+
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
171+
172+
let fld_record_inline (lbl : label) =
173+
Fld_record_inline
174+
{ name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name }
142175

143-
let fld_record_inline_set = ref ( fun (lbl : Types.label_description) ->
144-
Fld_record_inline_set lbl.lbl_name )
176+
let fld_record_inline_set (lbl : label) =
177+
Fld_record_inline_set
178+
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
145179

146-
let fld_record_extension_set = ref ( fun (lbl : Types.label_description) ->
147-
Fld_record_extension_set lbl.lbl_name )
180+
let fld_record_extension_set (lbl : label) =
181+
Fld_record_extension_set
182+
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
148183

149184
type immediate_or_pointer =
150185
| Immediate

jscomp/ml/lambda.mli

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,34 @@ type tag_info =
6363
| Blk_record_ext of {fields : string array; mutable_flag : mutable_flag}
6464
| Blk_lazy_general
6565

66+
val find_name :
67+
Parsetree.attribute -> Asttypes.label option
68+
6669
val tag_of_tag_info : tag_info -> int
6770
val mutable_flag_of_tag_info : tag_info -> mutable_flag
68-
val blk_record :
69-
(
70-
(Types.label_description* Typedtree.record_label_definition) array ->
71-
mutable_flag ->
72-
record_repr ->
73-
tag_info
74-
) ref
71+
val blk_record :
72+
(Types.label_description* Typedtree.record_label_definition) array ->
73+
mutable_flag ->
74+
record_repr ->
75+
tag_info
76+
7577

7678
val blk_record_ext :
77-
(
78-
(Types.label_description* Typedtree.record_label_definition) array ->
79-
mutable_flag ->
80-
tag_info
81-
) ref
79+
(Types.label_description* Typedtree.record_label_definition) array ->
80+
mutable_flag ->
81+
tag_info
82+
8283

8384
val blk_record_inlined :
84-
(
85-
(Types.label_description* Typedtree.record_label_definition) array ->
86-
string ->
87-
int ->
88-
string list ->
89-
tag:int ->
90-
attrs:Parsetree.attributes ->
91-
mutable_flag ->
92-
tag_info
93-
) ref
85+
(Types.label_description* Typedtree.record_label_definition) array ->
86+
string ->
87+
int ->
88+
string list ->
89+
tag:int ->
90+
attrs:Parsetree.attributes ->
91+
mutable_flag ->
92+
tag_info
93+
9494

9595

9696

@@ -110,16 +110,16 @@ type field_dbg_info =
110110
| Fld_array
111111

112112
val fld_record :
113-
(Types.label_description ->
114-
field_dbg_info) ref
113+
Types.label_description ->
114+
field_dbg_info
115115

116116
val fld_record_inline :
117-
(Types.label_description ->
118-
field_dbg_info) ref
117+
Types.label_description ->
118+
field_dbg_info
119119

120120
val fld_record_extension :
121-
(Types.label_description ->
122-
field_dbg_info) ref
121+
Types.label_description ->
122+
field_dbg_info
123123

124124
val ref_field_info : field_dbg_info
125125

@@ -133,16 +133,16 @@ type set_field_dbg_info =
133133
val ref_field_set_info : set_field_dbg_info
134134

135135
val fld_record_set :
136-
(Types.label_description ->
137-
set_field_dbg_info) ref
136+
Types.label_description ->
137+
set_field_dbg_info
138138

139139
val fld_record_inline_set :
140-
(Types.label_description ->
141-
set_field_dbg_info) ref
140+
Types.label_description ->
141+
set_field_dbg_info
142142

143143
val fld_record_extension_set :
144-
(Types.label_description ->
145-
set_field_dbg_info) ref
144+
Types.label_description ->
145+
set_field_dbg_info
146146

147147
type immediate_or_pointer =
148148
| Immediate

jscomp/ml/matching.ml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ open Printf
2626

2727
let dbg = false
2828

29-
let find_name (attr : Parsetree.attribute) =
30-
match attr with
31-
| ( { txt = "bs.as" | "as" },
32-
PStr
33-
[
34-
{
35-
pstr_desc =
36-
Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (s, _)) }, _);
37-
};
38-
] ) ->
39-
Some s
40-
| _ -> None
41-
4229
(* See Peyton-Jones, ``The Implementation of functional programming
4330
languages'', chapter 5. *)
4431
(*
@@ -1612,11 +1599,11 @@ let make_record_matching loc all_labels def = function
16121599
match lbl.lbl_repres with
16131600
| Record_float_unused -> assert false
16141601
| Record_regular | Record_optional_labels _ ->
1615-
Lprim (Pfield (lbl.lbl_pos, !Lambda.fld_record lbl), [arg], loc)
1602+
Lprim (Pfield (lbl.lbl_pos, Lambda.fld_record lbl), [arg], loc)
16161603
| Record_inlined _ ->
1617-
Lprim (Pfield (lbl.lbl_pos, !Lambda.fld_record_inline lbl), [arg], loc)
1604+
Lprim (Pfield (lbl.lbl_pos, Lambda.fld_record_inline lbl), [arg], loc)
16181605
| Record_unboxed _ -> arg
1619-
| Record_extension -> Lprim (Pfield (lbl.lbl_pos + 1, !Lambda.fld_record_extension lbl), [arg], loc)
1606+
| Record_extension -> Lprim (Pfield (lbl.lbl_pos + 1, Lambda.fld_record_extension lbl), [arg], loc)
16201607
in
16211608
let str =
16221609
match lbl.lbl_mut with

jscomp/ml/matching.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
open Typedtree
1919
open Lambda
2020

21-
val find_name :
22-
Parsetree.attribute -> Asttypes.label option
23-
2421
val call_switcher_variant_constant :
2522
(Location.t ->
2623
Lambda.lambda option ->

0 commit comments

Comments
 (0)