Built with doc-gen4, running Lean4. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑Ctrl+↓to navigate, Ctrl+🖱️to focus. On Mac, use Cmdinstead of Ctrl.
import Mt.Task
import Mt.Utils

namespace Mt

/-- A single thread of the system. It consists of a task to
  execute and a blocking predicate. The system only
  iterates a thread if the blocking predicate holds -/
structure 
Thread: SpecType 1
Thread
(
spec: Spec
spec
:
Spec: Type 1
Spec
) where
T: {spec : Spec} → Thread specType
T
:
Type: Type 1
Type
block_until: {spec : Spec} → Thread specspec.StateBool
block_until
:
spec: Spec
spec
.
State: SpecType
State
->
Bool: Type
Bool
task: {spec : Spec} → (self : Thread spec) → TaskM spec self.T
task
:
TaskM: SpecTypeType
TaskM
spec: Spec
spec
T: Type
T
variable {
spec: Spec
spec
:
Spec: Type 1
Spec
} local
instance: {spec : Spec} → IsReservation spec.Reservation
instance
:
IsReservation: TypeType
IsReservation
spec: Spec
spec
.
Reservation: SpecType
Reservation
:=
spec: Spec
spec
.
is_reservation: (self : Spec) → IsReservation self.Reservation
is_reservation
def
mk_thread: {T : Type} → TaskM spec TThread spec
mk_thread
{
T: Type
T
:
Type: Type 1
Type
} (
task: TaskM spec T
task
:
TaskM: SpecTypeType
TaskM
spec: Spec
spec
T: Type
T
) :
Thread: SpecType 1
Thread
spec: Spec
spec
:= {
T: Type
T
block_until :=λ
_: ?m.550
_
=>
true: Bool
true
task: TaskM spec T
task
} namespace Thread inductive
IterationResult: SpecType 1
IterationResult
(
spec: Spec
spec
:
Spec: Type 1
Spec
) where |
Done: {spec : Spec} → spec.StateIterationResult spec
Done
:
spec: Spec
spec
.
State: SpecType
State
->
IterationResult: SpecSort ?u.603
IterationResult
spec: Spec
spec
|
Panic: {spec : Spec} → spec.StateIterationResult spec
Panic
:
spec: Spec
spec
.
State: SpecType
State
->
IterationResult: SpecSort ?u.603
IterationResult
spec: Spec
spec
|
Running: {spec : Spec} → spec.StateThread specIterationResult spec
Running
:
spec: Spec
spec
.
State: SpecType
State
->
Thread: SpecType 1
Thread
spec: Spec
spec
->
IterationResult: SpecSort ?u.603
IterationResult
spec: Spec
spec
def
IterationResult.state: {spec : Spec} → IterationResult specspec.State
IterationResult.state
:
IterationResult: SpecType 1
IterationResult
spec: Spec
spec
->
spec: Spec
spec
.
State: SpecType
State
|
Done: {spec : Spec} → spec.StateIterationResult spec
Done
state: spec.State
state
=>
state: spec.State
state
|
Panic: {spec : Spec} → spec.StateIterationResult spec
Panic
state: spec.State
state
=>
state: spec.State
state
|
Running: {spec : Spec} → spec.StateThread specIterationResult spec
Running
state: spec.State
state
_ =>
state: spec.State
state
def
iterate: {spec : Spec} → Thread specspec.StateIterationResult spec
iterate
:
Thread: SpecType 1
Thread
spec: Spec
spec
->
spec: Spec
spec
.
State: SpecType
State
->
IterationResult: SpecType 1
IterationResult
spec: Spec
spec
| ⟨
T: Type
T
, _,
task: TaskM spec T
task
⟩,
state: spec.State
state
=> match
task: TaskM spec T
task
.
iterate: {spec : Spec} → {T : Type} → TaskM spec Tspec.StateTaskM.IterationResult spec T
iterate
state: spec.State
state
with |
TaskM.IterationResult.Done: {spec : Spec} → {T : Type} → spec.StateTTaskM.IterationResult spec T
TaskM.IterationResult.Done
state': spec.State
state'
_ =>
IterationResult.Done: {spec : Spec} → spec.StateIterationResult spec
IterationResult.Done
state': spec.State
state'
|
TaskM.IterationResult.Panic: {spec : Spec} → {T : Type} → spec.StateStringTaskM.IterationResult spec T
TaskM.IterationResult.Panic
state': spec.State
state'
_ =>
IterationResult.Panic: {spec : Spec} → spec.StateIterationResult spec
IterationResult.Panic
state': spec.State
state'
|
TaskM.IterationResult.Running: {spec : Spec} → {T : Type} → spec.State(spec.StateBool) → TaskM spec TTaskM.IterationResult spec T
TaskM.IterationResult.Running
state': spec.State
state'
block_until: spec.StateBool
block_until
task: TaskM spec T
task
=>
IterationResult.Running: {spec : Spec} → spec.StateThread specIterationResult spec
IterationResult.Running
state': spec.State
state'
{
T: Type
T
,
block_until: spec.StateBool
block_until
,
task: TaskM spec T
task
} /-- Small wrapper around `TaskM.valid`. A thread is considered valid if its underlying task is valid and ensures that it drops its reservation in the end. To prove `Thread.valid`, you should unfold `Thread.valid`, for example using `rw [Thread.valid]` and continue applying the validation theoreoms for `TaskM.valid`, like `TaskM.valid_bind` -/ def
valid: Thread specProp
valid
(
thread: Thread spec
thread
:
Thread: SpecType 1
Thread
spec: Spec
spec
) :
Prop: Type
Prop
:=
thread: Thread spec
thread
.
task: {spec : Spec} → (self : Thread spec) → TaskM spec self.T
task
.
valid: {spec : Spec} → {T : Type} → TaskM spec Tspec.Reservation(spec.StateBool) → (Tspec.ReservationProp) → Prop
valid
IsReservation.empty: {T : Type} → [self : IsReservation T] → T
IsReservation.empty
thread: Thread spec
thread
.
block_until: {spec : Spec} → Thread specspec.StateBool
block_until
_: ?m.2233
_
r: ?m.2236
r
=>
r: ?m.2236
r
=
IsReservation.empty: {T : Type} → [self : IsReservation T] → T
IsReservation.empty
) end Thread end Mt