Skip to content

Commit 01160ba

Browse files
committed
add remaining part of melange-re/melange#732
1 parent 6dd6465 commit 01160ba

6 files changed

+78
-0
lines changed

jscomp/core/bs_conditional_initial.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ let setup_env () =
4646
Record_attributes_check.check_duplicated_labels;
4747
Lambda.fld_record := Record_attributes_check.fld_record;
4848
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;
4953
Lambda.blk_record := Record_attributes_check.blk_record;
5054
Lambda.blk_record_inlined := Record_attributes_check.blk_record_inlined;
55+
Lambda.blk_record_ext := Record_attributes_check.blk_record_ext;
5156
Matching.names_from_construct_pattern :=
5257
Matching_polyfill.names_from_construct_pattern;
5358

jscomp/core/record_attributes_check.ml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ let fld_record_set (lbl : label) =
5151
Lambda.Fld_record_set
5252
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
5353

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+
5470
let blk_record (fields : (label * _) array) mut record_repr =
5571
let all_labels_info =
5672
Ext_array.map fields (fun (lbl, _) ->
@@ -59,6 +75,15 @@ let blk_record (fields : (label * _) array) mut record_repr =
5975
Lambda.Blk_record
6076
{ fields = all_labels_info; mutable_flag = mut; record_repr }
6177

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+
6287
let blk_record_inlined fields name num_nonconst optional_labels ~tag ~attrs mutable_flag =
6388
let fields =
6489
Array.map

jscomp/ml/lambda.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ type field_dbg_info =
121121
let fld_record = ref (fun (lbl : Types.label_description) ->
122122
Fld_record {name = lbl.lbl_name; mutable_flag = Mutable})
123123

124+
let fld_record_inline = ref (fun (lbl : Types.label_description) ->
125+
Fld_record_inline {name = lbl.lbl_name})
126+
127+
let fld_record_extension = ref (fun (lbl : Types.label_description) ->
128+
Fld_record_extension {name = lbl.lbl_name})
129+
124130
let ref_field_info : field_dbg_info =
125131
Fld_record { name = "contents"; mutable_flag = Mutable}
126132

@@ -134,6 +140,12 @@ let ref_field_set_info : set_field_dbg_info = Fld_record_set "contents"
134140
let fld_record_set = ref ( fun (lbl : Types.label_description) ->
135141
Fld_record_set lbl.lbl_name )
136142

143+
let fld_record_inline_set = ref ( fun (lbl : Types.label_description) ->
144+
Fld_record_inline_set lbl.lbl_name )
145+
146+
let fld_record_extension_set = ref ( fun (lbl : Types.label_description) ->
147+
Fld_record_extension_set lbl.lbl_name )
148+
137149
type immediate_or_pointer =
138150
| Immediate
139151
| Pointer

jscomp/ml/lambda.mli

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ val fld_record :
113113
(Types.label_description ->
114114
field_dbg_info) ref
115115

116+
val fld_record_inline :
117+
(Types.label_description ->
118+
field_dbg_info) ref
119+
120+
val fld_record_extension :
121+
(Types.label_description ->
122+
field_dbg_info) ref
123+
116124
val ref_field_info : field_dbg_info
117125

118126

@@ -128,6 +136,14 @@ val fld_record_set :
128136
(Types.label_description ->
129137
set_field_dbg_info) ref
130138

139+
val fld_record_inline_set :
140+
(Types.label_description ->
141+
set_field_dbg_info) ref
142+
143+
val fld_record_extension_set :
144+
(Types.label_description ->
145+
set_field_dbg_info) ref
146+
131147
type immediate_or_pointer =
132148
| Immediate
133149
| Pointer

jscomp/test/as_inline_record_test.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/as_inline_record_test.res

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ let getName = t =>
1212
| User({name}) => name
1313
}
1414

15+
let getName' = t =>
16+
switch t {
17+
| User(u) => u.name
18+
}
19+
1520
let getAge = t =>
1621
switch t {
1722
| User({age}) => age
1823
}
24+
25+
let getAge' = t =>
26+
switch t {
27+
| User(u) => u.age
28+
}

0 commit comments

Comments
 (0)