fix(transform): #5925 — keep comma-sequence operands ahead of hoisted awaits#5926
Merged
Conversation
… awaits The plain-async pre-pass hoists every nested await into a `let __await_N = await <operand>;` above the containing statement. For a comma sequence that moved the awaited operand's evaluation above the sequence's earlier operands: `this.l = new L, this.p = await this.l.start()` evaluated `this.l.start()` while `this.l` still held its pre-assignment value (null) — a TypeError under perry where node prints the result. Minifiers comma-fold consecutive statements, so any `const x = new X(); const y = await x.m();` pair in bundled async code hits this. Conditional branches (#342) and logical RHS (#5434) already have dedicated lifts for exactly this class of unsound hoist; Sequence had none. Fix: `lift_sequence_with_await` — when a sequence contains an await, lift the non-final operands to statements (each recursively hoisted, preserving evaluation order) and continue with the final operand as the expression value. Wired into both `hoist_awaits_in_expr_full` (nested sequences) and `hoist_awaits_avoiding_top_level` (statement-position sequences, re-processed so a final-operand await stays directly handled). The generator yield hoist (generator/hoist_yields.rs) has the same latent gap for yield-in-sequence; left as a follow-up per #5925. Fixes #5925. Claude-Session: https://claude.ai/code/session_01K1w6WLaFNKhf4aNxeSWHy6
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe async-to-generator pre-pass now special-cases ChangesSequence-aware await hoisting fix
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Source as "Source Sequence Expr"
participant Hoister as "hoist_awaits_avoiding_top_level"
participant Lifter as "lift_sequence_with_await"
participant Stmts as "Lifted Statements"
Source->>Hoister: sequence expr containing await
Hoister->>Lifter: detect await in sequence, delegate lifting
Lifter->>Stmts: push non-final operands as statements (hoisted in order)
Lifter->>Hoister: return final operand in place
Hoister->>Hoister: hoist await from final operand as __await_N
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
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.
Problem — #5925
The plain-async pre-pass hoists every nested
Expr::Awaitinto alet __await_N = await <operand>;above the containing statement. For a comma sequence, that moves the awaited operand's evaluation above the sequence's earlier operands:hoists to (pre-fix):
GOT 42ERR TypeError: Cannot read properties of null (reading 'start')Minifiers comma-fold consecutive statements, so any
const x = new X(); const y = await x.m();pair in bundled async code hits this — observed in a real-world 13 MB bundle where it broke an auth flow's listener startup. Conditional branches (#342) and logical RHS (#5434) already have dedicated lifts for this class of unsound hoist;Expr::Sequencehad none. Reproduces on currentorigin/main(v0.5.1219).Fix
lift_sequence_with_await: when a sequence contains an await, lift the non-final operands to statements pushed ontohoisted(each recursively hoisted first, so awaits inside earlier operands suspend in evaluation order), leaving the final operand as the expression value. The__await_Nlet the caller hoists for the final operand then lands AFTER the lifted operands. Wired into:hoist_awaits_in_expr_full(nested sequences), andhoist_awaits_avoiding_top_level(statement-position sequences — re-processed after the lift so a final-operand await stays in the linearizer's directly-handled position).The generator yield hoist (
generator/hoist_yields.rs) has the same latent gap foryield-in-sequence; noted in #5925 as a follow-up rather than piggybacking untested changes here.Validation
GOT 42); fails on stock main.crates/perry/tests/issue_5925_seq_await_order.rs:GOT 42);ORDER after-sink,first,second). Both pass locally withcargo test --release -p perry --test issue_5925_seq_await_order(2 passed).Fixes #5925.
https://claude.ai/code/session_01K1w6WLaFNKhf4aNxeSWHy6
Summary by CodeRabbit
Bug Fixes
awaithandling in comma-separated expressions so evaluation order is preserved correctly in more cases.await.Tests
awaitordering in assignment,letinitialization, and return scenarios.