extract

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package extract builds the interaction relation from a loaded workspace: the import-graph extractors for the language trio (DESIGN.md sections 6.2-6.4, schema/SPEC.md). One extraction pass populates one relation shared by every check (lesson 30).

Python stdlib module-name table.

Generated once from CPython 3.14.5 sys.stdlib_module_names (see BUILDLOG). Used by the DESIGN.md section-6.3 resolution order, step 1: stdlib imports never resolve to workspace members. Hand-committed data table; regenerate with the command recorded in BUILDLOG.md if the interpreter baseline moves.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallResolution

type CallResolution string

CallResolution classifies a call site in the side table.

const (
	// CallSyntactic: resolved to a workspace-local callable or type; the
	// relation carries the corresponding calls/instantiates row.
	CallSyntactic CallResolution = "syntactic"
	// CallExternal: the callee is a builtin, stdlib, or external-package
	// name (library-stdout matches these).
	CallExternal CallResolution = "external"
	// CallUnresolved: dynamic dispatch, local rebinding, star-import
	// ambiguity — honestly unknown, never guessed.
	CallUnresolved CallResolution = "unresolved"
)

type CallSite

type CallSite struct {
	Lang   vocab.Lang
	Member string
	// Module is the containing module's logical name.
	Module string
	// Container is the serialized ID of the innermost enclosing container
	// node (module, type, function, or closure).
	Container string
	// Callee is the alias-expanded dotted callee text ("print",
	// "sys.stdout.write", "pkg.mod.f"); empty when the callee expression is
	// not a dotted name.
	Callee     string
	Resolution CallResolution
	// Target is the serialized resolved node ID (syntactic only).
	Target      string
	File        string
	Span        relation.Span
	TestContext bool
}

CallSite is one call site (side data beside the relation).

type ExternalImport

type ExternalImport struct {
	Lang vocab.Lang
	// Member is the importing member's name.
	Member string
	// SrcModule is the importing module's logical name.
	SrcModule string
	// Specifier: Python — the full dotted import (matching uses the
	// top-level segment); Go — the full import path; TS/JS — the raw bare
	// specifier.
	Specifier string
	// File is the workspace-root-relative importing file.
	File        string
	Span        relation.Span
	TestContext bool
}

ExternalImport is one import site of an external (non-workspace) target.

type Result

type Result struct {
	Relation *relation.Relation
	// LineIndex maps a workspace-root-relative file path to the sorted byte
	// offsets at which its lines start (offset 0 is always present), over
	// the LF-normalized content.
	LineIndex map[string][]uint32
	// ExternalImports carries import sites whose specifier resolves to no
	// workspace member: the relation's node set covers only workspace
	// units, and library-forbidden-imports needs external specifiers
	// (flask, net/http, express). Side data beside the relation, sorted by
	// (lang, member, file, span, specifier).
	ExternalImports []ExternalImport
	// Calls carries every Python call site: syntactic (mirrored by a
	// relation row), external (builtins/stdlib/external packages — the
	// library-stdout surface), and unresolved (honestly unknown). The
	// relation itself carries only resolved local-to-local rows because
	// rows demand both endpoints exist as nodes; see BUILDLOG.
	Calls []CallSite
	// Unreachable carries dead statement regions (the unreachable-code
	// rule and the tier-1 removal transform).
	Unreachable []UnreachableRegion
}

Result is the extraction output: the frozen relation plus the line index used to derive 1-based lines from byte spans at output time.

func Extract

func Extract(ws *workspace.Workspace) (*Result, error)

Extract runs all extractors over the workspace and freezes the relation.

func (*Result) Line

func (r *Result) Line(file string, offset uint32) int

Line converts a byte offset in file to a 1-based line number. Files without an index (never read during extraction) report line 1.

type UnreachableRegion

type UnreachableRegion struct {
	Lang   vocab.Lang
	Member string
	Module string
	// Container is the serialized ID of the node owning the block.
	Container string
	File      string
	// Span covers the first through last unreachable statement.
	Span relation.Span
	// FirstLineSpan is the first unreachable statement (the finding site).
	FirstLineSpan relation.Span
	TestContext   bool
}

UnreachableRegion is one dead statement region (side data; the unreachable-code rule and the tier-1 removal transform consume it).

Jump to

Keyboard shortcuts

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