Cairn · module

Cairn.Fuzz.Host

lean/Cairn/Fuzz/Host.lean

The host

cairn fuzz's stand-in for the host's side of the world (docs/fuzz.md, "The host"): it keeps what the frames asked of it and answers the way the real host is allowed to, as the trusted claims state it (docs/trusted.md):

  • Requests (^914 answered once; ^1009 a cancelled request is still answered once, usually failed): each request a frame carries is answered once, in any order, as late as it likes, with a reply of its kind's shape or a failure; a request cancelled after it was sent is answered too (failed other "cancelled", or its answer if the work finished first), which the runtime swallows.
  • Images (^1006, ^1011): a load puts its pixels before it is answered, and a source the host holds is answered from what it holds unless reload; a failed reload drops the source; while an imageCache subscription runs and the held pixels are over its budget, the host drops the image used least recently that the latest frame doesn't draw and isn't the one just put, and says so with evicted (which can cross a load's reply).
  • Time (^908, ^909): every batch starts with a clock; mono never goes back; a frame's wake brings a clock at or up to 40 ms after it, which fires the due timers.
  • The Dock badge and announcements (^1030, ^1031): the badge is the label of the last badge effect, or none; every announce is recorded once, with its text and priority.
  • Subscriptions (^915 and the device claims): events for active subscriptions, every's ticks at most one a period; and, rarely, an event from a subscription the runtime just stopped, which crossed the stop.

Beyond the contract, and rarely: a reply to an id the runtime doesn't hold (answered before, or never sent). The runtime drops it (step_reply_ignored); it is there to show nothing else reacts.

Everything is decided by the generator from the sequence's seed and recorded in the operation (HostOp), so a sequence replays without it.

Imports Cairn.Fuzz.Rng, Cairn.Runtime

Order

Structures 3

structure

Cairn.Fuzz.Held

lean/Cairn/Fuzz/Host.lean:71
Held : Type

An image the host holds.

Fields
source : String
w : Nat
h : Nat
Instances

BEq Repr Inhabited

structure

Cairn.Fuzz.HostStats

lean/Cairn/Fuzz/Host.lean:80
HostStats : Type

What the host did, over a sequence or a run.

Fields
requests : Nat

Requests and cancels the frames carried.

cancels : Nat
replies : Nat

Replies to requests still awaited by the runtime, of which failures.

failed : Nat
cancelledReplies : Nat

Replies to requests cancelled after they were sent (the runtime swallows them).

stray : Nat

Replies the app's runtime still delivers but the app stopped waiting for are counted by the app, not here. Replies to ids the runtime doesn't hold.

clocks : Nat
wakes : Nat
timersDue : Nat

Timers due at a clock the host sent (they fire, unless an earlier one cancels them).

subEvents : Nat
lateSubEvents : Nat
loads : Nat
evictions : Nat
maxOutstanding : Nat

The most requests the host held at once.

leftOver : Nat

Requests still unanswered when sequences ended.

served : Nat

With a server: requests it handled (retransmissions included), of which retransmissions; replies lost after it handled them; requests failed before reaching it; and times the world acted on its own.

retransmits : Nat
lostAfter : Nat
failedBefore : Nat
ticks : Nat
badges : Nat

badge and announce effects.

announcements : Nat
Instances

Inhabited Repr

structure

Cairn.Fuzz.Host

lean/Cairn/Fuzz/Host.lean:141
Host : Type
Fields
now : Time
sent : List (Nat × Request)

Requests on a frame, not yet answered: id and request, oldest first.

cancelled : List Nat

Of those, the ones a later frame cancelled.

ready : List (Nat × Reply)

Answers decided before they are sent: a load whose pixels are already put, or a request the server has handled (HostOp.serve).

answered : List Nat

Ids answered lately, for stray replies.

held : List Held

Images held, least recently used first.

lastPut : Option String

The source put last: never the next one dropped.

started : List Nat

Subscription ids whose record has started, and globalKeys whose key is down.

keysDown : List Nat
stopped : List (Nat × Sub)

Subscriptions the runtime stopped lately.

badge : Option String

The Dock badge: the label of the last badge effect, none before any (^1030).

announced : Array (String × Priority)

The announcements posted, oldest first, the last 64 (^1031).

stats : HostStats
Instances

Inhabited

Inductive types 1

inductive

Cairn.Fuzz.HostOp

lean/Cairn/Fuzz/Host.lean:39
HostOp : Type

What the host does in one step. Self-contained: replaying it needs no seed.

Constructors
advance (ms : Nat) (wallJump : Int) : HostOp

The clock moves on by ms (wall time by ms + wallJump).

wake (late : Nat) : HostOp

The clock reaches the frame's wake, late ms after it.

reply (id : Nat) (r : Reply) : HostOp

Answer request id, sent and not yet answered (cancelled or not).

load (id w h : Nat) : HostOp

A loadImage request's work finishes before its answer is sent: its pixels are put.

sub (s : Sub) (e : SubEvent) (dt : Nat) : HostOp

An event for the active subscription s, dt ms after the last batch.

late (id : Nat) (e : SubEvent) : HostOp

An event from a subscription the runtime has stopped (it crossed the stop).

evict (source : String) : HostOp

Drop source's pixels to keep within the image budget, and send evicted.

stray (id : Nat) (r : Reply) : HostOp

Beyond the contract: a reply to an id the runtime doesn't hold.

serve (id seed : Nat) : HostOp

With a server (Custom.server): request id reaches the server, which handles it with the generator seeded seed (Server.handle); the world changes, and its reply waits until the host sends it (reply) or loses it (lose). A second serve of the same request is a retransmission: the server handles it again.

lose (id : Nat) (r : Reply) : HostOp

Lost after: the server handled request id, but its reply is lost; the app hears r.

fail (id : Nat) (r : Reply) : HostOp

Failed before: request id never reached the server, so the world is as it was; the app hears r.

tick (seed : Nat) : HostOp

The server's world acts on its own (Server.tick, seeded seed).

Instances

Inhabited BEq Repr

Definitions 34

def

Cairn.Fuzz.Held.bytes

lean/Cairn/Fuzz/Host.lean:77
bytes (x : Held) : Nat
def

Cairn.Fuzz.HostStats.add

lean/Cairn/Fuzz/Host.lean:117
add (a b : HostStats) : HostStats
def

Cairn.Fuzz.Host.isSent

lean/Cairn/Fuzz/Host.lean:170
isSent (h : Host) (id : Nat) : Bool
def

Cairn.Fuzz.Host.isCancelled

lean/Cairn/Fuzz/Host.lean:171
isCancelled (h : Host) (id : Nat) : Bool
def

Cairn.Fuzz.Host.request?

lean/Cairn/Fuzz/Host.lean:172
request? (h : Host) (id : Nat) : Option Request
def

Cairn.Fuzz.Host.heldOf

lean/Cairn/Fuzz/Host.lean:173
heldOf (h : Host) (src : String) : Option Held
def

Cairn.Fuzz.Host.heldBytes

lean/Cairn/Fuzz/Host.lean:174
heldBytes (h : Host) : Nat
def

Cairn.Fuzz.Host.put

lean/Cairn/Fuzz/Host.lean:178
put (h : Host) (src : String) (w ht : Nat) : Host

Put src's pixels: it becomes the most recently used and the last put.

def

Cairn.Fuzz.Host.drop

lean/Cairn/Fuzz/Host.lean:181
drop (h : Host) (src : String) : Host
def

Cairn.Fuzz.Host.touch

lean/Cairn/Fuzz/Host.lean:186
touch (h : Host) (drawn : List String) : Host

A published frame draws these sources: they become the most recently used.

def

Cairn.Fuzz.Host.absorb

lean/Cairn/Fuzz/Host.lean:191
absorb (h : Host) (es : List Effect) : Host

Take in the effects a step put on the frame, in order.

def

Cairn.Fuzz.Host.answer

lean/Cairn/Fuzz/Host.lean:209
answer (h : Host) (id : Nat) : Host

id is answered: the host forgets it.

def

Cairn.Fuzz.Server.takes

lean/Cairn/Fuzz/Host.lean:217
takes {S : Type} (sv : Server S) (r : Request) : Bool

Whether request r goes to server sv: one it handles, never a loadImage, whose answer the host's images follow (^1006).

def

Cairn.Fuzz.drawnIn

lean/Cairn/Fuzz/Host.lean:224
drawnIn : Laid → List String

The image sources a laid tree draws (Style.image, set once an image is ready).

def

Cairn.Fuzz.drawnList

lean/Cairn/Fuzz/Host.lean:228
drawnList : List Laid → List String
def

Cairn.Fuzz.drawnBy

lean/Cairn/Fuzz/Host.lean:234
drawnBy {S : Type} (rt : Runtime.State S) : List String

Every source the latest frame draws: the window's and the shown panels'.

def

Cairn.Fuzz.imageCaches

lean/Cairn/Fuzz/Host.lean:240
imageCaches {S : Type} (rt : Runtime.State S) : List (Nat × Nat)

The active imageCache subscriptions: ids and budgets.

def

Cairn.Fuzz.evictable

lean/Cairn/Fuzz/Host.lean:248
evictable {S : Type} (h : Host) (rt : Runtime.State S) : Option String

The image the host would drop next: while an imageCache runs and the held pixels are over the smallest budget, the least recently used one the latest frame doesn't draw and that wasn't just put (^1011).

def

Cairn.Fuzz.notices

lean/Cairn/Fuzz/Host.lean:258
notices {S : Type} (rt : Runtime.State S) (src : String) : List Event

The evicted notices for src, one to each running imageCache.

def

Cairn.Fuzz.Gen.bytes

lean/Cairn/Fuzz/Host.lean:265
bytes (lo hi : Nat) : Gen ByteArray
def

Cairn.Fuzz.Gen.fault

lean/Cairn/Fuzz/Host.lean:271
fault : Gen Fault
def

Cairn.Fuzz.Gen.failure

lean/Cairn/Fuzz/Host.lean:273
failure : Gen Reply
def

Cairn.Fuzz.Gen.word

lean/Cairn/Fuzz/Host.lean:275
word : Gen String
def

Cairn.Fuzz.defaultReply

lean/Cairn/Fuzz/Host.lean:282
defaultReply (h : Host) (r : Request) : Gen Reply

A reply of r's kind with random contents: bytes, a status, a size, a flag, or a fault (one in six). An image the host holds is answered with its size unless reload (^1006).

def

Cairn.Fuzz.genReply

lean/Cairn/Fuzz/Host.lean:303
genReply {S : Type} (c : Custom S) (s : S) (h : Host) (id : Nat) (r : Request) :
  Gen Reply

The reply to id: the app's generator if it has one for this request (a reply of the wrong shape becomes a failure), else the default.

def

Cairn.Fuzz.genCancelled

lean/Cairn/Fuzz/Host.lean:312
genCancelled {S : Type} (c : Custom S) (s : S) (h : Host) (id : Nat)
  (r : Request) : Gen Reply

The answer to a request cancelled after it was sent (^1009): failed other "cancelled", or, if its work had already finished (or can't be stopped), its ordinary answer.

def

Cairn.Fuzz.genSubEvent

lean/Cairn/Fuzz/Host.lean:321
genSubEvent {S : Type} (c : Custom S) (s : S) (h : Host) (id : Nat) (sub : Sub) :
  Gen SubEvent

An event for an active subscription: the app's generator, else one of the kind's events in an order the host can send them (started once, before any audio; a key's up after its down).

def

Cairn.Fuzz.subDelay

lean/Cairn/Fuzz/Host.lean:345
subDelay (sub : Sub) : Gen Nat

The period before an event of sub: every ms ticks at most once a period (^915).

def

Cairn.Fuzz.genAdvance

lean/Cairn/Fuzz/Host.lean:351
genAdvance : Gen HostOp

How far the clock moves when the host has nothing else to say.

def

Cairn.Fuzz.Host.share

lean/Cairn/Fuzz/Host.lean:361
share {S : Type} (h : Host) (rt : Runtime.State S) : Nat

How often, in percent, the host moves rather than the person: one time in thirty when it has nothing to say beyond the clock, else from one in five up to three in five as requests pile up, so that they are answered about as fast as they are made.

def

Cairn.Fuzz.genHost

lean/Cairn/Fuzz/Host.lean:367
genHost {S : Type} (c : Custom S) (h : Host) (rt : Runtime.State S) : Gen HostOp

The host's next move, given the latest frame.

def

Cairn.Fuzz.replyText

lean/Cairn/Fuzz/Host.lean:441
replyText : Reply → String

The operation as a person reading the log would say it.

def

Cairn.Fuzz.subText

lean/Cairn/Fuzz/Host.lean:451
subText : Sub → String
def

Cairn.Fuzz.HostOp.text

lean/Cairn/Fuzz/Host.lean:458
text : HostOp → String

Instances 9

instance

Cairn.Fuzz.instInhabitedHostOp

lean/Cairn/Fuzz/Host.lean:68
instInhabitedHostOp : Inhabited HostOp
instance

Cairn.Fuzz.instBEqHostOp

lean/Cairn/Fuzz/Host.lean:68
instBEqHostOp : BEq HostOp
instance

Cairn.Fuzz.instReprHostOp

lean/Cairn/Fuzz/Host.lean:68
instReprHostOp : Repr HostOp
instance

Cairn.Fuzz.instBEqHeld

lean/Cairn/Fuzz/Host.lean:75
instBEqHeld : BEq Held
instance

Cairn.Fuzz.instReprHeld

lean/Cairn/Fuzz/Host.lean:75
instReprHeld : Repr Held
instance

Cairn.Fuzz.instInhabitedHeld

lean/Cairn/Fuzz/Host.lean:75
instInhabitedHeld : Inhabited Held
instance

Cairn.Fuzz.instInhabitedHostStats

lean/Cairn/Fuzz/Host.lean:115
instInhabitedHostStats : Inhabited HostStats
instance

Cairn.Fuzz.instReprHostStats

lean/Cairn/Fuzz/Host.lean:115
instReprHostStats : Repr HostStats
instance

Cairn.Fuzz.instInhabitedHost

lean/Cairn/Fuzz/Host.lean:166
instInhabitedHost : Inhabited Host