Repository navigation
Async generators and async comprehensions in dynamic builds - #231
Merged
Merged
Conversation
async def, await, async for and async with build in the dynamic build. A coroutine awaited by another runs in place on the awaiting task's stack; each task's coroutine runs on its own stack (rt_gen.rs Coro, which gains throw()). asyncio is Brevi's own: CPython 3.13's asyncio ported to src/dynpy/py/asyncio.py and cut down to callbacks and timers, so tasks interleave in CPython's order. Programs using more of asyncio, or async code with a library CPython runs, are refused at build time. Also fixes time.sleep (it did not sleep in dynamic builds) and time.monotonic/perf_counter/process_time (they read the wall clock), and adds a lookup cache to classes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0136hkZhPtdW14Wtm51vEuNk
…e their group Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0136hkZhPtdW14Wtm51vEuNk
…s read Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0136hkZhPtdW14Wtm51vEuNk
… guard-unread tests use a metaclass Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0136hkZhPtdW14Wtm51vEuNk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0136hkZhPtdW14Wtm51vEuNk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Requested by Adam · project thread
What this changes
Follow-up to #230.
async defwithyield) now build natively. This coversasync for,anext,asend,athrow,aclose,ag_running, and CPython's errors: already running, reuse of an awaitedasend, ignoredGeneratorExit, andStopAsyncIterationraised inside the generator. The body runs on its own stack. Ayieldhands back a value. A pending future deep inside the body is passed up to the task.breakout ofasync for, is closed by the loop in a task at the same point CPython closes it, so itsfinallyprints in the same place.asyncio.runcloses the generators still open when it ends (shutdown_asyncgens). Without a loop, the generator is closed when it is dropped.async forclauses andawaitinside them. They run in place, as CPython 3.12+ runs them.yield frominside anasync defandreturn valueinside an async generator are refused too; CPython rejects both as syntax errors.How it was tested
sh tools/ci_local.shpasses, using CI's rustc 1.99.1: 2003 baseline solutions, 0 regressionstests/covers the change:tests/lib/asyncio_agen_{basics,flow,errors,close}try/finallyand are consumed several ways: fullasync for,breakpart way, async comprehensions, partly consumed then dropped, andasend/aclose. It generated 240 random programs. Each was run under both CPython and Brevi, and the outputs were compared.async forplus an async comprehension takes 0.106 s in Brevi and 0.122 s in CPython.Generated by Claude Code