View Source Hologram.Compiler.CallGraph (hologram v0.2.0)

Summary

Functions

Adds an edge between two vertices in the call graph.

Adds multiple edges to the call graph.

Adds the vertex to the call graph.

Builds a call graph from IR.

Builds a call graph from a module definition IR located in the given IR PLT.

Returns a clone of the given call graph.

Serializes the call graph and writes it to a file.

Returns graph edges.

Returns the underlying libgraph %Graph{} struct containing vertices and edges data.

Checks if an edge exists between two given vertices in the call graph.

Checks if the given vertex exists in the call graph.

Returns the edges in which the second vertex is either the given module or a function from the given module, and the first vertex is a function from a different module.

Lists the entry MFAs {module, function, arity} for a given page module.

Returns the list of MFAs that are reachable by the given page.

Lists entry runtime MFAs, which include MFAs used by the client runtime JS classes and client MFAs used by all pages and components. The returned MFAs are sorted.

Lists MFAs required by the runtime JS script.

Loads the graph from the given dump file.

Loads the graph from the given dump file if the file exists.

Returns the list of vertices that are MFAs belonging to the given module.

Given a diff of changes, updates the call graph by deleting the graph paths of modules that have been removed, rebuilding the graph paths of modules that have been updated, and adding the graph paths of modules that have been added.

Replace the state of underlying Agent process with the given graph.

Lists vertices that are reachable from the given graph vertex or vertices.

Removes call graph vertices for Elixir functions ported manually.

Removes call graph vertices and edges related to MFAs used by the runtime.

Removes the vertex from the call graph.

Removes the vertices from the call graph.

Returns sorted graph edges.

Lists MFAs that are reachable from the given call graph vertex or vertices. Unimplemented protocol implentations are excluded. The MFAs returned are sorted.

Returns sorted graph vertices.

Starts a new CallGraph agent with (optional) initial graph.

Stops the CallGraph agent.

Returns graph vertices.

Types

t()

@type t() :: %Hologram.Compiler.CallGraph{pid: pid()}

vertex()

@type vertex() :: module() | mfa()

Functions

add_edge(call_graph, from_vertex, to_vertex)

@spec add_edge(t(), vertex(), vertex()) :: t()

Adds an edge between two vertices in the call graph.

add_edges(call_graph, edges)

@spec add_edges(t(), [Graph.Edge.t()]) :: t()

Adds multiple edges to the call graph.

add_vertex(call_graph, vertex)

@spec add_vertex(t(), vertex()) :: t()

Adds the vertex to the call graph.

build(call_graph, ir, from_vertex \\ nil)

@spec build(t(), Hologram.Compiler.IR.t(), vertex() | nil) :: t()

Builds a call graph from IR.

build_for_module(call_graph, ir_plt, module)

@spec build_for_module(t(), Hologram.Commons.PLT.t(), module()) :: t()

Builds a call graph from a module definition IR located in the given IR PLT.

clone(call_graph)

@spec clone(t()) :: t()

Returns a clone of the given call graph.

Benchmark: https://github.com/bartblast/hologram/blob/master/benchmarks/compiler/call_graph/clone_1/README.md

dump(call_graph, path)

@spec dump(t(), String.t()) :: t()

Serializes the call graph and writes it to a file.

Benchmarks: https://github.com/bartblast/hologram/blob/master/benchmarks/compiler/call_graph/dump_2/README.md

edges(map)

@spec edges(t()) :: [Graph.Edge.t()]

Returns graph edges.

get_graph(map)

@spec get_graph(t()) :: Graph.t()

Returns the underlying libgraph %Graph{} struct containing vertices and edges data.

has_edge?(call_graph, from_vertex, to_vertex)

@spec has_edge?(t(), vertex(), vertex()) :: boolean()

Checks if an edge exists between two given vertices in the call graph.

has_vertex?(map, vertex)

@spec has_vertex?(t(), vertex()) :: boolean()

Checks if the given vertex exists in the call graph.

inbound_remote_edges(call_graph, to_module)

@spec inbound_remote_edges(t(), module()) :: [Graph.Edge.t()]

Returns the edges in which the second vertex is either the given module or a function from the given module, and the first vertex is a function from a different module.

list_page_entry_mfas(page_module)

@spec list_page_entry_mfas(module()) :: [mfa()]

Lists the entry MFAs {module, function, arity} for a given page module.

This function returns a list of MFAs that are considered entry points for a page, including functions from both the page module and its associated layout module.

Parameters

  • page_module - The module of the page for which to list entry MFAs.

Returns

A list of MFAs (tuples of {module, function, arity}) that serve as entry points for the given page module and its layout.

list_page_mfas(call_graph, page_module)

@spec list_page_mfas(t(), module()) :: [mfa()]

Returns the list of MFAs that are reachable by the given page.

list_runtime_entry_mfas()

@spec list_runtime_entry_mfas() :: [mfa()]

Lists entry runtime MFAs, which include MFAs used by the client runtime JS classes and client MFAs used by all pages and components. The returned MFAs are sorted.

list_runtime_mfas(call_graph)

@spec list_runtime_mfas(t()) :: [mfa()]

Lists MFAs required by the runtime JS script.

Benchmark: https://github.com/bartblast/hologram/blob/master/benchmarks/compiler/call_graph/list_runtime_mfas_1/README.md

load(call_graph, dump_path)

@spec load(t(), String.t()) :: t()

Loads the graph from the given dump file.

maybe_load(call_graph, dump_path)

@spec maybe_load(t(), String.t()) :: t()

Loads the graph from the given dump file if the file exists.

module_vertices(call_graph, module)

@spec module_vertices(t(), module()) :: [vertex()]

Returns the list of vertices that are MFAs belonging to the given module.

patch(call_graph, ir_plt, diff)

@spec patch(t(), Hologram.Commons.PLT.t(), map()) :: t()

Given a diff of changes, updates the call graph by deleting the graph paths of modules that have been removed, rebuilding the graph paths of modules that have been updated, and adding the graph paths of modules that have been added.

Benchmarks: https://github.com/bartblast/hologram/blob/master/benchmarks/compiler/call_graph/patch_3/README.md

put_graph(call_graph, graph)

@spec put_graph(t(), Graph.t()) :: t()

Replace the state of underlying Agent process with the given graph.

reachable(graph, vertex_or_vertices)

@spec reachable(Graph.t(), vertex() | [vertex()]) :: [vertex()]

Lists vertices that are reachable from the given graph vertex or vertices.

remove_manually_ported_mfas(call_graph)

@spec remove_manually_ported_mfas(t()) :: t()

Removes call graph vertices for Elixir functions ported manually.

Benchmark: https://github.com/bartblast/hologram/blob/master/benchmarks/compiler/call_graph/remove_manually_ported_mfas_1/README.md

remove_runtime_mfas!(call_graph, runtime_mfas)

@spec remove_runtime_mfas!(t(), [mfa()]) :: t()

Removes call graph vertices and edges related to MFAs used by the runtime.

remove_vertices/2 is very slow on large graphs - for a base case it would take over 7 seconds to remove runtime MFAs that way.

Benchmark: https://github.com/bartblast/hologram/blob/master/benchmarks/compiler/call_graph/remove_runtime_mfas!_2/README.md

remove_vertex(call_graph, vertex)

@spec remove_vertex(t(), vertex()) :: t()

Removes the vertex from the call graph.

remove_vertices(call_graph, vertices)

@spec remove_vertices(t(), [vertex()]) :: t()

Removes the vertices from the call graph.

Benchmarks: https://github.com/bartblast/hologram/blob/master/benchmarks/compiler/call_graph/remove_vertices_2/README.md

sorted_edges(call_graph)

@spec sorted_edges(t()) :: [Graph.Edge.t()]

Returns sorted graph edges.

sorted_reachable_mfas(graph, vertex_or_vertices)

@spec sorted_reachable_mfas(Graph.t(), vertex() | [vertex()]) :: [mfa()]

Lists MFAs that are reachable from the given call graph vertex or vertices. Unimplemented protocol implentations are excluded. The MFAs returned are sorted.

sorted_vertices(call_graph)

@spec sorted_vertices(t()) :: [vertex()]

Returns sorted graph vertices.

start(graph \\ Graph.new())

@spec start(Graph.t()) :: t()

Starts a new CallGraph agent with (optional) initial graph.

stop(call_graph)

@spec stop(t()) :: :ok

Stops the CallGraph agent.

vertices(map)

@spec vertices(t()) :: [vertex()]

Returns graph vertices.