fix(wasm): module-level member writes persist on the web target (#5016)#5022
Merged
Conversation
c220502 to
ba7dae8
Compare
Contributor
Author
CI statusThis branch is rebased on latest
Green: lint, api-docs-drift, security-audit, harmonyos-smoke. Still red — pre-existing
Both reproduce on a clean |
…n the web target (#5016) The HIR lowers both `obj.prop = v` and `obj[i] = v` to a single Expr::PutValueSet node. The perry-codegen-wasm backend had no arm for it, so every member write fell through emit_expr's `_ => TAG_UNDEFINED` catch-all and was silently dropped — module-level array/object mutation appeared immutable on the web target (reads returned the initializer). Native always worked. Regression of #1993. Handle PutValueSet in the WASM backend, mirroring the pre-PutValueSet lowering split: string-literal key -> class_set_field (preserves class getters/setters), any other key -> object_set_dynamic; both return the assigned RHS value. Companion walkers updated in tandem: string_collection (intern key/value strings), closures (collect closures in operands), js_fallback (emit JS assignment). WASM suite: 17->21 passing, 0 regressions (the 4 newly-green tests were broken by the same bug). Adds tests/wasm/26_module_array_element_write.ts.
68e3b6f to
476f8e4
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 #5016. On the web/wasm target, a write to a module-level array element or object property (
A[0] = ...,o.prop = ...) was silently dropped — subsequent reads returned the initializer. Native always worked. This broke the documented module-scope mutable-state pattern (const S = [...]; mutateS[i]) that Perry's own pitfalls guidance recommends, so games/UIs built for web never updated state (discovered shipping Bloom Jump to web). Regression of #1993.Root cause
The HIR lowers both member-write forms —
obj.prop = vandobj[i] = v— to a singleExpr::PutValueSetnode. The WASM backend (perry-codegen-wasm) never had a match arm for it, so every such assignment fell throughemit_expr's_ => TAG_UNDEFINEDcatch-all and the store was never emitted. The still-presentIndexSet/PropertySetarms had become dead code once lowering switched toPutValueSet— which is why the earlier #1993 fix appeared to regress.Fix
Handle
PutValueSetin the WASM backend, mirroring the pre-PutValueSetlowering split so behavior matches the existing arms:obj.prop = v) →class_set_field(so class getters/setters still fire)obj[i] = v) →object_set_dynamicCompanion expression walkers updated in tandem so the node is fully supported:
string_collection.rs(intern key string + value literals),closures.rs(collect closures used as value/key/target),js_fallback.rs(emit equivalent JS assignment).Verification
05_objects_arrays,07_classes,08_getters_setters,21_class_method_i64) were all broken by this same dropped-write bug. The 6 remaining failures are pre-existing and unrelated (higher-order array methods, map/set, regex/date, splice, ffi imports).tests/wasm/26_module_array_element_write.tsregression guard.🤖 Generated with Claude Code