Documentation
¶
Overview ¶
Package capturecensus checks the native read/capture boundary using typed facts extracted by workcensus. It owns storage policy, not source extraction. Reachability witnesses describe possible source paths, not runtime dominance.
Index ¶
- Constants
- Variables
- func AcceptanceCounts(list []Acceptance) map[string]int
- func CrossingInterfaces(list []BoundaryCrossing) map[string]int
- type Acceptance
- type BoundaryCrossing
- type Consumer
- type ContextSite
- type ContextSource
- type CrossUnitOwner
- type Declaration
- type Disposition
- type Inventory
- type NilDisposition
- type Policy
- type Read
- type ReviewedHeldValue
- type ReviewedNonNilResult
- type RouteEdge
- type ScopeEntry
- type SourceDeclaration
- type TypeName
Constants ¶
const ( // KindNilDisposition is a reviewed claim that a flagged nil cannot occur. KindNilDisposition = "nil-disposition" // KindRecordedOwner is a substitution waived because another change owns // it. No policy produces it any more; it stays forbidden. KindRecordedOwner = "recorded-owner" // KindCrossUnitOwner is a substitution still present in this tree that a // named merge unit fixes on its own lifetime owner; listed and counted, // never silent (approver, unit and fixing change are recorded). KindCrossUnitOwner = "cross-unit-owner" // KindAPIBoundary is a fresh context created in an exported function that // takes no context, which no request holder in the module reaches. KindAPIBoundary = "api-boundary" // KindNoRequestChain is a fresh context created where no caller chain in // the module reaches a function holding a request. KindNoRequestChain = "no-request-chain" // KindUnfulfilled is a substitution whose request holder reaches it only // across the public API (a caller in another package, or dynamic dispatch // into an exported method). Contract A is NOT met there: the census lists // and counts it against the tracked deferral, and it is never a pass. KindUnfulfilled = "unfulfilled-contract-a" // KindOwnedSource is a named context owned by work outliving any request. KindOwnedSource = "owned-source" // KindOutsideBoundary is a nil context passed to code that reaches no // context reader. KindOutsideBoundary = "outside-boundary" // KindReviewedHeld is a fresh context created where the function holds // contexts the census does not exclude (held.go) and a reviewed record, // pinned to those exact held values and to the source of every function // the review relied on, says why none is a request. Listed and counted, // never a pass; any change to what it is pinned to fails it as stale. KindReviewedHeld = "reviewed-held-value" // KindReviewedHolder is a caller on a walk whose held contexts are exactly // those of its own reviewed record, still current: listed and counted per // walk, walked past, never a pass. KindReviewedHolder = "reviewed-holder" // KindNilDetached is a nil context on a merged path whose convention is // that nil means detached, at a pinned use, reaching readers reviewed to // tolerate it. Listed and counted by root, never cleared. KindNilDetached = "nil-detached" // KindTrackedDefect is a real defect filed for Linear, listed until fixed. KindTrackedDefect = "tracked-defect" // KindDistinctDecision is a reviewed storage read responsibility. KindDistinctDecision = "distinct-decision" // KindProof is a rule of the nil analysis that proved a value non-nil. KindProof = "proof" // KindReviewedResult is a source-validated reviewed result contract, not an inferred proof. KindReviewedResult = "reviewed-result-contract" // KindConvention is a model convention the nil analysis trusted. KindConvention = "model-convention" )
Acceptance kinds. Contract A (no nil or substituted context reaches a function that reads one) forbids the first two outright.
const ( SuppliesContext = "" BodyBoundary = "body-boundary" )
The kinds of a named route edge: SuppliesContext is the default.
Variables ¶
var ForbiddenAcceptanceKinds = []string{KindNilDisposition, KindRecordedOwner}
ForbiddenAcceptanceKinds are the kinds Contract A does not allow at all.
Functions ¶
func AcceptanceCounts ¶
func AcceptanceCounts(list []Acceptance) map[string]int
AcceptanceCounts sums the acceptances by kind.
func CrossingInterfaces ¶
func CrossingInterfaces(list []BoundaryCrossing) map[string]int
CrossingInterfaces counts crossings by the interface methods they dispatch through ("static" and "function value" otherwise), so the population beyond Engine is visible.
Types ¶
type Acceptance ¶
Acceptance is one reason the census did not fail a finding, recorded by the one recorder (acceptanceLog.accept). Every path that turns a would-be violation into a non-violation goes through it, so the census can list and count all of them; Count is set for aggregated proof and convention rules.
func (Acceptance) String ¶
func (a Acceptance) String() string
String renders one acceptance for the census log.
type BoundaryCrossing ¶
type BoundaryCrossing struct {
Entry, Caller, Via, Holder string
}
BoundaryCrossing is one caller edge the in-package request walk does not follow: a caller outside the policy package, or a dynamic call into an exported method (the Engine interface, or any other interface or function value reaching it). Every such cut is recorded, so the census's exclusion population is listed and counted, never silent. Holder is the request holder found beyond the cut by the module-wide walk, or empty when none exists.
func (BoundaryCrossing) String ¶
func (c BoundaryCrossing) String() string
type ContextSite ¶
type ContextSite struct {
File, Function, Callee, Reason string
Line int
// Reaches is the first boundary call the fresh context reaches (the
// call, its target and position) that brought the site into the census.
Reaches string
}
ContextSite is one call in the policy package that passes context.Background or context.TODO into a function that reaches a ContextOwner. Reason records why no request context exists there; a site where one does is a violation.
type ContextSource ¶
type ContextSource struct {
Source string
Root workcensus.Root
Disposition, Reason string
}
ContextSource is the one named context of work whose lifetime belongs to an owner rather than to any request, such as the ordered notification drainer. Source may be used only on the work Root performs itself (the engine's DirectReachableFrom), and that work may use no fresh context. Disposition and Reason label the sites that use it.
type CrossUnitOwner ¶
type CrossUnitOwner struct{ Unit, FixingPR, Reason, Approver string }
CrossUnitOwner records a substitution still present in this tree that a named merge unit fixes on its own lifetime owner: the unit, the fixing change, why, and who approved the record. It is listed and counted as KindCrossUnitOwner, never silent, and fails as stale when it matches no substitution.
type Declaration ¶
type Disposition ¶
Disposition pins a read-based distinction. An edit to the body invalidates the decision. Owners, when supplied, must still be reachable in extracted facts.
type Inventory ¶
type Inventory struct {
SourceDeclarations []SourceDeclaration
Declarations []Declaration
Reads []Read
Consumers []Consumer
OwnerCalls []Consumer
ContextSites []ContextSite
// NilContextsElsewhere lists nil contexts passed to calls that reach no
// owner: findings for their own owners, not violations of this boundary.
NilContextsElsewhere []string
// NilContextsDisposed lists in-family nil flows accepted by a reviewed
// disposition entry, with its reason and reviewer.
NilContextsDisposed []string
// NilContextBoundary lists the functions a nil context must never reach:
// the context owners plus every context reader of the native engine.
NilContextBoundary []string
// Acceptances lists every finding the census did not fail, by kind, from
// its one recorder; AcceptanceCounts sums them.
Acceptances []Acceptance
// BoundaryCrossings lists every edge the in-package request walks cut (a
// caller outside the package, or a dynamic call into an exported method),
// with any request holder beyond it: the exclusion population of the
// public API stop.
BoundaryCrossings []BoundaryCrossing
Limitations []string
Violations []string
}
func Analyze ¶
func Analyze(i workcensus.Inventory, policy Policy) Inventory
Analyze consumes the same shared extraction in production guards and planted controls. Caller/callee objects, including alias and function-value candidates, are supplied by the engine. Unknown indirect calls remain approximation limits.
func Extract ¶
func Extract(c workcensus.Config, policy Policy) (Inventory, error)
Extract uses the shared engine's typed all-source selectors. In particular it includes unused methods, aliases, literals and arbitrary-name functions; it does not parse files, build another call graph, or supply familiar reader names.
type NilDisposition ¶
NilDisposition is a reviewed exception for in-family nil flows from one witness root that the model cannot prove non-nil: why the value is non-nil, who approved it, and the exact uses approved (nilWitnessUse keys). A flow from the root at any other use fails, and an approved use, or the root, that matches no current flow fails as stale.
type Policy ¶
type Policy struct {
Package, Native string
Entities, IDs, Views []string
Capture, Historical, Head, Scalar []string
Publication []string
BorrowedOptions []string
ContextOwners []string
CrossUnitOwners map[string]CrossUnitOwner
OutOfContract map[string]ScopeEntry
ExcludedPackages map[string]ScopeEntry
TrackedDefects map[string]ScopeEntry
DeferredPublicAPI ScopeEntry
// PublicPackages are packages whose exported API, like the policy
// package's, takes no request context in 1.4.4 (the tracked deferral);
// the request walk stops at their exported entry points too.
PublicPackages []string
// PublicEntries are single exported functions of other packages that are
// the same deferred boundary (by symbol).
PublicEntries []string
ContextSources []ContextSource
NonNilResults map[string]ReviewedNonNilResult
NilContextDispositions map[string]NilDisposition
// NilDetached are the nil flows of a merged detached-path convention, by
// witness root, each at its exact uses (KindNilDetached).
NilDetached map[string]NilDisposition
// ReviewedHeldValues are reviewed per-site records, by the function
// creating the fresh context (ReviewedHeldValue).
ReviewedHeldValues map[string]ReviewedHeldValue
ExtraResults []TypeName
Distinct map[string]Disposition
}
Policy identifies type and owner objects in the compiled package. Names are policy data; receiver identifiers, pointer syntax and declaration order are never used as identities. Alternate owners describe distinct read contracts.
func StoragePolicy ¶
func StoragePolicy() Policy
StoragePolicy is the native storage client's contract. Live entities and selectors consume the capture owner; explicit logical versions retain the release MVCC owner, heads retain their metadata owner, degrees retain the scalar prefix counter. Publication roots are inventoried alongside readers. No reader function names participate in discovering membership.
type Read ¶
type Read struct {
Declaration
Responsibility string
Path []string
}
type ReviewedHeldValue ¶
type ReviewedHeldValue struct {
EndsEdges []RouteEdge
TrackedHolders []RouteEdge
RouteSources map[string]string
Held []string
Sources map[string]string
Closure string
Modules []string
Callers map[string][]string
FieldWriters map[string][]string
Methods map[string][]string
Reason string
Approver string
}
ReviewedHeldValue is a reviewed record for one function whose held contexts, at the fresh contexts it creates, are not requests by a reading the census cannot prove. It is pinned to what was reviewed: Held is the exact list of held values the reading covers (heldDescription: producer, line in the function, function); the census treats exactly those occurrences as excluded roots, so values built from them by E4-E6 are covered too, and fails the record when any of them is gone or anything else is held. Sources is the sha256 (sourceDigests.of) of the source of the function itself and of every function the reading relies on (producers, callbacks and their bindings), keyed by symbol; Modules pins library versions ("path version", as in go.mod) the reading relies on; Callers the exact caller set of named functions (a callback's binding sites); FieldWriters the exact set of functions storing a struct field ("<package path>.<Type>.<field>", a callback field or a wrapper's embedded context); and Methods the exact method set of a type ("<package path>.<Type>", each method "Name declared" or "Name promoted"), so a wrapper gaining or overriding a method is seen. The census accepts the site only when all of these still match; any change, an added or removed held value, an edited function, a new binding or writer, a changed method set or version, fails the record as stale, so it is reviewed again. Closure is the digest of everything those sources reach (sourceDigests.closure), so a change below a pinned function stales the record without that function being named. A record matching no site fails.
EndsEdges names caller edges at which the site's walk may end. A SuppliesContext edge ends only where the census finds, on every call of the edge, a context the nil analysis cannot prove may be nil, so the fallback cannot run there. A BodyBoundary edge ends on a human reading of the caller's own body, that it runs work that is no request's. Either must have its caller's source pinned; a named edge the walk never reaches fails, and every other edge is walked. TrackedHolders names holders on a filed finding's route, each on one edge: listed and counted as tracked defects, never cleared, and walked past; any other holder is reported. RouteSources are source digests of those callers, outside Closure. A record is used only after it is validated at its site.
type ReviewedNonNilResult ¶
type ReviewedNonNilResult struct {
Index int
PackageFunctions []string
PackageFiles map[string]string
Review ReviewedHeldValue
}
ReviewedNonNilResult pins a reviewed normal-return contract to its complete relevant source closure and field-writer population. It confers no ownership or request-substitution exemption and makes no claim about other tuple slots.
type RouteEdge ¶
type RouteEdge struct{ Caller, Callee, Reason, Kind string }
RouteEdge is one caller edge of a site's walk, with why it is named.
type ScopeEntry ¶
ScopeEntry is a ruled census outcome outside Contract A, with its reason. Occurrences, when set, limits a tracked defect to those exact fresh contexts (heldDescription); any other in the function is judged as usual, and an entry none of them still matches fails.
type SourceDeclaration ¶
type SourceDeclaration struct{ ID, Kind, File, Symbol string }