Repository navigation
fix(runtime): preserve control flow in statement-position expressions - #605
Open
summer-boythink wants to merge 1 commit into
Open
summer-boythink wants to merge 1 commit into
summer-boythink wants to merge 1 commit into
Conversation
summer-boythink
force-pushed
the
fix/statement-position-control-flow
branch
4 times, most recently
from
November 11, 2026 06:54
850ae66 to
f16c583
Compare
Conditional and block expressions were lowered to JavaScript IIFEs even when their value was discarded. The IIFE created a function boundary, so return exited the IIFE instead of the enclosing handler and break or continue became illegal. Lower non-trailing if and block expressions directly in statement position and discard their JavaScript value instead of returning it. The Rust token stream keeps the block value, so branch type checking still matches the source expression. Expression-position lowering is unchanged. This also removes the return/break/continue known mismatches from the coherence suite. Closes tokio-rs#603
summer-boythink
force-pushed
the
fix/statement-position-control-flow
branch
from
November 11, 2026 06:59
f16c583 to
82be57e
Compare
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.
Summary
Fixes #603.
Conditional and block expressions were lowered to JavaScript IIFEs even when their value was discarded. The IIFE created a function boundary, so
returnexited the IIFE instead of the enclosing event handler, andbreakorcontinuebecame illegal.This change lowers non-trailing
ifand block expressions directly in statement position and discards their JavaScript value instead of turning it into areturnstatement. Discarded values are evaluated as statements rather than awaited, so lazy runtime futures are not started, matching Rust's drop behavior. The Rust token stream still keeps the block value, so branch type checking and inference match the source expression. Expression-position lowering is unchanged.The production change is limited to the expression grammar:
stmt.rsseparates the Rust block value from the JavaScript value usage, andblock.rs/expr_if.rsgain an explicit JavaScript value-usage choice.The coherence suite previously recorded
return_inside_if,break_inside_if, andcontinue_inside_ifas known mismatches. They now agree in Rust and JavaScript, so their baselines and known-mismatch tests are removed and replaced with regular control-flow coverage. The new tests also check that statement values are discarded, including async branches and an unpolled future.Testing
cargo test -p topcoat-runtime-coherencecargo test -p topcoat-runtime-macrocargo test -p topcoat-runtime-grammarcargo test -p topcoat-view-macrocargo test -p topcoat-runtimeifbranches with incompatible types still produce a Rust type errorcargo clippy -p topcoat-runtime-grammar -p topcoat-runtime-macro --all-targets --all-features --locked -- -D warningscargo clippy -p topcoat-runtime-coherence --tests --all-features --locked -- -D warningscargo +nightly fmt --all -- --checkcargo topcoat fmt --check(only the pre-existing Leptos benchmark errors)RUSTDOCFLAGS="--cfg docsrs -Dwarnings" cargo +nightly doc -p topcoat-runtime-grammar --all-features --no-deps --lockedAI disclaimer
This PR was prepared with the assistance of DeepSeek V4.1 Flash 1017. The model inspected the runtime expression codegen, implemented the statement-position lowering and value-discard handling, updated the known-mismatch baselines and tests, and ran the checks above. A human should review the diff before merging.