kit

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 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 ForEachBodySymbol

func ForEachBodySymbol(body *symbols.Scope, visit func(*symbols.Symbol))

forEachBodySymbol visits the symbols a metadata body declares, at any depth.

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 UnnamedMetadataBody

func UnnamedMetadataBody(scope *symbols.Scope, prefix *ast.PrefixMetadata) *symbols.Scope

unnamedMetadataBody is the scope of an unnamed annotation's body, which no symbol owns and the symbol walk therefore never reaches; nil for a named one.

func UnwrapMembership

func UnwrapMembership(node ast.Node) ast.Node

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

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 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
	// 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) 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 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) 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 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