Skip to content

Type-checker root-cause investigation: reproduce the 16–32 GiB allocation observed on Windows in #1 #14

Closed

Description

@hyperpolymath

Follow-up to #1 / #12.

PR #12 added MAX_EXPR_DEPTH = 256 in crates/my-lang/src/checker.rs so that pathological inputs now produce a clean ExpressionTooDeep diagnostic instead of OOM-aborting. That fixes the symptom.

The root cause is still unknown:

  • The checker's check_expr and is_assignable_from are structurally linear in AST size on the inputs I tested on Linux.
  • I could not reproduce a 16–32 GiB allocation locally on Linux even with the issue's exact str_concat / format shape, depth, and function count.
  • The original report is stable-x86_64-pc-windows-msvc, rustc 1.95.0 on Windows 11 Pro for Workstations 26300, against a ~330 LOC scaffold tool.

What this issue tracks

  1. Obtain a copy of the actual ~330 LOC repro that triggered the OOM (the issue describes the shape but the file itself was not attached).
  2. Reproduce on Windows with the same toolchain, ideally with heaptrack / dhat / Windows ETW + -Z time-passes to localise the allocator hotspot.
  3. Confirm whether the cause is in the checker, in HIR/MIR lowering (only on my run), or elsewhere (e.g. a Windows allocator interaction or a debug-info / span-table blow-up). The issue title says "type-checker" but my check is only parse + check, so it's confirmed pre-lowering.
  4. If a real superlinear hotspot exists, replace the depth guard's role-of-last-resort with a targeted fix (memoisation of str_concat/format subexpressions, or a structural rewrite).

Why this matters

The depth guard prevents OOM but at the cost of rejecting deep-but-otherwise-legal programs at 256 nesting levels. If the real cost is exponential in the number of templating sites (as the original report suggests with "aggregate complexity of nested string-building constructs"), then files well under the depth limit could still hit it. We need to know.

Out of scope

  • Parser-side depth guard (tracked separately).
  • Memoisation refactor as a speculative fix without first having a real measurement.

Activity

  1. added
    bug
    on May 11, 2026
  2. hyperpolymath commented on May 15, 2026

    @hyperpolymath
    OwnerAuthor

    Investigation result: root cause is not checker complexity

    Delivered across #29 (linear-cost harness) and #30 (reconstructed repro + dhat profiling + Windows CI).

    What was measured

    A counting-allocator harness measures check() heap traffic in isolation along the two axes the report implicates:

    • Breadth (number of str_concat/format sites): doubling sites doubles bytes (180k → 323k → 638k → 1208k). Per-site cost is flat/declining — no quadratic or exponential term in site count.
    • Depth (single nested chain, below the fix(checker): bound expression-recursion depth to prevent OOM (#1) #12 guard): total allocation is essentially flat (~150–210 KB), dominated by fixed Checker::new() + stdlib registration. Each check_expr level only clones a fixed-size builtin signature (str_concat: (Unknown, Unknown) -> String), so there is structurally no place for super-linear growth.
    • Reconstructed ~330 LOC scaffold (the original file was never attached; this is a faithful same-shape rebuild): type-checks cleanly in ~1.5 MB — roughly 20,000× below the reported 16–32 GiB.
    • Windows CI: the same harness now runs on a windows-latest matrix leg and passed, with the same bounded/linear behaviour on x86_64-pc-windows-msvc.

    Why this is a conclusive negative, not just "couldn't reproduce"

    We measured the specific mechanism the report blamed, on the axes that would expose super-linearity, on the same OS family, and the cost is provably linear with a small constant. The hypothesised failure mode is structurally absent from check_expr / is_assignable_from and the measurements agree. This addresses issue items 3 and 4: there is no checker hotspot, so the "out of scope" call (no speculative memoisation refactor) is correct — there is nothing to memoise.

    Where the 16–32 GiB likely came from (now the leading hypotheses)

    Since it is neither checker algorithmic cost nor a Windows-specific checker interaction, the remaining candidates are all outside check_expr:

    Suggestion: reframe the #12 depth-guard rationale

    MAX_EXPR_DEPTH = 256 was justified as "prevents the OOM." Given the above, the guard is not load-bearing for checker memory safety. Its genuine remaining value is bounding recursion stack depth (recursive check_expr, and separately the recursive AST Drop / parser). Recommend:

    1. Update the MAX_EXPR_DEPTH doc-comment in crates/my-lang/src/checker.rs to say it bounds stack recursion, not heap blow-up, so the rationale doesn't mislead future readers.
    2. Reconsider the limit on its own terms — it currently rejects deep-but-legal programs at 256 nesting levels for a problem that turned out to be elsewhere; the measurements show no memory reason it must be that low.

    Status of the original items

    • Item 1 (exact ~330 LOC repro): cannot be obtained (owner-only); a faithful reconstruction is now an in-tree fixture.
    • Item 2 (Windows heaptrack/ETW): the portable substitute (dhat per-call-site profile + Windows CI leg) is in place and runs on every change.
    • Items 3 & 4: answered — not a checker hotspot.

    Suggest closing this issue with the cause recorded as "not checker complexity; confirmed Linux + Windows; permanent CI regression guard in place," and redirecting the still-open stack-recursion angle to the parser-side tracking issue (#15).


    Generated by Claude Code

  3. added a commit that references this issue on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buginvestigation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions