query

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 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): Datalog over the design's fact base, so an engineer runs ad-hoc queries ("search your whole design as relations, including datasheets") and every answer carries the provenance of the facts that produced it. Rules and search share one vocabulary, since 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), which knows nothing about circuits. This package is agni's adapter over it:

  • 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 (relations, predicates, modules) is registered in the fact layer's vocabulary (facts.Registry.Vocabulary), 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 stays WASM-clean (the engine imports only the standard library, and this adapter 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 rendering this engine's catalog need not import 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). The engine refuses a name the goal does not use when the query is evaluated, 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 as `--bind` takes them, `n=GND`, `v=3.3`, and `t="3"` for text that would otherwise read as a number, sorted by name, so a value carried somewhere as text (a viewer link, agni issue 634) reads back as the value ParseBinding was given. A variable bound to several values is spelled once per value, in its order, which is how `--bind` and a link give a list.

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, as 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 the line of text p points into 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, and a threshold written `0.1mm`, which the engine folds to metres, compares against it correctly. A board is drawn in millimetres, so Display shows a length in millimetres again, and the cell's number is then 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 are the engine options the context asks for: its budget, when it carries one. Every evaluation agni runs for a caller passes them, so a budget set once on the context reaches each.

func Explain added in v0.2.2

func Explain(r *ExplainReport) datalog.Option

Explain asks an evaluation to fill r with its plan. It costs time in proportion to the rules and literals a query runs, not 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 as a query would spell them, `?n = "GND"` or `?v = 3.3`, and a variable bound to several values as the list it ranges over, `?n in ["I2C_SCL", "I2C_SDA"]`, 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: `"U1\."` is the four characters U, 1, a backslash and a dot (jaala v0.1.62). Go's quoting doubled that backslash, which spells another pattern. A value holding a quote with no backslash before it, or ending in a lone backslash, has no spelling in the language; it is shown the same way, and 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 a Datalog module's text defines, by bare name, so a host can check a module's paths against a vocabulary before composing it. An error is a module that does not parse, or that the language refuses 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.

A built-in rule or a compiled profile carries a query this repo's tests run, so one 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, which is what lets a request 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 stays 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 how many rows its answer has before any offset and limit, so a caller showing the first rows can say how many it left out (agni issue 896). A limit with no order by then solves the whole goal, since counting needs every row, though 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, where the failure is swallowed into a clean pass (agni issue 540). A registry with no relation installed still validates everything that needs no vocabulary, because stdlib/profiles 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 the program names that is neither a catalog relation (a fact relation or a computed built-in) nor defined by one of the program's own rules. It is the static half of the checks the evaluator makes, hoisted so a definition read from a document fails when it is READ rather than running to a silent empty answer.

It cannot see relations a not-yet-imported source registers, so it is applied where a program arrives from outside (decoding a definition), 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 carrying a work budget for every query evaluated under it (agni issue 792): a served query's own, and each query a check or review's query-backed rules evaluate. Work is what query.Work counts, candidate comparisons, each row a generator emits, and the connections a circuit walk examines. Zero or less carries no budget, so an unbudgeted context stays unbudgeted.

A budget applies per evaluation, so each query in a set, and each rule in a run, has the whole of it rather than sharing one.

func Work added in v0.3.0

func Work(b *Base) int64

Work is what evaluation over b has cost in the units a work budget charges: the engine's own count (Base.Work) plus what the circuit walks charged for their own steps (facts.Env.Spend), which the engine counts against a budget but reports 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 that value written into the goal as a constant does. One holding several ranges over them, so the goal answers for each, as if it were joined with a relation holding exactly those values (agni issue 1121), and one holding none 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, as ParseBinding reads one, into the values a query is asked with. 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 the error an evaluation stops with once its work passes its budget. A host tells it apart from a query that is wrong with errors.As, since running out of budget says 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, read from the signatures its relations and predicates declare and inferred 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, which is NOT inferable from the variable, because 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 it 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, because a subject in the domain and not in the failures is one the finding
	// goal declined to report, which for these rules is the good case.
	Witness string
	// Evidence, when set, names the entities a PASSING subject's proof rests on, 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, because 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.
	//
	// 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 and the passing subjects are the difference between them.

type EntityQuery added in v0.2.0

type EntityQuery struct {
	Kind    string // "pin" | "component" | "net" | "bus", 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. The caller BINDS the variables Binds names 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: ref, pin, net, or bus.

Binds is explicit rather than 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, the one a viewer asks when it offers only one.

type Entry added in v0.2.2

type Entry = ns.Entry

Entry is what sits at one path of the vocabulary: a module and its members, or a member with its signature, kind, doc and, for a derived relation, its definition. 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 is an error worded as a query would word it, suggestion included, and a library whose modules do not check 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 evaluator every agni surface answers with: the engine's semi-naive fixpoint, which 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 (the engine tests the two against each other); what differs is cost, and that a body's written order no longer decides it, so a rule opening with an unbound walk is reordered rather than walking from every net (WS3-114).

Citations can differ from Naive's on a recursive relation reachable two ways, since the rounds run in a different order; rows never do.

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): a plain-language intent, the datalog text that answers it, and the one concept it introduces. It is the shared catalog behind BOTH the web panel's click-to-run examples and the CLI's `agni query --examples`, 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 is what an evaluation asked to explain itself fills: the plan each rule body ran in, 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 is what the query's names resolve against: the shipped relations and library, plus
	// whatever library the run carries, a project's lib/ or modules sent with the request (agni issues
	// 779, 788). The rule validates, declares what it reads, and evaluates against it. Nil is the
	// process default, which is right for 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, when set on a component-subject datasheet rule, names the datasheet symbol the rule
	// checks (e.g. "IOUT"). 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
	// carries the same doc/page/section/confidence a built-in datasheet rule does. Empty = no citation.
	ParamSymbol string
	// ContextVars are further projected variables to carry as each finding's CONTEXT entities, the
	// entities the message names but is not about (agni issue 349). Empty for a rule whose message
	// names only its subject, which is most of them.
	//
	// A SLICE rather than a map keyed by role, because order is significant (chips render in the order
	// the message names them) 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.
	//
	// Not ContextVars, because a context entity is something the message NAMES and a tuple element is
	// part of what the verdict IS, and so of its id. A rule reporting one row per (host, required
	// signal) needs the signal here, or every row for one host answers to one name. Finding.Subject
	// stays singular either way
	// (docsite/content/build/check-rule.md#a-tuple-in-the-verdict-one-entity-in-the-finding).
	TupleVars []TupleVar
	// Domain, when set, declares the rule's CONSIDERED SET as a second goal beside the finding goal.
	// Its rows are every subject the rule examined, where the finding goal's rows are the subset that
	// came out wrong (agni issue 424). Unset keeps the failures-only shape, which under-reports the rule
	// and never overstates it.
	//
	// 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, so deriving its
	// domain would report the failures AS the considered set, the false coverage claim
	// StatesConsideredSet exists to prevent.
	Domain *Domain
}

FindingQuery declares a datalog-backed check rule (WS3-038), a datalog program whose every answer row becomes a check.Finding. It is how a datalog query becomes a catalog rule with a severity, a subject and a doc, rather than only an ad-hoc search.

Rule carries the rule's identity and metadata (Name, Severity, Summary, Tags, Detail, Reads); RuleFromQuery fills its Eval. Query is the COMPILED datalog program (WS3-043), produced by the caller with MustParse for a hand-authored string or Build for a generated AST. The goal MUST project SubjectVar (and PinVar when Kind is KindPin). Message is a template whose {var} placeholders are filled from each answer row. If Rule.Reads is empty it is derived from the query (the EDB relations it 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 is carried 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; a map, or a list holding anything but scalars, is refused.

A key it does not know is refused 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 line of text the position is on with a caret under its column (see Caret), so
	// every surface draws the one the engine drew. "" 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 and rejects one that names a relation this build does not know, suggesting the closest catalog name when the miss looks like a typo. The check is static (no design is 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 every query may use, the derived relations the set shares. It holds rules only; 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, because a misspelled `preamble` would otherwise drop the shared rules silently and every query using them would fail for a reason 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, so a caller that sends the query somewhere a set does not travel (a viewer link, agni issue 634) sends what the set would have asked.

func (QuerySet) Validate added in v0.2.2

func (s QuerySet) Validate() error

Validate reports what makes a set unusable as a whole: 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 one bad query is reported against its name when the set runs 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, because a picker showing relations and predicates in one list must not have to reconcile two shapes for the same row.

func Catalog

func Catalog() []RelationInfo

Catalog returns this engine's discoverable construct set: every fact-base relation, every derived relation a library module defines, and every predicate in the fact layer's vocabulary, the engine's own string tests included. 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, with Teaches carrying the concept a search leaves behind the way an example's does.

func Search() SearchQuery

Search returns the find-by-name template. It is one template rather than one per kind, since 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 where in its text 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 show the text as well asks ErrorPosition for 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 reason it is on ContextVar, since 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, as an unquoted number in a query is.

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 as the query language reads a constant: a quoted value is text, one that parses as a number is a number, and any other bare word is text, so `--bind n=GND` needs no quotes. In a position the schema types, 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), as a quoted constant in a query is.

type Var

type Var = datalog.Var

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

Jump to

Keyboard shortcuts

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