⚡ Remove frame size from promise types using back-pointer deallocation #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Previously, each promise had to store its frame size to enable manual deallocation. This required a complex handoff:
operator newm_frame_sizemember in constructorcontext.deallocate(m_frame_size)inself_destruct()This handoff mechanism forced every promise type to have a non-trivial destructor and carry an extra member variable.
Solution
Store a back-pointer before each coroutine frame pointing to the context's
m_stack_pointer. Nowoperator deletecan find and update the stack pointer directly, eliminating the need for promises to track their own size.Benefits
Removed from promises:
m_frame_sizemember variableself_destruct()methodSimplified context:
blocked_byinstead ofvariant<usize, blocked_by>Stack now uses
uintptr_t: Changed frombyte*touptr*for proper alignment of back-pointers.Added
context::resume(): Convenience method for manual event loops.Trade-off
Still allocates +1 word per frame (now for back-pointer instead of in promise), but memory layout is cleaner and promises are simpler.
Testing
Re-enabled all previously skipped tests - all passing.