Expand description
Keeping the recursion of the JSON-LD algorithms off the caller’s native stack.
Context conversion, the Context Processing algorithm, Expansion and Compaction all recurse once per nesting level of their input. An embedder may run them on a thread whose stack it has already partly used, such as a Tokio worker deep inside a request handler, so the recursion depth alone cannot decide whether the thread’s stack suffices.
A synchronous recursion point runs its callee through
on_sufficient_stack. An async one wraps its callee in Recursion:
boxing a recursive call moves the callee’s state to the heap but not its
polling, because a parent polls its child from inside its own poll, so
the native stack still deepens by one set of poll frames per level. Either
way, when less than RED_ZONE of the current stack is left, the callee
runs on a freshly allocated segment of SEGMENT bytes instead. Whatever
bounds a recursion stays what bounds it; this only guarantees the bound is
reached on any thread.
Structs§
- Recursion
- A recursive call of an
asyncalgorithm.
Constants§
- RED_
ZONE - Stack left below which a recursion level moves to a fresh segment.
- SEGMENT
- Size of each fresh stack segment.
Functions§
- on_
sufficient_ stack - Runs
callee, on a fresh stack segment when the current one is nearly used.