Skip to content

lowering: native ladders reach async return! matches - #161

Merged
simontreanor merged 1 commit into
mainfrom
lowering/native-async-return
Sep 28, 2026
Merged

simontreanor merged 1 commit into
mainfrom
lowering/native-async-return

Conversation

@simontreanor

Copy link
Copy Markdown
Owner

Follow-up to the native series. return! (match …) in an async { } block lowers through lower_async_bang_return, which builds its own match (one return await per arm, so a self tail call stays visible for #119's loop rewrite). Native mode never reached it, so every such match stayed a match.

  • try_lower_native_match takes a body mode (NativeArmBody::{Return, Assign, AwaitReturn}) instead of Option<&str>; lower_async_bang_return tries it first with AwaitReturn.
  • In that mode native also takes Option/Result shapes, since the async path never tries their ladder.
  • The cookbook agent (structured_concurrency) still gets its while True loop natively, with no recursive await left.

Real-program check (local only; the private dogfood game isn't touched or published): I copied the 11-module Scrabble game to a temp dir, applied the 4-line Task migration from #147, and compiled it both ways. The native build now has 0 match statements (the default has 63; 15 remained before this PR), and all 5 recorded replays (up to 2,343 lines of output) print identically.

Test: native_ladders_reach_async_return_bang_matches. DESIGN §5.6 updated.

return! (match ...) in an async block lowers through lower_async_bang_return,
which built its own match and so kept every one of them in native output. It
now tries the native ladder first (arm bodies returned awaited), Option and
Result shapes included since that path never tries their ladder. The self
tail call loop rewrite still fires on the cookbook agent. On a real 11-module
program the native output now has no match statement at all, and its recorded
game replays print the same in both modes.
@simontreanor
simontreanor merged commit e2bfedd into main Sep 28, 2026
20 checks passed
@simontreanor
simontreanor deleted the lowering/native-async-return branch September 28, 2026 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant