SpecLint.Typespec (spec_lint v0.1.0)

Copy Markdown View Source

Internal, unstable compiler translator; not a supported public API.

Translates typespec ASTs (as returned by <code>Code.Typespec</code>) into the compiler's own types (<code>Module.Types.Descr</code>).

Every translation is {descr, exact?}. The lattice cannot express integer ranges, sized binaries, charlists as strings and a few other refinements; those are widened and flagged inexact. An inexact translation always over-approximates the spec, never under-approximates it, so a disjointness proven against the translation holds for the real spec.

Summary

Types

A translated type: the descr and whether it is exact.

Functions

Translates one spec clause of module: {:ok, args, return} with one translation per argument and one for the return, or :error when the clause uses a construct with no sound translation (a constraint other than when x: type, an unknown built-in), with the construct as the reason. A named type that cannot be read is term(), inexact.

Translates one type AST in the context of module.

Types

translated()

@type translated() :: {term(), boolean()}

A translated type: the descr and whether it is exact.

Functions

spec(clause, module)

@spec spec(tuple(), module()) ::
  {:ok, [translated()], translated()} | {:error, term()}

Translates one spec clause of module: {:ok, args, return} with one translation per argument and one for the return, or :error when the clause uses a construct with no sound translation (a constraint other than when x: type, an unknown built-in), with the construct as the reason. A named type that cannot be read is term(), inexact.

type(ast, module)

@spec type(tuple(), module()) :: {:ok, translated()} | {:error, term()}

Translates one type AST in the context of module.