Documentation
¶
Overview ¶
Package smt is the `smt` analysis engine: an action's token flow as a transition relation over SMT terms, queried for a violation or deadlock within k moves, every witness replayed.
Index ¶
- Constants
- Variables
- type AcceptSite
- type BodyLoop
- type BusSlot
- type Cut
- type Diverging
- type Encoding
- func (e *Encoding) Assume(ctx *runtime.Context, sym *symbols.Symbol, scope *symbols.Scope) error
- func (e *Encoding) Completion() *solve.Query
- func (e *Encoding) Conditions(ctx *runtime.Context, syms []*symbols.Symbol, scope *symbols.Scope) (*Property, error)
- func (e *Encoding) Consistency() *solve.Query
- func (e *Encoding) Cuts(result *solve.Result) (Cut, error)
- func (e *Encoding) Deadlock() *Property
- func (e *Encoding) Decode(result *solve.Result) (*Witness, error)
- func (e *Encoding) DecodeOutputs(values []solve.Assignment) (map[string]string, error)
- func (e *Encoding) DecodePair(result *solve.Result, out Output) (*Diverging, error)
- func (e *Encoding) Failure(p *Property) *solve.Query
- func (e *Encoding) Fix(q *solve.Query, values []solve.Assignment) (*solve.Query, error)
- func (e *Encoding) LiveSchedule(result *solve.Result) (*Witness, error)
- func (e *Encoding) OutputVars() []*solve.Var
- func (e *Encoding) Outputs() []Output
- func (e *Encoding) Pair() (*Pair, error)
- func (e *Encoding) Sensitivity(out Output) (*solve.Query, error)
- func (e *Encoding) Uncertainty() *solve.Query
- func (e *Encoding) Violation(p *Property) *solve.Query
- type Engine
- func (e *Engine) Covers(_ *analysis.Model, q analysis.Question) analysis.Coverage
- func (*Engine) Describe() analysis.Description
- func (*Engine) Name() string
- func (e *Engine) Process() (string, error)
- func (e *Engine) Run(ctx context.Context, model *analysis.Model, q analysis.Question, ...) (analysis.Result, error)
- type Flow
- type FlowError
- type Frame
- type Input
- type Move
- type Named
- type Output
- type Pair
- type Property
- type PropertyKind
- type ScheduleError
- type SendSite
- type Slot
- type Sorts
- type State
- type UnsupportedError
- type Witness
- type WitnessError
Constants ¶
const ( // Absent is the node value of a slot no token occupies: one never filled, // or one whose token retired or was consumed. Absent = "Absent" // NoEdge is the edge value of a token that arrived over no succession: the // initial token, and a token a synchronization made. NoEdge = "none" // Pending is the edge value of a token at a repeated step whose move must // still take the split into its siblings, as the interpreter's // splitRepeatedStep spends a step on it. Pending = "pending" // Stutter is the choice of a move in which no token acts: the flow is // complete, or every token left is held. Stutter = "stutter" )
The constructors the finite sorts carry beside the flow's own nodes and edges.
const CopyPrefix = "B/"
CopyPrefix starts the name of every variable of the relation's second copy. No name the encoding gives a variable carries a `/`, so the copies stay apart.
const DefaultMoves = 40
DefaultMoves is the move bound k when the budget names no depth.
const DefaultUnroll = analysis.DefaultUnroll
DefaultUnroll is how many iterations of a body loop the encoding unrolls when the engine is given no other bound.
const EngineName = analysis.SMTEngineName
EngineName is the name the engine registers under.
const MarkVar = "mark"
MarkVar is the integer variable a violation or failure query adds: the state its model points at, so a witness knows how far to replay.
const MaxSlots = 32
MaxSlots bounds the token slots one encoding declares; a flow that may need more within k moves is refused with ErrSlotOverflow rather than encoded partially.
const NoInitialState = "assumptions admit no initial state"
NoInitialState is the reason a run claims nothing when its assumptions admit no initial state: a property over no run is vacuous, not proved.
const NoSensitivityWithin = "no sensitivity found within %d moves"
NoSensitivityWithin begins the reason of a bounded negative sensitivity answer: no two completed schedules differ, but some schedule is cut by the bounds.
const NoSignal = "none"
NoSignal is the signal value of an empty bus slot.
Variables ¶
var CopyNames = [2]string{"A", "B"}
CopyNames name the two copies as a report and a witness file spell them.
var ErrMalformedFlow = errors.New("smt: malformed action flow")
ErrMalformedFlow is the typed error for an action flow the interpreter would refuse to run: no initial node, a join with two successors, and the like.
var ErrNoWitness = errors.New("the result carries no model to decode")
ErrNoWitness is the typed error of a decode over a result that carries no model.
var ErrNotEncoded = errors.New("smt: not encoded")
ErrNotEncoded is the typed error for a construct this engine does not encode. The behavior is reported not covered; nothing is approximated.
var ErrScheduleFixed = errors.New("smt decides every schedule, not one")
ErrScheduleFixed is the typed error for a Holds question that fixes its schedule.
var ErrSlotOverflow = errors.New("smt: token slots exceeded")
ErrSlotOverflow is the typed error for a flow whose forks may put more tokens in flight within k moves than the encoding has slots for.
Functions ¶
This section is empty.
Types ¶
type AcceptSite ¶
AcceptSite is one accept node and what it waits for.
type BusSlot ¶
BusSlot is one message slot of the bus at one state: whether a message sits in it, its signal type, its payload and the move that posted it.
type Cut ¶
type Cut struct {
// Moves: a token may still act after move k.
Moves bool
// Unroll: a body loop ran past its unrolling.
Unroll bool
// Slots: a fork found no free token slot.
Slots bool
}
Cut is which bounds a model of Uncertainty shows reached.
type Diverging ¶
type Diverging struct {
Feature string
// Runs are copy A's and copy B's schedules, each followed to its completion.
Runs [2]*Witness
// Values are the output's final values under the two runs, runtime.UnsetText
// for a run that leaves it holding none.
Values [2]string
}
Diverging is a model of a Sensitivity query read back: the two runs and the output's value each leaves, spelt as the interpreter spells it.
type Encoding ¶
type Encoding struct {
Flow *Flow
Sorts Sorts
Moves int
Unroll int
// States[i] is the state after move i; States[0] is the initial state.
States []*State
// Choices[i-1] is the choice made in move i.
Choices []*Move
// Features are the variables the bodies and guards read or write, one per
// feature, ordered by name; each state holds a copy of every one.
Features []*solve.Var
// Choosable[i][t] holds when the token in slot t may act from state i.
Choosable [][]*solve.Term
// Completed[i] holds when no token is left in state i.
Completed []*solve.Term
// Inputs are the features of the initial state, free in their domains or
// pinned at the model's values, in the order the performance declares them.
Inputs []Input
// Assumptions names the conditions Assume asserted over the initial state, in order.
Assumptions []string
// Sorts, variables and assertions of the relation, for a query to build on.
Query *solve.Query
// contains filtered or unexported fields
}
Encoding is the transition relation of one action's flow over k moves: the states after each move, the choice each move makes, and the assertions that tie state i to state i-1 as one step of the interpreter would.
func Encode ¶
func Encode(ctx *runtime.Context, action *symbols.Symbol, graph *lower.ActionGraph, held runtime.Held, releases []string, k, unroll int) (*Encoding, error)
Encode builds the transition relation of action's flow graph for k moves, unrolling each body loop unroll times. The action's features resolve as the interpreter resolves them, through ctx; held is what the performance holds at its start: its features, own and inherited, and their values ahead of the defaults it declares. A feature held bound by nothing is free in state 0, in the domain its declared type gives it; releases names bound ones to free too.
func (*Encoding) Assume ¶
Assume asserts sym's requirement or constraint over state 0 alone, narrowing the initial states the queries range over; it is translated and refused as a property is.
func (*Encoding) Completion ¶
Completion is satisfiable exactly when some run completes within the bounds, MarkVar naming the state; its models, told apart by Outputs, are the exploration's outcomes.
func (*Encoding) Conditions ¶
func (e *Encoding) Conditions(ctx *runtime.Context, syms []*symbols.Symbol, scope *symbols.Scope) (*Property, error)
Conditions is the property that every one of syms' requirements and constraints (inherited conditions included) holds at every state: a state violating any violates it, one where any cannot be evaluated leaves it undefined; one reading a feature the action does not carry is refused. An empty set is refused as no condition.
func (*Encoding) Consistency ¶
Consistency is satisfiable exactly when some initial state meets the assumptions; unsat, the assumptions admit none and every query is vacuous.
func (*Encoding) Deadlock ¶
Deadlock is the property that no run stops short: a move stutters only once the flow is complete.
func (*Encoding) Decode ¶
Decode reads a model of a Violation or Failure query back as the run it describes, up to the state MarkVar points at.
func (*Encoding) DecodeOutputs ¶
DecodeOutputs reads the outputs of a completed run from an assignment over OutputVars, spelled as the interpreter spells a run's results, keyed by the attribute's name; an attribute holding no value is left out.
func (*Encoding) DecodePair ¶
DecodePair reads a model of the output's Sensitivity query back as its two runs.
func (*Encoding) Failure ¶
Failure is satisfiable exactly when some run within the bounds meets what the interpreter reports as an error: a body or guard that fails, or p undecidable.
func (*Encoding) Fix ¶
Fix is q narrowed to the runs whose OutputVars take the values assigned, so its model is one run of that outcome.
func (*Encoding) LiveSchedule ¶
LiveSchedule reads a model of Uncertainty back as the run it shows cut by the bound, its choices up to move k.
func (*Encoding) OutputVars ¶
OutputVars are the variables that tell one completed run's outcome from another's: each output's value and, where it may hold none, whether it does.
func (*Encoding) Outputs ¶
Outputs are the features the performance holds as the final state leaves them, in declaration order: what the interpreter reports as a run's results.
func (*Encoding) Pair ¶
Pair builds the two-copy relation once and keeps it: every variable but state 0's is declared again under CopyPrefix, every assertion asserted again over the renamed variables, and a value pinned in copy A pinned in copy B too.
func (*Encoding) Sensitivity ¶
Sensitivity is the two-copy query for the output: both copies complete within k moves with neither bound reached, and the output ends with different values — or held in one run and not the other.
func (*Encoding) Uncertainty ¶
Uncertainty is satisfiable exactly when some non-failing run is cut short by a bound (a token live after move k, a loop past its unrolling, no free slot); unsat makes an unsat property proved.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the `smt` analysis engine over the solver discover finds.
func New ¶
New returns the engine over the solver discover finds, nil discovering as solve.Discover does.
func (*Engine) Covers ¶
Covers takes a Holds or Sensitive question with the schedule free, its inputs free or as written; a fixed schedule, another kind and a question without its ask are refused.
func (*Engine) Describe ¶
func (*Engine) Describe() analysis.Description
Describe: every schedule of at most k moves over the inputs free in their declared domains, decided by a solver; an `unsat` with no bound reachable is a proof, a witness is replayed before it is claimed. A Sensitive question is decided over two copies of the schedule sharing the initial state, both witnesses replayed.
func (*Engine) Run ¶
func (e *Engine) Run(ctx context.Context, model *analysis.Model, q analysis.Question, budget analysis.Budget) (analysis.Result, error)
Run encodes the flow for Budget.Depth moves (DefaultMoves when none), body loops unrolled Budget.Unroll times (DefaultUnroll when none), and asks, in order, for a violation, a failure and a deadlock; a `sat` is replayed before it is claimed. A Sensitive question asks the two-copy query first, as decideSensitive spells.
type Flow ¶
type Flow struct {
// Graph is the lowered flow the interpreter runs; it stays the source of truth.
Graph *lower.ActionGraph
// Frames lists the root flow first, then each flow a node states of its own,
// in the order the nodes are met; FrameOf gives the frame each node runs in.
Frames []*Frame
FrameOf map[ast.Node]*Frame
// Nodes lists every frame's nodes, frame by frame in graph order; Index inverts it.
Nodes []ast.Node
Index map[ast.Node]int
// Labels names each node as a trace does, made unique by position where
// two nodes share a name.
Labels []string
// Edges lists every succession, in the order of its source node then its
// declaration; EdgeIndex inverts it. Incoming and Outgoing list a node's
// successions by index.
Edges []lower.ActionEdge
EdgeIndex map[lower.ActionEdge]int
Incoming map[ast.Node][]int
Outgoing map[ast.Node][]int
// Loops lists the body loops the encoding unrolls, in the order their
// statements are met walking the nodes.
Loops []BodyLoop
// Slots is how many tokens may be in flight at once within k moves, over
// every frame: the bound T.
Slots int
// Cyclic is set when a fan-out lies on a cycle, so the tokens in flight are
// bounded by k rather than by the graph, and the state records a full fan-out.
Cyclic bool
// Delivers is set when an object flow delivers to a node performing in a
// frame of its own, whose pin queues the deliveries it has yet to take.
Delivers bool
// Repeats is how many times each step is performed when that is not once,
// RepeatText its declared multiplicity for diagnostics, and Crosses those
// whose tokens each succeed to their join or merge on their own.
Repeats map[ast.Node]int64
RepeatText map[ast.Node]string
Crosses map[ast.Node]bool
// Repeated is set when any step is performed other than once, so a state
// records a slot the extra tokens needed but did not find.
Repeated bool
// Sends lists the send statements the bodies run; Bus is how many messages
// may sit on the bus at once within k moves: the bound M.
Sends []SendSite
Bus int
// Accepts lists the accept nodes; Timed is set when one waits on the clock.
Accepts []AcceptSite
Timed bool
}
Flow is an action's lowered flow as the encoding numbers it: every node and every succession of every frame has a stable index, and the constructs the stage encodes have been checked for, so the encoder meets nothing it must refuse.
type FlowError ¶
FlowError names the node whose shape the interpreter would refuse. It is ErrMalformedFlow.
type Frame ¶
type Frame struct {
// Index is the frame's position in Flow.Frames; the root is 0.
Index int
Graph *lower.ActionGraph
// Node performs the frame's flow; nil for the root. Parent is its frame.
Node ast.Node
Parent *Frame
// Nodes lists the frame's own nodes, in graph order.
Nodes []ast.Node
// Slots is how many tokens the frame's flow may hold at once within k moves.
Slots int
}
Frame is one flow the encoding runs: the root, or the flow a node states of its own, run by that node's performance.
type Input ¶
type Input struct {
// Name is the feature as the performance holds it, as `-check-input` spells it.
Name string
// Type is the declared type as written, "" without one.
Type string
// Var is the variable every state carries for the feature.
Var *solve.Var
// Free reports whether state 0 ranges over Domain rather than pinning Value.
Free bool
// Released reports whether the model binds the feature and the question freed it.
Released bool
// Optional reports a free feature whose multiplicity admits no value: state 0
// ranges over its absence too, which a witness spells `null`.
Optional bool
// Domain spells what narrows the sort (`>= 0`, `{Fast, Slow}`); "" when the sort alone is the domain.
Domain string
// Value is the value the performance holds at its start, ValInvalid when it holds none.
Value runtime.Value
// contains filtered or unexported fields
}
Input is one feature of the initial state as the encoding takes it: free in the domain its declared type narrows its sort to, or pinned at the value the model binds it to, in the order the performance declares them.
type Move ¶
type Move struct {
Index int
// Choice is the slot whose token acts, or Stutter.
Choice *solve.Var
// Travel is the succession the acting token left over — the decision
// witness where several guards held — or NoEdge for a move taking none.
Travel *solve.Var
// Held holds, per succession out of a decision node with a guard, when
// the acting token read that guard and it held; nil for every other succession.
Held []*solve.Var
}
Move is the choice made in move Index, from state Index-1 to state Index.
type Named ¶
Named is one variable of the state vector under the name it has at every move, so a query over two copies of the relation pairs them by name.
type Output ¶
type Output struct {
Name string
Var *solve.Var
// Has is nil for an attribute that holds a value in every state.
Has *solve.Var
}
Output is one attribute of the action as a completed run leaves it: the copy of its value the final state holds, and whether it holds one.
type Pair ¶
type Pair struct {
// Renamed is copy B's variable for each of copy A's, by A's name; a shared
// variable has no entry.
Renamed map[string]*solve.Var
// Query declares and asserts both copies.
Query *solve.Query
}
Pair is the relation twice over: copy A as encoded and copy B over renamed variables, the two sharing state 0 and so every free input. It is a function of the encoded relation alone, whatever the state vector holds.
type Property ¶
type Property struct {
Kind PropertyKind
// Conditions are the requirements and constraints asked about, in the order
// named; none for deadlock freedom. Several hold together, as one property.
Conditions []*symbols.Symbol
// Name is the property as a verdict names it.
Name string
// Violated[i] holds when state i violates the property: a required
// condition false there, or move i stuttered with tokens left.
Violated []*solve.Term
// Undefined[i] holds when the interpreter could not evaluate the property
// at state i: a feature it reads holds no value, or a side condition fails.
Undefined []*solve.Term
}
Property is a property of the runs of an encoding, decided at every state the interpreter reaches: after move 0 (the initial state) through move k.
type PropertyKind ¶
type PropertyKind int
PropertyKind is what a property asks of every state of a run.
const ( // PropertyDeadlock asks that no run stops with a token left that can never act. PropertyDeadlock PropertyKind = iota // PropertyRequirement asks that a requirement's conditions hold at every move boundary. PropertyRequirement // PropertyConstraint asks that a constraint's conditions hold at every move boundary. PropertyConstraint // PropertyConditions asks that requirements and constraints together hold at every move boundary. PropertyConditions )
func (PropertyKind) String ¶
func (k PropertyKind) String() string
type ScheduleError ¶
type ScheduleError struct {
Engine string
Schedule runtime.SchedulePolicy
}
ScheduleError reports a question asking about one schedule of an engine that decides them all.
func (*ScheduleError) Error ¶
func (e *ScheduleError) Error() string
func (*ScheduleError) Is ¶
func (e *ScheduleError) Is(target error) bool
Is matches ErrScheduleFixed.
type Slot ¶
type Slot struct {
At *solve.Var
Via *solve.Var
ID *solve.Var
// Able holds when the slot's token may act from this state, as the
// interpreter's step would offer it.
Able *solve.Var
// Parked holds when the token waits at an accept: for a message, or for
// the clock to reach Due. Both are nil for a flow without accepts.
Parked *solve.Var
Due *solve.Var
}
Slot is one token slot at one state: where its token is, the succession it arrived over and the ID the interpreter gave it.
type Sorts ¶
type Sorts struct {
// Node ranges over the flow's nodes and Absent.
Node solve.Sort
// Edge ranges over the flow's successions and NoEdge.
Edge solve.Sort
// Choice ranges over the token slots that may act in a move, and Stutter.
Choice solve.Sort
// Signal ranges over the signal types the sends post and NoSignal; its
// values are empty for a flow without sends.
Signal solve.Sort
}
Sorts are the finite datatype sorts one encoding declares.
type State ¶
type State struct {
Move int
Slots []Slot
NextID *solve.Var
// Values holds this state's copy of every feature the bodies read or
// write, keyed by the name the translator gives the feature.
Values map[string]*solve.Var
// Loop is set, per body loop, when the move reaching this state ran the
// loop past the unroll bound, so what follows is not known.
Loop []*solve.Var
// Failed is set when the move reaching this state met an error the
// evaluator reports: a division by zero, a guard that is not Boolean.
Failed *solve.Var
// Overflow is set when a move reaching this state exceeded what the state
// holds: a fork found no free slot, or a delivery found a pin's queue full.
Overflow *solve.Var
// Now is the clock in seconds; nil for a flow without timed accepts.
Now *solve.Var
// Bus holds the M message slots; BusOverflow is set when a send found none
// free. Both are empty for a flow without sends.
Bus []BusSlot
BusOverflow *solve.Var
}
State is the symbolic state after move Move; move 0 is the initial state. Each variable is a copy of its own, named `<what>@<move>`.
func (*State) Vector ¶
Vector lists the state's variables under their move-independent names: the slots, the clock, the bus, the flags, the feature copies and, for each flagged feature, the flag saying whether it holds a value. Two states of one encoding have vectors of the same names in the same order.
type UnsupportedError ¶
type UnsupportedError struct {
// Node is the action node the construct belongs to, as a trace names it.
Node string
// Construct is what was found: "accept", "send", "nested flow", …
Construct string
// Reason says which stage of the design encodes it, or why nothing does.
Reason string
}
UnsupportedError names the node and the construct that keep a behavior out of the encoding, and why. It is ErrNotEncoded.
func (*UnsupportedError) Error ¶
func (e *UnsupportedError) Error() string
func (*UnsupportedError) Is ¶
func (e *UnsupportedError) Is(target error) bool
Is makes an UnsupportedError match ErrNotEncoded.
type Witness ¶
type Witness struct {
// Mark is the state the query's model points at: the one violating the
// property, or the one a stutter left short.
Mark int
// Steps is how many moves the run makes before Mark, its stutters excluded:
// the interpreter's steps that reach the state Mark names.
Steps int
// Inputs are the values the solver chose for the free inputs in state 0, spelt
// as the notation reads them back, in the order the performance holds them.
Inputs []runtime.InputTaken
// Choices are the choice points the interpreter faces on the run, in the
// order it notes them: at each step the branch a decision took, then the
// token stepped, each only where the interpreter has several to pick from.
Choices []runtime.ChoiceTaken
}
Witness is a run the solver found, decoded as the interpreter's own choices so a replay policy can follow it move for move.
type WitnessError ¶
WitnessError is a model the relation's variables do not read back as a run: a value missing or of the wrong shape, which is a fault of the encoding.
func (*WitnessError) Error ¶
func (e *WitnessError) Error() string