Repository navigation
Keep tagged template calls whose result is unused - #9420
Conversation
Why:
`Js_analyzer.no_side_effect_expression` treated a tagged template as
pure when its tag and interpolated values were pure, so a tagged
template whose result is unused (`let _ =`, `->ignore`, an
unused binding, a discarded array) was removed and the tag function
never ran. A tagged template is a call of its tag, so it is now treated
like a call.
`Js_dump` printed the tag at the level of the surrounding expression.
A tag that inlining replaced with a function, a conditional or an
`await` had no parentheses: the template bound to the last branch of
the conditional and to the awaited promise, and a function was a syntax
error. The tag is now printed as a callee is. The interpolated values,
which `${}` encloses, are printed without parentheses.
JS modified (unused tagged templates):
Example:
let tag: taggedTemplate<int, int> = Obj.magic(() => 1)
let unusedResult = () => {
let _ = tag`a ${1}`
}
Before (js):
function unusedResult() {
}
After (js):
function unusedResult() {
tag`a ${1}`;
}
JS modified (tags of tagged templates):
Example:
let use = (tag: taggedTemplate<int, int>) => tag`x${1}`
let useFunction = () => use(Obj.magic((_s, _v) => 1))
let useConditional = (c, a, b) => use(c ? a : b)
let useAwaited = async p => use(await p)
Before (js):
function useFunction() {
return (_s, _v) => 1`x${1}`;
}
function useConditional(c, a, b) {
return c ? a : b`x${1}`;
}
async function useAwaited(p) {
return await p`x${1}`;
}
After (js):
function useFunction() {
return ((_s, _v) => 1)`x${1}`;
}
function useConditional(c, a, b) {
return (
c ? a : b
)`x${1}`;
}
async function useAwaited(p) {
return (await p)`x${1}`;
}
JS modified (interpolated values of tagged templates):
Example:
let f = (tag: taggedTemplate<int, int>, c) => tag`x${c ? 1 : 2}` + 1
Before (js):
function f(tag, c) {
return tag`x${(
c ? 1 : 2
)}` + 1 | 0;
}
After (js):
function f(tag, c) {
return tag`x${c ? 1 : 2}` + 1 | 0;
}
Review: Are tagged templates whose result is used affected? Only in how
their tag and interpolated values are parenthesised.
Review: Which checked-in outputs change? Only the new test's snapshot.
Signed-off-by: Rob <illusionalsagacity@users.noreply.github.com>
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page Keep tagged template calls whose result is unusedda4bea8 · illusionalsagacity · Nov 23, 2026, 20:40 UTC
JS modified (unused tagged templates) let tag: taggedTemplate<int, int> = Obj.magic(() => 1)
let unusedResult = () => {
let _ = tag`a ${1}`
}
function unusedResult() {
-
+ tag`a ${1}`;
}JS modified (tags of tagged templates) let use = (tag: taggedTemplate<int, int>) => tag`x${1}`
let useFunction = () => use(Obj.magic((_s, _v) => 1))
let useConditional = (c, a, b) => use(c ? a : b)
let useAwaited = async p => use(await p)
function useFunction() {
- return (_s, _v) => 1`x${1}`;
+ return ((_s, _v) => 1)`x${1}`;
}
function useConditional(c, a, b) {
- return c ? a : b`x${1}`;
+ return (
+ c ? a : b
+ )`x${1}`;
}
async function useAwaited(p) {
- return await p`x${1}`;
+ return (await p)`x${1}`;
}JS modified (interpolated values of tagged templates) let f = (tag: taggedTemplate<int, int>, c) => tag`x${c ? 1 : 2}` + 1
function f(tag, c) {
- return tag`x${(
- c ? 1 : 2
- )}` + 1 | 0;
+ return tag`x${c ? 1 : 2}` + 1 | 0;
}Review
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9420 +/- ##
=======================================
Coverage 82.22% 82.23%
=======================================
Files 461 462 +1
Lines 65573 65580 +7
=======================================
+ Hits 53916 53927 +11
+ Misses 11657 11653 -4
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
cknitt
left a comment
There was a problem hiding this comment.
Looks good to me. I built it, checked the fix against master with extra cases, and found no problems.
This review was done by Claude.
Bring the backport in line with the version of rescript-lang#9420 merged on master (1f729ec). Its changes to Js_analyzer and Js_dump are the same here. 12.x has no taggedTemplate type, so a tag is always a @taggedTemplate external, and the inlined function, conditional and awaited tags of master's tests can't be written in ReScript. Their printing is covered by Ounit_js_dump_tests instead. The other changes on this branch keep the calls that are no longer removed correct on 12.x: a @string variant payload is evaluated once (rescript-lang#9217 on master), and a @taggedTemplate external called in function form with strings that aren't literals is a plain call instead of a failed assertion in Js_dump. Signed-off-by: Rob <illusionalsagacity@users.noreply.github.com>
Part of #9398 (item 3).
Problem
Js_analyzertreated a tagged template as free of side effects when its tag and values were, so a tagged template whose result is unused (let _ =,->ignore) was removed and the tag function never ran. A tagged template is a call of its tag.Before:
After:
Reviewing this showed that the calls it keeps could print wrongly. A tag that inlining replaced with a function, a conditional or an
awaithad no parentheses (this already affected templates whose result is used):Before:
After:
Fix
no_side_effect_expression_desctreatsTagged_templatelikeCall. The tag is printed as a callee is, and the interpolated values without needless parentheses.Tests
tagged_template_effect_test.rescovers discarded results and inlined tags. No other checked-in output changes.12.x
12.x has the same bug, and I have a backport ready on
fix-tagged-template-effect-12.x. I'll open it againstmaintenance/12.xonce this one is reviewed.The fix was written by Claude. A second Claude agent reviewed the first version; this version addresses that review and has not been reviewed again.