DriftScript
Documentation

Guide

Hot reload

The four categories of change, and who decides what a restart means.

Hot reload is part of the runtime architecture rather than an addition to it. A runtime that gained it later would be one whose module identity was designed without it, and callers would hold direct references to generated functions.

The code is replaced and the state is not

A caller holds a module and reaches its functions through that module, so replacing one is a single assignment into a record every caller already reads through. Edit the body below and the tick count carries on from where it is.

// A value the page keeps, and a function the page replaces while it keeps it.
//
// `ticks` counts how many times `advance` has run since the page loaded. Edit the body below and
// the count carries on from where it was: the code is replaced, the state it was working on is
// not. That is what hot reload means here, and it is the reason records have no methods.

data Pulse {
    ticks: u32 = 0
    value: f32 = 0
}

fn advance(pulse: mut Pulse, dt: f32) {
    pulse.ticks = pulse.ticks +| 1
    pulse.value = pulse.value + dt
}

Four categories

A body change is patched and the state kept. A new field with a default is migrated and live instances updated in place. A renamed field or a changed type needs a declared migration or a stated reset policy. An ABI change is handed back to the consumer, in words.

A suspended task is state too

A task that is waiting keeps its locals and its resume point on a frame the scheduler owns, and the compiler lays out both. A patch across a live one is planned before anything is written: edit the body or a wait duration and the task keeps the time it has already waited, add or drop a local and the frame is migrated, change the type of a live local or move an await and the whole patch is declined naming the task. Nothing is half applied.

The consumer decides what a restart means

The runtime says what happened and why; it does not decide what a scene restart is for every application. The reason it gives is a sentence rather than a code, because the consumer is going to put it in front of a developer.