engine

package
v0.22.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 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 engine runs compiled rules over a FileSet: phase 1 fans files out to a worker pool, phase 2 fans finalizers out to a second one (spec §6). A crashed rule is an engine error, never a pass (spec §11).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(rls []*config.Rule, fset *scan.FileSet, workers int) ([]finding.Finding, error)

Run evaluates every rule against every in-scope file, then finalizers. workers <= 0 means GOMAXPROCS. Findings come back deterministically sorted. Every finding is a violation: there is no suppression channel.

Types

type Timing added in v0.6.2

type Timing map[string]time.Duration

Timing records per-rule evaluation time: phase 1 sums the rule's per-file evaluations, phase 2 adds its finalizer. It is observability, never input to a verdict — no finding, sort order, or exit code reads it.

type Timings added in v0.19.0

type Timings struct {
	Wall     Timing
	CPU      Timing
	CPUTotal time.Duration
}

Timings carries wall time for scheduling and CPU for cost accounting. CPU is nil and CPUTotal zero on unsupported platforms or when a test disables measurement; otherwise CPU has exactly the keys Wall has.

func RunTimed added in v0.6.2

func RunTimed(rls []*config.Rule, fset *scan.FileSet, workers int, progress func(ruleID string, elapsed time.Duration)) ([]finding.Finding, Timings, error)

RunTimed is Run plus per-rule wall and CPU accounting, and an optional completion callback: progress (may be nil) is invoked under the findings mutex as each finalizer finishes, with the rule's ID and its accumulated wall total — the hook behind `check -progress`. That flag exists because a whole-corpus lane can run for minutes with no output (every report format writes at the end), and an operator staring at a silent job cannot tell a slow rule from a hung one. Phase 1 cannot report per-rule completion the same way (a rule is complete only once every file has been visited), so the callback is finalizer-only; Timings covers both phases either way.

func RunTimedHinted added in v0.6.4

func RunTimedHinted(rls []*config.Rule, fset *scan.FileSet, workers int, progress func(ruleID string, elapsed time.Duration), prior Timing) ([]finding.Finding, Timings, error)

RunTimedHinted is RunTimed plus a scheduling hint: prior (may be nil) maps a rule id to the wall time that rule took in a PREVIOUS run — a Timing this package returned, carried across runs by `check --durations <report>`.

It changes the ORDER phase 2 dispatches each pool in, and nothing else. See dispatchOrder for what the order is and why the head start it recovers is worth taking. The hint is advisory in the strongest sense: a stale entry, a partial map, a rule the map does not name, or no map at all are all ordinary inputs, because dispatch order cannot reach a verdict. Findings are sorted before they are returned, the engine error is selected by declaration index, and the ordering is a permutation, so every rule still runs exactly once (TestRunDispatchOrderRunsEveryRuleExactlyOnceInEveryPool).

It does NOT re-order phase 1, and there is nothing there to re-order for: phase 1's pools dispatch FILE indices, and a worker evaluates every applicable rule against the file it took, so a rule's position in that inner loop does not decide when it starts.

Jump to

Keyboard shortcuts

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