Typle.Beam (Typle v0.1.0)

View Source

Reads inferred type signatures from compiled .beam files.

The Elixir 1.20 compiler stores function signatures in the "ExCk" chunk using an internal representation tagged :elixir_checker_v7. This module decodes that representation into Typle.Type structs.

Summary

Functions

Decodes an internal type representation from the ExCk chunk into a Typle.Type.

Reads all exported function signatures from a compiled module.

Types

signature()

@type signature() :: %{
  fun: atom(),
  arity: non_neg_integer(),
  clauses: [{[Typle.Type.t()], Typle.Type.t()}]
}

Functions

decode_type(map)

@spec decode_type(term()) :: Typle.Type.t()

Decodes an internal type representation from the ExCk chunk into a Typle.Type.

read_signatures(module_or_path)

@spec read_signatures(module() | String.t()) ::
  {:ok, [signature()]} | {:error, term()}

Reads all exported function signatures from a compiled module.

Accepts a module atom (looked up via :code.which/1) or a path to a .beam file.

Examples

iex> {:ok, sigs} = Typle.Beam.read_signatures(Integer)
iex> Enum.find(sigs, & &1.fun == :to_string and &1.arity == 1)
%{fun: :to_string, arity: 1, clauses: [{[_], _}]}