Commit 50d0d6f
Phase 3: pass-level tolerance classification in Analyzer.cs
Stacks on Phase 2 (#965). Closes the multi-error type-checker initiative
by adding per-item try/catch isolation to the analyzer's gathering passes
and a HasErrors gate before the analysis passes that assume a clean AST.
## What changed
### `TolerantStep` helper
New private helper in `Analyzer.cs`:
private static void TolerantStep(ITranslationErrorHandler handler, Action body)
{
try { body(); }
catch (TranslationException e) when (handler.Diagnostics.ContinueOnError)
{
handler.Diagnostics.Report(e);
}
}
In strict mode (ContinueOnError == false) the `when` filter is false so
the exception propagates exactly as before — bit-for-bit preservation of
today's throw-on-first-error semantics. In collecting mode the catch
captures the TranslationException into the collector and the loop
continues with the next item. Only TranslationException is caught; NREs
and other runtime exceptions still propagate so genuine bugs surface
loudly.
### Tolerant gathering passes (2a, 2b, 3, 3b, 7)
Each iteration wrapped in `TolerantStep`:
- **2a MachineChecker.Validate** — per-machine. One bad machine no
longer aborts MachineChecker for siblings.
- **3 FunctionBody + Validator** — per-function. One bad function
(TypeResolver throw on a bad var decl, missing-paths-return, etc.)
no longer aborts pass 3 for the rest of the program.
- **3b Invariants / Axioms / AssumeOnStarts / Pures / Foreign** —
per-item across all five subgroups. One bad invariant no longer
blocks axiom checking.
- **2b ValidateNoStaticHandlers** — per-machine.
- **7 InferMachineCreates** — per-machine. Already gated by HasErrors
in practice, but the wrapper is cheap insurance.
### Gathering→analysis boundary
New HasErrors gate placed after pass 2b (the last gathering pass) and
before pass 4 (ApplyPropagations):
if (handler.Diagnostics.HasErrors) return globalScope;
If any gathering pass collected an error, the analysis passes (4-7) and
the module-system passes (8-10) are skipped. The duplicate gate before
pass 8 (added in Phase 2 robustness) is kept as defense-in-depth — once
Phase 4+ converts pass-5 capability checks to Report, that second gate
will earn its keep.
## Why this matters
Without Phase 3, a single machine with a bad start state aborts MachineChecker
mid-pass, so a sibling machine's MoreThanOneParameterForHandlers error never
gets reported. A single function with a malformed var decl aborts pass 3, so
none of the OTHER functions' bodies get type-checked at all. Combined with
Phase 2's expression-level recovery, Phase 3 means a user with N independent
errors (in any combination of expressions, statements, machines, or functions)
sees ALL of them in one compile.
## Tests
### New: `MultiMachineErrors.p` + pinned counts
Three machines, each with one independent error (bool->int, missing
declaration, int+string binop). Pinned in MultiErrorAcceptanceTest:
strict=1, collecting=3. Validates that one machine's error doesn't
clobber its siblings' diagnostics in collecting mode.
### Existing: All Phase 2 acceptance tests unchanged
MultipleErrors (1/4), NestedExprErrors (1/2), ForeachBodyErrors (1/2),
SpecReceiveBodyError (1/3). Same counts as Phase 2 — Phase 3 doesn't
change behavior within a single machine.
### Existing: Phase1DormancyTest baseline
The "collecting >= strict count" invariant on every Correct/StaticError
test still holds. Phase 3 only *adds* errors (when multi-machine /
multi-function scenarios exist); it never removes.
## Phase 4 (deferred, NOT in this PR)
Convert pass 5 (capability checks) and pass 6 (ControlFlowChecker)
throw sites to Report so capability and control-flow violations also
accumulate across machines instead of aborting on first. The current
HasErrors gate already prevents these passes from running on a broken
AST, so they remain RequiresClean for now. Estimated: ~1 day if
warranted by user feedback.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent bd1cafe commit 50d0d6f
3 files changed
Lines changed: 161 additions & 46 deletions
File tree
- Src/PCompiler/CompilerCore/TypeChecker
- Tst
- RegressionTests/Feature3Exprs/StaticError/MultiMachineErrors
- UnitTests/TypeChecker
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
23 | 30 | | |
24 | 31 | | |
25 | | - | |
26 | | - | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
29 | | - | |
| 36 | + | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
33 | | - | |
34 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
35 | 45 | | |
36 | 46 | | |
37 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
38 | 50 | | |
39 | 51 | | |
40 | | - | |
41 | | - | |
| 52 | + | |
42 | 53 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
46 | 61 | | |
47 | 62 | | |
48 | 63 | | |
49 | 64 | | |
50 | | - | |
51 | | - | |
| 65 | + | |
52 | 66 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
56 | 74 | | |
57 | 75 | | |
58 | 76 | | |
59 | 77 | | |
60 | | - | |
61 | | - | |
| 78 | + | |
62 | 79 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
66 | 87 | | |
67 | 88 | | |
68 | 89 | | |
69 | 90 | | |
70 | | - | |
| 91 | + | |
71 | 92 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
79 | 103 | | |
80 | 104 | | |
81 | 105 | | |
82 | 106 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 107 | + | |
91 | 108 | | |
92 | | - | |
93 | | - | |
94 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
95 | 122 | | |
96 | 123 | | |
97 | | - | |
| 124 | + | |
98 | 125 | | |
99 | 126 | | |
100 | | - | |
| 127 | + | |
| 128 | + | |
101 | 129 | | |
102 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
103 | 141 | | |
104 | 142 | | |
105 | 143 | | |
| |||
147 | 185 | | |
148 | 186 | | |
149 | 187 | | |
150 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
151 | 191 | | |
152 | 192 | | |
153 | | - | |
| 193 | + | |
| 194 | + | |
154 | 195 | | |
155 | 196 | | |
156 | 197 | | |
| |||
193 | 234 | | |
194 | 235 | | |
195 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
196 | 262 | | |
197 | 263 | | |
198 | 264 | | |
| |||
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
65 | 75 | | |
66 | 76 | | |
67 | 77 | | |
| |||
0 commit comments