omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / docs / one_layer / DIAGNOSTICS_V1.md
| 1 | # Omega Stable Diagnostics Specification (v1) |
| 2 | |
| 3 | Defined under milestone A of issue #655 and essay priorities 1/2. |
| 4 | Replaces unstructured human-only compiler errors and ad-hoc JSON with a deterministic, line-oriented plain-text diagnostic stream emitted directly by `omc.om` (the single authoritative front end). |
| 5 | |
| 6 | ## 1. Wire Format and Syntax |
| 7 | |
| 8 | The diagnostics stream is UTF-8 plain text consisting of: |
| 9 | 1. Exactly one version line as the first non-comment line. |
| 10 | 2. Zero or more diagnostic record lines (one record per line). |
| 11 | |
| 12 | Comments begin with `#` or `note ` and are ignored. |
| 13 | Blank lines (containing only ASCII whitespace) are ignored. |
| 14 | |
| 15 | ### 1.1 Version Line |
| 16 | |
| 17 | The stream MUST begin with: |
| 18 | ```text |
| 19 | omega-diag v1 |
| 20 | ``` |
| 21 | |
| 22 | A valid program that passes all checks produces zero diagnostic records: |
| 23 | ```text |
| 24 | omega-diag v1 |
| 25 | ``` |
| 26 | (Exits with returncode 0.) |
| 27 | |
| 28 | Both `check` and `next` complete their stdout writes before reporting success. |
| 29 | A failed or zero-progress write exits with compiler output error 2. |
| 30 | `next` streams completed query records rather than buffering the entire visible |
| 31 | function/name list; a legal query is not limited by the diagnostic message pool. |
| 32 | The category, large-query, and `/dev/full` regression controls live in |
| 33 | `tests/diagnostics/experiment_issue655.sh`. |
| 34 | |
| 35 | ### 1.2 Record Line Format |
| 36 | |
| 37 | Each diagnostic record occupies exactly one line with whitespace-separated fields: |
| 38 | |
| 39 | ```text |
| 40 | <profile> <category> <span=start-end> <finality> <repairable> [<constraints>...] |
| 41 | ``` |
| 42 | |
| 43 | Example: |
| 44 | ```text |
| 45 | om1 TYPE span=42-47 FINAL REPAIRABLE code=7 expect=uint found=short |
| 46 | om2 SYNTAX span=108-112 INCOMPLETE REPAIRABLE code=15 expect=end |
| 47 | om1 NAME span=15-20 UNKNOWN REPAIRABLE code=3 name=helper |
| 48 | ``` |
| 49 | |
| 50 | ## 2. Field Definitions and Ordering |
| 51 | |
| 52 | Fields MUST appear in this exact order: |
| 53 | |
| 54 | 1. **`profile`**: |
| 55 | The language profile: `om1` or `om2`. |
| 56 | Example: `om1`, `om2`. |
| 57 | |
| 58 | 2. **`category`**: |
| 59 | The coarse error class, uppercase ASCII: |
| 60 | - `SYNTAX`: Malformed grammar, misplaced token, unexpected delimiter (omc codes 4, 5, 6, 9, 15, 16, 22). |
| 61 | - `TYPE`: Type mismatch, invalid conversion, sign error (omc codes 7, 11, 19). |
| 62 | - `NAME`: Unknown identifier, duplicate name, reserved word reuse (omc codes 3, 10, 13). |
| 63 | - `CAPACITY`: Resource pool exhaustion, register spill limit, memory table bounds (omc codes 12, 14, 23, 24). |
| 64 | - `RANGE`: Value out of representable bounds, shift count overflow (omc codes 8, 21). |
| 65 | - `FLOW`: Unreachable code, missing return, control flow violation (omc codes 17, 18). |
| 66 | - `CONTRACT`: Precondition/postcondition violation, invariant, layout constraint (omc codes 27, 28, 29, 30). |
| 67 | |
| 68 | 3. **`source_byte_span`**: |
| 69 | Formatted exactly as `span=<start>-<end>` where `<start>` and `<end>` are 0-indexed decimal byte offsets into the original source file. |
| 70 | `<start>` is inclusive; `<end>` is exclusive (`start <= end`). |
| 71 | Byte offsets are calculated against the raw input bytes prior to any compiler-prepended mode directives. |
| 72 | |
| 73 | 4. **`finality`**: |
| 74 | Certainty of the defect given incomplete prefixes: |
| 75 | - `FINAL`: Irreparable defect in completed statements (e.g. type conflict, invalid literal, malformed expression). No continuation can make this prefix valid without changing earlier tokens. |
| 76 | - `INCOMPLETE`: Error caused by premature termination or missing closure (e.g. unclosed `if`/`while`/`fn` block, cut token at EOF). A continuation can resolve this error by supplying the missing tokens. |
| 77 | - `UNKNOWN`: Undeclared identifier (e.g. call to an unparsed function or forward struct). A future declaration in the same compilation unit may resolve it. |
| 78 | |
| 79 | 5. **`repairable`**: |
| 80 | Indicates whether code editing can resolve the issue: |
| 81 | - `REPAIRABLE`: Can be repaired by modifying or appending Omega code. |
| 82 | - `UNREPAIRABLE`: Hardware or architectural limit reached (compiler capacity, pool limit). |
| 83 | Repairability is independent of finality: a `FINAL` or `UNKNOWN` record is still |
| 84 | `REPAIRABLE` unless its code is a capacity failure (12, 14, 23 or 24). |
| 85 | The compiler emits exactly one space between fields, including before `code=`. |
| 86 | |
| 87 | 6. **`constraints`** (Optional): |
| 88 | Trailing whitespace-delimited key-value pairs or token descriptions providing additional structured context: |
| 89 | - `code=<N>`: Exact omc error code (e.g. `code=7`). |
| 90 | - `expect=<cls>`: Expected token class or type (e.g. `expect=type`, `expect=end`). |
| 91 | - `found=<tok>`: Encountered token or identifier (e.g. `found=short`). |
| 92 | - `name=<id>`: Relevant identifier name. |
| 93 | |
| 94 | ## 3. Rejection of Malformed Input |
| 95 | |
| 96 | A parser or downstream agent reading this format MUST reject malformed input with a non-zero exit status. Specifically: |
| 97 | |
| 98 | 1. **`MALFORMED_VERSION`**: The first non-comment non-empty line does not match `^omega-diag v1$`. |
| 99 | 2. **`MALFORMED_FIELD_COUNT`**: A diagnostic record line contains fewer than 5 whitespace-separated fields. |
| 100 | 3. **`MALFORMED_PROFILE`**: Field 1 is not one of `om1`, `om2`. |
| 101 | 4. **`MALFORMED_CATEGORY`**: Field 2 is not one of the 7 specified uppercase category strings (`SYNTAX`, `TYPE`, `NAME`, `CAPACITY`, `RANGE`, `FLOW`, `CONTRACT`). |
| 102 | 5. **`MALFORMED_SPAN`**: Field 3 does not match `^span=[0-9]+-[0-9]+$` or has `start > end`. |
| 103 | 6. **`MALFORMED_FINALITY`**: Field 4 is not one of `FINAL`, `INCOMPLETE`, `UNKNOWN`. |
| 104 | 7. **`MALFORMED_REPAIRABLE`**: Field 5 is not one of `REPAIRABLE`, `UNREPAIRABLE`. |
| 105 | 8. **`MALFORMED_ENCODING`**: Line contains non-ASCII characters or CR (`\r`) line endings. |