Skip to content

Commit d8c6b28

Browse files
committed
restore deleted comments and fix simulation: prefix
1 parent 543cce4 commit d8c6b28

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

Veil/Core/Tools/ModelChecker/Simulation.lean

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ partial def scanOnce {ρ σ κ : Type} {th₀ : ρ}
9494
scanOnceLoop sys params th maxSteps initSt gen
9595

9696

97-
/-- Full trace loop: walk and record every step for counterexample.
97+
/-- Inner loop of a single random trace: walk from `currSt` for up to
98+
`stepsLeft` steps, picking a random enabled transition at each step.
9899
Returns `(violation?, updatedRng, stepsTaken)`. Used only for replay. -/
99100
@[inline, specialize]
100101
partial def simulateOnceLoop {ρ σ κ : Type} {th₀ : ρ}
@@ -111,6 +112,7 @@ partial def simulateOnceLoop {ρ σ κ : Type} {th₀ : ρ}
111112
| 0 => (none, gen, 0)
112113
| stepsLeft + 1 =>
113114
let outcomes := sys.tr th currSt
115+
-- Check assertion failures first (highest priority)
114116
let assertionFailures := outcomes.filterMap fun (_, outcome) =>
115117
match outcome with
116118
| .assertionFailure exId _ => some exId
@@ -129,6 +131,7 @@ partial def simulateOnceLoop {ρ σ κ : Type} {th₀ : ρ}
129131
let nexts := Concrete.extractSuccessfulTransitions outcomes
130132
if nexts.isEmpty then
131133
if !params.terminating.holdsOn th currSt then
134+
-- No enabled transitions and not a terminating state: deadlock
132135
(some (.foundViolation () .deadlock (some trace)), gen, trace.steps.size)
133136
else
134137
(none, gen, trace.steps.size)
@@ -144,7 +147,8 @@ partial def simulateOnceLoop {ρ σ κ : Type} {th₀ : ρ}
144147
simulateOnceLoop sys params th stepsLeft nextSt trace gen
145148

146149

147-
/-- Full trace run from random init state. Used only for replay. -/
150+
/-- Run a single random trace from a randomly chosen initial state.
151+
Returns `(violation?, updatedRng, stepsTaken)`. Used only for replay. -/
148152
@[inline, specialize]
149153
partial def simulateOnce {ρ σ κ : Type} {th₀ : ρ}
150154
(sys : EnumerableTransitionSystem ρ (List ρ) σ (List σ) Int κ (List (κ × ExecutionOutcome Int σ)) th₀)

Veil/Frontend/DSL/Module/Elaborators.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ private def getActionLabelNames (mod : Module) : CommandElabM (List String) := d
556556
let labelTypeName ← resolveGlobalConstNoOverload labelType
557557
return mod.actions.map (fun a => s!"{labelTypeName}.{a.name}") |>.toList
558558

559+
/-- Warn if the module contains transitions (which are slow to model check). -/
559560
private def warnAboutTransitions (mod : Module) : CommandElabM Unit := do
560561
let transitions := mod.procedures.filter (·.info.isTransition)
561562
if transitions.isEmpty then return
@@ -566,6 +567,7 @@ private def warnAboutTransitions (mod : Module) : CommandElabM Unit := do
566567
transition{if transitions.size > 1 then "s" else ""}: {names}\n\n\
567568
Consider encoding transitions as imperative actions where possible."
568569

570+
/-- Get the theory term, defaulting to `{}` if not provided and there are no theory fields. -/
569571
private def resolveTheoryTerm (cmdName : String) (theoryTermOpt : Option Term)
570572
(mod : Module) (instTerm : Term) : CommandElabM Term := do
571573
match theoryTermOpt with
@@ -584,6 +586,7 @@ private def mkIdentWithModName' (mod : Module) (name : Name) : Ident :=
584586

585587
/-- Build search parameters for model checking / simulation. -/
586588
private def buildSearchParameters (mod : Module) (config : ModelCheckerConfig) : CommandElabM Term := do
589+
-- Build SafetyProperty.mk syntax for a StateAssertion
587590
let mkProp (sa : StateAssertion) : CommandElabM Term :=
588591
`($(mkIdent ``Veil.ModelChecker.SafetyProperty.mk)
589592
($(mkIdent `name) := $(quote sa.name))

0 commit comments

Comments
 (0)