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ยง
- Coroutine
Saved ๐Locals - The set of
Locals that must be saved across yield points. - Liveness
Info ๐ - Storage
Conflict ๐Visitor - Suspend
Check ๐Data
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
CoroutineLayoutfor more. - locals_
live_ ๐across_ suspend_ points - Computes which locals have to be stored in the state-machine for the given coroutine.
- mir_
coroutine_ ๐witnesses