Fix asyncio related compiler/library issues by youknowone · Pull Request #6837 · RustPython/RustPython
📝 Walkthrough
Walkthrough
Refactors finally/unwind resolution to prefer outer handlers, updates context copy to accept a VM and deep-clone internal hamt state, extends socket getaddrinfo to accept bytes/text for host/port, adds SSL partial-write and ZeroReturn semantics, and makes generator/coroutine frame getters return Option.
Changes
| Cohort / File(s) | Summary |
|---|---|
Exception handling / codegen crates/codegen/src/compile.rs |
Rework unwind_fblock resolution to locate an outer fblock handler (indices 0..fblock_idx) and use its fb_stack_depth+1 and fb_preserve_lasti; avoid reusing inner FinallyTry handlers during unwinds. |
Context management crates/stdlib/src/contextvars.rs |
Change PyContext::copy to fn copy(&self, vm: &VirtualMachine) -> Self; deep-clone underlying hamt data and wrap via into_ref(vm.ctx). |
Socket / getaddrinfo crates/stdlib/src/socket.rs |
Add ArgStrOrBytesLike for host/port fields in GAIOptions; branch on Str vs Buf for host and port, perform IDNA or UTF-8 handling, and pass encoded port string when present. |
SSL API & compat crates/stdlib/src/ssl.rs, crates/stdlib/src/ssl/compat.rs |
Return SSLZeroReturnError on zero-return/EOF; implement partial-write semantics in ssl_write with bytes-tracking, BIO vs non-BIO differentiated errors (WantWrite vs Syscall), and adjust read close_notify handling. |
VM frame accessors crates/vm/src/builtins/asyncgenerator.rs, crates/vm/src/builtins/coroutine.rs, crates/vm/src/builtins/generator.rs |
Change ag_frame, cr_frame, and gi_frame to return Option<FrameRef> (None when closed, Some(frame) otherwise). |
posix sendfile (platform nuance) crates/vm/src/stdlib/posix.rs |
On macOS, if sendfile errored but some bytes were written, return the bytes written instead of raising; raise only when nothing was written. |
Sequence Diagram(s)
(omitted)
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~75 minutes
Possibly related PRs
- Fix asyncio compile #6739 — Changes exception-unwind handling in codegen with outer-handler resolution, directly related to compile.rs edits.
- flush on WantWrite #6717 — Alters ssl/compat.rs write/WantWrite behavior and partial-write handling, related to ssl/compat.rs changes here.
- Upgrade threading to 3.13.11; sys.setprofile & impl more threading #6691 — Updates VM frame accessors to return Option, related to the generator/coroutine/asyncgenerator changes.
Suggested reviewers
- ShaharNaveh
- fanninpm
- coolreader18
Poem
🐰 I hopped through handlers, outer-first and bright,
Cloned my contexts under VM's soft light,
Bytes and strings greeted the DNS hill,
TLS writes now nibble — not gulping their fill,
Frames tuck in softly, Optional at night.
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | ❓ Inconclusive | The PR title is too vague and generic. It mentions 'asyncio related' issues but the changeset addresses multiple unrelated systems: exception handling, context variables, socket/getaddrinfo, SSL, frame getters, and posix sendfile. | Revise the title to be more specific about the primary changes, such as 'Update frame getters to return Option and fix exception/SSL handling' or split into multiple focused PRs. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
- 📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.