1dialyzer(3) Erlang Module Definition dialyzer(3)
2
3
4
6 dialyzer - Dialyzer, a DIscrepancy AnaLYZer for ERlang programs.
7
8
10 Dialyzer is a static analysis tool that identifies software discrepan‐
11 cies, such as definite type errors, code that has become dead or
12 unreachable because of programming error, and unnecessary tests, in
13 single Erlang modules or entire (sets of) applications.
14
15 Dialyzer starts its analysis from either debug-compiled BEAM bytecode
16 or from Erlang source code. The file and line number of a discrepancy
17 is reported along with an indication of what the discrepancy is about.
18 Dialyzer bases its analysis on the concept of success typings, which
19 allows for sound warnings (no false positives).
20
22 Dialyzer has a command-line version for automated use. This section
23 provides a brief description of the options. The same information can
24 be obtained by writing the following in a shell:
25
26 dialyzer --help
27
28 For more details about the operation of Dialyzer, see section Using
29 Dialyzer from the GUI in the User's Guide.
30
31 Exit status of the command-line version:
32
33 0:
34 No problems were found during the analysis and no warnings were
35 emitted.
36
37 1:
38 Problems were found during the analysis.
39
40 2:
41 No problems were found during the analysis, but warnings were emit‐
42 ted.
43
44 Usage:
45
46 dialyzer [--add_to_plt] [--apps applications] [--build_plt]
47 [--check_plt] [-Ddefine]* [-Dname] [--dump_callgraph file]
48 [files_or_dirs] [--fullpath] [--get_warnings] [--gui] [--help]
49 [-I include_dir]* [--no_check_plt] [--no_indentation] [--no_native]
50 [--no_native_cache] [-o outfile] [--output_plt file] [-pa dir]*
51 [--plt plt] [--plt_info] [--plts plt*] [--quiet] [-r dirs]
52 [--raw] [--remove_from_plt] [--shell] [--src] [--statistics]
53 [--verbose] [--version] [-Wwarn]*
54
55 Note:
56 * denotes that multiple occurrences of the option are possible.
57
58
59 Options:
60
61 --add_to_plt:
62 The PLT is extended to also include the files specified with -c and
63 -r. Use --plt to specify which PLT to start from, and --output_plt
64 to specify where to put the PLT. Notice that the analysis possibly
65 can include files from the PLT if they depend on the new files.
66 This option only works for BEAM files.
67
68 --apps applications:
69 This option is typically used when building or modifying a PLT as
70 in:
71
72 dialyzer --build_plt --apps erts kernel stdlib mnesia ...
73
74 to refer conveniently to library applications corresponding to the
75 Erlang/OTP installation. However, this option is general and can
76 also be used during analysis to refer to Erlang/OTP applications.
77 File or directory names can also be included, as in:
78
79 dialyzer --apps inets ssl ./ebin ../other_lib/ebin/my_module.beam
80
81 --build_plt:
82 The analysis starts from an empty PLT and creates a new one from
83 the files specified with -c and -r. This option only works for BEAM
84 files. To override the default PLT location, use --plt or --out‐
85 put_plt.
86
87 --check_plt:
88 Check the PLT for consistency and rebuild it if it is not up-to-
89 date.
90
91 -Dname (or -Dname=value):
92 When analyzing from source, pass the define to Dialyzer. (**)
93
94 --dump_callgraph file:
95 Dump the call graph into the specified file whose format is deter‐
96 mined by the filename extension. Supported extensions are: raw,
97 dot, and ps. If something else is used as filename extension,
98 default format .raw is used.
99
100 files_or_dirs (for backward compatibility also as -c files_or_dirs):
101 Use Dialyzer from the command line to detect defects in the speci‐
102 fied files or directories containing .erl or .beam files, depending
103 on the type of the analysis.
104
105 --fullpath:
106 Display the full path names of files for which warnings are emit‐
107 ted.
108
109 --get_warnings:
110 Make Dialyzer emit warnings even when manipulating the PLT. Warn‐
111 ings are only emitted for files that are analyzed.
112
113 --gui:
114 Use the GUI.
115
116 --help (or -h):
117 Print this message and exit.
118
119 -I include_dir:
120 When analyzing from source, pass the include_dir to Dialyzer. (**)
121
122 --no_check_plt:
123 Skip the PLT check when running Dialyzer. This is useful when work‐
124 ing with installed PLTs that never change.
125
126 --no_indentation:
127 Do not insert line breaks in types, contracts, and Erlang Code when
128 formatting warnings.
129
130 --no_native (or -nn):
131 Bypass the native code compilation of some key files that Dialyzer
132 heuristically performs when dialyzing many files. This avoids the
133 compilation time, but can result in (much) longer analysis time.
134
135 --no_native_cache:
136 By default, Dialyzer caches the results of native compilation in
137 directory $XDG_CACHE_HOME/erlang/dialyzer_hipe_cache.
138 XDG_CACHE_HOME defaults to $HOME/.cache. Use this option to disable
139 caching.
140
141 -o outfile (or --output outfile):
142 When using Dialyzer from the command line, send the analysis
143 results to the specified outfile rather than to stdout.
144
145 --output_plt file:
146 Store the PLT at the specified file after building it.
147
148 -pa dir:
149 Include dir in the path for Erlang. This is useful when analyzing
150 files that have -include_lib() directives.
151
152 --plt plt:
153 Use the specified PLT as the initial PLT. If the PLT was built dur‐
154 ing setup, the files are checked for consistency.
155
156 --plt_info:
157 Make Dialyzer print information about the PLT and then quit. The
158 PLT can be specified with --plt(s).
159
160 --plts plt*:
161 Merge the specified PLTs to create the initial PLT. This requires
162 that the PLTs are disjoint (that is, do not have any module appear‐
163 ing in more than one PLT). The PLTs are created in the usual way:
164
165 dialyzer --build_plt --output_plt plt_1 files_to_include
166 dialyzer --build_plt --output_plt plt_n files_to_include
167
168 They can then be used in either of the following ways:
169
170 dialyzer files_to_analyze --plts plt_1 ... plt_n
171
172 or
173
174 dialyzer --plts plt_1 ... plt_n -- files_to_analyze
175
176 Notice the -- delimiter in the second case.
177
178 --quiet (or -q):
179 Make Dialyzer a bit more quiet.
180
181 -r dirs:
182 Same as files_or_dirs, but the specified directories are searched
183 recursively for subdirectories containing .erl or .beam files in
184 them, depending on the type of analysis.
185
186 --raw:
187 When using Dialyzer from the command line, output the raw analysis
188 results (Erlang terms) instead of the formatted result. The raw
189 format is easier to post-process (for example, to filter warnings
190 or to output HTML pages).
191
192 --remove_from_plt:
193 The information from the files specified with -c and -r is removed
194 from the PLT. Notice that this can cause a reanalysis of the
195 remaining dependent files.
196
197 --shell:
198 Do not disable the Erlang shell while running the GUI.
199
200 --src:
201 Override the default, which is to analyze BEAM files, and analyze
202 starting from Erlang source code instead.
203
204 --statistics:
205 Print information about the progress of execution (analysis phases,
206 time spent in each, and size of the relative input).
207
208 --verbose:
209 Make Dialyzer a bit more verbose.
210
211 --version (or -v):
212 Print the Dialyzer version and some more information and exit.
213
214 -Wwarn:
215 A family of options that selectively turn on/off warnings. (For
216 help on the names of warnings, use dialyzer -Whelp.) Notice that
217 the options can also be specified in the file with a -dialyzer()
218 attribute. For details, see section Requesting or Suppressing Warn‐
219 ings in Source Files.
220
221 Note:
222 ** options -D and -I work both from the command line and in the Dia‐
223 lyzer GUI; the syntax of defines and includes is the same as that used
224 by erlc(1).
225
226
227 Warning options:
228
229 -Werror_handling (***):
230 Include warnings for functions that only return by an exception.
231
232 -Wno_behaviours:
233 Suppress warnings about behavior callbacks that drift from the pub‐
234 lished recommended interfaces.
235
236 -Wno_contracts:
237 Suppress warnings about invalid contracts.
238
239 -Wno_fail_call:
240 Suppress warnings for failing calls.
241
242 -Wno_fun_app:
243 Suppress warnings for fun applications that will fail.
244
245 -Wno_improper_lists:
246 Suppress warnings for construction of improper lists.
247
248 -Wno_match:
249 Suppress warnings for patterns that are unused or cannot match.
250
251 -Wno_missing_calls:
252 Suppress warnings about calls to missing functions.
253
254 -Wno_opaque:
255 Suppress warnings for violations of opacity of data types.
256
257 -Wno_return:
258 Suppress warnings for functions that will never return a value.
259
260 -Wno_undefined_callbacks:
261 Suppress warnings about behaviors that have no -callback attributes
262 for their callbacks.
263
264 -Wno_unused:
265 Suppress warnings for unused functions.
266
267 -Wrace_conditions (***):
268 Include warnings for possible race conditions. Notice that the
269 analysis that finds data races performs intra-procedural data flow
270 analysis and can sometimes explode in time. Enable it at your own
271 risk.
272
273 -Wunderspecs (***):
274 Warn about underspecified functions (the specification is strictly
275 more allowing than the success typing).
276
277 -Wunknown (***):
278 Let warnings about unknown functions and types affect the exit sta‐
279 tus of the command-line version. The default is to ignore warnings
280 about unknown functions and types when setting the exit status.
281 When using Dialyzer from Erlang, warnings about unknown functions
282 and types are returned; the default is not to return these warn‐
283 ings.
284
285 -Wunmatched_returns (***):
286 Include warnings for function calls that ignore a structured return
287 value or do not match against one of many possible return values.
288 However, no warnings are included if the possible return values are
289 a union of atoms or a union of numbers.
290
291 The following options are also available, but their use is not recom‐
292 mended (they are mostly for Dialyzer developers and internal debug‐
293 ging):
294
295 -Woverspecs (***):
296 Warn about overspecified functions (the specification is strictly
297 less allowing than the success typing).
298
299 -Wspecdiffs (***):
300 Warn when the specification is different than the success typing.
301
302 Note:
303 *** denotes options that turn on warnings rather than turning them off.
304
305
307 Dialyzer can be used directly from Erlang. Both the GUI and the com‐
308 mand-line versions are also available. The options are similar to the
309 ones given from the command line, see section Using Dialyzer from the
310 Command Line.
311
313 Attribute -dialyzer() can be used for turning off warnings in a module
314 by specifying functions or warning options. For example, to turn off
315 all warnings for the function f/0, include the following line:
316
317 -dialyzer({nowarn_function, f/0}).
318
319 To turn off warnings for improper lists, add the following line to the
320 source file:
321
322 -dialyzer(no_improper_lists).
323
324 Attribute -dialyzer() is allowed after function declarations. Lists of
325 warning options or functions are allowed:
326
327 -dialyzer([{nowarn_function, [f/0]}, no_improper_lists]).
328
329 Warning options can be restricted to functions:
330
331 -dialyzer({no_improper_lists, g/0}).
332
333 -dialyzer({[no_return, no_match], [g/0, h/0]}).
334
335 For help on the warning options, use dialyzer -Whelp. The options are
336 also enumerated, see function gui/1 below (WarnOpts).
337
338 Note:
339 Warning option -Wrace_conditions has no effect when set in source
340 files.
341
342
343 Attribute -dialyzer() can also be used for turning on warnings. For
344 example, if a module has been fixed regarding unmatched returns, adding
345 the following line can help in assuring that no new unmatched return
346 warnings are introduced:
347
348 -dialyzer(unmatched_returns).
349
351 format_warning(Msg) -> string()
352
353 Types:
354
355 Msg = {Tag, Id, msg()}
356 See run/1.
357
358 Get a string from warnings as returned by run/1.
359
360 format_warning(Msg, Options) -> string()
361
362 Types:
363
364 Msg = {Tag, Id, msg()}
365 See run/1.
366 Options = [{indent_opt, boolean()}]
367
368 Get a string from warnings as returned by run/1.
369
370 If indent_opt is set to true (default), line breaks are inserted
371 in types, contracts, and Erlang code to improve readability.
372
373 gui() -> ok | {error, Msg}
374 gui(OptList) -> ok | {error, Msg}
375
376 Types:
377
378 OptList
379 See below.
380
381 Dialyzer GUI version.
382
383 OptList :: [Option]
384 Option :: {files, [Filename :: string()]}
385 | {files_rec, [DirName :: string()]}
386 | {defines, [{Macro :: atom(), Value :: term()}]}
387 | {from, src_code | byte_code}
388 %% Defaults to byte_code
389 | {init_plt, FileName :: string()}
390 %% If changed from default
391 | {plts, [FileName :: string()]}
392 %% If changed from default
393 | {include_dirs, [DirName :: string()]}
394 | {output_file, FileName :: string()}
395 | {output_plt, FileName :: string()}
396 | {check_plt, boolean()},
397 | {analysis_type, 'succ_typings' |
398 'plt_add' |
399 'plt_build' |
400 'plt_check' |
401 'plt_remove'}
402 | {warnings, [WarnOpts]}
403 | {get_warnings, boolean()}
404 | {native, boolean()}
405 %% Defaults to false when invoked from Erlang
406 | {native_cache, boolean()}
407
408 WarnOpts :: error_handling
409 | no_behaviours
410 | no_contracts
411 | no_fail_call
412 | no_fun_app
413 | no_improper_lists
414 | no_match
415 | no_missing_calls
416 | no_opaque
417 | no_return
418 | no_undefined_callbacks
419 | no_unused
420 | race_conditions
421 | underspecs
422 | unknown
423 | unmatched_returns
424 | overspecs
425 | specdiffs
426
427 plt_info(string()) -> {'ok', [{atom(), any()}]} | {'error', atom()}
428
429 Returns information about the specified PLT.
430
431 run(OptList) -> Warnings
432
433 Types:
434
435 OptList
436 See gui/0,1.
437 Warnings
438 See below.
439
440 Dialyzer command-line version.
441
442 Warnings :: [{Tag, Id, Msg}]
443 Tag :: 'warn_behaviour'
444 | 'warn_bin_construction'
445 | 'warn_callgraph'
446 | 'warn_contract_not_equal'
447 | 'warn_contract_range'
448 | 'warn_contract_subtype'
449 | 'warn_contract_supertype'
450 | 'warn_contract_syntax'
451 | 'warn_contract_types'
452 | 'warn_failing_call'
453 | 'warn_fun_app'
454 | 'warn_matching'
455 | 'warn_non_proper_list'
456 | 'warn_not_called'
457 | 'warn_opaque'
458 | 'warn_race_condition'
459 | 'warn_return_no_exit'
460 | 'warn_return_only_exit'
461 | 'warn_umatched_return'
462 | 'warn_undefined_callbacks'
463 | 'warn_unknown'
464 Id = {File :: string(), Line :: integer()}
465 Msg = msg() -- Undefined
466
467
468
469Ericsson AB dialyzer 4.3.1 dialyzer(3)