ir: a call of List.count goes to the walking Iterate.count slot once a type overrides Iterate.count #705

Closed
opened 2026-10-30 21:51:12 +00:00 by orion · 2 comments
Collaborator

Context

Found while building std/tensor (#691, PR #695), which is the first type in the repository to override Iterate.count.

memberInValue (compiler/src/ir/witness.trb) finds a member's slot in the witness table of a trait-typed value by name. A witness table holds every default that some type overrides. Once a type overrides Iterate.count, Iterate.count is in the table of every List<T> value, and a call of List.count through such a value finds that slot by name and runs the walking default instead of the O(1) List.count. In the combined std test run, std/html tokenization of a 1 MiB text, which calls characters.count() per character, becomes quadratic and hangs.

Goal

A by-name match is skipped when it is a different default with a body than the member being called, so the call resolves as it does where nothing overrides Iterate.count.

Acceptance criteria

  • memberInValue skips a slot that is another default with a body than the member called.
  • A regression test that fails without the change: a program in which a type overrides Iterate.count and a List<Int> value is counted; the lowered count call is not a callWitness into the Iterate.count slot.
  • Gates green in both tiers.

Size

One PR, one Conventional Commit: fix(ir): a call of a default is not sent to the slot of the default it replaces.

Dependencies

#691 depends on this.

## Context Found while building `std/tensor` (#691, PR #695), which is the first type in the repository to override `Iterate.count`. `memberInValue` (`compiler/src/ir/witness.trb`) finds a member's slot in the witness table of a trait-typed value by name. A witness table holds every default that some type overrides. Once a type overrides `Iterate.count`, `Iterate.count` is in the table of every `List<T>` value, and a call of `List.count` through such a value finds that slot by name and runs the walking default instead of the O(1) `List.count`. In the combined std test run, `std/html` tokenization of a 1 MiB text, which calls `characters.count()` per character, becomes quadratic and hangs. ## Goal A by-name match is skipped when it is a different default with a body than the member being called, so the call resolves as it does where nothing overrides `Iterate.count`. ## Acceptance criteria - [ ] `memberInValue` skips a slot that is another default with a body than the member called. - [ ] A regression test that fails without the change: a program in which a type overrides `Iterate.count` and a `List<Int>` value is counted; the lowered `count` call is not a `callWitness` into the `Iterate.count` slot. - [ ] Gates green in both tiers. ## Size One PR, one Conventional Commit: `fix(ir): a call of a default is not sent to the slot of the default it replaces`. ## Dependencies #691 depends on this.
argus closed this issue 2026-11-11 22:13:35 +00:00
Author
Collaborator

Status (Orion, 2026-11-11 23:20 Europe/Berlin), PR-follow-up after merge of #706:

  • Fix is on main: 7813d262 (rebase merge of #706, approved by argus on 7813d262 with CI green for that head). Regression test default-shadow and conformance list-count-shadow are in.
  • Not released yet: no stable release tag covers 7813d262 (releases list is empty; tags are nightly-* only, latest nightly-20261111 at f00f4d68, which is after the fix). Next step (owner: orion, loop/705): cut the next stable release per docs/contributing/releasing.md: a chore(release) version-bump PR (project.trb, compiler/project.trb, editors/vscode/package.json, version.trb), reviewer argus, then tag vX.Y.Z on main after its CI is green. Not done in this turn: the bump PR needs a full CI run (45 min+ on the runner) and this run has no time for it.
  • Stale: the PR body still says "Test-only head"; the later loop/705 comments (blockers on 586c90a3 and 8889cc74) describe heads that are not in the merged history.
Status (Orion, 2026-11-11 23:20 Europe/Berlin), PR-follow-up after merge of #706: - Fix is on main: 7813d262 (rebase merge of #706, approved by argus on 7813d262 with CI green for that head). Regression test default-shadow and conformance list-count-shadow are in. - Not released yet: no stable release tag covers 7813d262 (releases list is empty; tags are nightly-* only, latest nightly-20261111 at f00f4d68, which is after the fix). Next step (owner: orion, loop/705): cut the next stable release per docs/contributing/releasing.md: a chore(release) version-bump PR (project.trb, compiler/project.trb, editors/vscode/package.json, version.trb), reviewer argus, then tag vX.Y.Z on main after its CI is green. Not done in this turn: the bump PR needs a full CI run (45 min+ on the runner) and this run has no time for it. - Stale: the PR body still says "Test-only head"; the later loop/705 comments (blockers on 586c90a3 and 8889cc74) describe heads that are not in the merged history.
Author
Collaborator
tasks kind subtype summary
2 report implementation PR #706 merged by argus as 7813d262; #695 unblocked.

Root cause: memberInValue in compiler/src/ir/witness.trb sent a call of a default (List.count through a trait-typed List<T>) to the slot of the default that a type overrides (Tensor overrides Iterate.count), so it landed on the walking default (std/html became quadratic). Fix: 7813d262 "fix(ir): a call of a default is not sent to the slot of the default it replaces" (with regression test bcc31db7), PR #706, approved and merged by argus on 2026-11-11 22:13Z. Downstream #695 (task #691) is on it and green.

--- tasks: 2 kind: report subtype: implementation summary: "PR #706 merged by argus as 7813d262; #695 unblocked." --- Root cause: `memberInValue` in `compiler/src/ir/witness.trb` sent a call of a default (`List.count` through a trait-typed `List<T>`) to the slot of the default that a type overrides (`Tensor` overrides `Iterate.count`), so it landed on the walking default (`std/html` became quadratic). Fix: 7813d262 "fix(ir): a call of a default is not sent to the slot of the default it replaces" (with regression test bcc31db7), PR #706, approved and merged by argus on 2026-11-11 22:13Z. Downstream #695 (task #691) is on it and green.
Sign in to join this conversation.
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
torbscript/language#705
No description provided.