Skip to content

diagnostic: allocate stable error-code namespace ranges#405

Merged
danieljohnmorris merged 3 commits into
mainfrom
feature/adoption-2-error-namespace
May 18, 2026
Merged

diagnostic: allocate stable error-code namespace ranges#405
danieljohnmorris merged 3 commits into
mainfrom
feature/adoption-2-error-namespace

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

Adoption brief #2. Allocates stable ILO-<letter><digits> namespace ranges by compiler phase so agents and tools can route on prefix and the namespace stays forward-compatible. Matches Zero's documented ranges (PAR100, NAM003, TYP010-26, IMP001-3, ...) - same discipline, ilo's letter scheme.

Range Letter Area Status
ILO-L000-099 L Lexer / tokenisation active
ILO-P100-199 P Parser / syntax active
ILO-N200-299 N Names / resolution reserved
ILO-I300-399 I Imports reserved
ILO-T400-499 T Types active
ILO-V500-599 V Verifier (post-type checks) reserved
ILO-R600-699 R Runtime active
ILO-D700-799 D Deprecation warnings reserved
ILO-E800-899 E Engine-specific limitations reserved
ILO-S900-999 S Skill / spec system reserved

No existing code changes identifier. The historical block (L001-L003, P001-P021, T001-T036, R001-R026, W001) and the canonical hundreds-block are both in NAMESPACE_RANGES, so the existing prefixes keep working forever. New codes from now on land in the documented hundreds-block of their namespace, enforced by a cross-engine regression test.

ILO-D700-799 is reserved for deprecation warnings: when a feature is scheduled for removal it emits a compile-time warning without failing the build. The first ILO-D### ships with the first deprecation.

What's in the diff

  1. diagnostic: allocate stable error-code namespace ranges - registry.rs gains the namespace header comment, NAMESPACE_RANGES, parse_code, in_documented_range, and three unit tests (registry-in-range, parse roundtrip, reserved-room). Also backfills registry entries for codes that were emitted in the source but missing from the explainer table (P019, T030, T031, T036, R014, R099) - ilo --explain now resolves every emitted code.
  2. tests: assert every emitted error code lands in a documented namespace - cross-engine integration test. Drives a battery of diagnostic-provoking snippets through every engine selector (default / --run-tree / --run-vm / --jit), scrapes ILO-XYZNN codes off stderr, and asserts each one is in a documented range. Second test asserts ilo explain CODE succeeds for every REGISTRY entry.
  3. docs: document the error-code namespace ranges - rewrites the Error codes subsection of SPEC.md's Error Diagnostics chapter. ai.txt and skills/ilo/SKILL.md auto-regenerate from SPEC.md via build.rs. Companion update to the site at /Users/dan/code/ilo-lang/site/src/content/docs/docs/reference/diagnostics.md is staged separately and pushes alongside.

Test plan

  • cargo test --release --features cranelift - all suites pass, including the two new tests
  • cargo fmt --check clean
  • cargo clippy --release --features cranelift --all-targets -- -D warnings clean
  • cargo build --release regenerates ai.txt + SKILL.md from SPEC.md cleanly (no drift)
  • ilo --explain ILO-T030, ilo --explain ILO-R014, ilo --explain ILO-R099 all resolve (previously surfaced as unknown error code)
  • Every existing ILO-XXX code in the source is in NAMESPACE_RANGES - asserted by registry_codes_in_documented_ranges and the cross-engine regression test

Follow-ups

  • First time we ship a deprecation, allocate ILO-D700 and document the warning policy in SPEC.
  • The N / I / V namespaces have no codes yet by design; future diagnostics in those categories should land there instead of extending T###.

Document and enforce the ILO-<letter><digits> namespace layout in
src/diagnostic/registry.rs. Each compiler phase has a reserved
hundreds-block (L lexer, P parser, N names, I imports, T types,
V verifier, R runtime, D deprecation, E engine-specific, S skill /
spec) with generous spacing so future codes slot in without a
renumber. Reserved namespaces (N, I, V, D, E, S) carry no codes
today but are forward-declared.

Historical codes (L001-L003, P001-P021, T001-T036, R001-R026, W001)
stay valid forever - both the historical block and the canonical
hundreds-block are in NAMESPACE_RANGES so existing identifiers keep
working. New codes from now on go in the documented hundreds-block
of their namespace.

Backfill registry entries for codes that were emitted but missing
from the explainer table: P019 (use-import name not found),
T030 (circular type alias), T031 (alias shadows builtin),
T036 (call register overflow), R014 (auto-unwrap propagation),
R099 (internal runtime error). Without these, 'ilo --explain'
on those codes returned 'unknown error code' even though the
diagnostic was live in the codebase.

Add parse_code and in_documented_range helpers plus three unit
tests: parse_code_roundtrip, registry_codes_in_documented_ranges
(every REGISTRY entry lives in a documented range), and
reserved_namespaces_have_room (each forward-looking namespace has
at least 100 codes reserved).
Cross-engine regression test. Runs a battery of snippets known to
provoke diagnostics (one per active namespace plus a runtime
example) under every available engine selector (default / --run-tree
/ --run-vm / --jit when cranelift is enabled), scrapes every
ILO-XYZNN code from stderr, and asserts each one is in a
NAMESPACE_RANGES entry.

The second test asserts 'ilo explain CODE' succeeds for every
REGISTRY entry. If a code emits and 'explain' can't find it, the
agent loop breaks - this catches the case the previous commit
fixed (R014, T030, T036, ... were emitted without registry entries)
the next time it would regress.
Rewrite the 'Error codes' subsection of SPEC.md's Error Diagnostics
chapter to spell out the full namespace table (active and reserved),
the historical-codes-stay-valid contract, and the deprecation-warning
policy for ILO-D7xx. ai.txt and skills/ilo/SKILL.md auto-regenerate
from SPEC.md via build.rs.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/diagnostic/registry.rs 95.12% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@danieljohnmorris danieljohnmorris merged commit 7ca816b into main May 18, 2026
5 checks passed
@danieljohnmorris danieljohnmorris deleted the feature/adoption-2-error-namespace branch May 18, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant