query

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 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 query is the design query surface (WS3-029). It runs Datalog over the design's fact base, so an engineer runs ad-hoc queries ("search your whole design as relations, including datasheets"). Every answer carries the provenance of the facts that produced it. Rules and search share one vocabulary. A rule asserts a property over these relations, and a search is an arbitrary query over the same ones.

The engine itself lives in github.com/panyam/jaala/datalog (agni issue 731), and it knows nothing about circuits. This package is agni's adapter over it, and it holds two things.

  • a Source projecting a check.Model through a facts.Registry, so every relation the fact layer registers is queryable (source.go);
  • agni's own uses of queries: RuleFromQuery, the wire form, the catalog, and the teaching examples.

Every name a query calls is registered in the fact layer's vocabulary (facts.Registry.Vocabulary), whether it is a relation, a predicate or a module. So this package adds no names of its own. The circuit walks net.reaches and net.route live with the relations, in stdlib/relations.

The types are aliases for the engine's, so a Query built here is the engine's Query and nothing converts at the boundary.

The package is WASM-clean. The engine imports only the standard library, and this adapter imports only check, facts and the generated IR. So the whole chain read → Model → facts → query runs client-side in the browser.

Index

Constants

View Source
const (
	KindNetlist   = facts.KindNetlist
	KindBoard     = facts.KindBoard
	KindDatasheet = facts.KindDatasheet
	KindPredicate = facts.KindPredicate
	KindDerived   = facts.KindDerived
	KindExtension = facts.KindExtension
)

Relation kinds and their display order, re-exported so a caller can render this engine's catalog without importing the fact layer for the grouping labels alone.

Variables

View Source
var CompileGlob = stdlib.CompileGlob

CompileGlob compiles a shell-style glob the way the str.glob predicate does, for a Go caller that must match the same pattern the same way.

View Source
var CompilePattern = stdlib.CompilePattern

CompilePattern compiles a regular expression the way the str.match predicate does.

View Source
var KindOrder = facts.KindOrder

KindOrder is the display order of the kind groups, most-common first.

Functions

func Bind added in v0.2.2

func Bind(b Bindings) datalog.Option

Bind gives goal variables values from the caller, so a query asked about one net or part is the same text every time and carries the value as data (agni issue 793). When the query is evaluated, the engine refuses a binding if the goal does not use its name. So a misspelled binding fails rather than leaving the variable free.

func BindArgs added in v0.2.4

func BindArgs(b Bindings) []string

BindArgs spells bound values the way `--bind` takes them, such as `n=GND` and `v=3.3`. Text that would otherwise read as a number is quoted, as in `t="3"`. The values are sorted by name. A value may be carried somewhere as text, such as a viewer link (agni issue 634), and ParseBinding reads it back as the same value. A variable bound to several values is spelled once per value, in order. `--bind` and a link both give a list this way.

func BindEach added in v0.3.0

func BindEach(name string, vals []Value) datalog.Option

BindEach gives one goal variable several values, so the goal answers for each of them. For example, a rule asked about a few nets binds its subject variable to their names (agni issue 897).

func BudgetOf added in v0.2.2

func BudgetOf(ctx context.Context) int64

BudgetOf is the work budget ctx carries, or 0 for none.

func Caret added in v0.2.4

func Caret(text string, p Position) string

Caret renders p's line of text with a caret under its column, for a terminal or a fixed-width box. A tab before the column is kept as a tab, so the caret lines up however wide the reader's tabs are. It returns "" when p is not inside text.

func Display added in v0.2.2

func Display(v Value) string

Display is a value as a person reads it in an answer: a cell, a csv field, a rule's message.

A length is published in metres (see stdlib/relations), so a 0.08 mm track is the value 8e-05 with base unit m. The engine folds a threshold written `0.1mm` to metres, so the threshold compares against that value correctly. A board is drawn in millimetres, so Display shows a length in millimetres again. The cell's number then matches the one the board's own tools print. Every other value is shown as the engine holds it (agni issue 1035).

Twelve significant digits drop the noise of scaling by 1000, so 0.1524 mm reads 0.1524 and not 0.15240000000000004.

func EvalOptions added in v0.2.2

func EvalOptions(ctx context.Context) []datalog.Option

EvalOptions turns the context's budget, when it carries one, into engine options. agni passes them to every evaluation it runs for a caller, so a budget set once on the context reaches each one.

func Explain added in v0.2.2

func Explain(r *ExplainReport) datalog.Option

Explain asks an evaluation to fill r with its plan. Its cost grows with the rules and literals in a query, not with its tuples, so `agni query --explain` and a timed request can afford it.

func FindingQueryProto

func FindingQueryProto(fq FindingQuery) *checkspb.QueryRule

FindingQueryProto encodes the row-to-finding mapping that turns a datalog program into a rule.

func FormatBindings added in v0.2.2

func FormatBindings(b Bindings) []string

FormatBindings renders bound values the way a query would spell them, such as `?n = "GND"` or `?v = 3.3`. A variable bound to several values renders as the list it ranges over, such as `?n in ["I2C_SCL", "I2C_SDA"]`. The output is sorted by name, so a rendered view states the values beside its query.

Text goes between quotes exactly as it is, since a query string takes no escapes. So `"U1\."` is the four characters U, 1, a backslash and a dot (jaala v0.1.62). Go's quoting doubled that backslash and spelled another pattern. A value has no spelling in the language if it holds a quote with no backslash before it, or if it ends in a lone backslash. Such a value is shown the same way. It still binds, since a binding never travels as text.

func ModuleMembers added in v0.2.2

func ModuleMembers(text string) ([]string, error)

ModuleMembers reports the public members defined in a Datalog module's text, by bare name. A host uses it to check a module's paths against a vocabulary before composing it. It returns an error when the module does not parse, or when the language refuses it on its own terms.

func MustRuleFromQuery added in v0.2.0

func MustRuleFromQuery(fq FindingQuery) *check.Rule

MustRuleFromQuery is RuleFromQuery for a query that ships as CODE, panicking if it does not compile.

This repo's tests run the query of every built-in rule and every compiled profile. So a query there that does not validate is a programmer error. A package-level `var r = RuleFromQuery(q)` has nowhere to return an error to, so it panics at init rather than dropping the error. profiles.Compile panics on a malformed profile for the same reason.

func NarrowBudget added in v0.2.2

func NarrowBudget(ctx context.Context, work int64) context.Context

NarrowBudget returns ctx with its budget lowered to work when work is smaller, or set to work when ctx carries none. It never raises a budget. So a request can ask for less than a deployment allows, and never more. Zero or less leaves ctx as it is.

func NonInjectiveRules

func NonInjectiveRules(q Query) []string

NonInjectiveRules reports rules whose body lets two variables in the same position of the same relation bind the same value with nothing separating them. See the engine's documentation.

func QueryProto

func QueryProto(q Query) *checkspb.DatalogQuery

QueryProto encodes a datalog program as its wire form.

func Reads

func Reads(q Query) []string

Reads returns the fact-base relations a query references, sorted and deduped. A query-backed rule declares these as the facts it reads, and check.Available gates on them for params and board.

func ReadsFrom added in v0.2.0

func ReadsFrom(reg *facts.Registry, q Query) []string

ReadsFrom is Reads over an explicit relation vocabulary, for a caller composing its own.

func RuleFromQuery

func RuleFromQuery(fq FindingQuery) (*check.Rule, error)

RuleFromQuery compiles a FindingQuery into a check.Rule whose Eval runs the query over a design and maps each answer row to a Finding. The Finding's Prov is resolved from the Model by subject, so a query-backed finding is as locatable as a hand-written one.

IT VALIDATES THE QUERY AND REPORTS WHY IT CANNOT RUN, so a misspelled relation is an error at construction rather than an empty answer that reads as a CLEAN PASS (agni issue 540).

Use it where the query came from a person (a review manifest, a wire RuleDef, an overlay). For a query written into this repo as code, use MustRuleFromQuery.

func Total added in v0.2.2

func Total(n *int) datalog.Option

Total asks an evaluation to set *n to its answer's row count before any offset and limit. A caller showing the first rows can then say how many it left out (agni issue 896). Counting needs every row, so a limit with no order by then solves the whole goal. It still keeps only the rows it returns.

func Validate added in v0.2.0

func Validate(q Query, reg *facts.Registry) error

Validate reports why a query cannot run, reading only the query and the relation vocabulary it would run against. No design, no rows.

Without it, a rule compiled from a query fails only when it runs, and the run swallows the failure into a clean pass (agni issue 540). A registry with no relation installed still validates everything that needs no vocabulary. stdlib/profiles needs that, because it compiles its built-in profiles in an init() that runs before any relation catalog has registered.

func ValidateRelations

func ValidateRelations(q Query) error

ValidateRelations reports the first relation named in the program that is neither a catalog relation nor defined by one of the program's own rules. A catalog relation is a fact relation or a computed built-in. The evaluator makes the same checks, and this function runs their static half early. So a definition read from a document fails when it is READ, rather than running to a silent empty answer.

It cannot see relations registered by a source not yet imported. So it applies where a program arrives from outside (decoding a definition), and not to programs this build constructs.

func ValidateRelationsFrom added in v0.2.0

func ValidateRelationsFrom(reg *facts.Registry, q Query) error

ValidateRelationsFrom is ValidateRelations over an explicit relation vocabulary.

func WithBudget added in v0.2.2

func WithBudget(ctx context.Context, work int64) context.Context

WithBudget returns ctx with a work budget for every query evaluated under it (agni issue 792). That covers a served query, and each query that a check's or review's query-backed rules evaluate. query.Work counts the work as candidate comparisons, each row emitted by a generator, and each connection examined by a circuit walk. A budget of zero or less adds none, so an unbudgeted context is still unbudgeted.

A budget applies per evaluation. Each query in a set gets the whole budget, and so does each rule in a run. They don't share one.

func Witnesses added in v0.3.8

func Witnesses() datalog.Option

Witnesses asks an evaluation to record how each answer row was derived, in Table.Witness (agni issue 794). The engine keeps a derivation only when asked, so an evaluation that does not ask costs no more than before.

func Work added in v0.3.0

func Work(b *Base) int64

Work reports the cost of evaluation over b, in the units a work budget charges. It adds the engine's own count (Base.Work) to what the circuit walks charged for their own steps (facts.Env.Spend). The engine counts the walks' charge against a budget, but it reports that charge apart from its work.

Types

type Aggregate

type Aggregate = datalog.Aggregate

The query IR. See the engine's documentation for each; they are aliases, not copies.

type Atom

type Atom = datalog.Atom

The query IR. See the engine's documentation for each; they are aliases, not copies.

func Rel

func Rel(name string, args ...Term) Atom

Rel builds an atom Relation(args...).

type Base

type Base = datalog.Base

Base is a design's queryable fact base. Build one with NewBase.

func NewBase

func NewBase(m check.Model) *Base

NewBase projects a Model into its fact base over the process-default relation vocabulary. Use NewBaseFrom to supply one explicitly.

A binary that installs no relation catalog gets an EMPTY base, which looks like a query that matched nothing. Registry.Installed separates the two.

func NewBaseFrom added in v0.2.0

func NewBaseFrom(reg *facts.Registry, m check.Model) *Base

NewBaseFrom projects a Model into its fact base over the given relation vocabulary and indexes it for querying. The registry is captured, so what this base can answer is fixed at construction.

func NewSpecLibBase

func NewSpecLibBase(fs param.FactSource) *Base

NewSpecLibBase builds a fact base over a whole seeded datasheet corpus with NO design (WS10-010). The datasheet relations (`param.max`, `part.audience`) project over every PartSpec the FactSource yields, so `agni query --speclib` searches the spec library rather than one design's parts. Model-dependent relations and predicates (net.*, component.*, net.reaches) yield nothing.

func NewSpecLibBaseFrom added in v0.2.0

func NewSpecLibBaseFrom(reg *facts.Registry, fs param.FactSource) *Base

NewSpecLibBaseFrom is NewSpecLibBase over an explicit relation vocabulary.

type Bindings added in v0.3.4

type Bindings map[string][]Value

Bindings gives goal variables values from the caller, keyed by the variable's name with or without its `?`. A variable holding one value answers exactly as if the goal named that value as a constant. A variable holding several values ranges over them, so the goal answers for each one. That works like joining the goal with a relation holding exactly those values (agni issue 1121). A variable holding no values matches nothing.

func One added in v0.3.4

func One(vals map[string]Value) Bindings

One is a Bindings giving each variable a single value.

func ParseBindings added in v0.3.4

func ParseBindings(args []string) (Bindings, error)

ParseBindings reads `name=value` pairs into Bindings, each one as ParseBinding reads it. A name given more than once binds the variable to each of its values, in order.

type Body

type Body = datalog.Body

The query IR. See the engine's documentation for each; they are aliases, not copies.

type BodyAggregate added in v0.2.2

type BodyAggregate = datalog.BodyAggregate

BodyAggregate is an aggregate bound inside a clause: `?c = count(?n) : { pin(?r, ?n, _) }`.

type BudgetExceeded added in v0.2.2

type BudgetExceeded = datalog.BudgetExceeded

BudgetExceeded is returned when an evaluation's work passes its budget. A host uses errors.As to tell it apart from a wrong query. Running out of budget means the question was too expensive here, not that it was badly asked.

type ColumnKind added in v0.2.2

type ColumnKind = datalog.ColumnKind

ColumnKind says what one answer column denotes. See the engine's documentation.

func ColumnKinds added in v0.2.2

func ColumnKinds(q Query) ([]ColumnKind, error)

ColumnKinds reports what each answer column of q denotes over the process-default vocabulary. It reads the signatures declared by q's relations and predicates, and infers kinds through the query's rules.

func ColumnKindsFrom added in v0.2.2

func ColumnKindsFrom(reg *facts.Registry, q Query) ([]ColumnKind, error)

ColumnKindsFrom is ColumnKinds over an explicit relation vocabulary.

type Compare

type Compare = datalog.Compare

The query IR. See the engine's documentation for each; they are aliases, not copies.

type ContextVar added in v0.2.0

type ContextVar struct {
	Var  string // projected variable name, no leading "?"
	Kind string // check.KindNet | check.KindComponent | check.KindPin | check.KindBus
	Role string // the part it plays in the message ("terminal", "rail", "source")
}

ContextVar binds one projected datalog variable to a context entity on every finding a rule emits.

Kind is the entity's subject kind. It is NOT inferable from the variable. The same projected column could be a net name or a ref des, depending on the relation it came from. A wrong Kind produces a chip that highlights nothing, so Kind is required rather than defaulted.

func ContextVarsFromProto added in v0.2.0

func ContextVarsFromProto(ps []*checkspb.ContextVar) []ContextVar

ContextVarsFromProto decodes a rule's context-variable bindings, preserving order.

type Domain added in v0.2.0

type Domain struct {
	// Query is the compiled domain program. It shares the finding query's rule set by convention
	// rather than by construction, since a scope goal usually needs one rule of its own (the finding
	// goal's body with the failing condition dropped).
	Query Query
	// Witness is the template for a passing verdict's statement, interpolated from the domain row the
	// same way Message is from a finding row. REQUIRED when Domain is set.
	//
	// It may assert the positive condition ("{n} reaches an ESD clamp") even though the domain goal
	// does not prove it. A subject in the domain and not in the failures is one the finding goal
	// declined to report. For these rules, that is the good case.
	Witness string
	// Evidence names the entities that prove a PASSING subject passes, through the rule's own
	// ContextVars. Its rows are matched to passing subjects by the subject tuple.
	//
	// It is a third goal rather than a widening of the domain. The domain is the CONSIDERED SET,
	// passing and failing alike, and a failing subject has no proof to bind. So one query cannot
	// both enumerate the failures and bind the evidence (agni issue 662). The Go-walk requirements
	// get the same thing from check.PullUpVerdict, which returns its hops as entities.
	//
	// Evidence is optional. A passing subject with no evidence row keeps an empty context, since
	// some requirements prove a negative and have nothing to point at.
	Evidence *Query
}

Domain is a rule's considered set, expressed as a goal over the same datalog program as the rule. Its rows must project SubjectVar, PinVar and every TupleVar, so a domain row and a finding row key the same way. The passing subjects are then the domain rows minus the finding rows.

type EntityQuery added in v0.2.0

type EntityQuery struct {
	Kind    string // "pin" | "component" | "net" | "bus" | "area", matching a picked selection's kind
	Label   string // the question as the Ask row words it, unique within its kind
	Query   string
	Binds   []string
	Teaches string // the concept this preset introduces, shown the way an example's is
}

EntityQuery is one question about one entity kind. Binds names its variables, and the caller BINDS them from the selection (agni issue 793) rather than splicing values into the text. So the query is the same for every selection, and a designator holding a quote is asked about exactly. Each name is also the selection field that fills it, one of ref, pin, net, or bus.

Binds lists its names explicitly rather than taking every field a selection carries, because one preset's input is another's output. The pin preset answers ?net and the net preset is asked about one.

func EntityQueries added in v0.2.0

func EntityQueries() []EntityQuery

EntityQueries returns the questions for every entity kind a viewer can select, grouped by kind. The first question of a kind is its default. A viewer that offers only one question asks that one.

type Entry added in v0.2.2

type Entry = ns.Entry

Entry describes one path of the vocabulary. It holds either a module and its members, or a member with its signature, kind and doc, plus its definition for a derived relation. See ns.Entry.

func Describe added in v0.2.2

func Describe(path string) (Entry, error)

Describe answers what is at path in the process-default vocabulary, "" being the root. An unknown path returns an error worded as a query would word it, with a suggestion. If a library's modules do not check, Describe returns that error rather than a partial answer.

func DescribeFrom added in v0.2.2

func DescribeFrom(reg *facts.Registry, path string) (Entry, error)

DescribeFrom is Describe over an explicit vocabulary.

type Evaluator

type Evaluator = datalog.Evaluator

Evaluator answers a Query over a Base.

var Default Evaluator = SemiNaive{}

Default is the engine's semi-naive fixpoint, and every agni surface answers with it. It plans each rule body, inlines single-rule relations, and derives a relation called with a bound argument only for the values the query demands. It answers as Naive does, and the engine tests the two against each other. They differ in cost. A body's written order also no longer decides that cost, so a rule opening with an unbound walk is reordered rather than walking from every net (WS3-114).

On a recursive relation reachable two ways, citations can differ from Naive's, since the rounds run in a different order. Rows never differ.

type ExampleQuery

type ExampleQuery struct {
	Label   string // plain-language intent, shown on the chip ("Parts on a rail above 3V")
	Query   string // the datalog text the chip fills and runs
	Teaches string // the one concept this rung introduces ("join", "filter", ...)
}

ExampleQuery is one runnable teaching query (WS14-002). It holds a plain-language intent, the datalog text that answers it, and the one concept it introduces. BOTH the web panel's click-to-run examples and the CLI's `agni query --examples` read this one catalog, so the two surfaces cannot drift.

func Examples

func Examples() []ExampleQuery

Examples returns the shared teaching-query catalog (WS14-002), in concept-ladder order. The web panel and the CLI both read this one source.

type ExplainReport added in v0.2.2

type ExplainReport = datalog.Report

ExplainReport holds an evaluation's account of itself, filled when the evaluation is asked to explain. It records the plan of each rule body, where its work went, and how each relation was read (jaala's Explain, panyam/jaala#147).

type Expr added in v0.2.2

type Expr = datalog.Expr

Expr is arithmetic or a function call, legal as a comparison's operand: `?w = ?v * ?i`.

type FindingQuery

type FindingQuery struct {
	Rule  check.Rule
	Query Query
	// Vocabulary resolves the query's names. It holds the shipped relations and library, plus any
	// library the run brings, either a project's lib/ or modules sent with the request (agni issues
	// 779, 788). The rule validates against it, declares what it reads from it, and evaluates
	// against it. Nil means the process default, which suits a query written into this repo.
	Vocabulary *facts.Registry
	Kind       string // check.KindNet | check.KindComponent | check.KindPin
	SubjectVar string // projected variable name (no leading ?) bound to Finding.Subject
	PinVar     string // projected variable name bound to Finding.Pin (KindPin only; "" otherwise)
	Message    string // template; each {var} is replaced by that variable's bound value in the row
	// ParamSymbol names the datasheet symbol to check, such as "IOUT", on a component-subject
	// datasheet rule. RuleFromQuery then resolves that parameter's citation from the subject's
	// seeded spec and attaches it to Finding.DatasheetProv. So a datalog-authored datasheet finding
	// has the same doc/page/section/confidence as a built-in datasheet rule's finding. Empty means
	// no citation.
	ParamSymbol string
	// ContextVars are further projected variables, each set as a CONTEXT entity on each finding.
	// The message names a context entity but is not about it (agni issue 349). Most rules leave it
	// empty, because their message names only the subject.
	//
	// It is a SLICE rather than a map keyed by role, for two reasons. Order matters, since chips
	// render in the message's order. And two entities may share a role ("A and B both strap to
	// address N"). See
	// docsite/content/build/check-rule.md#if-the-sentence-names-two-entities-carry-both.
	ContextVars []ContextVar
	// TupleVars are further projected variables that join SubjectVar to form the VERDICT's subject
	// tuple, in the rule's own order. Empty for the ordinary one-subject case.
	//
	// These are not ContextVars. The message NAMES a context entity, while a tuple element is part
	// of what the verdict IS, and so part of its id. Imagine a rule reporting one row per (host,
	// required signal). It needs the signal here, or every row for one host answers to one name.
	// Finding.Subject is singular either way
	// (docsite/content/build/check-rule.md#a-tuple-in-the-verdict-one-entity-in-the-finding).
	TupleVars []TupleVar
	// Domain declares the rule's CONSIDERED SET as a second goal beside the finding goal. Its rows
	// are every subject the rule examined, and the finding goal's rows are the subset that came out
	// wrong (agni issue 424). Without a Domain the rule keeps the failures-only shape. That shape
	// under-reports the rule and never overstates it.
	//
	// The domain is DECLARED RATHER THAN DERIVED. For the ESD and pull-up requirements, the domain
	// is the finding goal's body minus its negated literal. But signal-dangling ends in a
	// comparison. Deriving its domain would report the failures AS the considered set.
	// StatesConsideredSet exists to prevent that false coverage claim.
	Domain *Domain
}

FindingQuery declares a datalog-backed check rule (WS3-038). Every answer row of its datalog program becomes a check.Finding. Through it, a datalog query becomes a catalog rule with a severity, a subject and a doc, rather than only an ad-hoc search.

Rule holds the rule's identity and metadata (Name, Severity, Summary, Tags, Detail, Reads), and RuleFromQuery fills its Eval. Query is the COMPILED datalog program (WS3-043). The caller produces it with MustParse for a hand-authored string or Build for a generated AST. The goal MUST project SubjectVar, and PinVar too when Kind is KindPin. Message is a template, and each answer row fills its {var} placeholders. If Rule.Reads is empty, it is derived from the query as the EDB relations the query reads, so check.Available gates it correctly.

type Literal

type Literal = datalog.Literal

The query IR. See the engine's documentation for each; they are aliases, not copies.

func Cmp

func Cmp(l Term, op string, r Term) Literal

Cmp builds a comparison literal, Op in {<, <=, =, !=, >, >=}.

func Neg

func Neg(a Atom) Literal

Neg wraps an atom as a negated body literal.

func Pos

func Pos(a Atom) Literal

Pos wraps an atom as a positive body literal.

type Naive

type Naive = datalog.Naive

Naive is the engine's reference evaluator: rule bodies run in written order and derived relations are computed in full. Tests compare against it; agni answers with Default.

type NamedQuery added in v0.2.2

type NamedQuery struct {
	Name        string `yaml:"name"`
	Query       string `yaml:"query"`
	Description string `yaml:"description"`
	// Bind gives this query's goal variables values (agni issue 793), as RunQueryRequest's bindings
	// do. YAML types each value, so `3.3` binds a number and `"3"` or `GND` binds text, and a list
	// binds the variable to each of its values (agni issue 1121).
	Bind Bindings `yaml:"-"`
}

A NamedQuery is one entry of a QuerySet. Name identifies it in the answer and must be unique in its set. Description goes into the rendered report for the reader.

func (*NamedQuery) UnmarshalYAML added in v0.2.2

func (q *NamedQuery) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML reads a query's `bind:` map into typed values. A value is a scalar or a list of scalars. It refuses a map, or a list holding anything but scalars.

It refuses a key it does not know, with its line, as ParseQuerySet refuses one at the top. A custom decoder does not inherit the decoder's KnownFields, so a misspelled `descripton:` used to drop the description with no error.

type Order added in v0.2.2

type Order = datalog.Order

Order is one `order by` item.

type Position added in v0.2.4

type Position struct {
	Offset int // bytes from the start of the text
	Line   int
	Column int
	// Caret is the position's line of text with a caret under its column (see Caret). Every surface
	// draws this caret, so each one shows what the engine drew. It is "" when the position is not
	// inside the text.
	Caret string
}

Position is where in a query's text a syntax error points. Line and Column count from 1, and Column counts characters rather than bytes, as an editor does.

func ErrorPosition added in v0.2.4

func ErrorPosition(err error) (Position, bool)

ErrorPosition reports where in its query's text err points, when err is a syntax error. An error about a query that parsed, such as a relation the vocabulary lacks, has no position.

type Query

type Query = datalog.Query

The query IR. See the engine's documentation for each; they are aliases, not copies.

func Build

func Build(rules []Rule, goal []Literal, sel ...Term) Query

Build assembles a Query from its rules, the goal literals to solve, and the projected answer terms.

func MustParse

func MustParse(s string) Query

MustParse parses a query string and panics on error, for hand-authored rules constructed at package init, where a malformed built-in query is a programming error surfaced at startup.

func Parse

func Parse(s string) (Query, error)

Parse parses the query text syntax. A query that does not parse fails with a *SyntaxError, which says where in s the parser stopped (ErrorPosition).

func QueryFromProto

func QueryFromProto(p *checkspb.DatalogQuery) (Query, error)

QueryFromProto decodes a datalog program. It rejects a program that names a relation unknown to this build, and suggests the closest catalog name when the miss looks like a typo. The check is static, with no design loaded. So it catches an author's mistake at read time rather than presenting an empty answer as a clean result.

type QuerySet added in v0.2.2

type QuerySet struct {
	Title    string       `yaml:"title"`
	Preamble string       `yaml:"preamble"`
	Queries  []NamedQuery `yaml:"queries"`
}

A QuerySet is a named list of queries answered over one read of a design (agni issue 729). So an audit workbook is versioned together, shares derived relations, and costs one read of the design instead of one per question.

Preamble holds rules shared by every query in the set, the set's derived relations. It holds rules only, and each query brings its own goal.

func ParseQuerySet added in v0.2.2

func ParseQuerySet(b []byte) (QuerySet, error)

ParseQuerySet reads a query set from YAML and validates it. An unknown key is an error. Otherwise a misspelled `preamble` would drop the shared rules silently. Every query using them would then fail, for a reason found nowhere in its own text.

func (QuerySet) Compile added in v0.2.2

func (s QuerySet) Compile(i int) (Query, error)

Compile returns the i'th query with the preamble's rules in front of it, ready to evaluate. A syntax error's position is within the i'th query's own text.

func (QuerySet) Text added in v0.2.4

func (s QuerySet) Text(i int) string

Text is the i'th query as Compile parses it, with the preamble's rules in front. A caller may send the query somewhere the set does not go, such as a viewer link (agni issue 634). It then sends what the set would have asked.

func (QuerySet) Validate added in v0.2.2

func (s QuerySet) Validate() error

Validate reports a problem that makes the whole set unusable. That means no queries, a query with no name or no text, a repeated name, or a preamble that is not rules alone. It does NOT compile the queries. So when the set runs, one bad query is reported against its name while the rest still answer.

type RelationInfo

type RelationInfo = facts.RelationInfo

RelationInfo describes one queryable relation or predicate for discovery surfaces. It is an alias for the fact layer's type. A picker shows relations and predicates in one list, and with one type it never has to reconcile two shapes for the same row.

func Catalog

func Catalog() []RelationInfo

Catalog returns every construct this engine can discover. That covers every fact-base relation, every derived relation defined by a library module, and every predicate in the fact layer's vocabulary, including the engine's own string tests. The result is sorted by kind (KindOrder) then name, so a caller renders a stable grouped list without re-sorting.

func CatalogFrom added in v0.2.0

func CatalogFrom(reg *facts.Registry) []RelationInfo

CatalogFrom is Catalog over an explicit relation vocabulary.

type Row

type Row = datalog.Row

The query IR. See the engine's documentation for each; they are aliases, not copies.

type Rule

type Rule = datalog.Rule

The query IR. See the engine's documentation for each; they are aliases, not copies.

func Def

func Def(head Atom, body ...Literal) Rule

Def builds a rule Head :- body. Disjunction is several Defs sharing a Head relation.

type SearchQuery added in v0.2.0

type SearchQuery struct {
	Query string
	// Bind names the variable the caller binds, without its `?`.
	Bind string
	// Pattern is the value bound to Bind, with {term} standing for the escaped text. It holds the
	// (?i) here rather than in each client, so the search is case-insensitive wherever it runs.
	Pattern string
	Teaches string
}

SearchQuery is the find-by-name template. Like an example's, its Teaches field names the concept a search leaves behind.

func Search() SearchQuery

Search returns the find-by-name template. It is one template rather than one per kind. The answer names each hit's kind in its own column, so a search for "CAN" shows the net, the connector and the bus label together.

type SemiNaive added in v0.2.2

type SemiNaive = datalog.SemiNaive

SemiNaive is the evaluator agni answers with (see Default).

type SyntaxError added in v0.2.4

type SyntaxError struct {
	At Position
	// contains filtered or unexported fields
}

SyntaxError is a query that would not parse, with the place in its text where the parser stopped. Its message is the engine's, unchanged, so a caller printing the error prints what it always has. A caller that can also show the text asks ErrorPosition where to point.

func (*SyntaxError) Error added in v0.2.4

func (e *SyntaxError) Error() string

func (*SyntaxError) Unwrap added in v0.2.4

func (e *SyntaxError) Unwrap() error

Unwrap returns the engine's own parse error.

type Table added in v0.2.2

type Table = datalog.Table

Table is an answer as columns and rows of values (Evaluator.EvalTable).

type Term

type Term = datalog.Term

The query IR. See the engine's documentation for each; they are aliases, not copies.

func Num

func Num(f float64) Term

Num builds a numeric-constant term.

func Str

func Str(s string) Term

Str builds a string-constant term.

func V

func V(name string) Term

V builds a variable term (?name in the text syntax).

type TupleVar added in v0.2.0

type TupleVar struct {
	Var  string // projected variable name, no leading "?"
	Kind string // check.KindNet | check.KindComponent | check.KindSignal | ...
}

TupleVar binds one projected datalog variable to an element of the verdict's subject tuple. Kind is required, for the same reason as on ContextVar. A datalog variable is a bare string binding, and nothing about the column says whether it holds a net name, a ref des or a required-signal role.

type Value

type Value = ns.Value

The query IR. See the engine's documentation for each; they are aliases, not copies.

func Number added in v0.2.2

func Number(f float64) Value

Number is a numeric value. It reads as an unquoted number in a query does.

func ParseBinding added in v0.2.2

func ParseBinding(s string) (string, Value, error)

ParseBinding reads one `name=value` pair, the form `agni query --bind` takes. The value is read the way the query language reads a constant. A quoted value is text, a value that parses as a number is a number, and any other bare word is text, so `--bind n=GND` needs no quotes. Where the schema types a position, the engine then reads the value as that type either way (panyam/jaala#65). So the quoting matters only for a variable nothing types, where `--bind 'n="3"'` binds the text.

func Text added in v0.2.2

func Text(s string) Value

Text is a string Value to bind to a goal variable (agni issue 793). It reads as a quoted constant in a query does.

type Var

type Var = datalog.Var

The query IR. See the engine's documentation for each; they are aliases, not copies.

type Witness added in v0.3.8

type Witness = datalog.Witness

Witness records how one fact of an answer holds. It is either a leaf from the fact base, with its citations, or the rule that derived the fact, with that rule's body witnesses in written order (jaala's Witness).

Jump to

Keyboard shortcuts

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