aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer
diff options
context:
space:
mode:
authorMagnus Henoch <[email protected]>2019-06-12 14:01:17 +0100
committerMagnus Henoch <[email protected]>2019-06-12 14:06:49 +0100
commit1be45363ac9b5ca4370a9769952f6f7641a067ad (patch)
tree7a32c3b72c51643c7a348895ed285810bc488696 /lib/dialyzer
parentcdc4d654777256790b277d24c709dd7e3831c451 (diff)
downloadotp-1be45363ac9b5ca4370a9769952f6f7641a067ad.tar.gz
otp-1be45363ac9b5ca4370a9769952f6f7641a067ad.tar.bz2
otp-1be45363ac9b5ca4370a9769952f6f7641a067ad.zip
Allow native compilation when calling Dialyzer from Erlang
Invoking Dialyzer through the function dialyzer:run/1 instead of from the command line activates "Erlang mode", meaning that warnings are returned instead of printed, and that HiPE compilation of modules does not take place. With this change, HiPE compilation can optionally be enabled in this situation by passing the option {native, true}. Caching of natively compiled modules is enabled by default, but can be turned off using the option {native_cache, false}.
Diffstat (limited to 'lib/dialyzer')
-rw-r--r--lib/dialyzer/doc/src/dialyzer.xml5
-rw-r--r--lib/dialyzer/src/dialyzer.hrl4
-rw-r--r--lib/dialyzer/src/dialyzer_cl.erl19
-rw-r--r--lib/dialyzer/src/dialyzer_cl_parse.erl4
-rw-r--r--lib/dialyzer/src/dialyzer_options.erl4
5 files changed, 28 insertions, 8 deletions
diff --git a/lib/dialyzer/doc/src/dialyzer.xml b/lib/dialyzer/doc/src/dialyzer.xml
index 443de7b0dd..8dd814982d 100644
--- a/lib/dialyzer/doc/src/dialyzer.xml
+++ b/lib/dialyzer/doc/src/dialyzer.xml
@@ -537,7 +537,10 @@ Option :: {files, [Filename :: string()]}
'plt_check' |
'plt_remove'}
| {warnings, [WarnOpts]}
- | {get_warnings, bool()}
+ | {get_warnings, boolean()}
+ | {native, boolean()}
+ %% Defaults to false when invoked from Erlang
+ | {native_cache, boolean()}
WarnOpts :: error_handling
| no_behaviours
diff --git a/lib/dialyzer/src/dialyzer.hrl b/lib/dialyzer/src/dialyzer.hrl
index 4a12b9b671..e1821f10eb 100644
--- a/lib/dialyzer/src/dialyzer.hrl
+++ b/lib/dialyzer/src/dialyzer.hrl
@@ -160,7 +160,9 @@
indent_opt = ?INDENT_OPT :: iopt(),
callgraph_file = "" :: file:filename(),
check_plt = true :: boolean(),
- solvers = [] :: [solver()]}).
+ solvers = [] :: [solver()],
+ native = maybe :: boolean() | 'maybe',
+ native_cache = true :: boolean()}).
-record(contract, {contracts = [] :: [contract_pair()],
args = [] :: [erl_types:erl_type()],
diff --git a/lib/dialyzer/src/dialyzer_cl.erl b/lib/dialyzer/src/dialyzer_cl.erl
index f887f661bd..403fcb6279 100644
--- a/lib/dialyzer/src/dialyzer_cl.erl
+++ b/lib/dialyzer/src/dialyzer_cl.erl
@@ -489,10 +489,20 @@ expand_dependent_modules_1([], Included, _ModDeps) ->
-spec hipe_compile([file:filename()], #options{}) -> 'ok'.
-hipe_compile(Files, #options{erlang_mode = ErlangMode} = Options) ->
- NoNative = (get(dialyzer_options_native) =:= false),
+hipe_compile(Files, #options{erlang_mode = ErlangMode,
+ native = Native,
+ native_cache = NativeCache} = Options) ->
+ NoNative =
+ case ErlangMode of
+ true ->
+ %% In Erlang mode, native compilation must be explicitly enabled
+ Native =/= true;
+ false ->
+ %% In CLI mode, perform native compilation unless disabled
+ Native =:= false
+ end,
FewFiles = (length(Files) < ?MIN_FILES_FOR_NATIVE_COMPILE),
- case NoNative orelse FewFiles orelse ErlangMode of
+ case NoNative orelse FewFiles of
true -> ok;
false ->
case erlang:system_info(hipe_architecture) of
@@ -508,8 +518,7 @@ hipe_compile(Files, #options{erlang_mode = ErlangMode} = Options) ->
dialyzer_worker],
report_native_comp(Options),
{T1, _} = statistics(wall_clock),
- Cache = (get(dialyzer_options_native_cache) =/= false),
- native_compile(Mods, Cache),
+ native_compile(Mods, NativeCache),
{T2, _} = statistics(wall_clock),
report_elapsed_time(T1, T2, Options)
end
diff --git a/lib/dialyzer/src/dialyzer_cl_parse.erl b/lib/dialyzer/src/dialyzer_cl_parse.erl
index 280cae81d5..cadc2116b0 100644
--- a/lib/dialyzer/src/dialyzer_cl_parse.erl
+++ b/lib/dialyzer/src/dialyzer_cl_parse.erl
@@ -316,7 +316,9 @@ common_options() ->
{use_spec, get(dialyzer_options_use_contracts)},
{warnings, get(dialyzer_warnings)},
{check_plt, get(dialyzer_options_check_plt)},
- {solvers, get(dialyzer_solvers)}].
+ {solvers, get(dialyzer_solvers)},
+ {native, get(dialyzer_options_native)},
+ {native_cache, get(dialyzer_options_native_cache)}].
%%-----------------------------------------------------------------------
diff --git a/lib/dialyzer/src/dialyzer_options.erl b/lib/dialyzer/src/dialyzer_options.erl
index 3b30036c1c..f88f4f8ea2 100644
--- a/lib/dialyzer/src/dialyzer_options.erl
+++ b/lib/dialyzer/src/dialyzer_options.erl
@@ -197,6 +197,10 @@ build_options([{OptionName, Value} = Term|Rest], Options) ->
solvers ->
assert_solvers(Value),
build_options(Rest, Options#options{solvers = Value});
+ native ->
+ build_options(Rest, Options#options{native = Value});
+ native_cache ->
+ build_options(Rest, Options#options{native_cache = Value});
_ ->
bad_option("Unknown dialyzer command line option", Term)
end;