Skip to content

fix(wasm): a tagged template passes its strings array to the tag (#14727) - #14730

Merged
TheHypnoo merged 2 commits into
PerryTS:mainfrom
raliclo:fix/14727-tagged-template-web
Nov 16, 2026
Merged

TheHypnoo merged 2 commits into
PerryTS:mainfrom
raliclo:fix/14727-tagged-template-web

Conversation

@raliclo

@raliclo raliclo commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On --target web a tagged template passed undefined to 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`) threw TypeError: Cannot read properties of undefined (reading 'tag') on main (Node: tagged). This is part 2 of #14727.

Cause

HIR lowers tag`a${x}b` to Call { callee: <tag>, args: [TaggedTemplateStrings { site_id, cooked, raw }, x] }, and <strings>.raw on a typed receiver to TemplateRaw. The wasm emitter had no arm for either, so both fell through to the catch-all undefined. For T.tag`x` the callee is PropertyGet(ClassRef(T), "tag"); the emitter read tag off the class value, which is undefined on web, while the ordinary call T.tag(...) lowers to StaticMethodCall and works.

Changes

  • emit/expr/arrays.rs: TaggedTemplateStrings builds the cooked and raw arrays and calls a new tagged_template bridge with the site id. TemplateRaw calls a new template_raw bridge.
  • wasm_runtime.js: tagged_template keeps one template object per call site (GetTemplateObject). The first evaluation freezes the cooked array with a frozen, non-enumerable raw; every later evaluation of that site returns the same object. A different site with the same text gets a different object. template_raw reads raw.
  • emit/expr/calls.rs: Call { callee: PropertyGet(ClassRef(C), m) } with m a static method of C emits as StaticMethodCall.
  • 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_tag covers a static-method tag with substitutions, an instance-method tag, a function tag reading s.raw (typed, via TemplateRaw) and s.raw on an any receiver, escape handling (a\nb cooked 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. this inside an object-literal or static method, rest parameters, and Object.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

cargo test -q -p perry-codegen-wasm --lib a_tagged_template_passes_its_strings_array_to_any_tag
#   with the emitter/runtime changes reverted: FAILED
#     TypeError: Cannot read properties of undefined (reading 'tag')
#   with them: ok
cargo test -q -p perry-codegen-wasm --lib          # 77 passed
cargo clippy -p perry-codegen-wasm                 # same 11 warnings as main, none in touched files
cargo build-perry --release && scripts/gc_call_effects/sidecars.sh target/release
python3 scripts/parity.py run language/{array,destructuring,function,string,class,object} --mode web
bash tests/integration/wasm/run_wasm_tests.sh
BASE_SHA=upstream/main scripts/run_lint_gates.sh

Web parity A/B against a pristine build of main at 64257c3 (this build carried both #14727 fixes, this one and the assignment-default one):

subject main pass branch pass of
language/array 49 51 330
language/destructuring 1 1 8
language/function 22 23 239
language/string 15 15 102
language/class 75 75 570
language/object 46 46 428

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 extra array passes 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

  • I have NOT bumped the workspace version or edited CHANGELOG.md
  • My commits follow the loose feat: / fix: / docs: / chore: prefix convention used in the log
  • I've read CONTRIBUTING.md and agree to the Code of Conduct

🤖 Generated with Claude Code

https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p

Summary by CodeRabbit

  • New Features
    • Tagged templates on the web target now pass cooked and raw string segments to function, instance-method, and static-method tags.
    • Tags can access the raw strings through the template strings array’s raw property.
    • The strings array is frozen and reused for repeated evaluations at the same call site, while separate call sites receive distinct arrays.
  • Bug Fixes
    • Static-method tags now work without triggering a TypeError.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Walkthrough

The WASM target now emits tagged-template strings for static method, instance method, and function tags. The runtime provides frozen cooked and raw arrays and reuses the strings array for each call site.

Changes: WASM tagged-template support

Layer / File(s) Summary
Tagged-template lowering
crates/perry-codegen-wasm/src/emit/expr/calls.rs, crates/perry-codegen-wasm/src/emit/expr/arrays.rs, crates/perry-codegen-wasm/src/emit/string_collection.rs
The emitter recognizes static method tags on class references. It emits tagged-template strings through tagged_template and template_raw, and collects bridge names and string contents.
Runtime strings and validation
crates/perry-codegen-wasm/src/wasm_runtime.js, crates/perry-codegen-wasm/src/emit/tests.rs, changelog.d/14730-wasm-tagged-template.md
The runtime caches frozen cooked and raw arrays by call-site ID. The test checks tag types, interpolated values, cooked and raw segments, and array identity across evaluations. The changelog records the web-target behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

Sequence Diagram(s)

sequenceDiagram
  participant WASMEmitter
  participant wasm_runtime
  participant TagFunction
  WASMEmitter->>wasm_runtime: Call tagged_template with site ID, cooked, and raw arrays
  wasm_runtime->>wasm_runtime: Freeze and cache the arrays
  wasm_runtime-->>WASMEmitter: Return the cached cooked array
  WASMEmitter->>TagFunction: Pass the strings array and interpolated values
Loading

Suggested reviewers: thehypnoo, ralic

Merge Risk: Minimal · up to b3269

The change makes tagged templates on the web target pass their strings array to the tag, and the supplied evidence shows no remaining merge-blocking risk. The author notes known remaining gaps, which are tracked in the related issue.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its subject: a tagged template now passes its strings array to the tag on the wasm target. The PR covers this, plus the static-method tag call path, so the title is related…
Description check Passed The description follows the template. It has a Summary, a Changes list with file paths, a Related issue line (Refs #14727, part 2 of 3), and a detailed Test plan with commands and results. The checkli…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix and its subject: a tagged template now passes its strings array to the tag on the wasm target. The PR covers this, plus the static-method tag call path, so the title is related to the main change. It omits the static-method part, which is acceptable because the title does not need every detail. The title also carries the issue number, which is minor noise.

Full details: Description check

Explanation

The description follows the template. It has a Summary, a Changes list with file paths, a Related issue line (Refs #14727, part 2 of 3), and a detailed Test plan with commands and results. The checklist is ticked. It omits the template's HTML comments, which is expected. It does not include a Screenshots section, which is optional. The template's test-plan checkbox items are replaced by a free-form command list, but the required information is present.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 944f70e4-9ca8-443a-8863-a11f24e67633
Commits

Reviewing files that changed from the base of the PR and between 64257c3 and e417925.

Files selected for processing: 6

  • changelog.d/14730-wasm-tagged-template.md
  • crates/perry-codegen-wasm/src/emit/expr/arrays.rs
  • crates/perry-codegen-wasm/src/emit/expr/calls.rs
  • crates/perry-codegen-wasm/src/emit/string_collection.rs
  • crates/perry-codegen-wasm/src/emit/tests.rs
  • crates/perry-codegen-wasm/src/wasm_runtime.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

TheHypnoo pushed a commit to raliclo/perry that referenced this pull request Nov 16, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
@TheHypnoo
TheHypnoo force-pushed the fix/14727-tagged-template-web branch 2 times, most recently from 30a87d1 to b3269c6 Compare November 16, 2026 15:24
TheHypnoo pushed a commit to raliclo/perry that referenced this pull request Nov 16, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
ralic and others added 2 commits November 16, 2026 16:28
…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
@TheHypnoo
TheHypnoo force-pushed the fix/14727-tagged-template-web branch from b3269c6 to a2d6e56 Compare November 16, 2026 15:28
@TheHypnoo
TheHypnoo merged commit cac54dd into PerryTS:main Nov 16, 2026
5 checks passed
@raliclo
raliclo deleted the fix/14727-tagged-template-web branch November 17, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants