Skip to content

Commit 2ae27f2

Browse files
binarinmergify[bot]
authored andcommitted
Fix all dependencies for the dialyzer
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. (cherry picked from commit 949b535) (cherry picked from commit 3a3ff30) # Conflicts: # deps/rabbit/BUILD.bazel # deps/rabbit/src/rabbit_access_control.erl # deps/rabbit/src/rabbit_exchange.erl # deps/rabbit_common/src/rabbit_misc.erl # deps/rabbitmq_consistent_hash_exchange/BUILD.bazel # deps/rabbitmq_mqtt/BUILD.bazel
1 parent 0784b02 commit 2ae27f2

File tree

27 files changed

+177
-72
lines changed

27 files changed

+177
-72
lines changed

deps/rabbit/BUILD.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ load(
1010
"rabbitmq_integration_suite",
1111
"rabbitmq_suite",
1212
"rabbitmq_test_helper",
13+
"without",
1314
)
1415
load(":bats.bzl", "bats")
1516

@@ -213,7 +214,8 @@ plt(
213214
)
214215

215216
dialyze(
216-
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
217+
# A few `lg` functions are unknown
218+
dialyzer_opts = without("-Wunknown", RABBITMQ_DIALYZER_OPTS),
217219
plt = ":base_plt",
218220
)
219221

@@ -519,9 +521,12 @@ rabbitmq_suite(
519521
additional_srcs = [
520522
"test/mirrored_supervisor_SUITE_gs.erl",
521523
],
524+
<<<<<<< HEAD
522525
deps = [
523526
"//deps/rabbit_common:erlang_app",
524527
],
528+
=======
529+
>>>>>>> 3a3ff308aa (Fix all dependencies for the dialyzer)
525530
)
526531

527532
rabbitmq_suite(

deps/rabbit/apps/rabbitmq_prelaunch/BUILD.bazel

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ load("@rules_erlang//:xref2.bzl", "xref")
22
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
33
load(
44
"//:rabbitmq.bzl",
5-
"RABBITMQ_DIALYZER_OPTS",
65
"APP_VERSION",
6+
"RABBITMQ_DIALYZER_OPTS",
77
"rabbitmq_app",
88
"rabbitmq_suite",
99
)
@@ -41,7 +41,10 @@ xref(
4141

4242
plt(
4343
name = "base_plt",
44-
apps = ["runtime_tools", "eunit"],
44+
apps = [
45+
"runtime_tools",
46+
"eunit",
47+
],
4548
plt = "//:base_plt",
4649
deps = DEPS + RUNTIME_DEPS + [
4750
"@systemd//:erlang_app",
@@ -50,8 +53,8 @@ plt(
5053
)
5154

5255
dialyze(
53-
plt = ":base_plt",
5456
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
57+
plt = ":base_plt",
5558
)
5659

5760
suites = [

deps/rabbit/src/rabbit_access_control.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
%%----------------------------------------------------------------------------
1818

19+
<<<<<<< HEAD
1920
-export_type([permission_atom/0]).
2021

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

2324
%%----------------------------------------------------------------------------
2425

26+
=======
27+
>>>>>>> 3a3ff308aa (Fix all dependencies for the dialyzer)
2528
-spec check_user_pass_login
2629
(rabbit_types:username(), rabbit_types:password()) ->
2730
{'ok', rabbit_types:user()} |
@@ -179,7 +182,7 @@ create_vhost_access_authz_data(PeerAddr, Context) ->
179182
maps:merge(PeerAddr, Context).
180183

181184
-spec check_resource_access
182-
(rabbit_types:user(), rabbit_types:r(atom()), permission_atom(), rabbit_types:authz_context()) ->
185+
(rabbit_types:user(), rabbit_types:r(atom()), rabbit_types:permission_atom(), rabbit_types:authz_context()) ->
183186
'ok' | rabbit_types:channel_exit().
184187

185188
check_resource_access(User, R = #resource{kind = exchange, name = <<"">>},

deps/rabbit/src/rabbit_channel.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227

228228
-export_type([channel_number/0]).
229229

230-
-type channel_number() :: non_neg_integer().
230+
-type channel_number() :: rabbit_types:channel_number().
231231

232232
-export_type([channel/0]).
233233

deps/rabbit/src/rabbit_exchange.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222
%%----------------------------------------------------------------------------
2323

2424
-export_type([name/0, type/0]).
25+
<<<<<<< HEAD
2526

2627
-type name() :: rabbit_types:r('exchange').
2728
-type type() :: atom().
29+
=======
30+
-type name() :: rabbit_types:exchange_name().
31+
-type type() :: rabbit_types:exchange_type().
32+
>>>>>>> 3a3ff308aa (Fix all dependencies for the dialyzer)
2833
-type fun_name() :: atom().
2934

3035
%%----------------------------------------------------------------------------

deps/rabbit/src/rabbit_guid.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
-export_type([guid/0]).
2727

28-
-type guid() :: binary().
28+
-type guid() :: rabbit_types:guid().
2929

3030
%%----------------------------------------------------------------------------
3131

deps/rabbit/src/rabbit_router.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

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

18-
-type routing_key() :: binary().
18+
-type routing_key() :: rabbit_types:routing_key().
1919
-type match_result() :: [rabbit_types:binding_destination()].
2020

2121
%%----------------------------------------------------------------------------

deps/rabbit/src/vhost.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
-define(record_version, vhost_v2).
3636

37-
-type(name() :: binary()).
37+
-type(name() :: rabbit_types:vhost()).
3838

3939
-type(metadata_key() :: atom()).
4040

deps/rabbit_common/BUILD.bazel

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load("@rules_erlang//:xref2.bzl", "xref")
22
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
33
load(
44
"//:rabbitmq.bzl",
5+
"RABBITMQ_DIALYZER_OPTS",
56
"assert_suites",
67
"rabbitmq_app",
78
"rabbitmq_suite",
@@ -55,6 +56,7 @@ RUNTIME_DEPS = [
5556
"@thoas//:erlang_app",
5657
"@recon//:erlang_app",
5758
"@credentials_obfuscation//:erlang_app",
59+
"@ranch//:erlang_app",
5860
]
5961

6062
APP_NAME = "rabbit_common"
@@ -89,6 +91,8 @@ EXTRA_APPS = [
8991
"syntax_tools",
9092
"tools",
9193
"xmerl",
94+
"runtime_tools",
95+
"os_mon",
9296
]
9397

9498
rabbitmq_app(
@@ -106,23 +110,17 @@ rabbitmq_app(
106110
runtime_deps = RUNTIME_DEPS,
107111
)
108112

109-
xref(
110-
additional_libs = [
111-
"@ranch//:erlang_app",
112-
],
113-
)
113+
xref()
114114

115115
plt(
116116
name = "base_plt",
117-
apps = [
118-
"mnesia",
119-
"crypto",
120-
"ssl",
121-
] + EXTRA_APPS,
117+
apps = EXTRA_APPS + ["mnesia"],
122118
plt = "//:base_plt",
119+
deps = RUNTIME_DEPS,
123120
)
124121

125122
dialyze(
123+
dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
126124
plt = ":base_plt",
127125
)
128126

deps/rabbit_common/src/rabbit_authz_backend.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
%% Something went wrong. Log and die.
5151
-callback check_resource_access(rabbit_types:auth_user(),
5252
rabbit_types:r(atom()),
53-
rabbit_access_control:permission_atom(),
53+
rabbit_types:permission_atom(),
5454
rabbit_types:authz_context()) ->
5555
boolean() | {'error', any()}.
5656

@@ -63,7 +63,7 @@
6363
%% Something went wrong. Log and die.
6464
-callback check_topic_access(rabbit_types:auth_user(),
6565
rabbit_types:r(atom()),
66-
rabbit_access_control:permission_atom(),
66+
rabbit_types:permission_atom(),
6767
rabbit_types:topic_access_context()) ->
6868
boolean() | {'error', any()}.
6969

deps/rabbit_common/src/rabbit_binary_generator.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
-type frame() :: [binary()].
2323

2424
-spec build_simple_method_frame
25-
(rabbit_channel:channel_number(), rabbit_framing:amqp_method_record(),
25+
(rabbit_types:channel_number(), rabbit_framing:amqp_method_record(),
2626
rabbit_types:protocol()) ->
2727
frame().
2828
-spec build_simple_content_frames
29-
(rabbit_channel:channel_number(), rabbit_types:content(),
29+
(rabbit_types:channel_number(), rabbit_types:content(),
3030
non_neg_integer(), rabbit_types:protocol()) ->
3131
[frame()].
3232
-spec build_heartbeat_frame() -> frame().
@@ -39,9 +39,9 @@
3939
(rabbit_types:content()) ->
4040
rabbit_types:unencoded_content().
4141
-spec map_exception
42-
(rabbit_channel:channel_number(), rabbit_types:amqp_error() | any(),
42+
(rabbit_types:channel_number(), rabbit_types:amqp_error() | any(),
4343
rabbit_types:protocol()) ->
44-
{rabbit_channel:channel_number(),
44+
{rabbit_types:channel_number(),
4545
rabbit_framing:amqp_method_record()}.
4646

4747
%%----------------------------------------------------------------------------

deps/rabbit_common/src/rabbit_core_metrics.erl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
%%----------------------------------------------------------------------------
6060
-type(channel_stats_id() :: pid() |
6161
{pid(),
62-
{rabbit_amqqueue:name(), rabbit_exchange:name()}} |
63-
{pid(), rabbit_amqqueue:name()} |
64-
{pid(), rabbit_exchange:name()}).
62+
{rabbit_types:rabbit_amqqueue_name(), rabbit_types:exchange_name()}} |
63+
{pid(), rabbit_types:rabbit_amqqueue_name()} |
64+
{pid(), rabbit_types:exchange_name()}).
6565

6666
-type(channel_stats_type() :: queue_exchange_stats | queue_stats |
6767
exchange_stats | reductions).
@@ -80,17 +80,17 @@
8080
-spec channel_stats(pid(), rabbit_types:infos()) -> ok.
8181
-spec channel_stats(channel_stats_type(), channel_stats_id(),
8282
rabbit_types:infos() | integer()) -> ok.
83-
-spec channel_queue_down({pid(), rabbit_amqqueue:name()}) -> ok.
84-
-spec channel_queue_exchange_down({pid(), {rabbit_amqqueue:name(),
85-
rabbit_exchange:name()}}) -> ok.
86-
-spec channel_exchange_down({pid(), rabbit_exchange:name()}) -> ok.
83+
-spec channel_queue_down({pid(), rabbit_types:rabbit_amqqueue_name()}) -> ok.
84+
-spec channel_queue_exchange_down({pid(), {rabbit_types:rabbit_amqqueue_name(),
85+
rabbit_types:exchange_name()}}) -> ok.
86+
-spec channel_exchange_down({pid(), rabbit_types:exchange_name()}) -> ok.
8787
-spec consumer_created(pid(), binary(), boolean(), boolean(),
88-
rabbit_amqqueue:name(), integer(), boolean(), activity_status(), list()) -> ok.
88+
rabbit_types:rabbit_amqqueue_name(), integer(), boolean(), activity_status(), list()) -> ok.
8989
-spec consumer_updated(pid(), binary(), boolean(), boolean(),
90-
rabbit_amqqueue:name(), integer(), boolean(), activity_status(), list()) -> ok.
91-
-spec consumer_deleted(pid(), binary(), rabbit_amqqueue:name()) -> ok.
92-
-spec queue_stats(rabbit_amqqueue:name(), rabbit_types:infos()) -> ok.
93-
-spec queue_stats(rabbit_amqqueue:name(), integer(), integer(), integer(),
90+
rabbit_types:rabbit_amqqueue_name(), integer(), boolean(), activity_status(), list()) -> ok.
91+
-spec consumer_deleted(pid(), binary(), rabbit_types:rabbit_amqqueue_name()) -> ok.
92+
-spec queue_stats(rabbit_types:rabbit_amqqueue_name(), rabbit_types:infos()) -> ok.
93+
-spec queue_stats(rabbit_types:rabbit_amqqueue_name(), integer(), integer(), integer(),
9494
integer()) -> ok.
9595
-spec node_stats(atom(), rabbit_types:infos()) -> ok.
9696
-spec node_node_stats({node(), node()}, rabbit_types:infos()) -> ok.

deps/rabbit_common/src/rabbit_misc.erl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,25 @@ is_regular_file(Name) ->
14501450
_ -> false
14511451
end.
14521452

1453+
<<<<<<< HEAD
1454+
=======
1455+
%% not exported by supervisor
1456+
-type supervisor_child_id() :: term().
1457+
-type supervisor_sup_ref() :: (Name :: atom())
1458+
| {Name :: atom(), Node :: node()}
1459+
| {'global', Name :: atom()}
1460+
| {'via', Module :: module(), Name :: any()}
1461+
| pid().
1462+
1463+
%% this used to be in supervisor2
1464+
-spec find_child(Supervisor, Name) -> [pid()] when
1465+
Supervisor :: supervisor_sup_ref(),
1466+
Name :: supervisor_child_id().
1467+
find_child(Supervisor, Name) ->
1468+
[Pid || {Name1, Pid, _Type, _Modules} <- supervisor:which_children(Supervisor),
1469+
Name1 =:= Name].
1470+
1471+
>>>>>>> 3a3ff308aa (Fix all dependencies for the dialyzer)
14531472
%% -------------------------------------------------------------------------
14541473
%% Begin copypasta from gen_server2.erl
14551474

deps/rabbit_common/src/rabbit_net.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
{raw, non_neg_integer(), non_neg_integer(), binary()}].
3333
-type hostname() :: inet:hostname().
3434
-type ip_port() :: inet:port_number().
35+
-type rabbit_proxy_socket() :: {'rabbit_proxy_socket', ranch_transport:socket(), ranch_proxy_header:proxy_info()}.
3536
% -type host_or_ip() :: binary() | inet:ip_address().
3637
-spec is_ssl(socket()) -> boolean().
3738
-spec ssl_info(socket()) -> 'nossl' | ok_val_or_error([{atom(), any()}]).
38-
-spec proxy_ssl_info(socket(), ranch_proxy:proxy_socket()) -> 'nossl' | ok_val_or_error([{atom(), any()}]).
39+
-spec proxy_ssl_info(socket(), rabbit_proxy_socket() | 'undefined') -> 'nossl' | ok_val_or_error([{atom(), any()}]).
3940
-spec controlling_process(socket(), pid()) -> ok_or_any_error().
4041
-spec getstat(socket(), [stat_option()]) ->
4142
ok_val_or_error([{stat_option(), integer()}]).
@@ -65,7 +66,7 @@
6566
-spec peername(socket()) ->
6667
ok_val_or_error({inet:ip_address(), ip_port()}).
6768
-spec peercert(socket()) ->
68-
'nossl' | ok_val_or_error(rabbit_ssl:certificate()).
69+
'nossl' | ok_val_or_error(rabbit_cert_info:certificate()).
6970
-spec connection_string(socket(), 'inbound' | 'outbound') ->
7071
ok_val_or_error(string()).
7172
% -spec socket_ends(socket() | ranch_proxy:proxy_socket() | ranch_proxy_ssl:ssl_socket(),

0 commit comments

Comments
 (0)