Skip to main content

Module layout

Module layout 

Source
Expand description

Coroutine StateTransform inverts control flow in a coroutine from a function with yield points to a state machine. Each yield point corresponds to a state variant, and each variant stores the locals that are needed to continue the coroutine.

The state transform creates a poll method such that calling the coroutine f() is equivalent to:

โ“˜
fn initial_mir(state: CoroutineState, mut resume_arg: ResumeTy) {
    // Repeatedly poll the state machine.
    loop {
        match final_mir(&mut state, resume_arg) {
            CoroutineState::Yielded(yield_value) => resume_arg = yield yield_value,
            CoroutineState::Complete(return_value) => return return_value,
        }
    }
}

This file compute for each yield point the set of locals that need to be saved in the coroutine state. This is also used for borrowck to compute the set of types held inside that state, which determine trait and region predicates that hold for this state.

Structsยง

CoroutineSavedLocals ๐Ÿ”’
The set of Locals that must be saved across yield points.
LivenessInfo ๐Ÿ”’
StorageConflictVisitor ๐Ÿ”’
SuspendCheckData ๐Ÿ”’

Constantsยง

SELF_ARG ๐Ÿ”’

Functionsยง

check_field_tys_sized ๐Ÿ”’
check_must_not_suspend_def ๐Ÿ”’
check_must_not_suspend_ty ๐Ÿ”’
check_suspend_tys ๐Ÿ”’
compute_layout ๐Ÿ”’
compute_storage_conflicts ๐Ÿ”’
For every saved local, looks for which locals are StorageLive at the same time. Generates a bitset for every local of all the other locals that may be StorageLive simultaneously with that local. This is used in the layout computation; see CoroutineLayout for more.
locals_live_across_suspend_points ๐Ÿ”’
Computes which locals have to be stored in the state-machine for the given coroutine.
mir_coroutine_witnesses ๐Ÿ”’