graph

package
v0.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package graph holds the cross-language symbol graph: nodes are symbols (functions, types, kernels, asm procedures), edges are structural or cross-language binding relations. The graph is the structural pillar of spectackle — it lets an LLM compute the impact radius of a change across language boundaries (Go -> C -> CUDA) without reading file contents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PersonalizedRank

func PersonalizedRank(g Graph, focus []NodeID, depth, iters int, damping float64) map[NodeID]float64

PersonalizedRank computes personalized PageRank over the subgraph within depth hops of the focus seeds (SPX-GRA-004). Relevance in a call graph flows both ways — a callee matters to its caller and vice versa — so the adjacency is undirected. Restart mass is split uniformly over the seeds; nodes outside the subgraph score 0. Deterministic: fixed iteration count and float sums accumulated in sorted node order (map iteration order would flip last bits).

Types

type Direction

type Direction uint8

Direction selects edge traversal direction.

const (
	Out Direction = iota
	In
	Both
)

type Edge

type Edge struct {
	Src, Dst NodeID
	Kind     EdgeKind
	File     string
	Line     int
}

Edge is a directed relation between two nodes. File:Line locate the edge site (e.g. the call or launch statement), not the definitions.

type EdgeKind

type EdgeKind uint8

EdgeKind classifies an edge.

const (
	EUnknown  EdgeKind = iota
	EDef               // container defines symbol (file -> func, type -> method)
	ECall              // same-language call
	EIncl              // #include / import
	ECgo               // Go <-> C boundary (import "C", //export)
	EAsm               // Go decl <-> asm TEXT implementation
	ELaunch            // host code launches GPU kernel (<<<>>>, pipeline creation)
	EUse               // reference that is not a call (type use, var read)
	ESpecLink          // EARS rule bound to node (from .spectackle/links.tsv)
)

func EdgeKindFromString

func EdgeKindFromString(s string) EdgeKind

EdgeKindFromString is the inverse of EdgeKind.String; EUnknown for no match.

func (EdgeKind) String

func (k EdgeKind) String() string

type Graph

type Graph interface {
	Upsert(nodes []Node, edges []Edge)
	Node(id NodeID) (Node, bool)
	// Find returns up to k nodes whose ID or name contains q (case-insensitive),
	// filtered by kind (KUnknown = any), best matches first.
	Find(q string, k int, kind NodeKind) []Node
	// Neighbors returns edges incident to id in the given direction, filtered
	// by edge kinds (empty = all).
	Neighbors(id NodeID, dir Direction, kinds []EdgeKind) []Edge
	// Impact runs a bounded BFS from seeds and returns the reachable subgraph.
	// Each node appears exactly once, at its minimum BFS distance (SPX-GRA-002).
	Impact(seeds []NodeID, depth int, dir Direction, kinds []EdgeKind) ([]Node, []Edge)
	// Stats returns the total node and edge counts — a cheap size/health
	// signal (no traversal), used by the `state` overview tool.
	Stats() (nodes, edges int)
}

Graph is the queryable symbol graph. Implementations must be safe for concurrent readers with a single writer.

func NewMem

func NewMem() Graph

NewMem returns an empty in-memory graph.

type Lang

type Lang string

Lang tags the language a node belongs to.

const (
	LangGo     Lang = "go"
	LangC      Lang = "c"
	LangCpp    Lang = "cpp"
	LangCuda   Lang = "cu"
	LangAsm    Lang = "asm"
	LangObjC   Lang = "objc"
	LangMSL    Lang = "msl"
	LangPy     Lang = "py"
	LangJS     Lang = "js"
	LangTS     Lang = "ts"
	LangRs     Lang = "rs"
	LangJava   Lang = "java"
	LangRb     Lang = "rb"
	LangPHP    Lang = "php"
	LangKt     Lang = "kt"
	LangSwift  Lang = "swift"
	LangCs     Lang = "cs"
	LangScala  Lang = "scala"
	LangSh     Lang = "sh"
	LangLua    Lang = "lua"
	LangZig    Lang = "zig"
	LangPerl   Lang = "pl"
	LangDart   Lang = "dart"
	LangGroovy Lang = "groovy"
	LangEx     Lang = "ex"
	LangErl    Lang = "erl"
	LangJl     Lang = "jl"
	LangHs     Lang = "hs"
	LangMl     Lang = "ml"
	LangR      Lang = "r"
	LangF90    Lang = "f90"
	LangGLSL   Lang = "glsl"
)

type Node

type Node struct {
	ID      NodeID
	Kind    NodeKind
	Lang    Lang
	File    string // repo-relative path
	Line    int    // 1-based definition start line
	EndLine int    // 1-based definition end line (anchor span; 0 = unknown)
	Sig     string // compact signature, e.g. "(n int,a float32)error"
	Rank    float32
}

Node is a symbol in the cross-language graph.

type NodeID

type NodeID string

NodeID is a stable short identifier, "<lang>:<qualified-name>", e.g. "go:saxpy.Saxpy", "cu:saxpy_kernel". See internal/ids.

type NodeKind

type NodeKind uint8

NodeKind classifies a node.

const (
	KUnknown NodeKind = iota
	KFunc             // function
	KMethod           // method (receiver-bound)
	KType             // type / struct / class
	KVar              // package/global variable
	KKernel           // CUDA __global__ / Metal kernel / compute entry point
	KAsmProc          // asm TEXT procedure
	KFile             // file-level node
	KDir              // directory-level node
)

func (NodeKind) String

func (k NodeKind) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL