Documentation
¶
Overview ¶
Package kit contains the reusable validation pass framework.
Index ¶
- Constants
- func BodyScope(scope *symbols.Scope, decl ast.Node) *symbols.Scope
- func DeclarationScope(sym *symbols.Symbol) *symbols.Scope
- func IsReference(n ast.Node) bool
- func MemberSymbols(ctx *Context, root *symbols.Scope) []*symbols.Symbol
- func Move[K comparable](s CountSet[K], old, cur map[K]bool, name func(K) string, ...)
- func MultiplicityOf(sym *symbols.Symbol) *ast.Multiplicity
- func ReferenceScope(sym *symbols.Symbol) *symbols.Scope
- func Symbols(ctx *Context, root *symbols.Scope) []*symbols.Symbol
- func UnwrapMembership(node ast.Node) ast.Node
- func WalkScoped(root *symbols.Scope, visit func(scope *symbols.Scope, node ast.Node))
- func WalkSymbols(ctx *Context, root *symbols.Scope, visit func(*symbols.Symbol))
- type AboutUnion
- type Batch
- type ChainStep
- type Context
- func (c *Context) DownstreamOfFailure(ref ast.Node) bool
- func (c *Context) DownstreamSpan(span source.Span) bool
- func (c *Context) Gathers() *Gathers
- func (c *Context) InBatch(b *Batch)
- func (c *Context) Model() *semantics.Model
- func (c *Context) Resolver() *resolve.Resolver
- func (c *Context) SetFailures(spans []source.Span)
- func (c *Context) Share(resolver *resolve.Resolver, model *semantics.Model, gathers *Gathers)
- type ContributorNamer
- type CountSet
- type Gathers
- func (g *Gathers) Contributors(name string) ([]string, bool)
- func (g *Gathers) Gather(ctx *Context, doc string, f func(root *symbols.Scope))
- func (g *Gathers) Gathered(doc string) bool
- func (g *Gathers) Has(doc string) bool
- func (g *Gathers) Regather(ctx *Context, docs map[string]bool) []string
- func (g *Gathers) Reset()
- func (g *Gathers) Union(key string) Regatherer
- func (g *Gathers) UnionOf(ctx *Context, key string, build func() Regatherer) Regatherer
- type Options
- type Pass
- type PassLevel
- type Regatherer
- type ScopedNode
- type Walker
Constants ¶
const AboutGather = "\x00identity"
AboutGather names the gather of the `about`-annotated elements no workspace document declares.
Variables ¶
This section is empty.
Functions ¶
func BodyScope ¶
BodyScope returns the scope decl declares into, or scope itself when the scope builder gave it none.
func DeclarationScope ¶
w8cScopeOf returns the scope a declaration's own references resolve in.
func IsReference ¶
w8cIsReference reports whether n names a feature rather than computing a value.
func MemberSymbols ¶
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 ¶
ReferenceScope returns the scope a symbol's own references resolve in.
func UnwrapMembership ¶
UnwrapMembership strips the membership a declaration reaches a body wrapped in.
func WalkScoped ¶ added in v0.9.2
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.
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 ¶
w8cChainStep is one chaining feature: the node resolving to it and the span of the segment naming it.
func ChainSteps ¶
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
// Source reads the document's notation, which a fix reconstructing text
// needs; nil leaves it unreadable. A batch sets it from Batch.Source.
Source source.Lookup
// 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 ¶
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 ¶
DownstreamSpan reports whether span contains a blocking failure.
func (*Context) 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
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 ¶
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 ¶
Resolver returns the shared resolver for this context, creating it on first use so multiple passes reuse one memoized instance.
func (*Context) SetFailures ¶
SetFailures records the blocking spans of the tiers below the pass about to run. Only the registry calls it, once per pass.
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 Gathers ¶
type Gathers struct {
// contains filtered or unexported fields
}
Gathers holds workspace-wide audit state and the unions built from documents.
func (*Gathers) Contributors ¶ added in v0.9.2
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) Gathered ¶
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 ¶
Has reports whether doc is among the gathered workspace documents, with locking.
func (*Gathers) Regather ¶
Regather updates the requested documents and reports changed union keys. Nothing is gathered for a union no analysis has asked for yet.
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).
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
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.