[erlang-questions] Unions of Cardinality > 13

Kostis Sagonas kostis@REDACTED
Mon Feb 19 08:29:32 CET 2018


On 02/19/2018 06:27 AM, AJ Foster wrote:
> I am new to the Erlang ecosystem, so please excuse / assist with my 
> vocabulary. I’ve observed that Dialyzer behaves differently with union 
> types of different cardinality, with a threshold of 13 items. An example 
> is below:
> 
>      <SNIP>

Yes, this is correct.

> My questions: where is this threshold defined, and can it be configured? 

This threshold is defined here:

 
https://github.com/erlang/otp/blob/fe1df7fc6bf050cb6c9bbd99eb9393c426b62f67/lib/hipe/cerl/erl_types.erl#L257

It can easily be changed, and in fact perhaps it should have been 
increased by now.  I think I have been running my own version of 
dialyzer with 21 (or 23?) for a number of years now and I have not 
experienced any memory issues.  On the other hand, all the machines I 
use have at least 8 GB of RAM.

However, no matter what number is chosen, with the current code there 
will always be a point where the analysis collapses (loses) information 
and thus becomes approximate.  But this is OK.  Dialyzer is NOT a type 
checker; it's a _discrepancy analyzer_, meaning that it only guarantees 
that the issues it reports are indeed issues (this is the "Dialyzer is 
never wrong" slogan), not that it finds all type errors.

> Alternatively, is there a better way of constructing large union types 
> that will allow Dialyzer to check them as “strictly” as types with fewer 
> items?

Perhaps there is.  Feel free to experiment.

Kostis




More information about the erlang-questions mailing list