profiles

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 18 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 profiles turns a declarative interface definition into check rules (WS3-034). An interface profile (SPI-NOR, eMMC, CAN, ...) names its required signals and support needs. Compile generates a datalog program per requirement and wraps each with query.RuleFromQuery (WS3-038), so adding an interface is a data value rather than new code, and one mechanism replaces ~130 near-identical "verify signal X connected" review items (docsite/content/architecture/rules-and-checks.md). The generated datalog uses only the merged pin/net relations (component.net, the string/pattern predicates, net.reaches, net.rail, net.pin_count).

A signal is matched by NET NAME through one of the matcher forms in matcher.go (affix, glob, or regex), and the completeness check anchors on a designated always-present signal. A declared host (WS3-042) is the complementary path. Without one, a wholly-absent interface is silent, since nothing declares it should exist.

Index

Constants

View Source
const (
	StatePresent       = "present"
	StateMissing       = "missing"
	StateDangling      = "dangling"
	StatePullupMissing = "pullup_missing"
)

Coverage states (WS9-041). Each matches the condition a profile rule fires on, so a coverage cell and a finding never disagree. missing is signal-missing, dangling is signal-dangling, and pullup_missing is missing-pullup.

View Source
const BuiltinSourceName = "profile"

BuiltinSourceName is the catalog source name the built-in profiles register under, so their rules compose as "profile/<rule>". Supersession SELECTS on it, so an overlay replacing the built-in reading of an interface does not reach rules that share the interface tag from some other source.

View Source
const TagProfile = "profile"

TagProfile is the tag key every generated rule carries, valued with the profile's Name. WS9-041 groups coverage by it, and catalog supersession selects a whole interface family with it (WS3-056).

View Source
const TagRequirement = "requirement"

TagRequirement is the tag key Compile stamps on every generated rule, valued with the Type of the Requirement that produced it. The "profile" tag says which interface a rule belongs to and this one says which requirement of that interface it answers, so a consumer can select one requirement's rule instead of the profile's whole compiled set (WS3-115).

Do not match on the rule NAME instead. It encodes the type only by convention (termination compiles to "<profile>-termination-missing", esd to "<profile>-esd-missing"), so it drifts when a compiler picks a different suffix.

The type is unique within a profile, since two requirements of one type compile to the same rule name and catalog composition rejects a duplicate composed name.

Variables

View Source
var A2B = mustParse(a2bYAML)

A2B is ADI's Automotive Audio Bus, a single twisted-pair line (A2B_P/A2B_N) carrying data and power, daisy-chained master→slave. v0 is a data-value profile checking the bus pair is present, host-complete, and not dangling; it does NOT model the coupling/termination network or the downstream I2S/I2C (datasheet/topology concerns).

View Source
var CAN = mustParse(canYAML)

CAN is the CAN bus interface, anchored on CANH. The bus side is the differential pair CANH/CANL, the controller side is TXD/RXD, and each bus end wants a 120Ω resistor across CANH/CANL. The `termination` requirement is compiled by termination.go with no change to Compile (WS3-045).

v0 checks presence, dangling, host-completeness, termination and ESD. It does NOT model bit-timing, the optional split-termination stabilizing cap, or bus length, which need a datasheet or geometry rather than a netlist.

View Source
var EMMC = mustParse(emmcYAML)

EMMC is the eMMC (embedded MultiMediaCard) interface, with a clock, a command line (needs a pull-up), eight data lines, and a reset. It has the SAME requirement shape as SPI-NOR on a differently-shaped bus (WS3-046). CMD is the anchor and the pulled-up line.

v0 checks presence + CMD pull-up + dangling only. The DAT-line boot-mode strap and an active-low RST_N spelling are datasheet/strap concerns, deferred out of v0.

View Source
var LIN = mustParse(linYAML)

LIN is the LIN (Local Interconnect Network) bus interface, a single-wire bus line with a pull-up to VBAT (1kΩ master / 30kΩ slave) plus TXD/RXD on the controller side. LIN is the anchor and the pulled-up line. It reuses the existing requirement types (signal-missing, host-incomplete, missing-pullup, signal-dangling) and needs no new compiler, so like eMMC it is a pure data-value profile.

v0 checks presence + the bus pull-up + dangling + host-completeness. It does NOT model the master/slave role, the INH/wake pins, or dominant-timeout (datasheet/strap concerns).

View Source
var MDIO = mustParse(mdioYAML)

MDIO is the Ethernet PHY management bus profile. MDIO is bidirectional and open-drain, so it needs a pull-up, and MDC is the STA-sourced clock, which does not. MDIO is the anchor.

It is a profile rather than a wider built-in I2C pull-up pattern, since doing both would report the same net from two rules (agni issue 516). A finding here names the net only, with no pull-up hops as the built-in carries. See docsite/content/guide/interface-profiles.md#why-mdio-is-a-profile-and-not-a-wider-built-in.

View Source
var PCIE = mustParse(pcieYAML)

PCIE is PCI Express, with differential TX (PET) and RX (PER) lane pairs, a reference-clock pair, and PERST# reset. v0 is a data-value profile checking these are present, host-complete, and not dangling; it does NOT model the TX AC-coupling caps, per-lane multiplicity, or lane width (datasheet/topology concerns).

View Source
var Profiles = []Profile{SPINOR, EMMC, CAN, LIN, A2B, PCIE, SGMII, MDIO}

Profiles is the built-in interface-profile set. Adding an interface is one entry here plus its Profile value; the compiler and registration below need no change.

View Source
var SGMII = mustParse(sgmiiYAML)

SGMII is the Serial Gigabit Media-Independent Interface between a MAC and a PHY: differential TX (TXP/TXN) and RX (RXP/RXN) SerDes pairs. v0 is a data-value profile checking the pairs are present, host-complete, and not dangling; it does NOT model AC-coupling, on-die termination, or the optional MDIO/MDC management (datasheet concerns).

View Source
var SPINOR = mustParse(spinorYAML)

SPINOR is the SPI-NOR flash interface: chip-select (needs a pull-up), clock, and the four IO lines. Signals are matched by net-name suffix; CS is the anchor, since a SPI bus in use always has a chip-select. A standard SPI-NOR pinout is not customer-specific, so this profile is shared.

Functions

func Anchored

func Anchored(m check.Model, p Profile) bool

Anchored reports whether profile p's CONVENTION completeness check can hang on this model, meaning its anchor signal matches some net. InUse alone does not answer that (WS3-099). InUse is the twin of the datalog `in_use` relation (two distinct signals), while signalMissingRule conjoins in_use with the ANCHOR net existing. So an interface can clear InUse through two NON-anchor signals while the anchor is absent, the completeness rule reports nothing, and zero findings score a clean pass on a bus nothing checked. The review gate needs both halves. They stay separate predicates rather than one widened InUse because the secondary rules (signal-dangling, missing-pullup) gate on InUse alone, and those DO evaluate without the anchor.

A profile that declares NO anchor generates no convention completeness rule at all (signalMissingRule returns nil), so there is nothing for a missing anchor to block and it counts as vacuously anchored.

func Compile

func Compile(p Profile) []*check.Rule

Compile turns a Profile into its check rules. Each declared Requirement is looked up in the requirement registry and its compiler run, dropping the ones that return nil (no host, no pull-up signal). Applicability lives in each compiler, with no per-requirement special-casing here (WS3-045). The rules carry a "profile" tag (Profile.Name) so a consumer can group them by interface.

It panics on an invalid Go-literal profile, since Parse/Load reject the same cases for YAML.

func Components

func Components(m check.Model, p Profile) map[string]bool

Components returns the RefDes of the parts on interface p's nets, the component analogue of Nets. A per-interface datasheet ask joins on the component because an interface chip sits on both its signal nets and its power rails. So a component-subject finding (e.g. rail-nominal-out-of-recommended on the memory die) is kept when the part is on one of the interface's nets, even though the rail carries no interface suffix. It shares Nets' single walk (scope), so the host-beats-convention precedence is the same.

An empty result means present but unmatched, a clean pass. Absence is InUse's job (see present.go).

func Diagnose

func Diagnose(netNames []string, p Profile) []string

Diagnose reports config-quality problems with profile p as applied to a design's net names. It flags a matcher claiming an implausible share of the board, and two of the profile's own signals resolving to the same net. It returns human-readable lines, empty when the profile looks sound.

These are NOT design findings, and must never be reported as any. An over-broad matcher is a mistake in the profile the author wrote, so emitting it as a Finding would put a config problem into a design report and score it against the design.

It takes net NAMES rather than a check.Model because names are all it reads. That makes it testable without building a design, and callable from a surface that has read a design but not built a model, which is where the CLI sits.

func DocRules

func DocRules() []*check.Rule

DocRules returns one representative rule per requirement TYPE for the docsite catalog generator (tools/catalogdocs). Profile rules are generated per-profile, so there is no static catalog to enumerate; this projects each requirement's Detail into a single page-worthy rule with a generic caption (requirementCaption) in place of the profile-specific runtime Summary. Callers must not mutate the returned rules.

func HostDeclared

func HostDeclared(m check.Model, p Profile) bool

HostDeclared reports whether a component on the model DECLARES this profile's host interface (its HostAttrKey=HostAttrVal attribute, WS3-042). False for a profile with no host binding. The review gate distinguishes a host-bound profile whose host is declared, so the host path can evaluate, from one whose host is annotated nowhere. The host path cannot evaluate that one, so the item reads not-automated rather than a hollow pass (WS3-090).

func InUse

func InUse(m check.Model, p Profile) bool

InUse reports whether interface p's signal convention is in use on the model. It is the Go twin of the generated `in_use` relation (profile.go), true when at least TWO DISTINCT signals of the profile appear as nets, matched by each signal's full declared matcher (netMatchesSignal, the Go twin of the generated netMatch). This is the review's absence gate (WS3-090), and it must agree with the rules, or an interface the rules will not fire on gets scored as a clean pass. It is only HALF that agreement, because the convention completeness rule conjoins in_use with the anchor net, which is Anchored (WS3-099); the run gate is both. The whole matcher applies, so a prefix- or glob-discriminated profile (PCIe signals prefixed `PCIE_`) must NOT read in-use just because foreign nets share a bare suffix (`LIN_TX`, `CAN_RX`). A lone matching signal is not evidence (a real corpus has many `_CS` nets), hence the two-distinct-signal floor.

func Named

func Named(m check.Model, p Profile) bool

Named reports WEAK evidence that interface p is on the board. At least two of its signals appear as nets matched by SUFFIX ALONE, dropping the prefix that narrows an affix matcher and ignoring host. It is looser than InUse, and exists only to separate a host-bound interface that IS on the board but whose host/convention cannot resolve (annotated on no component and not strictly in use -> not-automated, the intended check is blocked) from one that is simply absent (-> not-applicable). WS3-090. Do NOT use it as the run gate; that is InUse/HostDeclared, which agree with the rules.

A glob or regex signal has no suffix to drop, so there is no looser reading of it than the matcher itself and it falls back to netMatchesSignal. Without that fallback its empty suffix would match every net and report every design as "named".

func Nets

func Nets(m check.Model, p Profile) map[string]bool

Nets returns the net names that belong to interface p on this design, the scope a review filters a broad rule's findings to so a per-interface ask (e.g. "CAN ESD") sees only that interface's nets. When the interface declares a host and the host is on the design, the scope is exactly the host's nets, which disambiguates suffixes shared across buses such as LIN's _TX/_RX. Otherwise it is the nets matched by the profile's signal matchers, the same ones the rules compile to, so a scoped item cannot pull in a net no finding can name.

An empty result means present but unmatched, a clean pass. Absence is InUse's job (see present.go).

func ProfileProto

func ProfileProto(p Profile) *checkspb.ProfileDef

ProfileProto encodes an interface profile as its wire form.

func RegisterRequirement

func RegisterRequirement(name string, c func(Profile, Requirement) *check.Rule)

RegisterRequirement adds a requirement-type compiler under name, overwriting any existing entry. It is the extension hook for an out-of-module overlay to ship its own requirement type, like check.RegisterSource and formats.Register.

A type registered this way declares no params, and any params a profile gives it reach the compiler unchecked. Use RegisterRequirementWithValidator when the type needs params, so an incomplete declaration is an error at load rather than a surprise inside Compile.

func RegisterRequirementWithValidator

func RegisterRequirementWithValidator(name string, c func(Profile, Requirement) *check.Rule, v func(params map[string]string) error)

RegisterRequirementWithValidator registers a requirement-type compiler together with a validator for its params (WS3-047). The validator runs at LOAD time for a YAML-authored profile and at Compile time for a Go-literal one. Its error text is shown to the profile author verbatim, so it should name the params it wanted. It is separate from RegisterRequirement to keep that public signature unchanged.

func RequirementTypes

func RequirementTypes() []string

RequirementTypes returns the registered requirement type names, sorted. Exported because a profile arrives from more than one place (YAML through Load, a serialized rule definition through the deck reader, WS3-103), and each has to reject an unknown type with the same teaching error rather than skipping it into a declared check that never runs.

func Source

func Source(name string, ps []Profile) check.RuleSource

Source compiles the given profiles into a named check.RuleSource so the CLI can splice overlay profiles into the catalog via check.CatalogWith, the same way --conventions does. The name is the namespace prefix and must differ from the built-in "profile" source (CatalogWith rejects a duplicate source name); the CLI uses "profile-overlay" so an overlay rule is distinguishable from a built-in one by its namespace. It SUPERSEDES rather than augments, so an overlay profile carrying the name of a built-in one replaces that built-in's rules in the composed catalog (WS3-056). Augmenting was WS3-054's v0 and it produces false failures, not just duplicates. A naming map that re-binds some roles and leaves others at core naming lets the CORE profile still anchor and clear its in-use gate, so it reports every re-bound role as a missing signal at severity error while the overlay reads the same design clean. Re-binding the ANCHOR role hides the effect, because the core profile stops anchoring and goes quiet, so the closer a house convention sits to the core one, the more false failures augmenting generates.

Supersession is keyed on the profile NAME and scoped to the built-in "profile" source. Same interface name means same interface, so the overlay's reading of it wins. Scoped to the built-ins, two overlay sources that both define an interface do not delete each other, which under a source-agnostic rule would depend on composition order.

func Validate

func Validate(p Profile) error

Validate reports why a profile cannot do what it says: a missing name, no signals, an unnamed signal, a requirement with no type, more than one anchor, an unsound signal matcher, or a completeness requirement with no anchor to hang on.

It is exported and separate from Parse because a profile arrives by more than one route (YAML, and a serialized rule definition since WS3-103), and a second authoring route with its own idea of validity is how an unsound profile eventually gets in. The two failure classes it covers produce a rule which cannot fire rather than a rule that errors. An over-broad matcher silently claims foreign nets, and a completeness requirement with no anchor compiles to nothing at all, so an item bound to it scores a clean pass while the declared check never existed (WS3-099).

func ValidateRequirements

func ValidateRequirements(p Profile) error

ValidateRequirements checks each declared requirement against the registry, that its type has a compiler in this build and that its params satisfy that type's validator (WS3-047). Both failures are author errors in the declaration, and both produce a check that cannot run (an unknown type silently skipped, or a compiler handed params it cannot use).

Separate from Validate because this half needs the requirement REGISTRY, which Validate (and so Parse) does not depend on. Parse stays structure-only and WASM-clean, and a built-in Go literal reaches its params gate through Compile instead. Exported for the same reason as Validate and RequirementTypes (WS3-103).

Types

type InterfaceCoverage

type InterfaceCoverage struct {
	Profile string
	Anchor  string
	Signals []SignalCoverage
}

InterfaceCoverage is one DETECTED interface profile's coverage. Anchor is the net the profile is anchored at, for context and locate, and Signals holds every required signal in profile order.

func Coverage

func Coverage(ctx context.Context, p Profile, m check.Model, base func() *query.Base) *InterfaceCoverage

Coverage projects a profile onto a design's per-signal coverage matrix, or nil when the interface is not DETECTED, matching the rules. DETECTED means two of its signals are present or a component declares the interface via its host attribute. It uses the same signal matcher (matcher.go) and the same check.PullUpReachesRail the profile rules decide on, so the panel and the findings cannot drift; see InUse in present.go for why they must agree.

base supplies the fact base the host binding is asked of, and is called only for an interface with fewer than two signals present. Pass the one the model keeps (service.BuildModelCached), since projecting a base costs about 50ms on a large board and a caller walks every profile (agni issue 985). A nil base builds one from the default registry on each call.

type Profile

type Profile struct {
	Name    string
	Signals []Signal

	HostAttrKey string // a declared component attribute key (e.g. "interface"); "" = no host binding
	HostAttrVal string // ... and its value (e.g. "SPI_NOR")

	// HostClass binds the host by the DATASHEET's declared device class (e.g. "crystal"), matched
	// against component.device_class. "" = no class binding. It needs a seeded param set. Without
	// --params no component has a spec, so no host is found and the host path stays silent rather
	// than guessing.
	//
	// Both sides go through classify.NormalizeDeviceClass, which folds only what the WS10-015
	// vocabulary KNOWS. For those, case and vendor aliases both fold, so a datasheet saying "XTAL" or
	// "Crystal" matches a profile declaring "crystal". A class the vocabulary does NOT recognize
	// passes through unchanged INCLUDING ITS CASE, so "LDO" and "ldo" do not match. Two classes in the
	// seeded corpus ("ldo", "mcu") are in that position, so a profile binding one of them must spell
	// it as the datasheet does. Widening the vocabulary is WS10-004.
	HostClass string

	// Requirements is the ordered list of checks this profile declares (WS3-045). Each names a
	// registered requirement-type compiler and carries its params, and Compile iterates them
	// uniformly, so a new interface or a new requirement type like CAN's termination is a declaration
	// rather than engine code.
	Requirements []Requirement
}

Profile is one interface definition. Name appears in rule names, messages and the "profile" tag. The Signal flagged Anchor is the always-present one the CONVENTION completeness check hangs on when no host is declared.

Host binding (WS3-042). When a component DECLARES this interface via an attribute (component.attr(?ref, HostAttrKey, HostAttrVal), e.g. interface=SPI_NOR), an ADDITIONAL completeness check anchors on it ("this component is the flash, so its bus must have CS/SCLK/IO0-3"). That check can flag a WHOLLY-ABSENT bus (a host wired to none of its signals), which the convention path cannot. It runs alongside the convention path, so a design that declares no host still gets the convention and confidence-gate check.

TWO host forms, either or both, and a component matching either is a host (WS3-044). The ATTRIBUTE form is the design stating its own intent, so it is authoritative and needs nothing seeded. The CLASS form infers from the datasheet (a part IS an SPI-NOR flash because its spec says device_class is spi_nor_flash), so host binding works on a design that carries MPNs but no interface annotation.

Identifying a host by MPN prefix stays rejected, since a hardcoded part-family list is unverified and rots. The class form keys on component.device_class rather than component.class because the latter also carries keyword evidence from the ref-des and description, which would bring that guess back in.

func ByName

func ByName(name string) (Profile, bool)

ByName returns the built-in profile with the given Name (SPI_NOR, eMMC, CAN, LIN); ok is false if none matches. It is the lookup a naming map (WS3-054) uses to find the core profile it re-binds.

func Load

func Load(r io.Reader) (Profile, error)

Load reads a YAML profile from r, parses+structurally-validates it (Parse), and additionally checks that every declared requirement type is registered, reporting an unknown type with the list of known types so an overlay author sees what is available. This is the entry point for external/customer profiles (LoadDir, the CLI --profile-path flag).

func LoadDir

func LoadDir(dir string) ([]Profile, error)

LoadDir loads every *.yaml / *.yml profile in dir (non-recursive), sorted by filename for deterministic order. It is the file-facing entry point for overlay/customer profiles (the CLI --profile-path flag); the os dependency lives here, isolated from the WASM-clean Parse/Load path. An empty or missing dir is an error (a caller that wants "optional" checks existence first).

func LoadFS added in v0.2.2

func LoadFS(fsys fs.FS, dir string) ([]Profile, error)

LoadFS is LoadDir over dir inside fsys, for a host whose profiles are not on the host filesystem (a project mounted in memory in the wasm engine).

func Parse

func Parse(b []byte) (Profile, error)

Parse reads a YAML profile declaration into a Profile and validates its STRUCTURE (name present, at least one signal, at most one anchor) and every signal's MATCHER (exactly one form, compiling, not over-broad; see validateSignalMatcher). It does NOT check that requirement types are registered. Load does that, so Parse stays free of any registry dependency and WASM-clean (yaml only, no os). Built-in profiles load through mustParse, which adds ValidateRequirements; external/customer profiles go through Load for the teaching type-check.

func ProfileFromProto

func ProfileFromProto(p *checkspb.ProfileDef) Profile

ProfileFromProto decodes an interface profile. Callers that took it from outside this build should run Validate before compiling, as the deck reader does.

func (Profile) HasHost

func (p Profile) HasHost() bool

HasHost reports whether this profile is host-bound (WS3-042), by attribute or by device class. A host-bound profile whose host is found nowhere cannot evaluate its host path, which the review gate treats distinctly from an absent interface (WS3-090).

func (Profile) IsHost

func (p Profile) IsHost(m check.Model, c *ir.Component) bool

IsHost reports whether component c is a host of this profile, meaning it carries the declared attribute or its seeded datasheet declares the bound device class. This is the ONE definition of "host", read by the review scope (Nets/Components) and HostDeclared, with hostRules as its datalog twin.

Keep them in step, because a disagreement is invisible. A host the datalog anchors on but the scope does not recognise produces findings that HostDeclared reports as unevaluable, so a review shows an interface both failing and not-automated (WS3-044).

The class path yields nothing without a seeded param set (PartSpec is nil for every component), so a class-bound profile is silent rather than wrong on a design read without --params.

type Requirement

type Requirement struct {
	Type   string
	Params map[string]string
}

Requirement is one declared check in a Profile, a registered compiler Type (signal-missing, missing-pullup, signal-dangling, host-incomplete, termination, esd) plus its Params (empty for most; termination names the two bridged net suffixes). Adding a requirement TYPE is registering one compiler, and adding a requirement to a profile is one slice entry.

type Signal

type Signal struct {
	Name   string
	Prefix string
	Suffix string
	Glob   string
	Regex  string
	PullUp bool
	Anchor bool // the always-present signal the convention completeness check hangs on (at most one)
}

Signal is one interface member, identified by how its net is NAMED. A signal declares exactly one matcher form (WS3-057), all evaluated in matcher.go:

  • Suffix, optionally narrowed by Prefix (both must match). The default, with the prefix telling apart buses that share a suffix (prefix "PCIE_" + suffix "_TXP", so a UWB serdes _TXP cannot anchor a PCIe check).
  • Glob, a whole-name shell-style pattern ("ETH_SW*_A_H"), for naming where the identity is the PREFIX and the suffix is generic.
  • Regex, an unanchored RE2 pattern for multi-instance naming a glob cannot express.

PullUp marks a line that must reach a rail through a pull-up resistor.

type SignalCoverage

type SignalCoverage struct {
	Name  string
	Net   string
	State string
}

SignalCoverage is one required signal's state within a detected interface. Net is the matched net name, "" when the signal is Missing.

Jump to

Keyboard shortcuts

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