make iteration suspendable

Merged
DA
12d ago
+1796-570

Attempting to make it possible to suspend in the middle of a for loop, and experiments with making map and friends suspendable iterators too.


Summary by cubic

Makes iteration suspension-capable: for loops, comprehensions, and lazy map/filter advancement now pause at host calls and resume, instead of raising NotImplementedError when a user __next__ or callback suspends. map and filter are now lazy iterators (previously eager, returning a list), backed by a new MapFilter heap type that advances one item per suspension point, including unread files and user classes. A new continuation and compile_iteration_catcher frame handle suspended advancement while letting exceptions land in the outer try. Nested lazy advancement shares a bounded native dispatch stack, so deep callback chains raise RecursionError rather than overflowing the host stack.

Migration

  • Dump format bumps to version 17; restored code no longer pins map/filter to the old eager behavior, so previously compiled functions return lazy iterators after restore.
  • Synchronous consumers (list(), sorted, itertools adaptors) still cannot suspend: they raise a catchable NotImplementedError inside the callback.