Diagnostic and Error Codes Specification
Purpose
The ARES Diagnostic system provides granular feedback to the software developer during all phases of the compilation pipeline. It aims to be "human-readable but machine-parsable," returning structured CompilerError objects (types.ts:34) that pinpoint the exact filename, line, and column of a syntax violation or semantic mismatch. This document serves as the canonical reference for all diagnostic levels and their troubleshooting procedures.
Prerequisites
- None.
Diagnostic Levels
| Level | Severity | Description |
|---|---|---|
error | Critical | Prevents compilation; Phase is terminated immediately. |
warning | High | Potential runtime issue or performance bottleneck; Analysis continues. |
info | Low | Optimization tips or heuristic decisions; Analysis continues. |
Operational Behavior
- Phase 1 (Lexing): Detects unmatched string quotes, non-ARES characters, or reserved keyword misuse.
- Phase 2 (Parsing): Detects grammar violations (e.g., missing semicolons, unmatched braces) via Chevrotain's error reporting.
- Phase 3 (Semantic Analysis): Detects type mismatches, unbound identifiers, and invalid intent parameters.
- Phase 5 (Routing): Provides warnings if a high-complexity script is forced into an inefficient target backend (e.g., in Python).
Implementation Mapping
Incorrect ARES Source vs. Diagnostic Output
Example 1: Syntax Mismatch (ParseError)
Incorrect Source:
aresif x > 0 print x // Missing braces for the block
Diagnostic Output:
json{ "type": "ParseError", "line": 2, "column": 5, "message": "Expecting token of type --> LCurly <-- but found --> Print <--", "severity": "error" }
Example 2: Type Conflict (SemanticError)
Incorrect Source:
areslet count: int = "forty-two"
Diagnostic Output:
json{ "type": "SemanticError", "line": 1, "column": 18, "message": "Type mismatch: Cannot assign StringLiteral to Variable of type int.", "severity": "error" }
Example 3: Routing Warning (Info/Warning)
Source:
aresusing python use matrix_multiply on big_data // O(N^3) on large data in Python
Diagnostic Output:
json{ "type": "RoutingInfo", "severity": "warning", "message": "Caution: Forcing Python target for O(N^3) task on potential large dataset. Performance may be degraded." }
Mathematical Model
The total number of diagnostics for a program is the union of errors from all pipeline stages : The compilation is successful if and only if:
Complexity
- Error Detection: proportional to AST nodes or tokens.
- Reporting overhead: constant time per error generated.
Examples
Defining a Custom Semantic Error:
If isSorted is required for a binary_search intent but not found, the analyzer.ts generates a SemanticError warning instead of a hard crash.
Traces
Trace for let x = undefined_var:
- Analyzer scans
visitLet. - Initializer lookup finds
undefined_var. - Symbol table check returns
null. diagnostics.push()adds theSemanticErrorwith the identifier's source location.- Compilation proceeds for other nodes but Phase 3 marked as failed.
Edge Cases
- Lookahead Errors: In Phase 2, if the parser is deep in a nested rule, it may return a list of expected tokens rather than a single specific error. ARES selects the most probable candidate for reporting.
- Lazy Diagnostics: Warnings about missing formatting tools (
black,prettier) are only emitted at the end of Phase 7 (Codegen).
Failure Modes
- Cascading Errors: A single syntax error (e.g., missing
{) can trigger multiple subsequentParseErrorreports as the parser struggles to re-sync. Developers should focus on the FIRST reported error. - Suppressed Warnings: The
--silentCLI flag suppressesinfoandwarningdiagnostics but nevererror.
Compatibility
- IDE Support: Diagnostic objects follow a subset of the Language Server Protocol (LSP) format for easy integration.
Testing
- Diagnostic Integrity:
tests/diagnostics.test.tsruns 20+ "broken" ARES scripts and asserts that the compiler returns the correcttypeandmessagefor each. - Location Accuracy: Verifies that reported
lineandcolumnnumbers match the physical location of the error in the source file.
Related Entities
src/types.ts: TheCompilerErrorinterface.5_api_reference/01_compiler_api.md: How diagnostics are returned in theCompilationResult.
Source Attribution
- Component:
src/semantics/analyzer.ts(Semantics),src/parser/parser.ts(Syntax). - Standards: Follows LLVM and Rust diagnostic best-practice formatting.