Expand description
Defines a C API for working with stack graphs in other languages.
Structs§
- sg_edge
- Connects two nodes in a stack graph.
- sg_file
- A source file that we have extracted stack graph data from.
- sg_
files - An array of all of the files in a stack graph. File handles are indices into this array. There will never be a valid file at index 0; a handle with the value 0 represents a missing file.
- sg_
forward_ partial_ path_ stitcher - Implements a phased forward partial path stitching algorithm.
- sg_node
- A node in a stack graph.
- sg_
node_ handle_ set - Encodes a set of node handles.
- sg_
node_ id - Uniquely identifies a node in a stack graph.
- sg_
node_ source_ info - A tuple of a node handle and source information for that node. Used with the
sg_add_source_info
function to add source information to a stack graph. - sg_
nodes - An array of all of the nodes in a stack graph. Node handles are indices into this array. There will never be a valid node at index 0; a handle with the value 0 represents a missing node.
- sg_
offset - The offset of a character within a string (typically a line of source code), using several different units
- sg_
partial_ path - A portion of a name-binding path.
- sg_
partial_ path_ arena - Manages the state of a collection of partial paths to be used in the path-stitching algorithm.
- sg_
partial_ path_ database - Contains a “database” of partial paths.
- sg_
partial_ path_ edge - Details about one of the edges in a partial path
- sg_
partial_ path_ edge_ list - The edges in a path keep track of precedence information so that we can correctly handle shadowed definitions.
- sg_
partial_ path_ edge_ list_ cell - An element of a partial path edge list.
- sg_
partial_ path_ edge_ list_ cells - The array of all of the partial path edge list content in a partial path arena.
- sg_
partial_ path_ list - A list of paths found by the path-finding algorithm.
- sg_
partial_ paths - An array of all of the partial paths in a partial path database. Partial path handles are indices into this array. There will never be a valid partial path at index 0; a handle with the value 0 represents a missing partial path.
- sg_
partial_ scope_ stack - A pattern that might match against a scope stack. Consists of a (possibly empty) list of exported scopes, along with an optional scope stack variable.
- sg_
partial_ scope_ stack_ cell - An element of a partial scope stack.
- sg_
partial_ scope_ stack_ cells - The array of all of the partial scope stack content in a partial path arena.
- sg_
partial_ scoped_ symbol - A symbol with an unknown, but possibly empty, list of exported scopes attached to it.
- sg_
partial_ symbol_ stack - A pattern that might match against a symbol stack. Consists of a (possibly empty) list of partial scoped symbols.
- sg_
partial_ symbol_ stack_ cell - An element of a partial symbol stack.
- sg_
partial_ symbol_ stack_ cells - The array of all of the partial symbol stack content in a partial path arena.
- sg_
position - All of the position information that we have about a character in a source file
- sg_
source_ info - Contains information about a range of code in a source code file.
- sg_
source_ infos - An array of all of the source information in a stack graph. Source information is associated
with nodes, so node handles are indices into this array. It is not guaranteed that there
will an entry in this array for every node handle; if you have a node handle whose value is
larger than
count
, then use a 0-valuedsg_source_info
if you need source information for that node. - sg_span
- All of the position information that we have about a range of content in a source file
- sg_
stack_ graph - Contains all of the nodes and edges that make up a stack graph.
- sg_
stitcher_ config - sg_
string - Arbitrary string content associated with some part of a stack graph.
- sg_
strings - An array of all of the interned strings in a stack graph. String handles are indices into this array. There will never be a valid string at index 0; a handle with the value 0 represents a missing string.
- sg_
symbol - A name that we are trying to resolve using stack graphs.
- sg_
symbols - An array of all of the symbols in a stack graph. Symbol handles are indices into this array. There will never be a valid symbol at index 0; a handle with the value 0 represents a missing symbol.
- sg_
utf8_ bounds - A half-open range identifying a range of characters in a string.
Enums§
- sg_
deque_ direction - Describes in which direction the content of a deque is stored in memory.
- sg_
node_ kind - The different kinds of node that can appear in a stack graph.
- sg_
result - Describes the result of a computation
Constants§
- SG_
JUMP_ TO_ NODE_ HANDLE - The handle of the singleton “jump to scope” node.
- SG_
JUMP_ TO_ NODE_ ID - The local_id of the singleton “jump to scope” node.
- SG_
LIST_ EMPTY_ HANDLE - The handle of an empty list.
- SG_
NULL_ HANDLE - The null value for all of our handles.
- SG_
ROOT_ NODE_ HANDLE - The handle of the singleton root node.
- SG_
ROOT_ NODE_ ID - The local_id of the singleton root node.
Functions§
- sg_
forward_ partial_ path_ stitcher_ free - Frees a forward path stitcher.
- sg_
forward_ partial_ path_ stitcher_ from_ nodes - Creates a new forward partial path stitcher that is “seeded” with a set of starting stack graph nodes. The path stitcher will be set up to find complete paths only.
- sg_
forward_ partial_ path_ stitcher_ from_ partial_ paths - Creates a new forward partial path stitcher that is “seeded” with a set of initial partial paths.
- sg_
forward_ partial_ path_ stitcher_ process_ next_ phase - Runs the next phase of the algorithm. We will have built up a set of incomplete partial paths
during the previous phase. Before calling this function, you must ensure that
db
contains all of the possible partial paths that we might want to extend any of those candidate partial paths with. - sg_
forward_ partial_ path_ stitcher_ set_ max_ work_ per_ phase - Sets the maximum amount of work that can be performed during each phase of the algorithm. By bounding our work this way, you can ensure that it’s not possible for our CPU-bound algorithm to starve any worker threads or processes that you might be using. If you don’t call this method, then we allow ourselves to process all of the extensions of all of the paths found in the previous phase, with no additional bound.
- sg_
forward_ partial_ path_ stitcher_ set_ similar_ path_ detection - Sets whether similar path detection should be enabled during path stitching. Paths are similar if start and end node, and pre- and postconditions are the same. The presence of similar paths can lead to exponential blow up during path stitching. Similar path detection is disabled by default because of the accociated preformance cost.
- sg_
partial_ path_ arena_ add_ partial_ path_ edge_ lists - Adds new partial path edge lists to the partial path arena.
count
is the number of partial path edge lists you want to create. The content of each partial path edge list comes from two arrays. Thelengths
array must havecount
elements, and provides the number of edges in each partial path edge list. Theedges
array contains the contents of each of these partial path edge lists in one contiguous array. Its length must be the sum of all of the counts in thelengths
array. - sg_
partial_ path_ arena_ add_ partial_ scope_ stacks - Adds new partial scope stacks to the partial path arena.
count
is the number of partial scope stacks you want to create. The content of each partial scope stack comes from three arrays. Thelengths
array must havecount
elements, and provides the number of scopes in each scope stack. Thescopes
array contains the contents of each of these scope stacks in one contiguous array. Its length must be the sum of all of the counts in thelengths
array. Thevariables
array must havecount
elements, and provides the optional scope stack variable for each partial scope stack. - sg_
partial_ path_ arena_ add_ partial_ symbol_ stacks - Adds new partial symbol stacks to the partial path arena.
count
is the number of partial symbol stacks you want to create. The content of each partial symbol stack comes from two arrays. Thelengths
array must havecount
elements, and provides the number of symbols in each partial symbol stack. Thesymbols
array contains the contents of each of these partial symbol stacks in one contiguous array. Its length must be the sum of all of the counts in thelengths
array. Thevariables
array must havecount
elements, and provides the optional symbol stack variable for each partial symbol stack. - sg_
partial_ path_ arena_ find_ all_ complete_ paths - Finds all complete paths reachable from a set of starting nodes, placing the result into the
path_list
output parameter. You must free the path list when you are done with it by callingsg_path_list_done
. - sg_
partial_ path_ arena_ find_ partial_ paths_ in_ file - Finds all partial paths in a file that are productive and as complete as possible, placing
the result into the
partial_path_list
output parameter. You must free the path list when you are done with it by callingsg_partial_path_list_done
. - sg_
partial_ path_ arena_ free - Frees a path arena, and all of its contents.
- sg_
partial_ path_ arena_ new - Creates a new, initially empty partial path arena.
- sg_
partial_ path_ arena_ partial_ path_ edge_ list_ cells - Returns a reference to the array of partial path edge list content in a partial path arena. The resulting array pointer is only valid until the next call to any function that mutates the partial path arena.
- sg_
partial_ path_ arena_ partial_ scope_ stack_ cells - Returns a reference to the array of partial scope stack content in a partial path arena. The resulting array pointer is only valid until the next call to any function that mutates the partial path arena.
- sg_
partial_ path_ arena_ partial_ symbol_ stack_ cells - Returns a reference to the array of partial symbol stack content in a partial path arena. The resulting array pointer is only valid until the next call to any function that mutates the path arena.
- sg_
partial_ path_ database_ add_ partial_ paths - Adds new partial paths to the partial path database.
paths
is the array of partial paths that you want to add;count
is the number of them. - sg_
partial_ path_ database_ ensure_ both_ directions - Ensures all partial paths in the database are availabe in both forwards and backwards orientation.
- sg_
partial_ path_ database_ ensure_ forwards - Ensures all partial paths in the database are in forwards orientation.
- sg_
partial_ path_ database_ find_ local_ nodes - Determines which nodes in the stack graph are “local”, taking into account the partial paths in this database. The result is valid until the next call to this function, or until the database is freed.
- sg_
partial_ path_ database_ free - Frees a partial path database, and all of its contents.
- sg_
partial_ path_ database_ local_ nodes - Returns a reference to the set of stack graph nodes that are local, according to this database of partial paths. The resulting set is only valid until the next call to any function that mutates the partial path database.
- sg_
partial_ path_ database_ mark_ local_ nodes - Marks that a list of stack graph nodes are local.
- sg_
partial_ path_ database_ new - Creates a new, initially empty partial path database.
- sg_
partial_ path_ database_ partial_ paths - Returns a reference to the array of partial path data in this partial path database. The resulting array pointer is only valid until the next call to any function that mutates the partial path database.
- sg_
partial_ path_ list_ count - sg_
partial_ path_ list_ free - sg_
partial_ path_ list_ new - Creates a new, empty sg_partial_path_list.
- sg_
partial_ path_ list_ paths - sg_
stack_ graph_ add_ edges - Adds new edges to the stack graph. You provide an array of
struct sg_edges
instances. A stack graph can contain at most one edge between any two nodes. It is not an error if you try to add an edge that already exists, but it won’t have any effect on the graph. - sg_
stack_ graph_ add_ files - Adds new files to the stack graph. You provide all of the file content concatenated together
into a single string, and an array of the lengths of each file. You also provide an output
array, which must have the same size as
lengths
. We will place each file’s handle in the output array. - sg_
stack_ graph_ add_ source_ infos - Adds new source information to the stack graph. You provide an array of
sg_node_source_info
instances. Any existing source information for any node mentioned in the array is overwritten. - sg_
stack_ graph_ add_ strings - Adds new strings to the stack graph. You provide all of the string content concatenated
together into a single string, and an array of the lengths of each string. You also provide an
output array, which must have the same size as
lengths
. We will place each string’s handle in the output array. - sg_
stack_ graph_ add_ symbols - Adds new symbols to the stack graph. You provide all of the symbol content concatenated
together into a single string, and an array of the lengths of each symbol. You also provide an
output array, which must have the same size as
lengths
. We will place each symbol’s handle in the output array. - sg_
stack_ graph_ files - Returns a reference to the array of file data in this stack graph. The resulting array pointer is only valid until the next call to any function that mutates the stack graph.
- sg_
stack_ graph_ free - Frees a stack graph, and all of its contents.
- sg_
stack_ graph_ get_ or_ create_ nodes - Adds new nodes to the stack graph. You provide an array of
struct sg_node
instances. You also provide an output array, which must have the same length asnodes
, in which we will place each node’s handle in the stack graph. - sg_
stack_ graph_ new - Creates a new, initially empty stack graph.
- sg_
stack_ graph_ nodes - Returns a reference to the array of nodes in this stack graph. The resulting array pointer is only valid until the next call to any function that mutates the stack graph.
- sg_
stack_ graph_ source_ infos - Returns a reference to the array of source information in this stack graph. The resulting array pointer is only valid until the next call to any function that mutates the stack graph.
- sg_
stack_ graph_ strings - Returns a reference to the array of string data in this stack graph. The resulting array pointer is only valid until the next call to any function that mutates the stack graph.
- sg_
stack_ graph_ symbols - Returns a reference to the array of symbol data in this stack graph. The resulting array pointer is only valid until the next call to any function that mutates the stack graph.
Type Aliases§
- sg_
file_ handle - A handle to a file in a stack graph. A zero handle represents a missing file.
- sg_
node_ handle - A handle to a node in a stack graph. A zero handle represents a missing node.
- sg_
partial_ path_ edge_ list_ cell_ handle - A handle to an element of a partial path edge list. A zero handle represents a missing partial path edge list. A UINT32_MAX handle represents an empty partial path edge list.
- sg_
partial_ path_ handle - A handle to a partial path in a partial path database. A zero handle represents a missing partial path.
- sg_
partial_ scope_ stack_ cell_ handle - A handle to an element of a partial scope stack. A zero handle represents a missing partial scope stack. A UINT32_MAX handle represents an empty partial scope stack.
- sg_
partial_ symbol_ stack_ cell_ handle - A handle to an element of a partial symbol stack. A zero handle represents a missing partial symbol stack. A UINT32_MAX handle represents an empty partial symbol stack.
- sg_
scope_ stack_ variable - Represents an unknown list of exported scopes.
- sg_
string_ handle - A handle to an interned string in a stack graph. A zero handle represents a missing string.
- sg_
symbol_ handle - A handle to a symbol in a stack graph. A zero handle represents a missing symbol.
- sg_
symbol_ stack_ variable - Represents an unknown list of scoped symbols.