Skip to content

Commit df7c8a7

Browse files
authored
Merge pull request #11267 from bjorng/bjorn/compiler/use-native-record-types
compiler: Migrate type representation records to native records
2 parents 35f5850 + f2ffa8d commit df7c8a7

22 files changed

Lines changed: 448 additions & 337 deletions

erts/emulator/test/op_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,11 +1006,11 @@ combined_relops(_Config) ->
10061006
{func_info,{atom,?FUNCTION_NAME},{atom,test},1},
10071007
{label,2},
10081008
{test,is_ge,{f,4},
1009-
[{tr,{x,0},{t_integer,{0,1000}}},
1009+
[{tr,{x,0},#beam_types:t_integer{elements={0,1000}}},
10101010
{integer,10}]},
10111011
{test,is_ge,
10121012
{f,3},
1013-
[{tr,{x,0},{t_integer,{0,1000}}},
1013+
[{tr,{x,0},#beam_types:t_integer{elements={0,1000}}},
10141014
{integer,5}]},
10151015
{label,3},
10161016
{move,{atom,a},{x,0}},

erts/emulator/test/tuple_SUITE_data/get_two_tuple_elements.S

Lines changed: 129 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -48,118 +48,182 @@
4848

4949
{function, get_two_tuple_elements, 0, 2}.
5050
{label,1}.
51-
{line,[{location,"get_two_tuple_elements.erl",4}]}.
51+
{line,[{location,"erts/emulator/test/tuple_SUITE_data/get_two_tuple_elements.erl",
52+
26}]}.
5253
{func_info,{atom,get_two_tuple_elements},{atom,get_two_tuple_elements},0}.
5354
{label,2}.
5455
{allocate,2,0}.
5556
{init_yregs,{list,[{y,0},{y,1}]}}.
5657
{move,{atom,x},{x,0}}.
57-
{line,[{location,"get_two_tuple_elements.erl",5}]}.
58-
{call,1,{f,9}}.
59-
{'%',{var_info,{x,0},
60-
[{type,{t_union,{t_atom,[x]},
61-
none,
62-
{t_integer,{1,2}},
63-
none,none,none}}]}}.
58+
{line,[{location,"erts/emulator/test/tuple_SUITE_data/get_two_tuple_elements.erl",
59+
27}]}.
60+
{call,1,{f,9}}. % id/1
61+
{'%',
62+
{var_info,
63+
{x,0},
64+
[{type,
65+
#beam_types:t_union{
66+
atom = #beam_types:t_atom{elements = [x]},
67+
list = none,
68+
number = #beam_types:t_integer{elements = {1,2}},
69+
tuple_set = none,native_record_set = none,
70+
other = none}}]}}.
6471
{move,{x,0},{y,1}}.
6572
{move,{integer,1},{x,0}}.
66-
{line,[{location,"get_two_tuple_elements.erl",5}]}.
67-
{call,1,{f,9}}.
68-
{'%',{var_info,{x,0},
69-
[{type,{t_union,{t_atom,[x]},
70-
none,
71-
{t_integer,{1,2}},
72-
none,none,none}}]}}.
73+
{call,1,{f,9}}. % id/1
74+
{'%',
75+
{var_info,
76+
{x,0},
77+
[{type,
78+
#beam_types:t_union{
79+
atom = #beam_types:t_atom{elements = [x]},
80+
list = none,
81+
number = #beam_types:t_integer{elements = {1,2}},
82+
tuple_set = none,native_record_set = none,
83+
other = none}}]}}.
7384
{move,{x,0},{y,0}}.
7485
{move,{integer,2},{x,0}}.
75-
{line,[{location,"get_two_tuple_elements.erl",5}]}.
76-
{call,1,{f,9}}.
77-
{'%',{var_info,{x,0},
78-
[{type,{t_union,{t_atom,[x]},
79-
none,
80-
{t_integer,{1,2}},
81-
none,none,none}}]}}.
86+
{call,1,{f,9}}. % id/1
87+
{'%',
88+
{var_info,
89+
{x,0},
90+
[{type,
91+
#beam_types:t_union{
92+
atom = #beam_types:t_atom{elements = [x]},
93+
list = none,
94+
number = #beam_types:t_integer{elements = {1,2}},
95+
tuple_set = none,native_record_set = none,
96+
other = none}}]}}.
8297
{test_heap,7,1}.
8398
{put_tuple2,{x,0},{list,[{atom,x},{atom,y},{x,0}]}}.
8499
{put_tuple2,{x,1},{list,[{y,0},{x,0}]}}.
85100
{move,{y,1},{x,0}}.
86101
{trim,2,0}.
87-
{line,[{location,"get_two_tuple_elements.erl",5}]}.
88-
{call,2,{f,5}}.
89-
{'%',{var_info,{x,0},[{type,{t_number,any}}]}}.
90-
{test,is_eq_exact,{f,3},[{x,0},{integer,3}]}.
102+
{call,2,{f,5}}. % xx/2
103+
{'%',{var_info,{x,0},[{type,#beam_types:t_integer{elements = {2,4}}}]}}.
104+
{test,is_eq_exact,
105+
{f,3},
106+
[{tr,{x,0},#beam_types:t_integer{elements = {2,4}}},{integer,3}]}.
91107
{move,{atom,ok},{x,0}}.
92108
{deallocate,0}.
93109
return.
94110
{label,3}.
95-
{line,[{location,"get_two_tuple_elements.erl",5}]}.
96111
{badmatch,{x,0}}.
97112

98113

99114
{function, xx, 2, 5}.
100115
{label,4}.
101-
{line,[{location,"get_two_tuple_elements.erl",8}]}.
116+
{line,[{location,"erts/emulator/test/tuple_SUITE_data/get_two_tuple_elements.erl",
117+
30}]}.
102118
{func_info,{atom,get_two_tuple_elements},{atom,xx},2}.
103119
{label,5}.
104-
{'%',{var_info,{x,0},
105-
[{type,{t_union,{t_atom,[x]},
106-
none,
107-
{t_integer,{1,2}},
108-
none,none,none}}]}}.
120+
{'%',
121+
{var_info,
122+
{x,0},
123+
[{type,
124+
#beam_types:t_union{
125+
atom = #beam_types:t_atom{elements = [x]},
126+
list = none,
127+
number = #beam_types:t_integer{elements = {1,2}},
128+
tuple_set = none,native_record_set = none,
129+
other = none}}]}}.
109130
{'%',
110131
{var_info,
111132
{x,1},
112133
[{type,
113-
{t_tuple,2,true,
114-
#{1 => {t_union,{t_atom,[x]},none,{t_integer,{1,2}},none,none,none},
115-
2 =>
116-
{t_tuple,3,true,
117-
#{1 => {t_atom,[x]},
118-
2 => {t_atom,[y]},
119-
3 =>
120-
{t_union,
121-
{t_atom,[x]},
122-
none,
123-
{t_integer,{1,2}},
124-
none,none,none}}}}}}]}}.
134+
#beam_types:t_tuple{
135+
size = 2,exact = true,
136+
elements =
137+
#{1 =>
138+
#beam_types:t_union{
139+
atom = #beam_types:t_atom{elements = [x]},
140+
list = none,
141+
number = #beam_types:t_integer{elements = {1,2}},
142+
tuple_set = none,native_record_set = none,other = none},
143+
2 =>
144+
#beam_types:t_tuple{
145+
size = 3,exact = true,
146+
elements =
147+
#{1 => #beam_types:t_atom{elements = [x]},
148+
2 => #beam_types:t_atom{elements = [y]},
149+
3 =>
150+
#beam_types:t_union{
151+
atom = #beam_types:t_atom{elements = [x]},
152+
list = none,
153+
number = #beam_types:t_integer{elements = {1,2}},
154+
tuple_set = none,native_record_set = none,
155+
other = none}}}}}}]}}.
125156
{get_tuple_element,{x,1},0,{x,0}}.
126157
{get_tuple_element,{x,1},1,{x,1}}.
127158
{get_tuple_element,{x,1},2,{x,1}}.
128159
{move,nil,{x,2}}.
129-
{call_only,3,{f,7}}.
160+
{call_only,3,{f,7}}. % yy/3
130161

131162

132163
{function, yy, 3, 7}.
133164
{label,6}.
134-
{line,[{location,"get_two_tuple_elements.erl",17}]}.
165+
{line,[{location,"erts/emulator/test/tuple_SUITE_data/get_two_tuple_elements.erl",
166+
39}]}.
135167
{func_info,{atom,get_two_tuple_elements},{atom,yy},3}.
136168
{label,7}.
137-
{'%',{var_info,{x,0},
138-
[{type,{t_union,{t_atom,[x]},
139-
none,
140-
{t_integer,{1,2}},
141-
none,none,none}}]}}.
142-
{'%',{var_info,{x,1},
143-
[{type,{t_union,{t_atom,[x]},
144-
none,
145-
{t_integer,{1,2}},
146-
none,none,none}}]}}.
169+
{'%',
170+
{var_info,
171+
{x,0},
172+
[{type,
173+
#beam_types:t_union{
174+
atom = #beam_types:t_atom{elements = [x]},
175+
list = none,
176+
number = #beam_types:t_integer{elements = {1,2}},
177+
tuple_set = none,native_record_set = none,
178+
other = none}}]}}.
179+
{'%',
180+
{var_info,
181+
{x,1},
182+
[{type,
183+
#beam_types:t_union{
184+
atom = #beam_types:t_atom{elements = [x]},
185+
list = none,
186+
number = #beam_types:t_integer{elements = {1,2}},
187+
tuple_set = none,native_record_set = none,
188+
other = none}}]}}.
147189
{'%',{var_info,{x,2},[{type,nil}]}}.
148-
{line,[{location,"get_two_tuple_elements.erl",18}]}.
149-
{gc_bif,'+',{f,0},2,[{x,0},{x,1}],{x,0}}.
190+
{line,[{location,"erts/emulator/test/tuple_SUITE_data/get_two_tuple_elements.erl",
191+
40}]}.
192+
{gc_bif,'+',
193+
{f,0},
194+
2,
195+
[{tr,{x,0},
196+
#beam_types:t_union{
197+
atom = #beam_types:t_atom{elements = [x]},
198+
list = none,
199+
number = #beam_types:t_integer{elements = {1,2}},
200+
tuple_set = none,native_record_set = none,other = none}},
201+
{tr,{x,1},
202+
#beam_types:t_union{
203+
atom = #beam_types:t_atom{elements = [x]},
204+
list = none,
205+
number = #beam_types:t_integer{elements = {1,2}},
206+
tuple_set = none,native_record_set = none,other = none}}],
207+
{x,0}}.
150208
return.
151209

152210

153211
{function, id, 1, 9}.
154212
{label,8}.
155-
{line,[{location,"get_two_tuple_elements.erl",20}]}.
213+
{line,[{location,"erts/emulator/test/tuple_SUITE_data/get_two_tuple_elements.erl",
214+
42}]}.
156215
{func_info,{atom,get_two_tuple_elements},{atom,id},1}.
157216
{label,9}.
158-
{'%',{var_info,{x,0},
159-
[{type,{t_union,{t_atom,[x]},
160-
none,
161-
{t_integer,{1,2}},
162-
none,none,none}}]}}.
217+
{'%',
218+
{var_info,
219+
{x,0},
220+
[{type,
221+
#beam_types:t_union{
222+
atom = #beam_types:t_atom{elements = [x]},
223+
list = none,
224+
number = #beam_types:t_integer{elements = {1,2}},
225+
tuple_set = none,native_record_set = none,
226+
other = none}}]}}.
163227
return.
164228

165229

@@ -169,7 +233,6 @@
169233
{func_info,{atom,get_two_tuple_elements},{atom,module_info},0}.
170234
{label,11}.
171235
{move,{atom,get_two_tuple_elements},{x,0}}.
172-
{line,[]}.
173236
{call_ext_only,1,{extfunc,erlang,get_module_info,1}}.
174237

175238

@@ -180,5 +243,4 @@
180243
{label,13}.
181244
{move,{x,0},{x,1}}.
182245
{move,{atom,get_two_tuple_elements},{x,0}}.
183-
{line,[]}.
184246
{call_ext_only,2,{extfunc,erlang,get_module_info,2}}.

lib/compiler/src/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ HRL_FILES= \
114114
beam_asm.hrl \
115115
beam_disasm.hrl \
116116
beam_ssa_alias_debug.hrl \
117-
beam_ssa_opt.hrl \
118117
beam_ssa.hrl \
119118
beam_types.hrl \
120119
core_parse.hrl

lib/compiler/src/beam_asm.hrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343
%%
4444
%% To aid in the above, the validator will explode upon encountering them in an
4545
%% unfamiliar context.
46-
-record(tr, {r :: beam_reg(), t :: type()}).
46+
-record(tr, {r :: beam_reg(), t :: beam_types:type()}).

lib/compiler/src/beam_call_types.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
-export([will_succeed/3, types/3, arith_type/2]).
3131

32+
-type type() :: beam_types:type().
33+
-type normal_type() :: beam_types:normal_type().
34+
3235
%%
3336
%% Define an upper limit for functions that return sizes of data
3437
%% structures. The chosen value is about half the maxium size of a

lib/compiler/src/beam_core_to_ssa.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ get_anno(#cg_select{anno=Anno}) -> Anno.
159159
ds :: sets:set(), %Defined variables
160160
funs=[], %Fun functions
161161
free=#{}, %Free variables
162-
rec_defaults :: #{atom() => type()}, %Native records.
162+
rec_defaults :: #{atom() => beam_types:type()}, %Native records.
163163
ws=[] :: [warning()], %Warnings.
164164
beam_debug_info=false :: boolean()
165165
}.
@@ -168,7 +168,10 @@ get_anno(#cg_select{anno=Anno}) -> Anno.
168168
{'ok', #b_module{}, [warning()]}.
169169

170170
module(#c_module{name=#c_literal{val=Mod},exports=Es,attrs=As,defs=Fs}, Options) ->
171-
_ = beam_ssa:module_info(module), %Load modules with records.
171+
%% Load modules with exported native records.
172+
_ = beam_ssa:module_info(module),
173+
_ = beam_ssa_opt:module_info(module),
174+
_ = beam_types:module_info(module),
172175

173176
Records = records(As),
174177
Anno = #{records => Records},

lib/compiler/src/beam_dict.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fname(Name, #asm{fnames=Fnames}=Dict) ->
246246
{Index,Dict#asm{fnames=Fnames#{Name=>Index}}}
247247
end.
248248

249-
-spec type(type(), bdict()) -> {non_neg_integer(), bdict()} | none.
249+
-spec type(beam_types:type(), bdict()) -> {non_neg_integer(), bdict()} | none.
250250

251251
type(Type, #asm{types=Types0}=Dict) ->
252252
ExtType = beam_types:encode_ext(Type),

lib/compiler/src/beam_ssa.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
-type var_name() :: atom() | non_neg_integer().
136136

137137
-type literal_value() :: atom() | integer() | float() | list() |
138-
nil() | tuple() | map() | binary() | fun().
138+
nil() | tuple() | map() | binary() | fun() | record().
139139

140140
-type op() :: {'bif',atom()} |
141141
{'float',float_op()} |

lib/compiler/src/beam_ssa_alias.erl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@
3232
%% information.
3333
-define(MAX_REPETITIONS, 16).
3434

35-
-include("beam_ssa_opt.hrl").
35+
-include("beam_ssa.hrl").
36+
3637
-include("beam_types.hrl").
3738
-include("beam_ssa_alias_debug.hrl").
3839

40+
-type func_id() :: beam_ssa_opt:func_id().
41+
-type func_info_db() :: beam_ssa_opt:func_info_db().
42+
-type st_map() :: beam_ssa_opt:st_map().
43+
44+
-import_record(beam_ssa_opt, [func_info, opt_st]).
45+
3946
-ifdef(DEBUG_ALIAS).
4047
-define(DP(FMT, ARGS), io:format(FMT, ARGS)).
4148
-define(DP(FMT), io:format(FMT)).
@@ -101,7 +108,7 @@ fn(#b_local{name=#b_literal{val=N},arity=A}) ->
101108

102109
-type sharing_state() :: any(). % A graph
103110

104-
-type type_db() :: #{ beam_ssa:b_var() := type() }.
111+
-type type_db() :: #{ beam_ssa:b_var() := beam_types:type() }.
105112

106113
%%%
107114
%%% Optimization pass which calculates the alias status of values and

lib/compiler/src/beam_ssa_bc_size.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@
4242
-export([opt/1]).
4343

4444
-import(lists, [any/2,member/2,reverse/1,sort/1]).
45+
-import_record(beam_ssa_opt, [func_info, opt_st]).
4546

46-
-include("beam_ssa_opt.hrl").
47+
-include("beam_ssa.hrl").
48+
49+
-type st_map() :: beam_ssa_opt:st_map().
4750

4851
-spec opt(st_map()) -> st_map().
4952

0 commit comments

Comments
 (0)