aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/beam_types.hrl
blob: 825eca4c64846bea3d08ff47f463ca398a970fec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2019. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%

%% Common term types for passes operating on beam SSA and assembly. Helper
%% functions for wrangling these can be found in beam_types.erl
%%
%% The type lattice is as follows:
%%
%%  any                  Any Erlang term (top element).
%%
%%    - #t_atom{}        Atom, or a set thereof.
%%    - #t_bitstring{}   Bitstring.
%%    - #t_bs_context{}  Match context.
%%    - #t_fun{}         Fun.
%%    - #t_map{}         Map.
%%    - number           Any number.
%%       -- float        Floating point number.
%%       -- integer      Integer.
%%    - list             Any list.
%%       -- cons         Cons (nonempty list).
%%       -- nil          The empty list.
%%    - #t_tuple{}       Tuple.
%%    - #t_abstract{}    Psuedo-type used in the validator to track tuples
%                        under construction, match context positions, etc.
%%
%%  none                 No type (bottom element).

-define(ATOM_SET_SIZE, 5).

-record(t_atom, {elements=any :: 'any' | [atom()]}).
-record(t_fun, {arity=any :: arity() | 'any'}).
-record(t_integer, {elements=any :: 'any' | {integer(),integer()}}).
-record(t_bitstring, {unit=1 :: pos_integer()}).
-record(t_bs_context, {slots=0 :: non_neg_integer(),
                       valid=0 :: non_neg_integer()}).
-record(t_map, {elements=#{} :: map_elements()}).
-record(t_tuple, {size=0 :: integer(),
                  exact=false :: boolean(),
                  elements=#{} :: tuple_elements()}).
-record(t_abstract, {kind :: atom()}).

%% Known element types, unknown elements are assumed to be 'any'. The key is
%% a 1-based integer index for tuples, and a plain literal for maps (that is,
%% not wrapped in a #b_literal{}, just the value itself).

-type tuple_elements() :: #{ Key :: pos_integer() => type() }.
-type map_elements() :: #{ Key :: term() => type() }.

-type elements() :: tuple_elements() | map_elements().

-type type() :: any | none |
                list | number |
                #t_atom{} | #t_bitstring{} | #t_bs_context{} | #t_fun{} |
                #t_integer{} | #t_map{} | #t_tuple{} | #t_abstract{} |
                'cons' | 'float' | 'nil'.