[erlang-questions] Parametric modules and Dialyzer

VegaS <>
Tue Aug 14 10:41:55 CEST 2012

Hello all!

We are using parametric modules in our project and were quite happy with
them unless we have started using Dialyzer.
Dialyzer fails on parametric modules because functions in parametric
modules are expanded with module params argument on compilation stage - so
function's specs are unmatched.

I know that parametric modules not the official part of Erlang, but I'd
like to get both parametric modules and dialyzer working. I have tried to
do some work on this:
1. Try to fix specs on parametric module's functions with parse_transform -
simply extend specs on this stage, but this won't work, code just won't
compile (because of specs for unknown functions)
2. More complicated approach - try to implement parametric modules with
parse_transform (create "new" function and extend all module functions and
specs). This looks working unless some code like
     SomeFun = local_fun/1, SomeFun(Arg) and some variations like this
local function is assigned to record field.
3. Decided that there no way out besides patching OTP sources or not using
parametric modules at all. After looking at OTP sources I have found, that
parametric modules are expanded on on "expand_module" compiler pass. And on
that stage specs are not expanded. I Have patched this stage with specs
expand. All were correct, but dialyzer fails with message like specs were
not fixed, so no luck... This happend because dialyzer using
"abstract_code" from beam to extract specs and pass "save_abstract_code" is
just before "expand_module" pass.
Simple changing these passes order broke dialyzer at all.
4. The last attempt were to patch dialyzer - on the stage, when it extracts
specs info from beam's abstract_code section. At this place I insert
function's specs expanding with last parametric parameter - and it works!

So the question is what the rigth way to make both parametric modules and
dialyzer working?
At my opinion there are no way except OTP sources patching - but what the
rigth place for making such patch?

I can attach my patch here but it is little ugly (I were tired by previous
explorations) and I think I have chosen not rigth place for changing.

Lihanov Alexandr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120814/f246fecf/attachment.html>

More information about the erlang-questions mailing list