# `VulnCheck.Beam.CallGraph`
[🔗](https://github.com/Voskan/vulncheck/blob/v1.0.1/lib/vulncheck/beam/call_graph.ex#L1)

Immutable call graph indexed by caller and callee.

Built from module summaries: static and resolved dynamic edges, `{M, F, A}`
references and, for modules without debug info, over-approximated edges
from every exported function to every imported function (`:imports`).
Further edges (behaviour callbacks, supervisor children, ...) are added
with `add_edges/2`.

# `t`

```elixir
@type t() :: %VulnCheck.Beam.CallGraph{
  in_edges: %{
    required(VulnCheck.Types.MFA.t()) =&gt; [VulnCheck.Types.CallEdge.t()]
  },
  modules: %{required(String.t()) =&gt; VulnCheck.Types.ModuleSummary.t()},
  out_edges: %{
    required(VulnCheck.Types.MFA.t()) =&gt; [VulnCheck.Types.CallEdge.t()]
  },
  pairs: %{
    required({VulnCheck.Types.MFA.t(), VulnCheck.Types.MFA.t()}) =&gt; boolean()
  }
}
```

# `add_edges`

```elixir
@spec add_edges(t(), [VulnCheck.Types.CallEdge.t()]) :: t()
```

Adds edges to the graph. Duplicate pairs prefer proven edges, with ties
keeping the first edge.

# `build`

```elixir
@spec build(
  %{required(String.t()) =&gt; VulnCheck.Types.ModuleSummary.t()}
  | [VulnCheck.Types.ModuleSummary.t()],
  keyword()
) :: t()
```

Builds the graph from summaries (a map keyed by module name or a list).

# `callers`

```elixir
@spec callers(t(), VulnCheck.Types.MFA.t()) :: [VulnCheck.Types.CallEdge.t()]
```

Incoming edges of a function.

# `edge_count`

```elixir
@spec edge_count(t()) :: non_neg_integer()
```

Number of distinct edges.

# `edges_from`

```elixir
@spec edges_from(t(), VulnCheck.Types.MFA.t()) :: [VulnCheck.Types.CallEdge.t()]
```

Outgoing edges of a function.

# `module?`

```elixir
@spec module?(t(), String.t()) :: boolean()
```

Returns `true` when the module was loaded from a `.beam` file.

# `reachable`

```elixir
@spec reachable(t(), [VulnCheck.Types.MFA.t() | VulnCheck.Types.Entrypoint.t()]) ::
  MapSet.t(VulnCheck.Types.MFA.t())
```

All functions reachable from `roots` (MFAs or entrypoints), roots included.

# `reachable_modules`

```elixir
@spec reachable_modules(MapSet.t(VulnCheck.Types.MFA.t())) :: MapSet.t(String.t())
```

Modules containing at least one reachable function.

# `shortest_path`

```elixir
@spec shortest_path(
  t(),
  [VulnCheck.Types.MFA.t() | VulnCheck.Types.Entrypoint.t()],
  MapSet.t(VulnCheck.Types.MFA.t()) | [VulnCheck.Types.MFA.t()]
) :: {:ok, [VulnCheck.Types.TraceHop.t()]} | :none
```

Finds a shortest call chain (fewest hops) from any root to any target.

Returns `{:ok, hops}` where the first hop is the entrypoint and every
following hop carries the call site (`file:line`) in its caller and the
kind of the edge, or `:none`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
