Skip to content

Type resolution corruption when single source file exceeds ~14K lines #1

Closed

Description

@ehartford

Summary

The compiler silently corrupts type resolution when a single .w source file exceeds approximately 14,000 lines of code. The symptom is unresolved type for field '' in struct 'StructName' errors with empty field names, or unresolved type for field 'field_name' in struct 'StructName' for fields that are clearly valid.

Reproduction

Adding ~200 lines of new function bodies to src/Codegen.w (currently ~14K lines) triggers the error. The same code compiles fine when split across multiple builds using a two-phase bootstrap approach (stubs first, then real implementations after seed update).

Key observations:

  • Adding 350 lines of comments (no code) does NOT trigger the error — 14,125 lines with comments builds fine
  • Adding ~200 lines of code (new function bodies with local variables, function calls, etc.) DOES trigger it
  • The error is deterministic, not intermittent
  • The error manifests differently on repeated builds but always involves type resolution
  • Sometimes appears as unresolved type for field '' in struct 'ContextError' (empty field name)
  • Sometimes appears as unresolved type for field 'mir_input' in struct 'Codegen'

Root Cause Hypothesis

The issue is likely an internal pool or table overflow in the compiler's type resolution phase. When the total number of AST nodes, symbols, or type entries exceeds a fixed-size buffer or triggers a reallocation that invalidates existing pointers, type resolution silently produces garbage results instead of failing cleanly.

Impact

This is currently worked around by:

  1. Removing dead code to stay under the limit
  2. Two-phase bootstrap (add stubs, update seed, fill in implementations)

But src/Codegen.w is already at 14,013 lines and growing. The AST codegen removal (Phase 4 in docs/deprecate_ast.md) will help by deleting ~3,000-5,000 lines, but the limit will eventually be hit again as the compiler evolves.

Suggested Fix

Either:

  1. Find and fix the overflow: Add bounds checking / dynamic resizing to whichever internal table is overflowing. The type_extra Vec or the sema type tables are likely candidates.
  2. Support multi-file compilation units: Allow splitting large files like Codegen.w into multiple files that share the same struct scope.
  3. Add a clear error: At minimum, detect the overflow condition and emit a clear diagnostic instead of silently corrupting type data.

Environment

  • Platform: macOS ARM64 (Darwin 25.3.0)
  • Self-hosting compiler, fixpoint-verified
  • LLVM 22 statically linked

Activity

  1. added a commit that references this issue on Nov 2, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions