Extend the tight-loop lane to while and do-while statements#2688
Merged
Conversation
for-loops with structurally-Normal bodies bypass per-iteration completion bookkeeping, suspension probes and per-statement ceremony via TightForBody; while and do-while loops with the same body shapes still paid all of it. Reuse JintForStatement''s body-shape predicate and run eligible while / do-while bodies through the same ExecuteDiscarded lane: test, discarded body statements and deferred-error polls per iteration, with amortized constraints driven through the shared countdown. Bodies with lexical declarations stay generic (while has no loop-env flattening machinery), as do observable-completion contexts, debug mode, exact constraints and suspendable frames. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…chmark The suite had for-loop accumulator coverage but nothing exercising the same tight-lane body shapes under while / do-while statements. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
for-loops with structurally-Normal bodies (expression statements, var/let/const, if/else chains — nothing that routes a break/continue/return/label) bypass per-iteration completion bookkeeping, suspension probes and per-statement ceremony viaJintForStatement.TightForBody.whileanddo-whileloops with the identical body shapes still paid all of it — aCompletionstruct and value-liveness check per iteration, two suspendable probes, and full_body.Executedispatch.This extends the same lane to
whileanddo-while: the sharedIsTightBodyShapepredicate decides eligibility, and eligible bodies run through the sameExecuteDiscardedpath — test, discarded body statements and a deferred-error poll per iteration, with amortized constraints (timeout/cancellation/memory) driven through the existing shared countdown. Bodies with lexical declarations stay on the generic path (while/do-while have no loop-env flattening machinery, so aletstill needs its per-iteration block environment), as do observable-completion contexts (eval/global completion values), debug mode, exact constraints and suspendable (generator/async) frames.Benchmarks (default jobs, adjacent A/B on latest main)
New
FunctionLocalNumberLoopBenchmarkrows (the while/do-while twins of the existing for-loop accumulators; committed alongside):Allocations unchanged (904 B both sides — the lane removes per-iteration
Completionstructs, which don't allocate).SunSpider rows with while loops (crypto-md5/sha1, string-unpack-code, bitops-nsieve-bits, string-tagcloud) are neutral — their hot loops are for-loops or top-level while loops whose completion values are observable, so they don't hit the new lane; this PR targets function-local while/do-while, which the suite otherwise didn't cover.
Semantics (12-case REPL verification, cold + cache-armed)
while/do-while sums, do-while runs body once when test false, break/continue/labeled-continue bodies stay generic and correct,
letin body forces the generic path with correct closures, observable completion values (eval) force generic path, empty body with side-effectful test, exceptions propagate from tight bodies with correct loop state.Gates
🤖 Generated with Claude Code