Repository navigation
fix(wasm): a tagged template passes its strings array to the tag (#14727) - #14730
Conversation
|
Caution Review failedThe pull request is closed. No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
30a87d1 to
b3269c6
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
…ryTS#14727) On the web target ``T.tag`x` `` returned undefined, and on main it threw a TypeError. The emitter had no arm for `TaggedTemplateStrings` or `TemplateRaw`, so every tag received `undefined` for its strings array, and a call through `PropertyGet(ClassRef, m)`, the shape a tagged template on a class lowers to, read the method off an undefined class value. - `TaggedTemplateStrings` builds the cooked and raw arrays and asks a new `tagged_template` bridge for the call site's template object: frozen, with a frozen non-enumerable `raw`, and the same object on every evaluation of that site. - `TemplateRaw` reads `raw` through a new `template_raw` bridge. - `C.m(args)` with `m` a static method of `C` emits as `StaticMethodCall`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
b3269c6 to
a2d6e56
Compare
Summary
On
--target weba tagged template passedundefinedto its tag in place of the strings array, and a tag that is a static method was not called at all:class T { static tag(s: any) { return "tagged"; } } console.log(T.tag`x`)threwTypeError: Cannot read properties of undefined (reading 'tag')onmain(Node:tagged). This is part 2 of #14727.Cause
HIR lowers
tag`a${x}b`toCall { callee: <tag>, args: [TaggedTemplateStrings { site_id, cooked, raw }, x] }, and<strings>.rawon a typed receiver toTemplateRaw. The wasm emitter had no arm for either, so both fell through to the catch-allundefined. ForT.tag`x`the callee isPropertyGet(ClassRef(T), "tag"); the emitter readtagoff the class value, which isundefinedon web, while the ordinary callT.tag(...)lowers toStaticMethodCalland works.Changes
emit/expr/arrays.rs:TaggedTemplateStringsbuilds the cooked and raw arrays and calls a newtagged_templatebridge with the site id.TemplateRawcalls a newtemplate_rawbridge.wasm_runtime.js:tagged_templatekeeps one template object per call site (GetTemplateObject). The first evaluation freezes the cooked array with a frozen, non-enumerableraw; every later evaluation of that site returns the same object. A different site with the same text gets a different object.template_rawreadsraw.emit/expr/calls.rs:Call { callee: PropertyGet(ClassRef(C), m) }withma static method ofCemits asStaticMethodCall.emit/string_collection.rs: interns the raw strings and the two bridge names.emit/tests.rs:a_tagged_template_passes_its_strings_array_to_any_tagcovers a static-method tag with substitutions, an instance-method tag, a function tag readings.raw(typed, viaTemplateRaw) ands.rawon ananyreceiver, escape handling (a\nbcooked vs raw), and identity (site() === site(), a different site is a different object,Array.isArray,length).Native Perry already prints what Node prints for all of these; web now matches for these shapes. Some tagged-template programs still differ on web because of separate web gaps that a plain call shows too, e.g.
thisinside an object-literal or static method, rest parameters, andObject.isFrozen. A class held in a variable (const C = T; C.tagx``) needs class values on web (#14665).Related issue
Refs #14727 (part 2 of 3; the issue stays open for part 3, per-evaluation class state).
Test plan
Web parity A/B against a pristine build of
mainat 64257c3 (this build carried both #14727 fixes, this one and the assignment-default one):No case passes on main and fails on the branch. The one newly passing case,
language/function/test_gap_function_decl_rebound_nested, comes from the assignment-default fix. The two extraarraypasses were timeouts (exit 124) in the main run under load and pass on main when re-run alone. No other case changed status, so this change turns none of these cases green; the unit test above is the acceptance coverage.run_wasm_tests.sh: the same three failures on main and the branch (04_functions,10_higher_order,19_ffi_imports).run_lint_gates.sh: the same 22 FAIL lines on main and the branch (all pre-existing on this macOS host; none names a touched file).Checklist
feat:/fix:/docs:/chore:prefix convention used in the log🤖 Generated with Claude Code
https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
Summary by CodeRabbit
rawproperty.