にゃははー

はへらー

Erlangの静的解析ツールを使ってみる

Erlang Tips まずここ読む

使ってみる

dialyzer

なんか --succ_typings はunknown optionと言われてしまう。なくなったのか?

とりあえずソースを渡せばいいらしいので投げてみる。

$ dialyzer clusterccd.erl
  Checking whether the PLT /home/flast/.dialyzer_plt is up-to-date...
dialyzer: Could not find the PLT: /home/flast/.dialyzer_plt
Use the options:
   --build_plt   to build a new PLT; or
   --add_to_plt  to add to an existing PLT

For example, use a command like the following:
   dialyzer --build_plt --apps erts kernel stdlib mnesia
Note that building a PLT such as the above may take 20 mins or so

If you later need information about other applications, say crypto,
you can extend the PLT by the command:
  dialyzer --add_to_plt --apps crypto
For applications that are not in Erlang/OTP use an absolute file name.

うぐっ...読んでみると.dialyzer_pltというファイルが無いといけないらしい。自動では作られない様なので書いてあるとおりに --build_plt をしてみる。mnesiaは使わないからとりあえず erts kernel stdlib で走らせてみる。20分以上かかるかも知れないという不吉な文が見えるが気にせず進める。

$ dialyzer --build_plt --apps erts kernel stdlib
  Compiling some key modules to native code... done in 3m45.33s
  Creating PLT /home/flast/.dialyzer_plt ...
Unknown functions:
  compile:file/2
  compile:forms/2
  compile:noenv_forms/2
  compile:output_generated/1
  crypto:des3_cbc_decrypt/5
  crypto:start/0
Unknown types:
  compile:option/0
 done in 23m6.17s
done (passed successfully)

はぁ...

done in 23m6.17s

ほんとに20分以上掛かりました本当にありがとうございます!

...まぁとりあえずこれで使えるはず。ということでもう一回投げてみる。

$ dialyzer clusterccd.erl
  Checking whether the PLT /home/flast/.dialyzer_plt is up-to-date... yes
  Proceeding with analysis...
Unknown functions:
  node_manager:new_link/1
 done in 0m1.42s
done (passed successfully)

うまくいった。特にwarningとかは見えないからとりあえずガードに引っかかって呼び出しできないパターンとかはないってことなのだろう。
Unknown functionsと言われてるのは別のモジュールの関数のことのようなのでunknownで当然だ。そのモジュールも一緒に投げてみることにする。

$ dialyzer clusterccd.erl node_manager.erl
  Checking whether the PLT /home/flast/.dialyzer_plt is up-to-date... yes
  Proceeding with analysis... done in 0m2.32s
done (passed successfully)

にゃる。

typer

こっちは関数の型を推論するツールのようだ。とりあえず投げる。

$ typer clusterccd.erl
 Unknown functions: [{node_manager,new_link,1}]

%% File: "clusterccd.erl"
%% ----------------------
-spec prefixed([1..255,...]) -> 'ok'.
-spec prefixed([1..255,...],[any()]) -> 'ok'.
-spec main() -> 'ok'.
-spec hostname_validation() -> 'ok' | 'true'.
-spec loop(pid()) -> 'ok' | {'manage',_,'terminate'}.

こちらもunknown functionsと言われているのでそのモジュールも投げる。

$ typer clusterccd.erl node_manager.erl

%% File: "clusterccd.erl"
%% ----------------------
-spec prefixed([1..255,...]) -> 'ok'.
-spec prefixed([1..255,...],[any()]) -> 'ok'.
-spec main() -> 'ok'.
-spec hostname_validation() -> 'ok' | 'true'.
-spec loop(pid()) -> 'ok' | {'manage',_,'terminate'}.

%% File: "node_manager.erl"
%% ------------------------
-spec prefixed([1..255,...]) -> 'ok'.
-spec prefixed([1..255,...],[any()]) -> 'ok'.
-spec get() -> any().
-spec new(maybe_improper_list(),fun((_) -> pid())) -> pid().
-spec new(maybe_improper_list()) -> pid().
-spec new_link(maybe_improper_list()) -> pid().
-spec nodes_get(atom() | pid() | port() | {atom(),atom()},[any()]) -> [any()].
-spec nodes_enter(_,[any()]) -> [any()].
-spec nodes_leave(_,[any()]) -> [any()].
-spec nodes_RR([any()]) -> no_return().

なるほど。

あと、typerは先の.dialyzer_pltを参照しているらしく、.dialyzer_pltを別名に変えてみたりすると、

$ typer clusterccd.erl
typer: Dialyzer's PLT is missing or is not up-to-date; please (re)create it

と言われる。

typerはそれほど使わないかもしれないがdialyzerは積極的に使いたい。