Repository navigation
fix(transform): scan PutValueSet closures when seeding generator func/local ids - #4366
Merged
Merged
Conversation
…/local ids
A module containing any generator (`function*`) mis-compiled every
function expression assigned to a member via strict PutValue
(`obj.f = function(){...}`) into the generator's synthesized iterator:
calling `obj.f(...)` returned `{value: undefined, done: true}` instead of
invoking the function.
Root cause: the generator state-machine transform seeds its synthesized
`next`/`return`/`throw` closure ids from `compute_max_func_id(module) + 1`,
but `scan_expr_for_max_func` (and its local-id sibling) had no `PutValueSet`
arm — the assigned Closure was invisible to the scan, so `max_id` stayed
below it and the synthesized closures reused its func_id. At codegen one
LLVM function per func_id wins, so `obj.f` dispatched into the generator's
`next`. Adds `PutValueSet` arms to both scanners (mirrors the existing
PropertySet / ArrayPush / NativeMethodCall collision fixes).
test262: built-ins/GeneratorPrototype 50->24, AsyncGeneratorPrototype
36->26 (-36 across generator categories, no regressions). Verified
Node-identical in both PERRY_NO_AUTO_OPTIMIZE and default builds; async
functions and non-generator modules unaffected.
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
A module containing any generator (
function*) mis-compiled every function expression assigned to a member via strict PutValue —obj.f = function(){...}— into the generator's synthesized iterator. Callingobj.f(...)returned{value: undefined, done: true}instead of invoking the function.This is a single-root-cause codegen bug with broad blast radius: it breaks the common
proto.method = function(){...}pattern (including the test262assert.jsharness'sassert._isSameValue), which is why it surfaced as ~36 "generator semantics" failures that were actually function-dispatch failures.Root cause
The generator state-machine transform seeds its synthesized
next/return/throwclosure ids fromcompute_max_func_id(module) + 1. Butscan_expr_for_max_func(and its local-id siblingscan_expr_for_max_local) had noPutValueSetarm —obj.f = function(){}lowers toExpr::PutValueSet { value: Closure{...}, .. }, so the assigned Closure's func_id was invisible to the scan. With no other functions presentmax_idstayed0, so the synthesized closures got func_id1— colliding with the user closure's func_id1. At codegen there's one LLVM function per func_id, soobj.f(1,2)dispatched into the generator'snextbody.Fix
Add a
PutValueSetarm to bothscan_expr_for_max_funcandscan_expr_for_max_localingenerator/id_scan.rs, descending intotarget/key/value/receiver. This mirrors the existing collision fixes forPropertySet/ArrayPush/NativeMethodCall/ array fast-paths (#393/#531/#154/#1824).Results
test262, uncapped via
scripts/parity_gap_report.py:−36 across generator categories, no regressions.
Verified Node-identical in both
PERRY_NO_AUTO_OPTIMIZE=1and default builds:Async functions + member-assigned closures and non-generator modules are unaffected (their dispatch was already correct / the transform only consumes this count when synthesizing generator closures).
cargo test -p perry-transform29/29,-p perry-runtime977/977.The remaining generator failures are separate, deeper semantics gaps (try/finally resumption sequencing,
.return/.throwstate transitions, methodlength/namedescriptors).