kit

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package kit contains the reusable validation pass framework.

Index

Constants

View Source
const AboutGather = "\x00identity"

AboutGather names the gather of the `about`-annotated elements no workspace document declares.

Variables

This section is empty.

Functions

func BodyScope

func BodyScope(scope *symbols.Scope, decl ast.Node) *symbols.Scope

BodyScope returns the scope decl declares into, or scope itself when the scope builder gave it none.

func DeclarationScope

func DeclarationScope(sym *symbols.Symbol) *symbols.Scope

w8cScopeOf returns the scope a declaration's own references resolve in.

func IsReference

func IsReference(n ast.Node) bool

w8cIsReference reports whether n names a feature rather than computing a value.

func MemberSymbols

func MemberSymbols(ctx *Context, root *symbols.Scope) []*symbols.Symbol

w8cSymbols lists the scope tree's symbols once each, in visiting order, and caches the list on ctx for the passes that share it.

func Move

func Move[K comparable](s CountSet[K], old, cur map[K]bool, name func(K) string, changed map[string]bool)

Move replaces one document's contribution and names flipped memberships.

func MultiplicityOf

func MultiplicityOf(sym *symbols.Symbol) *ast.Multiplicity

w8cMultiplicityOf returns the multiplicity a declaration declares, or nil.

func ReferenceScope

func ReferenceScope(sym *symbols.Symbol) *symbols.Scope

ReferenceScope returns the scope a symbol's own references resolve in.

func Symbols

func Symbols(ctx *Context, root *symbols.Scope) []*symbols.Symbol

func UnwrapMembership

func UnwrapMembership(node ast.Node) ast.Node

UnwrapMembership strips the membership a declaration reaches a body wrapped in.

func WalkScoped added in v0.9.2

func WalkScoped(root *symbols.Scope, visit func(scope *symbols.Scope, node ast.Node))

WalkScoped visits every node of the document whose scope tree root heads, each with the scope it is written in: a node that declares a scope of its own is visited in the enclosing one, and its descendants in its own.

func WalkSymbols

func WalkSymbols(ctx *Context, root *symbols.Scope, visit func(*symbols.Symbol))

WalkSymbols visits every symbol of the scope subtree exactly once.

Types

type AboutUnion

type AboutUnion interface {
	Regatherer
	RegatherAbout(ctx *Context, g *Gathers, changed map[string]bool)
}

AboutUnion also gathers what lies outside the workspace documents.

type Batch added in v0.9.2

type Batch struct {
	// Documents names the documents the batch analyzes, in the order asked for.
	Documents []string
	// Gathers is what the workspace-wide audits gather, once for the batch, on
	// first use by any of its contexts; nil leaves each context to gather alone.
	Gathers *Gathers
	// Source reads the documents' notation, which comment and documentation
	// bodies come from; nil leaves every body unreadable, as an editor never is.
	Source source.Lookup
	// Record has each analysis record what it read of the index, for the
	// interface record written from it; off, nothing of a run is kept.
	Record bool
}

Batch is what a batch of analyses computes once before its documents are analyzed together; anything a pass would gather over every document belongs here.

type ChainStep

type ChainStep struct {
	Node ast.Node
	Span source.Span
}

w8cChainStep is one chaining feature: the node resolving to it and the span of the segment naming it.

func ChainSteps

func ChainSteps(target ast.Node) []ChainStep

w8cChainSteps splits a chain target into chaining features: only a `.` starts a new one, a `::`-qualified name is a single chaining feature.

type Context

type Context struct {
	Name             string
	Kind             source.Kind
	Index            *symbols.Index
	ParseDiagnostics []diag.Diagnostic
	// Options is what the caller asked for, fixed at construction: a pass reads
	// it, and nothing mutates it during a run.
	Options Options
	// Batch is the batch this document is analyzed in, nil when it is analyzed
	// alone; every context of a batch reads the one value and none writes it.
	Batch *Batch
	// contains filtered or unexported fields
}

Context carries shared state made available to every pass in a run: the document name, the global symbol index, a lazily-created shared resolver, and the syntax diagnostics produced by the caller's parse (passes must not import the parser, so these enter here).

func NewContext

func NewContext(name string, kind source.Kind, idx *symbols.Index, parseDiags []diag.Diagnostic, opts Options, newModel func(*resolve.Resolver) *semantics.Model) *Context

NewContext builds a Context; newModel makes the semantic model on first use of Model().

func (*Context) DownstreamOfFailure

func (c *Context) DownstreamOfFailure(ref ast.Node) bool

DownstreamOfFailure reports whether a reference an element's meaning rests on — its type, its metaclass — carries a blocking fault from a lower tier, so a pass whose subject is that element has nothing sound to judge.

func (*Context) DownstreamSpan

func (c *Context) DownstreamSpan(span source.Span) bool

DownstreamSpan reports whether span contains a blocking failure.

func (*Context) Gathers

func (c *Context) Gathers() *Gathers

Gathers is what the workspace-wide audits gathered per document, shared across analyses by a workspace and made afresh for a context outside one.

func (*Context) InBatch added in v0.9.2

func (c *Context) InBatch(b *Batch)

InBatch places the context in batch, reading the gathers the batch shares instead of gathering alone; a nil batch leaves it analyzing on its own.

func (*Context) Model

func (c *Context) Model() *semantics.Model

Model returns the shared semantic model (specialization graph, multiplicity, inherited members, evaluator) for this context, creating it on first use over the shared resolver so constraint passes reuse one memoized instance.

func (*Context) Resolver

func (c *Context) Resolver() *resolve.Resolver

Resolver returns the shared resolver for this context, creating it on first use so multiple passes reuse one memoized instance.

func (*Context) SetFailures

func (c *Context) SetFailures(spans []source.Span)

SetFailures records the blocking spans of the tiers below the pass about to run. Only the registry calls it, once per pass.

func (*Context) Share

func (c *Context) Share(resolver *resolve.Resolver, model *semantics.Model, gathers *Gathers)

Share hands the context a resolver, model and gathers that outlive it — a workspace's, kept across analyses — instead of the fresh ones it would make.

type ContributorNamer added in v0.9.2

type ContributorNamer interface {
	// Contributors names the contributors of the union that answers name, or
	// false when name is none of its.
	Contributors(name string) ([]string, bool)
}

ContributorNamer is a union that can name the workspace documents whose contribution to it is not empty: the documents a judgment read by one of its names depends on, for a record of that judgment's document to carry.

type CountSet

type CountSet[K comparable] map[K]int

CountSet is a union of per-document sets.

func (CountSet[K]) Has

func (s CountSet[K]) Has(k K) bool

type Gathers

type Gathers struct {
	// contains filtered or unexported fields
}

Gathers holds workspace-wide audit state and the unions built from documents.

func NewGathers

func NewGathers() *Gathers

NewGathers returns gathers with nothing gathered yet.

func (*Gathers) Contributors added in v0.9.2

func (g *Gathers) Contributors(name string) ([]string, bool)

Contributors names the workspace documents whose contribution to the union answering name is not empty, sorted; false when no built union answers it.

func (*Gathers) Gather

func (g *Gathers) Gather(ctx *Context, doc string, f func(root *symbols.Scope))

Gather runs f over doc's root in doc's own resolver frame.

func (*Gathers) Gathered

func (g *Gathers) Gathered(doc string) bool

Gathered reports whether doc is among the gathered workspace documents. It is unlocked for unions inside Regather/RegatherAbout, which run under the lock.

func (*Gathers) Has

func (g *Gathers) Has(doc string) bool

Has reports whether doc is among the gathered workspace documents, with locking.

func (*Gathers) Regather

func (g *Gathers) Regather(ctx *Context, docs map[string]bool) []string

Regather updates the requested documents and reports changed union keys. Nothing is gathered for a union no analysis has asked for yet.

func (*Gathers) Reset

func (g *Gathers) Reset()

Reset forgets every gathered document and union.

func (*Gathers) Union

func (g *Gathers) Union(key string) Regatherer

Union returns the union under key if built, else nil.

func (*Gathers) UnionOf

func (g *Gathers) UnionOf(ctx *Context, key string, build func() Regatherer) Regatherer

UnionOf returns the union under key, built on first use over every gathered document.

type Options

type Options struct {
	// Conformance is the strictness the notation is judged at.
	Conformance diag.ConformanceMode
}

Options is the analysis configuration of one run. The zero value is what every existing caller gets: today's behavior, unchanged.

type Pass

type Pass interface {
	Level() PassLevel
	Run(ctx *Context, name string, root *ast.RootNamespace) []diag.Diagnostic
}

Pass is a single validation rule. Level reports its dependency tier; Run executes it over a whole document and returns any diagnostics found.

type PassLevel

type PassLevel int

PassLevel is the dependency tier of a validation pass. Passes at a higher level are skipped when a lower level produced an error, avoiding cascade noise (e.g. no type-check on an unresolved reference).

const (
	LevelSyntax PassLevel = iota
	LevelNameResolution
	LevelType
	LevelConstraint
)

func (PassLevel) String

func (l PassLevel) String() string

String returns the lowercase name of the level, or "unknown".

type Regatherer

type Regatherer interface {
	Regather(ctx *Context, g *Gathers, doc string, changed map[string]bool)
}

Regatherer is one workspace-wide gather, kept per document by Gathers.

type ScopedNode added in v0.9.2

type ScopedNode struct {
	Scope *symbols.Scope
	Node  ast.Node
}

ScopedNode is a node of a document with the scope it is written in.

func ScopedNodes added in v0.9.2

func ScopedNodes(ctx *Context, root *symbols.Scope) []ScopedNode

ScopedNodes lists what WalkScoped visits under root, in visiting order. The list of the document ctx analyzes is kept on ctx for the passes that walk it again; any other root is walked each time.

type Walker

type Walker struct {
	Ctx *Context
	// contains filtered or unexported fields
}

w8cWalker visits every symbol of a document's scope tree once, deduping by pointer: one declaration may be registered under several keys.

func (*Walker) Walk

func (w *Walker) Walk(scope *symbols.Scope, visit func(*symbols.Symbol))

Jump to

Keyboard shortcuts

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