You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compiler diagnostic ownership is currently split across package boundaries:
@8f4e/language-spec owns shared diagnostic shapes and ErrorCode.
packages/compiler/src/compilerError.ts owns getError(...) and the default compiler error messages.
compiler-adjacent packages such as @8f4e/constant-resolver cannot emit normal compiler diagnostics without
importing compiler internals or throwing a package-local error that the compiler wraps at the integration boundary.
This keeps package boundaries clean, but it makes shared diagnostics feel adapter-heavy as more compiler subpackages
appear.
Proposed Solution
Create a small @8f4e/compiler-diagnostics package that depends on @8f4e/language-spec and owns compiler diagnostic
construction.
The package should export:
getError(...);
the default message registry for ErrorCode;
shared detail formatting types/helpers;
lightweight helpers for attaching source/block diagnostic context if they can stay generic.
Keep @8f4e/language-spec focused on shared types, codes, and structural contracts. Keep phase-specific context
assembly in the compiler or the package that owns the phase.
Anti-Patterns
Do not make compiler-adjacent packages import packages/compiler/src/compilerError.ts.
Do not move broad compiler phase logic into the diagnostics package.
Do not let diagnostics depend on tokenizer, compiler, or constant-resolver implementation details.
Do not turn language-spec into the message-formatting package unless a dedicated diagnostics package proves too
costly.
Implementation Plan
Step 1: Create the Package
Add packages/compiler/packages/diagnostics.
Configure Nx build, typecheck, test, and package metadata following nearby compiler subpackages.
Add a dependency on @8f4e/language-spec.
Step 2: Move Diagnostic Construction
Move getError(...) and its detail formatting support out of packages/compiler/src/compilerError.ts.
Re-export or replace compiler imports so current compiler code keeps using a stable import path.
Keep error codes and diagnostic shapes in @8f4e/language-spec.
Step 3: Update Compiler-Adjacent Packages
Let packages such as @8f4e/constant-resolver decide whether to keep package-local domain errors or throw shared
diagnostics directly when they have enough context.
If a wrapper remains useful, make it a thin context adapter rather than a message-shaping adapter.
Step 4: Validate Boundaries
Confirm @8f4e/compiler-diagnostics has no dependency on @8f4e/compiler.
Confirm @8f4e/compiler and compiler subpackages use the shared diagnostic package consistently.
Add a small package-level test for representative diagnostics.
Created from 459-extract-compiler-diagnostics-package.md.
TODO: Extract Compiler Diagnostics Package
Problem Description
Compiler diagnostic ownership is currently split across package boundaries:
@8f4e/language-specowns shared diagnostic shapes andErrorCode.packages/compiler/src/compilerError.tsownsgetError(...)and the default compiler error messages.@8f4e/constant-resolvercannot emit normal compiler diagnostics withoutimporting compiler internals or throwing a package-local error that the compiler wraps at the integration boundary.
This keeps package boundaries clean, but it makes shared diagnostics feel adapter-heavy as more compiler subpackages
appear.
Proposed Solution
Create a small
@8f4e/compiler-diagnosticspackage that depends on@8f4e/language-specand owns compiler diagnosticconstruction.
The package should export:
getError(...);ErrorCode;Keep
@8f4e/language-specfocused on shared types, codes, and structural contracts. Keep phase-specific contextassembly in the compiler or the package that owns the phase.
Anti-Patterns
packages/compiler/src/compilerError.ts.language-specinto the message-formatting package unless a dedicated diagnostics package proves toocostly.
Implementation Plan
Step 1: Create the Package
packages/compiler/packages/diagnostics.@8f4e/language-spec.Step 2: Move Diagnostic Construction
getError(...)and its detail formatting support out ofpackages/compiler/src/compilerError.ts.@8f4e/language-spec.Step 3: Update Compiler-Adjacent Packages
@8f4e/constant-resolverdecide whether to keep package-local domain errors or throw shareddiagnostics directly when they have enough context.
Step 4: Validate Boundaries
@8f4e/compiler-diagnosticshas no dependency on@8f4e/compiler.@8f4e/compilerand compiler subpackages use the shared diagnostic package consistently.Validation Checkpoints
npx nx run @8f4e/compiler-diagnostics:testnpx nx run @8f4e/compiler-diagnostics:typechecknpx nx run @8f4e/compiler:testnpx nx run @8f4e/compiler:typecheckrg -n "from './compilerError'|from '../compilerError'|compilerError" packages/compilerSuccess Criteria
getError(...)lives outsidepackages/compiler/src.@8f4e/compiler.@8f4e/language-specremains the home of diagnostic types and error codes, not message formatting.Affected Components
packages/compiler/src/compilerError.ts- likely deleted, reduced to a re-export, or moved.packages/compiler/packages/language-spec/src/errors.ts- remains the source of error codes and diagnostic types.packages/compiler/packages/sub-program/packages/constant-resolver- candidate consumer for shared diagnostics.packages/compiler/packages/sub-program/src/compileSubProgram.ts- currentConstantResolverErrorwrapper may become thinner.Risks & Considerations
Related Items
docs/todos/292-refactor-error-systems-and-document-syntax-vs-compiler-error-boundaries.mddocs/todos/archived/458-decouple-module-execution-order-from-memory-layout.md