Values through a binding, asked where rules read: a logged Result written in place, callbacks by name at their slot (356 silent sites to 330) #136

Merged
sionzee merged 142 commits from values-asked-everywhere into main 2026-11-22 17:33:51 +01:00
Owner

Based on values-through-bindings (#135), and contains it: the diff shown is this piece alone.

#135 built one answer to "what does this name stand for" (a const read once, a function passed by name) and left it to each rule to ask. About 35 rules did not. This puts the question where rules get what they match, so that a rule does not have to know about it:

console.log(validate<User>(event.data));        // a Result that is only logged: nothing looks at it
const r = validate<User>(event.data);  console.log(r);     // the same program; only this form was reported

res.json().then(handle);     function handle(body: unknown) { ... }      // a callback by name, read where its slot is

What moved

Written another way Silent sites Reports the fixture does not have
a value through a const 126 → 121 247 → 208 (138 are missing-mut, by design)
a callback passed by name 40 → 27 64 → 22
a value written in place where the rule follows a binding 33 → 25 19 → 19
the whole list 356 → 330 716 → 635
  • A value is judged by where it goes. The analyzer's main walk, no-hidden-any and the kept-Result pass visit a value kept in a const at its read. A binding with a written type is the exception: there the type is where the value goes.
  • Readers of arguments follow the name: the built-in checks (btoa, the pieces of new RegExp, new URL(x, import.meta.url), the isNaN(d.getTime()) guard), the shape collector the whole-program pass asks, return unreachable(x).
  • A callback by name is read at its slot by no-swallowed-error, unused-task-signal, undeclared-return-type and the test structure (a suite's body passed by name).
  • must-use-result has one classifier for "only logged, or turned into text", used for the value in place and for the binding: 10 → 6 silent sites one way, 11 → 2 the other.

This closed less than hoped, and that is a result

A value through a const went from 126 to 121. Rules are separate visitors with their own passes; no single place covers them, and what remains must be threaded rule by rule. Against that: on an adopter's project and on four open-source code bases this piece gains no finding at all, and #135 gained 14 in one rule. Real code rarely writes the forms the harness generates for these lines (it hoists any sub-expression, including ones nobody would hoist). So the remaining lines of this group are honest gaps of low yield, and I do not plan a third piece on them; the list keeps them visible, with the pass each rule matches in.

Evidence

  • Nothing lost on the fixtures, the three examples and twenty held-out projects. On the adopter one finding goes, and it was wrong: undeclared-return-type on an arrow kept in a const whose only use is as an argument, which the rule exempts when written in place ("typed by the argument it is"). The same on one open-source function passed to .then.
  • Nothing gained there either (see above).
  • The transform is untouched: safe-ts emit byte-identical to the base.
  • Cost: per-file analysis on that project's largest entry 216 ms and 219 ms, whole-program pass 637 ms and 633 ms (minimum of 15 interleaved runs, on a loaded machine).

What turns red on upgrade

A Result that is only logged or turned into text, written in place, is must-use-result, as it already was through a const: console.log(validate<T>(x)), String(unsafe(() => ...)). Four lines in this repository's fixtures gained that expectation.

What is left

  • About 30 rules that match a value where it is written, in their own passes.
  • Results read off a return in another file, through a const.
  • A named function as its callback for the failure-propagation analysis: about 10 sites. Reporting it at the call inside, as for one written in place, would move every by-name expectation the fixtures pin, so it is a change of the model and is described in the list, not made.

Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review) in Claude Code.

Based on `values-through-bindings` (#135), and contains it: the diff shown is this piece alone. #135 built one answer to "what does this name stand for" (a `const` read once, a function passed by name) and left it to each rule to ask. About 35 rules did not. This puts the question where rules get what they match, so that a rule does not have to know about it: ```ts console.log(validate<User>(event.data)); // a Result that is only logged: nothing looks at it const r = validate<User>(event.data); console.log(r); // the same program; only this form was reported res.json().then(handle); function handle(body: unknown) { ... } // a callback by name, read where its slot is ``` ## What moved | Written another way | Silent sites | Reports the fixture does not have | |---|---|---| | a value through a `const` | 126 → 121 | 247 → 208 (138 are `missing-mut`, by design) | | a callback passed by name | 40 → 27 | 64 → 22 | | a value written in place where the rule follows a binding | 33 → 25 | 19 → 19 | | **the whole list** | **356 → 330** | **716 → 635** | - **A value is judged by where it goes.** The analyzer's main walk, `no-hidden-any` and the kept-`Result` pass visit a value kept in a `const` at its read. A binding with a written type is the exception: there the type is where the value goes. - **Readers of arguments follow the name**: the built-in checks (`btoa`, the pieces of `new RegExp`, `new URL(x, import.meta.url)`, the `isNaN(d.getTime())` guard), the shape collector the whole-program pass asks, `return unreachable(x)`. - **A callback by name is read at its slot** by `no-swallowed-error`, `unused-task-signal`, `undeclared-return-type` and the test structure (a suite's body passed by name). - **`must-use-result` has one classifier for "only logged, or turned into text"**, used for the value in place and for the binding: 10 → 6 silent sites one way, 11 → 2 the other. ## This closed less than hoped, and that is a result A value through a `const` went from 126 to 121. Rules are separate visitors with their own passes; no single place covers them, and what remains must be threaded rule by rule. Against that: **on an adopter's project and on four open-source code bases this piece gains no finding at all**, and #135 gained 14 in one rule. Real code rarely writes the forms the harness generates for these lines (it hoists any sub-expression, including ones nobody would hoist). So the remaining lines of this group are honest gaps of low yield, and I do not plan a third piece on them; the list keeps them visible, with the pass each rule matches in. ## Evidence - **Nothing lost** on the fixtures, the three examples and twenty held-out projects. On the adopter one finding goes, and it was wrong: `undeclared-return-type` on an arrow kept in a `const` whose only use is as an argument, which the rule exempts when written in place ("typed by the argument it is"). The same on one open-source function passed to `.then`. - **Nothing gained** there either (see above). - **The transform is untouched**: `safe-ts emit` byte-identical to the base. - **Cost:** per-file analysis on that project's largest entry 216 ms and 219 ms, whole-program pass 637 ms and 633 ms (minimum of 15 interleaved runs, on a loaded machine). ## What turns red on upgrade A `Result` that is only logged or turned into text, written in place, is `must-use-result`, as it already was through a `const`: `console.log(validate<T>(x))`, `String(unsafe(() => ...))`. Four lines in this repository's fixtures gained that expectation. ## What is left - About 30 rules that match a value where it is written, in their own passes. - Results read off a `return` in another file, through a `const`. - A named function as its callback for the failure-propagation analysis: about 10 sites. Reporting it at the call inside, as for one written in place, would move every by-name expectation the fixtures pin, so it is a change of the model and is described in the list, not made. Created with Claude Opus 5.5 (implementation) and Claude Fable 5.2 (review) in Claude Code.
The question asked where rules read: values and callbacks by name through the shared readers
All checks were successful
Benchmarks / bench (pull_request) Successful in 2m23s
Tests / test (pull_request) Successful in 10m33s
5024f58fa1
Open after values-through-bindings: `Values` existed, but only a handful of rules asked it
(126 silent and 247 new sites under hoist-const, 40 and 64 under callback-hoisted, 33 under
inline-const).

Closes, at the shared places a rule gets what it matches:
- visitors that judge a value by where it goes visit a value kept in a `const` at its read
  (`Values::defers` / `read`): the analyzer's walk, no-hidden-any, the kept-Result pass
  (`kept.rs`); a `const` with a type written stays where it is (`Values::typed`);
- the argument readers follow it (`Values::follow`): the built-ins' checks (btoa, new RegExp,
  new URL(x, import.meta.url), the isNaN(d.getTime()) guard), the shapes the whole program asks
  about (`shape.rs` sites), `return unreachable(x)` in a switch's rest;
- a function passed once by name is read as written at its slot (`function_of`,
  `defers_function`): no-swallowed-error, unused-task-signal, undeclared-return-type (typed by
  the argument it is), the test structure (a suite's body by name);
- the reverse direction for must-use-result: a Result written in place and only logged or
  turned into text (`kept::weak_use`) is reported as the local that is only logged was.

misses.txt: silent 356 -> 330, new 716 -> 635; hoist-const 126/247 -> 121/208, callback-hoisted
40/64 -> 27/22, inline-const 33/19 -> 25/19. Fixture changes: hidden_any/main.ts:98,
hidden_any/threads.ts:25, sinks/server.ts:50,83 (a validation or unsafe Result written in place
and only logged or turned into text, the twin of the bound form already reported).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sionzee changed target branch from values-through-bindings to main 2026-11-22 17:32:26 +01:00
Merge main: the piece below has landed
Some checks failed
Tests / test (pull_request) Has been cancelled
Benchmarks / bench (pull_request) Has been cancelled
cca5f93175
Co-Authored-By: Claude Fable 5.2 <[email protected]>
sionzee deleted branch values-asked-everywhere 2026-11-22 17:33:52 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!136
No description provided.