Skip to content

Commit

Permalink
Export oft-used types w/o exposing implementation
Browse files Browse the repository at this point in the history
Export more types that meet these criteria:

- Documented
- Convenient for client code. They are already
used in specs of public functions of their respective
modules.
- These types do not expose implementation details.

The types are:

ets.erl:
- type() :: set | ordered_set | bag | duplicate_bag.

re.erl:
- mp() :: {re_pattern,_ ,_ ,_ ,_ }.*

supervisor.erl:
- `restart() :: 'permanent' | 'transient' | 'temporary'
- `mfargs() :: {M :: module(), F :: atom(), A :: [term()]
   | undefined}.`
- `shutdown() :: 'brutal_kill' | timeout().`

The reason for this change is to fix the status quo, which is
that teams either must:
- copy/pasta the types into client code, leading to code bloat and having
to manually keep the types in sync.
- OR refer to non-exported types, which will mean either more noise
or less accuracy from code analysis tools. For example,
Dialyzer will either warn or treat the types as `term()`.
  • Loading branch information
mheiber committed Jan 20, 2021
1 parent 7b8a8a4 commit d1e9071
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/stdlib/src/ets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

-export([i/0, i/1, i/2, i/3]).

-export_type([tab/0, tid/0, match_spec/0, comp_match_spec/0, match_pattern/0]).
-export_type([tab/0, tid/0, type/0, match_spec/0, comp_match_spec/0, match_pattern/0]).

%%-----------------------------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions lib/stdlib/src/re.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
%%
-module(re).
-export([grun/3,urun/3,ucompile/2,replace/3,replace/4,split/2,split/3]).
-export_type([mp/0]).

-type mp() :: {re_pattern, _, _, _, _}.

Expand Down
7 changes: 4 additions & 3 deletions lib/stdlib/src/supervisor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@

%%--------------------------------------------------------------------------

-export_type([sup_flags/0, child_spec/0, strategy/0,
startchild_ret/0, startchild_err/0,
startlink_ret/0, startlink_err/0]).
-export_type([sup_flags/0, child_spec/0, mfargs/0,
restart/0, strategy/0, startchild_ret/0,
startchild_err/0, startlink_ret/0, startlink_err/0,
shutdown/0]).

%%--------------------------------------------------------------------------

Expand Down

0 comments on commit d1e9071

Please sign in to comment.