Documentation
¶
Overview ¶
Package model is the design read-surface CONTRACT: the Model interface a rule or query evaluates against, plus the value types that interface exposes. It imports only the generated IR/geom/param protos, never the check implementation, its rules, or the param logic package, so a consumer (an auto-layout, a diff, an overlay) can depend on the contract without pulling the analysis engine into its build. The default implementation is check.NewModel, and check re-exports these names as aliases, so check.Model / check.ComponentClass and this package's names are the same types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderRoute ¶ added in v0.2.2
RenderRoute is the ONE renderer for a series route, and every surface that prints one calls it. The rendered string is a format callers depend on (DECISIONS.md, "A path is not a query column"), so a second implementation, such as the IO-map rules rendering off a check.Trace, must call this rather than copy it (#664). It takes plain hops so neither caller's walk type leaks in.
Types ¶
type BoardNet ¶
BoardNet is one net's routed copper: the entity the geometric rules quantify over, with findings aggregating per net (copper primitives have no stable identity of their own). Net is the join key to ir.Net.name.
type BoardRules ¶ added in v0.2.2
BoardRules are the board-wide minimums a design declares for its copper, in nanometres, the process the designer routed the board for (agni issue 933). Zero means the design declares no such minimum, and a rule then falls back to its own default rather than to zero.
type BoardSeg ¶
BoardSeg is one routed track segment. Coordinates and width are in the sidecar's units (nanometers for the KiCad producer).
type BoardVia ¶
BoardVia is one via. Annular returns the copper ring width around the drill, which is the quantity the annular-width rule bounds.
type ComponentClass ¶
type ComponentClass string
ComponentClass is the device class of a placed component, the component.class fact (docsite/content/architecture/rules-and-checks.md#the-fact-base-and-querying-it). Values are stable strings so rules and reports can match on them. A class the derivation cannot establish is ClassUnknown, never a guess, so class-quantified rules stay silent on unfamiliar designs.
const ( ClassResistor ComponentClass = "resistor" ClassCapacitor ComponentClass = "capacitor" ClassInductor ComponentClass = "inductor" ClassFerrite ComponentClass = "ferrite" // ClassThermistor is a temperature-dependent resistor (NTC inrush limiters, PTC resettable fuses, // temperature sense elements). Its family is ClassResistor, because it is a two-terminal resistor // for every topological question and not for anything temperature-related, the same split // ClassFerrite makes against ClassInductor. Without it a thermistor emits no component.class row // and drops out of every class-scoped rule; on one real board that was 15 parts (agni issue 627). ClassThermistor ComponentClass = "thermistor" ClassDiode ComponentClass = "diode" ClassLED ComponentClass = "led" ClassTVS ComponentClass = "tvs" ClassZener ComponentClass = "zener" ClassFuse ComponentClass = "fuse" ClassConnector ComponentClass = "connector" ClassTestConnector ComponentClass = "test_connector" ClassTestPoint ComponentClass = "test_point" ClassClock ComponentClass = "clock" ClassOscillator ComponentClass = "oscillator" ClassCrystal ComponentClass = "crystal" ClassCeramicResonator ComponentClass = "ceramic_resonator" ClassIC ComponentClass = "ic" ClassTransistor ComponentClass = "transistor" // ClassIdealDiodeController is a controller that drives an external FET to behave as a diode // (ORing controllers, ideal-diode controllers, power muxes). No netlist labels a FET plus bias // network as an ideal diode, so reverse-blocking analysis takes the identity from a seeded // datasheet or reports that it does not know (agni issue 74). It is DATASHEET-DRIVEN like the // crystal / ceramic_resonator split, reached through deviceClassAliases from a seeded // device_class rather than from a refdes prefix or a name keyword. ClassIdealDiodeController ComponentClass = "ideal_diode_controller" ClassUnknown ComponentClass = "unknown" )
The component.class vocabulary. ClassLED, ClassTVS, and ClassZener are distinct from ClassDiode (protection and indicator rules quantify over them separately), and ClassFerrite from ClassInductor, even though each is electrically a subtype. ClassZener is distinct from ClassTVS because a Zener is a slower clamp than a fast ESD TVS (esd-clamp-not-tvs, WS3-078, credits them differently). ClassTestConnector is distinct from ClassConnector because a debug, test, edge-card or programming connector is a bench interface, not a field-facing harness, so protection rules (esd, input-protection) that quantify over ClassConnector exclude it. A board-to-board connector is NOT a class, because whether it faces the field depends on the product rather than the part; a design declares it in its intent instead (Model.ExposedConnector, agni issue 831).
ClassClock is the clock-source FAMILY (WS10-015), with ClassOscillator, ClassCrystal, and ClassCeramicResonator as its subtypes. The family is NOT ClassCrystal, since an active oscillator CONTAINS a crystal rather than being one, so a family-level clock rule must not answer HasClass(crystal) for it. A part's clock TYPE branches rules (an oscillator uses no external load caps, a ceramic resonator has them integrated, a bare crystal needs them). Crystal-vs-resonator is datasheet-driven, because the vendor label is unreliable and the two are structurally alike. So the keyword/structural path only resolves the oscillator subtype or stays at the family, and the crystal / ceramic_resonator subtype comes from a seeded device_class.
func ComponentClasses ¶ added in v0.2.2
func ComponentClasses() []ComponentClass
ComponentClasses is every class in the vocabulary above except ClassUnknown, in declaration order. Anything that enumerates the vocabulary reads this rather than keeping its own list (agni issue 677). Go cannot enumerate constants, so TestComponentClassesListsEveryConstant reads the const block and holds this list to it.
type Model ¶
type Model interface {
// select: the entity sets a rule quantifies over.
Nets() []*ir.Net
Components() []*ir.Component
// SourceFormat is the reader label of the design's source (e.g. "kicad-pcb", "edif-2.0.0"),
// "" when unknown. The catalog-availability gate (check.Available) reads it, so a board.* rule is
// only available for a board-carrying format.
SourceFormat() string
// HasParams reports whether a datasheet parameter tier is attached (a ParamProvider was
// supplied through check.WithParamProvider), whether or not any specific part is seeded. A datasheet rule
// is applicable exactly when this is true.
HasParams() bool
// HasBoard reports whether a board-geometry tier is attached (a non-nil BoardGeometry was
// supplied through check.WithBoard), independent of the design's source
// format. That is what makes a geometric rule applicable under `agni review --board-path`,
// where the netlist SourceFormat is not a board format. A board file with no routed copper
// still reports true (checked, clean).
HasBoard() bool
// SuppliesDiagnostic reports whether the reader COMPUTED a diagnostic, named by its
// InputDiagnostics field name ("ref_des_collisions"). It separates "looked and found none" from
// "never looked", which every list below flattens into the same empty slice. A rule whose subject
// is one of these diagnostics gates on it (check.Available), so a format whose reader cannot
// detect the construct reports not-applicable rather than passing.
SuppliesDiagnostic(name string) bool
// reader-emitted input diagnostics (docsite/content/architecture/rules-and-checks.md#where-a-rule-runs):
// wire endpoints on nothing, and ref-des collisions. Empty for sources that carry none; a thin
// rule reports each.
DanglingEndpoints() []*ir.DanglingEndpoint
NoJunctionEndpoints() []*ir.DanglingEndpoint
RefDesCollisions() []*ir.RefDesCollision
// UnmodeledBuses are bus constructs a reader detected but does not expand into member nets
// (WS1-034). Empty for sources with no bus; the bus-not-modeled rule reports each so a bussed
// design is flagged, not silently mis-read.
UnmodeledBuses() []*ir.BusNotModeled
// UnresolvedSymbols are symbol references the reader could not open or parse (WS1-052), each
// with the placements that lost their pins. Non-empty means the netlist is INCOMPLETE by an
// unknown amount, and a rule reading connectivity cannot tell those pinless parts from a design
// where the connections were never drawn. Rules that read pin or connectivity facts are gated to
// inconclusive while this is non-empty (check.Run).
UnresolvedSymbols() []*ir.UnresolvedSymbol
// ResolvedSymbols are the symbol references that DID load, one per distinct reference, with the
// pin count each supplied. It is the other half of UnresolvedSymbols, so a rule over symbol
// resolution can state what it examined rather than only what failed (agni issue 418).
//
// Empty is ambiguous, and SuppliesDiagnostic("resolved_symbols") separates the cases: a reader
// that declares the diagnostic and returns nothing placed no symbol, while one that does not
// declare it never looked. Skipping that check reads "we read without symbols" as "we checked and
// everything was fine".
ResolvedSymbols() []*ir.ResolvedSymbol
// JoinedTaps are the wire-end-on-wire-body taps something DOES join, with the construct that
// joined them (agni issue 420). It is the other half of NoJunctionEndpoints, and the two
// partition the taps, so no tap is on both lists.
//
// Gate on SuppliesDiagnostic("junction_taps") before reading an empty slice as "no tap was
// silent", since a reader that never looked at wire geometry returns the same nothing.
JoinedTaps() []*ir.JoinedTap
// UnannotatedComponents are the placeholder designators the source has not assigned yet ("R?",
// "C?"), one entry per placeholder with every placement wearing it. Unlike UnresolvedSymbols
// nothing was LOST in the read, since the parts and their pins are all present. What is absent is
// an identity, so a consumer must not key on these designators (see internal/refdes).
UnannotatedComponents() []*ir.UnannotatedComponent
// traverse / pin-role: a pin's electrical direction, or the unspecified zero value when the
// source carries no part-type pin data (so direction-based rules do not fire).
PinDir(refDes, pin string) ir.PinDirection
// PinDeclared reports whether the component's part type declares this pin at all, even with an
// explicitly unspecified electrical type. False for pins known only from net connections (a
// board footprint's pads, a partially-read hierarchy), where the unspecified PinDir means "the
// read never saw the symbol" rather than "the author declared nothing". A rule keying on
// declared-but-untyped pins (unspecified-pin-with-driver) must not read a read gap as an
// authoring gap.
PinDeclared(refDes, pin string) bool
// traverse / param-join: the pin's NAME as its part type declares it ("VCCA", "GND"), or "" when
// the source carries no part-type pin data. Unlike the designator, which changes when the same
// die ships in a different package, the name is die-relative, so a datasheet join leads with it;
// see param.ResolvePin for the precedence.
PinName(refDes, pin string) string
// IsPinlessPart reports whether a component resolves to a part type that declares no pins, as a
// mounting hole, a logo or a module's assembly symbol does (agni issue 937). False for a component
// whose part type the read does not carry, since its pins are then unknown rather than absent.
IsPinlessPart(refDes string) bool
// IsFitted reports whether a component is assembled onto the board, false for a part the design
// marks do-not-populate. A DNP part stays in the netlist, since its footprint and nets are real, but
// a rule crediting a part with doing something electrical (a resistor pulling a line up) asks this
// first, because an unfitted part does nothing (agni issue 938).
IsFitted(refDes string) bool
// on_net: whether a ref_des appears on at least one net (section-aware).
IsConnected(refDes string) bool
// membership: whether a ref_des is known to the design at all, either a listed component or a
// connection ref (a netlist read may carry connections without a component list). Unlike
// IsConnected, it is true for a listed-but-unconnected part.
HasComponent(refDes string) bool
// pair: whether a net with the given name exists (case-insensitive).
HasNetName(name string) bool
// whether a net is a power/ground rail: asserted-driven or global, or a ground/power-rail
// name. Such rails are distributed by power-symbol taps, not drawn wires (WS9-039). Unknown
// net -> false.
IsPowerRail(name string) bool
// role: whether a net carries the ground / rail naming role, reading the STAMPED role fact
// (ir.Net.roles, filled at ingestion) and falling back to this model's naming lexicon only for a
// net that skipped the loader (WS3-106). They take the net rather than its name because names
// are not unique (see NetNameCount), so a by-name lookup can answer about a different net.
// IsRailNet is NARROWER than IsPowerRail, which also answers true for a driven-or-global net and
// for grounds, and it excludes IsRegulatorInternalNet. A rule asking "is this a rail" wants
// IsRailNet.
IsGroundNet(n *ir.Net) bool
IsRailNet(n *ir.Net) bool
IsRegulatorInternalNet(n *ir.Net) bool
HasAnyRole(n *ir.Net, roles ...ir.Role) bool
// naming lexicon: does a bare NAME match a role vocabulary, for the callers that hold no net to
// read a stamped role from (the spec-language name FFIs over a literal, and pin-name role
// derivation). Reads the lexicon this model's design was READ with (WS3-106), so a project's
// conventions reach a name match without a package global.
IsPowerRailName(name string) bool
IsGroundName(name string) bool
IsFeedbackName(name string) bool
IsSwitchingName(name string) bool
IsControlName(name string) bool
IsGateDriveName(name string) bool
// pair: how many nets carry EXACTLY this name (case-sensitive, unlike HasNetName). More than
// one means the design states the same name for electrically distinct nets. Connect-by-name
// formats cannot produce that (the solver merges them) and explicit-net-list formats (EDIF) can,
// so it is either an authoring slip or a reader gap (duplicate-net-name reads this).
NetNameCount(name string) int
// pins: every part-type pin of every placed component (empty for sources that
// carry no part-type pin data, so pin-level rules do not fire), and per-pin net
// membership. PinConnected is the per-pin analogue of IsConnected: whether this
// specific (ref_des, designator) appears in any net's connections.
Pins() []PinInst
PinConnected(refDes, pin string) bool
// pin-role (WS1-009): the pin's semantic role, DERIVED from its declared name within
// the component's device-class context (anode/cathode only for the diode family;
// power/ground rail names on any class). It is a projection like component.class, never an
// IR field, because no source format states polarity as data. RoleUnknown when the name
// carries no recognized convention; rules skip, never guess.
PinRole(refDes, pin string) PinRole
// PinNetName is the name of the net this pin appears on ("" when unconnected). A pin belongs to
// one net by definition, so a pin in several nets' connection lists is malformed input, and
// PinNetName then reports the first net in design order. That pick is safe because the conflict
// surfaces through PinNetConflicts and the pin-net-conflict rule.
PinNetName(refDes, pin string) string
// PinNetConflicts are the malformed-input diagnostics PinNetName's contract relies on: every
// pin that appears in more than one net's connections, with the full net list. Collected once
// at model build from the normalized IR, not a reader InputDiagnostic, since no reader-only
// information is involved.
PinNetConflicts() []PinNetConflict
// no-connect channel: whether the source can express "intentionally unconnected" at
// all, meaning any NO_CONNECT-typed pin, any no-connect-flagged net, or a designer's NC_ /
// no_connect net name. Where the channel is absent (a bare EDIF netlist), an unwired pin
// carries no NC flag because none
// exists, not because the designer missed it, so per-pin absence rules must not fire.
HasNoConnectChannel() bool
// power-output typing channel (WS3-072 PR2): whether the source format classifies
// power-OUTPUT pins at all. EDIF's port grammar carries only INPUT/OUTPUT/INOUT (no
// power_out) and IPC-2581 is a board format with no pin electrical types, so on those a
// power rail's driver reads as a plain input. A rule that infers "unpowered" from the
// ABSENCE of a typed driver (power-input-not-driven) must not fire where this is false,
// because the source is under-typed rather than undriven.
FormatTypesPowerOut() bool
// net-class channel (WS3-105): whether the design carries any tool-assigned net-class
// membership at all. Only a KiCad project supplies it (net_settings in the .kicad_pro);
// an EDIF or IPC-2581 read, a bare .kicad_sch, and a project that declares no classes all
// leave every net_class empty. A rule SCOPED by net class would evaluate over nothing there and
// read as a pass, so such a rule declares CapNetClass and reads not-applicable instead.
HasNetClasses() bool
// net-class DEFINITIONS (WS3-111): the per-class routing constraints the project declares
// (clearance, track width, via sizes), as ir.Constraint nodes of kind "netclass". Separate
// from HasNetClasses because membership and definitions are two independent blocks of
// net_settings, so a project can assign nets to a class it never defines, or define classes
// it assigns nothing to.
NetClassDefs() []*ir.Constraint
// reach (WS3-011): the bounded series-walk neighborhood of a net, meaning nets reachable by
// crossing two-net pass elements (R/L/ferrite/fuse) with rails excluded. A series element splits
// the net, so "a fuse sits between connector and regulator" is invisible to any per-net
// quantifier.
Reach(start *ir.Net, hops int) Reach
// ReachToTerminus is the same walk with one admission rule changed: a bus-like net is a legal
// DESTINATION and still an illegal transit node. A question whose answer is "we landed on a
// rail" (a pull-up's terminus, a trace to a pin that sits on one) cannot be asked of Reach,
// which drops such a net from the result set entirely.
ReachToTerminus(start *ir.Net, hops int) Reach
Between(from, to *ir.Net, class ComponentClass, hops int) bool
// board tier (WS3-008): each net's routed copper from the board-geometry sidecar.
// Empty when the model was built without a board; see check.WithBoard.
BoardNets() []BoardNet
// board_rules (agni issue 933): the copper minimums the design declares, today from a KiCad
// project's board.design_settings.rules. The zero value when it declares none, so a rule can fall
// back to a fabrication floor of its own.
BoardRules() BoardRules
// component.class: the MOST-SPECIFIC device class from the normalized device_classes set
// (WS3-071), stamped once at ingestion by the classify pass and refined by part-type data.
// ClassUnknown when the design carries no usable signal, so class-quantified rules skip
// rather than misfire.
ComponentClass(refDes string) ComponentClass
// HasClass reports whether a component carries a class in its device_classes SET, so a rule
// asks family membership (HasClass(ref, ClassDiode) is true for a diode, an LED, or a TVS)
// rather than equality against the single most-specific class (WS3-071). An unknown ref-des
// or class is false.
HasClass(refDes string, class ComponentClass) bool
// ExposedConnector reports whether a component is a connector that faces the outside of the
// product: a connector the design's intent does not declare internal (agni issue 831). The
// exposure rules ask this rather than HasClass(ref, ClassConnector), because whether a connector
// faces the field is a fact about one product, which only its declaration can state.
ExposedConnector(refDes string) bool
// Classes returns the full device_classes set for a component (specific class plus family
// tags), or nil for an unknown/unclassified ref-des. The set backing component.class(ref, class).
Classes(refDes string) []ComponentClass
// params tier (WS10-003): the design-side part identity (BomLine mpn, else the component's mpn
// field, else "") and the seeded datasheet spec joined to it. The MPN is joined on every model;
// the spec is nil when the model has no provider (check.WithParamProvider) or the part is
// unseeded, so datasheet-backed rules skip rather than false-pass; see params.go.
ComponentMPN(refDes string) string
PartSpec(refDes string) *parampb.PartSpec
}
Model is the query interface a rule evaluates against: the entity sets it selects over and the derived facts it reads. A Run depends only on this interface, so an alternate implementation (lazy, cached, columnar) can be substituted without touching any rule.
The generic combinators (Select/Exists/Count in package check) are not methods because Go generics cannot be interface methods. They operate on the slices the interface returns.
type PinInst ¶
PinInst is one part-type pin of one placed component: the entity pin-level rules quantify over. It exists only for components whose part type declares pins (a netlist-only source with no part data yields none). It carries no direction, so every consumer resolves it through Model.PinDir and sees the same last-section-wins value; membership is Model.PinConnected.
type PinNetConflict ¶
type PinNetConflict struct {
RefDes string
Pin string
Nets []string
Prov *ir.Provenance
}
PinNetConflict is one malformed-input pin: it appears in more than one net's connections, which the pins-to-net many-to-one invariant forbids. Nets lists every claiming net in design order; Prov locates the second claim (the first place the input is provably wrong).
type PinRole ¶
type PinRole string
PinRole is the semantic role of a pin, derived from its declared name within the component's device-class context (Model.PinRole).
const ( RoleAnode PinRole = "anode" RoleCathode PinRole = "cathode" RolePower PinRole = "power" RoleGround PinRole = "ground" // Transistor terminals (WS3-117), assigned only within the transistor class for the same reason // the polarity roles are diode-only: a bare "G", "S" or "D" pin name means something on almost // every part, so an ungated match would mis-role most of a design. RoleGate PinRole = "gate" RoleSource PinRole = "source" RoleDrain PinRole = "drain" RoleUnknown PinRole = "unknown" )
The pin-role vocabulary. Polarity roles are assigned only within the diode family (diode, led, tvs) so a "K" pin on an IC never reads as a cathode; power/ground come from rail-name conventions on any class. RoleUnknown is the default, and rules skip unknowns rather than guess.
type Reach ¶
type Reach struct {
Nets []*ir.Net
Crossed map[string]bool
Parent map[string]ReachStep // net name -> how it was entered
// Depth is the number of series crossings from the start net as the BFS recorded it (the
// start net is 0, so the walk is reflexive at distance zero). Do not re-derive it by chasing
// Parent, because where parallel passes bridge the same two nets the chain is one of several
// paths and its length can disagree with the walk's. Reachability rules read it (WS3-112).
Depth map[string]int // net name -> series crossings from the start
}
Reach is a bounded series-walk neighborhood (WS3-011), the nets reachable from a start net by crossing SERIES PASS ELEMENTS, in BFS order (start first), plus the ref-des set of the elements crossed. See Model.Reach for why protection rules need it. Parent records how each net was entered, for PathTo / ThroughOnPath, and the Model implementation's walk populates it.
func (Reach) PathTo ¶
PathTo returns the series path from the walk's start net to target, in crossing order (start first, target last); nil when target was not reached. Where parallel passes exist (two resistors bridging the same two nets) any of them is equally on the path for a protection question.
func (Reach) RouteLine ¶ added in v0.2.2
RouteLine renders the route from the walk's start to target as one line, naming the nets it passed through and the part crossed between each pair:
VBUS -> [R5] -> VBUS_F -> [L1] -> VDD_3V3
It is the fourth reading of one walk, beside PathTo (the nets), ThroughOnPath (the parts) and StepsTo (both, with pins), for when the rendering IS the answer, so a query can bind a route as a value and a table can carry it in a cell (agni issue 518).
It returns one of three things:
- a route, when target was reached across one or more crossings
- target's own name, when target IS the start, since the two points are one electrical node
- "", when target was not reached
Pins are left out to keep a table column narrow; StepsTo has them.
func (Reach) StepsTo ¶ added in v0.2.0
StepsTo returns the crossings from the walk's start to target, in crossing order; nil when the target was not reached or IS the start. It is ThroughOnPath with the whole step kept, pins included, for a caller reporting the route (agni issue 518). ThroughOnPath stays for the callers asking a membership question over the path ("is a fuse on it").
type ReachStep ¶
type ReachStep struct {
From string
Through string
FromPin string // Through's pin on the From net
ToPin string // Through's pin on the net this step reached
}
ReachStep records how a net was reached during the series walk: the net crossed FROM, the pass element (ref-des) crossed THROUGH, and that element's own pin on each side of the crossing.
The pins let a step render as "R5.1 to R5.2" rather than a bare component name. They come off ir.Connection.pin_ref on each net. Either may be empty on a source whose connections carry no pin reference, and a renderer must handle that.