Skip to content

Commit 519bcfa

Browse files
mergify[bot]binarinmichaelklishinHoloRin
authored
Fix all dependencies for the dialyzer (backport #7196) (backport #7291) (backport #7295) (#7349)
* 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 (cherry picked from commit 2ae27f2) # Conflicts: # deps/rabbit_common/src/rabbit_misc.erl * Resolve conflicts (cherry picked from commit b205ac9) # Conflicts: # deps/rabbit_common/src/rabbit_misc.erl * Avoid using a type from rabbit in rabbit_common to avoid a dep cycle (cherry picked from commit bca40c6) * Resolved additional errors from merge Leaving MQTT alone, as this branch does not contain #5895, which fixed a great many dialyzer warnings. (cherry picked from commit 3f9e6f9) * fixup merge artifacts * Avoid referencing unexported types from jsx * Additional dialyzer fixes --------- Co-authored-by: Alexey Lebedeff <[email protected]> Co-authored-by: Michael Klishin <[email protected]> Co-authored-by: Rin Kuryloski <[email protected]>
1 parent 133fc55 commit 519bcfa

File tree

29 files changed

+146
-92
lines changed

29 files changed

+146
-92
lines changed

deps/rabbit/BUILD.bazel

Lines changed: 3 additions & 4 deletions
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

@@ -212,7 +213,8 @@ plt(
212213
)
213214

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

@@ -513,9 +515,6 @@ rabbitmq_suite(
513515
additional_srcs = [
514516
"test/mirrored_supervisor_SUITE_gs.erl",
515517
],
516-
deps = [
517-
"//deps/rabbit_common:erlang_app",
518-
],
519518
)
520519

521520
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: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616

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

19-
-export_type([permission_atom/0]).
20-
21-
-type permission_atom() :: 'configure' | 'read' | 'write'.
22-
23-
%%----------------------------------------------------------------------------
24-
2519
-spec check_user_pass_login
2620
(rabbit_types:username(), rabbit_types:password()) ->
2721
{'ok', rabbit_types:user()} |
@@ -179,7 +173,7 @@ create_vhost_access_authz_data(PeerAddr, Context) ->
179173
maps:merge(PeerAddr, Context).
180174

181175
-spec check_resource_access
182-
(rabbit_types:user(), rabbit_types:r(atom()), permission_atom(), rabbit_types:authz_context()) ->
176+
(rabbit_types:user(), rabbit_types:r(atom()), rabbit_types:permission_atom(), rabbit_types:authz_context()) ->
183177
'ok' | rabbit_types:channel_exit().
184178

185179
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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
%%----------------------------------------------------------------------------
2323

2424
-export_type([name/0, type/0]).
25-
26-
-type name() :: rabbit_types:r('exchange').
27-
-type type() :: atom().
25+
-type name() :: rabbit_types:exchange_name().
26+
-type type() :: rabbit_types:exchange_type().
2827
-type fun_name() :: atom().
2928

3029
%%----------------------------------------------------------------------------

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
"@jsx//: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_exchange_type.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
%% The no_return is there so that we can have an "invalid" exchange
2626
%% type (see rabbit_exchange_type_invalid).
2727
-callback route(rabbit_types:exchange(), rabbit_types:delivery()) ->
28-
rabbit_router:match_result().
28+
[rabbit_types:binding_destination()].
2929

3030
%% called BEFORE declaration, to check args etc; may exit with #amqp_error{}
3131
-callback validate(rabbit_types:exchange()) -> 'ok'.

deps/rabbit_common/src/rabbit_json.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ decode(JSON) ->
1818
decode(JSON, ?DEFAULT_DECODE_OPTIONS).
1919

2020

21-
-spec decode(jsx:json_text(), jsx_to_term:config()) -> jsx:json_term().
21+
-spec decode(jsx:json_text(), proplists:proplist()) -> jsx:json_term().
2222
decode(JSON, Opts) ->
2323
jsx:decode(JSON, Opts).
2424

@@ -29,7 +29,7 @@ try_decode(JSON) ->
2929
try_decode(JSON, ?DEFAULT_DECODE_OPTIONS).
3030

3131

32-
-spec try_decode(jsx:json_text(), jsx_to_term:config()) ->
32+
-spec try_decode(jsx:json_text(), proplists:proplist()) ->
3333
{ok, jsx:json_term()} | {error, Reason :: term()}.
3434
try_decode(JSON, Opts) ->
3535
try
@@ -42,7 +42,7 @@ try_decode(JSON, Opts) ->
4242
encode(Term) ->
4343
encode(Term, []).
4444

45-
-spec encode(jsx:json_term(), jsx_to_json:config()) -> jsx:json_text().
45+
-spec encode(jsx:json_term(), proplists:proplist()) -> jsx:json_text().
4646
encode(Term, Opts) ->
4747
jsx:encode(fixup_terms(Term), Opts).
4848

@@ -51,7 +51,7 @@ encode(Term, Opts) ->
5151
try_encode(Term) ->
5252
try_encode(Term, []).
5353

54-
-spec try_encode(jsx:json_term(), jsx_to_term:config()) ->
54+
-spec try_encode(jsx:json_term(), proplists:proplist()) ->
5555
{ok, jsx:json_text()} | {error, Reason :: term()}.
5656
try_encode(Term, Opts) ->
5757
try

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)