37
37
-on_load (on_load / 0 ).
38
38
-endif .
39
39
40
- % % Initially, is_registry_initialized/0 always returns false and this `Call'
41
- % % is always called. The case statement is here to convince Dialyzer that the
42
- % % function could return values of type `__ReturnedIfUninitialized' or
40
+ % % In this registry stub, most functions want to return `init_required' to let
41
+ % % {@link rabbit_ff_registry_wrapper} do the first time initialization.
42
+ % %
43
+ % % The inner case statement is here to convince Dialyzer that the function
44
+ % % could return values of type `__ReturnedIfUninitialized' or
43
45
% % `__NeverReturned'.
44
46
% %
45
47
% % If the function was only calling itself (`Call'), Dialyzer would consider
46
- % % that it would never return.
48
+ % % that it would never return. With the outer case, Dialyzer would conclude
49
+ % % that `__ReturnedIfUninitialized' is always returned and other values will
50
+ % % never be returned and there is no point in expecting them.
47
51
% %
48
- % % With just `is_registry_initialized()' case, Dialyzer would conclude that
49
- % % `__ReturnedIfUninitialized' is always returned and other values will never
50
- % % be returned and there is no point in expecting them .
52
+ % % In the end, `Call' is never executed because {@link
53
+ % % rabbit_ff_registry_wrapper} is responsible for calling the registry
54
+ % % function again after initialization .
51
55
% %
52
56
% % With both cases in place, it seems that we can convince Dialyzer that the
53
57
% % function returns values matching its spec.
54
58
-define (convince_dialyzer (__Call , __ReturnedIfUninitialized , __NeverReturned ),
55
- case is_registry_initialized () of
59
+ case always_return_true () of
56
60
false ->
57
61
__Call ;
58
62
true ->
62
66
end
63
67
end ).
64
68
65
- -spec get (rabbit_feature_flags :feature_name ()) ->
66
- rabbit_feature_flags :feature_props_extended () | undefined .
69
+ -spec get (FeatureName ) -> Ret when
70
+ FeatureName :: rabbit_feature_flags :feature_name (),
71
+ Ret :: FeatureProps | init_required ,
72
+ FeatureProps :: rabbit_feature_flags :feature_props_extended () |
73
+ undefined .
67
74
% % @doc
68
75
% % Returns the properties of a feature flag.
69
76
% %
74
81
% % @returns the properties of the specified feature flag.
75
82
76
83
get (FeatureName ) ->
77
- _ = rabbit_ff_registry_factory :initialize_registry (),
78
84
? convince_dialyzer (
79
85
? MODULE :get (FeatureName ),
80
- undefined ,
86
+ init_required ,
81
87
#{provided_by => rabbit }).
82
88
83
- -spec list (all | enabled | disabled ) -> rabbit_feature_flags :feature_flags ().
89
+ -spec list (Which ) -> Ret when
90
+ Which :: all | enabled | disabled ,
91
+ Ret :: FeatureFlags | init_required ,
92
+ FeatureFlags :: rabbit_feature_flags :feature_flags ().
84
93
% % @doc
85
94
% % Lists all, enabled or disabled feature flags, depending on the argument.
86
95
% %
@@ -92,10 +101,11 @@ get(FeatureName) ->
92
101
% % @returns A map of selected feature flags.
93
102
94
103
list (Which ) ->
95
- _ = rabbit_ff_registry_factory :initialize_registry (),
96
- ? convince_dialyzer (? MODULE :list (Which ), #{}, #{}).
104
+ ? convince_dialyzer (? MODULE :list (Which ), init_required , #{}).
97
105
98
- -spec states () -> rabbit_feature_flags :feature_states ().
106
+ -spec states () -> Ret when
107
+ Ret :: FeatureStates | init_required ,
108
+ FeatureStates :: rabbit_feature_flags :feature_states ().
99
109
% % @doc
100
110
% % Returns the states of supported feature flags.
101
111
% %
@@ -105,10 +115,12 @@ list(Which) ->
105
115
% % @returns A map of feature flag states.
106
116
107
117
states () ->
108
- _ = rabbit_ff_registry_factory :initialize_registry (),
109
- ? convince_dialyzer (? MODULE :states (), #{}, #{}).
118
+ ? convince_dialyzer (? MODULE :states (), init_required , #{}).
110
119
111
- -spec is_supported (rabbit_feature_flags :feature_name ()) -> boolean ().
120
+ -spec is_supported (FeatureName ) -> Ret when
121
+ FeatureName :: rabbit_feature_flags :feature_name (),
122
+ Ret :: Supported | init_required ,
123
+ Supported :: boolean ().
112
124
% % @doc
113
125
% % Returns if a feature flag is supported.
114
126
% %
@@ -120,10 +132,12 @@ states() ->
120
132
% % otherwise.
121
133
122
134
is_supported (FeatureName ) ->
123
- _ = rabbit_ff_registry_factory :initialize_registry (),
124
- ? convince_dialyzer (? MODULE :is_supported (FeatureName ), false , true ).
135
+ ? convince_dialyzer (? MODULE :is_supported (FeatureName ), init_required , true ).
125
136
126
- -spec is_enabled (rabbit_feature_flags :feature_name ()) -> boolean () | state_changing .
137
+ -spec is_enabled (FeatureName ) -> Ret when
138
+ FeatureName :: rabbit_feature_flags :feature_name (),
139
+ Ret :: Enabled | init_required ,
140
+ Enabled :: boolean () | state_changing .
127
141
% % @doc
128
142
% % Returns if a feature flag is enabled or if its state is changing.
129
143
% %
@@ -135,8 +149,7 @@ is_supported(FeatureName) ->
135
149
% % its state is transient, or `false' otherwise.
136
150
137
151
is_enabled (FeatureName ) ->
138
- _ = rabbit_ff_registry_factory :initialize_registry (),
139
- ? convince_dialyzer (? MODULE :is_enabled (FeatureName ), false , true ).
152
+ ? convince_dialyzer (? MODULE :is_enabled (FeatureName ), init_required , true ).
140
153
141
154
-spec is_registry_initialized () -> boolean ().
142
155
% % @doc
@@ -169,7 +182,9 @@ is_registry_initialized() ->
169
182
is_registry_written_to_disk () ->
170
183
always_return_true ().
171
184
172
- -spec inventory () -> rabbit_feature_flags :inventory ().
185
+ -spec inventory () -> Ret when
186
+ Ret :: Inventory | init_required ,
187
+ Inventory :: rabbit_feature_flags :inventory ().
173
188
174
189
inventory () ->
175
190
_ = rabbit_ff_registry_factory :initialize_registry (),
0 commit comments