Skip to content

Commit

Permalink
Fix all dependencies for the dialyzer
Browse files Browse the repository at this point in the history
This is the latest commit in the series, it fixes (almost) all the
problems with missing and circular dependencies for typing.

The only 2 unsolved problems are:

- `lg` dependency for `rabbit` - the problem is that it's the only
  dependency that contains NIF. And there is no way to make dialyzer
  ignore it - looks like unknown check is not suppressable by dialyzer
  directives. In the future making `lg` a proper dependency can be a
  good thing anyway.

- some missing elixir function in `rabbitmq_cli` (CSV, JSON and
  logging related).

- `eetcd` dependency for `rabbitmq_peer_discovery_etcd` - this one
  uses sub-directories in `src/`, which confuses dialyzer (or our bazel
  machinery is not able to properly handle it). I've tried the latest
  rules_erlang which flattens directory for .beam files, but it wasn't
  enough for dialyzer - it wasn't able to find core erlang files. This
  is a niche plugin and an unusual dependency, so probably not worth
  investigating further.
  • Loading branch information
binarin committed Feb 13, 2023
1 parent f47c7cb commit 949b535
Show file tree
Hide file tree
Showing 27 changed files with 154 additions and 83 deletions.
6 changes: 4 additions & 2 deletions deps/rabbit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ load(
"rabbitmq_integration_suite",
"rabbitmq_suite",
"rabbitmq_test_helper",
"without",
)
load(":bats.bzl", "bats")

Expand Down Expand Up @@ -213,7 +214,8 @@ plt(
)

dialyze(
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
# A few `lg` functions are unknown
dialyzer_opts = without("-Wunknown", RABBITMQ_DIALYZER_OPTS),
plt = ":base_plt",
)

Expand Down Expand Up @@ -518,7 +520,7 @@ rabbitmq_integration_suite(
size = "small",
additional_srcs = [
"test/mirrored_supervisor_SUITE_gs.erl",
]
],
)

rabbitmq_suite(
Expand Down
9 changes: 6 additions & 3 deletions deps/rabbit/apps/rabbitmq_prelaunch/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ load("@rules_erlang//:xref2.bzl", "xref")
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
load(
"//:rabbitmq.bzl",
"RABBITMQ_DIALYZER_OPTS",
"APP_VERSION",
"RABBITMQ_DIALYZER_OPTS",
"rabbitmq_app",
"rabbitmq_suite",
)
Expand Down Expand Up @@ -41,7 +41,10 @@ xref(

plt(
name = "base_plt",
apps = ["runtime_tools", "eunit"],
apps = [
"runtime_tools",
"eunit",
],
plt = "//:base_plt",
deps = DEPS + RUNTIME_DEPS + [
"@systemd//:erlang_app",
Expand All @@ -50,8 +53,8 @@ plt(
)

dialyze(
plt = ":base_plt",
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
plt = ":base_plt",
)

suites = [
Expand Down
8 changes: 1 addition & 7 deletions deps/rabbit/src/rabbit_access_control.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@

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

-export_type([permission_atom/0]).

-type permission_atom() :: 'configure' | 'write' | 'read'.

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

-spec check_user_pass_login
(rabbit_types:username(), rabbit_types:password()) ->
{'ok', rabbit_types:user()} |
Expand Down Expand Up @@ -179,7 +173,7 @@ create_vhost_access_authz_data(PeerAddr, Context) ->
maps:merge(PeerAddr, Context).

-spec check_resource_access
(rabbit_types:user(), rabbit_types:r(atom()), permission_atom(), rabbit_types:authz_context()) ->
(rabbit_types:user(), rabbit_types:r(atom()), rabbit_types:permission_atom(), rabbit_types:authz_context()) ->
'ok' | rabbit_types:channel_exit().

check_resource_access(User, R = #resource{kind = exchange, name = <<"">>},
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@

-export_type([channel_number/0]).

-type channel_number() :: non_neg_integer().
-type channel_number() :: rabbit_types:channel_number().

-export_type([channel/0]).

Expand Down
4 changes: 2 additions & 2 deletions deps/rabbit/src/rabbit_exchange.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
%%----------------------------------------------------------------------------

-export_type([name/0, type/0]).
-type name() :: rabbit_types:r('exchange').
-type type() :: atom().
-type name() :: rabbit_types:exchange_name().
-type type() :: rabbit_types:exchange_type().
-type fun_name() :: atom().

%%----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_guid.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

-export_type([guid/0]).

-type guid() :: binary().
-type guid() :: rabbit_types:guid().

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

Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_router.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

-export_type([routing_key/0, match_result/0]).

-type routing_key() :: binary().
-type routing_key() :: rabbit_types:routing_key().
-type match_result() :: [rabbit_types:binding_destination()].

%%----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/src/vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

-define(record_version, vhost_v2).

-type(name() :: binary()).
-type(name() :: rabbit_types:vhost()).

-type(limits() :: list()).

Expand Down
18 changes: 8 additions & 10 deletions deps/rabbit_common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ load("@rules_erlang//:xref2.bzl", "xref")
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
load(
"//:rabbitmq.bzl",
"RABBITMQ_DIALYZER_OPTS",
"assert_suites",
"rabbitmq_app",
"rabbitmq_suite",
Expand Down Expand Up @@ -55,6 +56,7 @@ RUNTIME_DEPS = [
"@thoas//:erlang_app",
"@recon//:erlang_app",
"@credentials_obfuscation//:erlang_app",
"@ranch//:erlang_app",
]

APP_NAME = "rabbit_common"
Expand Down Expand Up @@ -89,6 +91,8 @@ EXTRA_APPS = [
"syntax_tools",
"tools",
"xmerl",
"runtime_tools",
"os_mon",
]

rabbitmq_app(
Expand All @@ -106,23 +110,17 @@ rabbitmq_app(
runtime_deps = RUNTIME_DEPS,
)

xref(
additional_libs = [
"@ranch//:erlang_app",
],
)
xref()

plt(
name = "base_plt",
apps = [
"mnesia",
"crypto",
"ssl",
] + EXTRA_APPS,
apps = EXTRA_APPS + ["mnesia"],
plt = "//:base_plt",
deps = RUNTIME_DEPS,
)

dialyze(
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
plt = ":base_plt",
)

Expand Down
4 changes: 2 additions & 2 deletions deps/rabbit_common/src/rabbit_authz_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
%% Something went wrong. Log and die.
-callback check_resource_access(rabbit_types:auth_user(),
rabbit_types:r(atom()),
rabbit_access_control:permission_atom(),
rabbit_types:permission_atom(),
rabbit_types:authz_context()) ->
boolean() | {'error', any()}.

Expand All @@ -63,7 +63,7 @@
%% Something went wrong. Log and die.
-callback check_topic_access(rabbit_types:auth_user(),
rabbit_types:r(atom()),
rabbit_access_control:permission_atom(),
rabbit_types:permission_atom(),
rabbit_types:topic_access_context()) ->
boolean() | {'error', any()}.

Expand Down
8 changes: 4 additions & 4 deletions deps/rabbit_common/src/rabbit_binary_generator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
-type frame() :: [binary()].

-spec build_simple_method_frame
(rabbit_channel:channel_number(), rabbit_framing:amqp_method_record(),
(rabbit_types:channel_number(), rabbit_framing:amqp_method_record(),
rabbit_types:protocol()) ->
frame().
-spec build_simple_content_frames
(rabbit_channel:channel_number(), rabbit_types:content(),
(rabbit_types:channel_number(), rabbit_types:content(),
non_neg_integer(), rabbit_types:protocol()) ->
[frame()].
-spec build_heartbeat_frame() -> frame().
Expand All @@ -39,9 +39,9 @@
(rabbit_types:content()) ->
rabbit_types:unencoded_content().
-spec map_exception
(rabbit_channel:channel_number(), rabbit_types:amqp_error() | any(),
(rabbit_types:channel_number(), rabbit_types:amqp_error() | any(),
rabbit_types:protocol()) ->
{rabbit_channel:channel_number(),
{rabbit_types:channel_number(),
rabbit_framing:amqp_method_record()}.

%%----------------------------------------------------------------------------
Expand Down
24 changes: 12 additions & 12 deletions deps/rabbit_common/src/rabbit_core_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
%%----------------------------------------------------------------------------
-type(channel_stats_id() :: pid() |
{pid(),
{rabbit_amqqueue:name(), rabbit_exchange:name()}} |
{pid(), rabbit_amqqueue:name()} |
{pid(), rabbit_exchange:name()}).
{rabbit_types:rabbit_amqqueue_name(), rabbit_types:exchange_name()}} |
{pid(), rabbit_types:rabbit_amqqueue_name()} |
{pid(), rabbit_types:exchange_name()}).

-type(channel_stats_type() :: queue_exchange_stats | queue_stats |
exchange_stats | reductions).
Expand All @@ -80,17 +80,17 @@
-spec channel_stats(pid(), rabbit_types:infos()) -> ok.
-spec channel_stats(channel_stats_type(), channel_stats_id(),
rabbit_types:infos() | integer()) -> ok.
-spec channel_queue_down({pid(), rabbit_amqqueue:name()}) -> ok.
-spec channel_queue_exchange_down({pid(), {rabbit_amqqueue:name(),
rabbit_exchange:name()}}) -> ok.
-spec channel_exchange_down({pid(), rabbit_exchange:name()}) -> ok.
-spec channel_queue_down({pid(), rabbit_types:rabbit_amqqueue_name()}) -> ok.
-spec channel_queue_exchange_down({pid(), {rabbit_types:rabbit_amqqueue_name(),
rabbit_types:exchange_name()}}) -> ok.
-spec channel_exchange_down({pid(), rabbit_types:exchange_name()}) -> ok.
-spec consumer_created(pid(), binary(), boolean(), boolean(),
rabbit_amqqueue:name(), integer(), boolean(), activity_status(), list()) -> ok.
rabbit_types:rabbit_amqqueue_name(), integer(), boolean(), activity_status(), list()) -> ok.
-spec consumer_updated(pid(), binary(), boolean(), boolean(),
rabbit_amqqueue:name(), integer(), boolean(), activity_status(), list()) -> ok.
-spec consumer_deleted(pid(), binary(), rabbit_amqqueue:name()) -> ok.
-spec queue_stats(rabbit_amqqueue:name(), rabbit_types:infos()) -> ok.
-spec queue_stats(rabbit_amqqueue:name(), integer(), integer(), integer(),
rabbit_types:rabbit_amqqueue_name(), integer(), boolean(), activity_status(), list()) -> ok.
-spec consumer_deleted(pid(), binary(), rabbit_types:rabbit_amqqueue_name()) -> ok.
-spec queue_stats(rabbit_types:rabbit_amqqueue_name(), rabbit_types:infos()) -> ok.
-spec queue_stats(rabbit_types:rabbit_amqqueue_name(), integer(), integer(), integer(),
integer()) -> ok.
-spec node_stats(atom(), rabbit_types:infos()) -> ok.
-spec node_node_stats({node(), node()}, rabbit_types:infos()) -> ok.
Expand Down
File renamed without changes.
12 changes: 10 additions & 2 deletions deps/rabbit_common/src/rabbit_misc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1319,10 +1319,18 @@ is_regular_file(Name) ->
_ -> false
end.

%% not exported by supervisor
-type supervisor_child_id() :: term().
-type supervisor_sup_ref() :: (Name :: atom())
| {Name :: atom(), Node :: node()}
| {'global', Name :: atom()}
| {'via', Module :: module(), Name :: any()}
| pid().

%% this used to be in supervisor2
-spec find_child(Supervisor, Name) -> [pid()] when
Supervisor :: supervisor:sup_ref(),
Name :: supervisor:child_id().
Supervisor :: supervisor_sup_ref(),
Name :: supervisor_child_id().
find_child(Supervisor, Name) ->
[Pid || {Name1, Pid, _Type, _Modules} <- supervisor:which_children(Supervisor),
Name1 =:= Name].
Expand Down
5 changes: 3 additions & 2 deletions deps/rabbit_common/src/rabbit_net.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
{raw, non_neg_integer(), non_neg_integer(), binary()}].
-type hostname() :: inet:hostname().
-type ip_port() :: inet:port_number().
-type rabbit_proxy_socket() :: {'rabbit_proxy_socket', ranch_transport:socket(), ranch_proxy_header:proxy_info()}.
% -type host_or_ip() :: binary() | inet:ip_address().
-spec is_ssl(socket()) -> boolean().
-spec ssl_info(socket()) -> 'nossl' | ok_val_or_error([{atom(), any()}]).
-spec proxy_ssl_info(socket(), ranch_proxy:proxy_socket()) -> 'nossl' | ok_val_or_error([{atom(), any()}]).
-spec proxy_ssl_info(socket(), rabbit_proxy_socket() | 'undefined') -> 'nossl' | ok_val_or_error([{atom(), any()}]).
-spec controlling_process(socket(), pid()) -> ok_or_any_error().
-spec getstat(socket(), [stat_option()]) ->
ok_val_or_error([{stat_option(), integer()}]).
Expand Down Expand Up @@ -65,7 +66,7 @@
-spec peername(socket()) ->
ok_val_or_error({inet:ip_address(), ip_port()}).
-spec peercert(socket()) ->
'nossl' | ok_val_or_error(rabbit_ssl:certificate()).
'nossl' | ok_val_or_error(rabbit_cert_info:certificate()).
-spec connection_string(socket(), 'inbound' | 'outbound') ->
ok_val_or_error(string()).
% -spec socket_ends(socket() | ranch_proxy:proxy_socket() | ranch_proxy_ssl:ssl_socket(),
Expand Down
Loading

0 comments on commit 949b535

Please sign in to comment.