dialyzer
The Dialyzer, a DIscrepancy AnalYZer for ERlang programs
The Dialyzer is a static analysis tool that identifies software discrepancies such as definite type errors, code which has become dead or unreachable due to some programming error, unnecessary tests, etc. in single Erlang modules or entire (sets of) applications. Dialyzer starts its analysis from either debug-compiled BEAM bytecode or from Erlang source code. The file and line number of a discrepancy is reported along with an indication of what the discrepancy is about. Dialyzer bases its analysis on the concept of success typings which allows for sound warnings (no false positives).
Read more about Dialyzer and about how to use it from the GUI in Dialyzer User's Guide.
Using the Dialyzer from the command line
Dialyzer also has a command line version for automated use. Below is a brief description of the list of its options. The same information can be obtained by writing
dialyzer --help
in a shell. Please refer to the GUI description for more details on the operation of Dialyzer.
The exit status of the command line version is:
0 - No problems were encountered during the analysis and no warnings were emitted. 1 - Problems were encountered during the analysis. 2 - No problems were encountered, but warnings were emitted.
Usage:
dialyzer [--help] [--version] [--shell] [--quiet] [--verbose] [-pa dir]* [--plt plt] [--plts plt*] [-Ddefine]* [-I include_dir]* [--output_plt file] [-Wwarn]* [--raw] [--src] [--gui] [files_or_dirs] [-r dirs] [--apps applications] [-o outfile] [--build_plt] [--add_to_plt] [--remove_from_plt] [--check_plt] [--no_check_plt] [--plt_info] [--get_warnings] [--dump_callgraph file] [--no_native] [--fullpath] [--statistics] [--no_native_cache]
Options:
files_or_dirs
(for backwards compatibility also
as: -c files_or_dirs
).erl
or
.beam
files, depending on the type of the
analysis.-r dirs
.erl
or
.beam
files in them, depending on the type of
analysis.--apps applications
dialyzer --build_plt --apps erts kernel stdlib mnesia ...to conveniently refer to library applications corresponding to the Erlang/OTP installation. However, the option is general and can also be used during analysis in order to refer to Erlang/OTP applications. In addition, file or directory names can also be included, as in:
dialyzer --apps inets ssl ./ebin ../other_lib/ebin/my_module.beam
-o outfile
(or
--output outfile
)--raw
--src
-Dname
(or -Dname=value
)-I include_dir
include_dir
to Dialyzer. (**)-pa dir
dir
in the path for Erlang (useful when
analyzing files that have '-include_lib()'
directives).--output_plt file
--plt plt
--plts plt*
dialyzer --build_plt --output_plt plt_1 files_to_include ... dialyzer --build_plt --output_plt plt_n files_to_includeand then can be used in either of the following ways:
dialyzer files_to_analyze --plts plt_1 ... plt_nor:
dialyzer --plts plt_1 ... plt_n -- files_to_analyze(Note the -- delimiter in the second case)
-Wwarn
dialyzer -Whelp
).
Note that the options can also be given in the file with a
-dialyzer()
attribute. See Requesting or Suppressing Warnings in
Source Files below for details.--shell
--version
(or -v
)--help
(or -h
)--quiet
(or -q
)--verbose
--statistics
--build_plt
-c
and
-r
. Only works for beam files. Use
--plt
or --output_plt
to
override the default plt location.--add_to_plt
-c
and -r
. Use
--plt
to specify which plt to start from,
and --output_plt
to specify where to put the plt.
Note that the analysis might include files from the plt if they depend
on the new files. This option only works with beam files.--remove_from_plt
-c
and -r
is removed
from the plt. Note that this may cause a re-analysis of the remaining
dependent files.--check_plt
--no_check_plt
--plt_info
--plt(s)
.--get_warnings
--dump_callgraph file
--no_native
(or -nn
)--no_native_cache
$XDG_CACHE_HOME/erlang/dialyzer_hipe_cache
directory.
XDG_CACHE_HOME
defaults to $HOME/.cache
.
Use this option to disable caching.--fullpath
--gui
Note!
* denotes that multiple occurrences of these options are possible.
** options -D
and -I
work both from command-line and in the Dialyzer GUI;
the syntax of defines and includes is the same as that used by erlc
.
Warning options:
-Wno_return
-Wno_unused
-Wno_improper_lists
-Wno_fun_app
-Wno_match
-Wno_opaque
-Wno_fail_call
-Wno_contracts
-Wno_behaviours
-Wno_missing_calls
-Wno_undefined_callbacks
-callback
attributes for their callbacks.-Wunmatched_returns
***-Werror_handling
***-Wrace_conditions
***-Wunderspecs
***-Wunknown
***The following options are also available but their use is not recommended: (they are mostly for Dialyzer developers and internal debugging)
-Woverspecs
***-Wspecdiffs
***Note!
*** Identifies options that turn on warnings rather than turning them off.
Using the Dialyzer from Erlang
You can also use Dialyzer directly from Erlang. Both the GUI and the command line versions are available. The options are similar to the ones given from the command line, so please refer to the sections above for a description of these.
Requesting or Suppressing Warnings in Source Files
The -dialyzer()
attribute can be used for turning off
warnings in a module by specifying functions or warning options.
For example, to turn off all warnings for the function
f/0
, include the following line:
-dialyzer({nowarn_function, f/0}).
To turn off warnings for improper lists, add the following line to the source file:
-dialyzer(no_improper_lists).
The -dialyzer()
attribute is allowed after function
declarations. Lists of warning options or functions are allowed:
-dialyzer([{nowarn_function, [f/0]}, no_improper_lists]).
Warning options can be restricted to functions:
-dialyzer({no_improper_lists, g/0}).
-dialyzer({[no_return, no_match], [g/0, h/0]}).
For help on the warning options use dialyzer -Whelp
. The
options are also enumerated below (WarnOpts
).
Note!
The -dialyzer()
attribute is not checked by the Erlang
Compiler, but by the Dialyzer itself.
Note!
The warning option -Wrace_conditions
has no effect when
set in source files.
The -dialyzer()
attribute can also be used for turning on
warnings. For instance, if a module has been fixed regarding
unmatched returns, adding the line
-dialyzer(unmatched_returns).
can help in assuring that no new unmatched return warnings are introduced.
Functions
gui() -> ok | {error, Msg}
gui(OptList) -> ok | {error, Msg}
OptList -- see below
Dialyzer GUI version.
OptList :: [Option] Option :: {files, [Filename :: string()]} | {files_rec, [DirName :: string()]} | {defines, [{Macro :: atom(), Value :: term()}]} | {from, src_code | byte_code} %% Defaults to byte_code | {init_plt, FileName :: string()} %% If changed from default | {plts, [FileName :: string()]} %% If changed from default | {include_dirs, [DirName :: string()]} | {output_file, FileName :: string()} | {output_plt, FileName :: string()} | {check_plt, boolean()}, | {analysis_type, 'succ_typings' | 'plt_add' | 'plt_build' | 'plt_check' | 'plt_remove'} | {warnings, [WarnOpts]} | {get_warnings, bool()} WarnOpts :: no_return | no_unused | no_improper_lists | no_fun_app | no_match | no_opaque | no_fail_call | no_contracts | no_behaviours | no_undefined_callbacks | unmatched_returns | error_handling | race_conditions | overspecs | underspecs | specdiffs | unknown
run(OptList) -> Warnings
OptList -- see gui/0,1
Warnings -- see below
Dialyzer command line version.
Warnings :: [{Tag, Id, Msg}] Tag :: 'warn_behaviour' | 'warn_bin_construction' | 'warn_callgraph' | 'warn_contract_not_equal' | 'warn_contract_range' | 'warn_contract_subtype' | 'warn_contract_supertype' | 'warn_contract_syntax' | 'warn_contract_types' | 'warn_failing_call' | 'warn_fun_app' | 'warn_matching' | 'warn_non_proper_list' | 'warn_not_called' | 'warn_opaque' | 'warn_race_condition' | 'warn_return_no_exit' | 'warn_return_only_exit' | 'warn_umatched_return' | 'warn_undefined_callbacks' | 'warn_unknown' Id = {File :: string(), Line :: integer()} Msg = msg() -- Undefined
format_warning(Msg) -> string()
Msg = {Tag, Id, msg()} -- See run/1
Get a string from warnings as returned by dialyzer:run/1.
plt_info(string()) -> {'ok', [{atom(), any()}]} | {'error', atom()}
Returns information about the specified plt.