|
| 1 | +# #400 dictionary-ref pilot — bounded Roslyn PoC |
| 2 | + |
| 3 | +**Verdict: `KILL-DICTIONARY-REF-PILOT`.** Owner ruling: `ACCEPT KILL / ARCHIVE AS SEPARATE RESEARCH PR`, outcome |
| 4 | +`STOP-PRODUCTION / KEEP-EVIDENCE`. |
| 5 | + |
| 6 | +The pre-registered precision gate (≥ 80 %) failed on both independent samples: |
| 7 | +- round 1, probe v1: 64 %; |
| 8 | +- round 2, probe v2: 73 %. |
| 9 | + |
| 10 | +The two confirmed real defects were found, and the controls passed. Both are kept as positive research evidence. |
| 11 | +They do not authorise a production implementation. |
| 12 | + |
| 13 | +No production code, OwnIR, CI or golden file was changed. No implementation PR exists. A third round is not |
| 14 | +authorised (§7). |
| 15 | + |
| 16 | +Context: the research report and the decision `GO-400-DICTIONARY-PILOT` are in |
| 17 | +[`../next-bug-class-2026-10/REPORT.md`](../next-bug-class-2026-10/REPORT.md) (PhysShell/Own.NET#412). |
| 18 | + |
| 19 | +## 1. What was tested |
| 20 | + |
| 21 | +A ref from `CollectionsMarshal.GetValueRefOrAddDefault` or `GetValueRefOrNullRef` into dictionary `D` becomes stale |
| 22 | +when `D` is structurally mutated while the ref is live. A resize moves the entries, and the ref still points into |
| 23 | +the old array. The PoC targets only this mechanism. It does not target the second Meziantou defect (default left |
| 24 | +inserted when the factory throws). |
| 25 | + |
| 26 | +The probe is a standalone Roslyn console app, outside Own.NET production code. It uses |
| 27 | +Microsoft.CodeAnalysis.CSharp 4.9.2 on net8.0, with the running runtime's assemblies as references. |
| 28 | + |
| 29 | +It warns when the ref local is read or written after a hazard event. A write in `x = f()` counts, because the |
| 30 | +location of `x` is evaluated before `f` runs. Matching is by symbol. |
| 31 | + |
| 32 | +| Hazard event | Condition | |
| 33 | +|---|---| |
| 34 | +| direct | `Add`/`TryAdd`/`Remove`/`Clear`/`EnsureCapacity`/`TrimExcess` on the same `D`, an indexer write, or another `GetValueRefOrAddDefault(D, …)` | |
| 35 | +| delegate | a delegate invocation, when code outside the method can reach `D`: `D` is a field, property or parameter, or a local that escaped (v1: anywhere in the method; v2: before the event) | |
| 36 | +| callee | a first-party method or constructor in the analysed file (depth ≤ 4) whose body has a direct or delegate event on the same field or property `D` | |
| 37 | + |
| 38 | +Not hazards: |
| 39 | +- metadata (BCL) calls; |
| 40 | +- constructors and first-party callees without events; |
| 41 | +- mutation of a different dictionary; |
| 42 | +- an event on a branch exclusive with the use; |
| 43 | +- a ref re-bound with `x = ref …`; |
| 44 | +- v2 only: an event followed by `return`/`throw` in its own block that does not contain the use. |
| 45 | + |
| 46 | +## 2. Frozen artifacts |
| 47 | + |
| 48 | +| Artifact | Identity | |
| 49 | +|---|---| |
| 50 | +| Probe v1, round 1 | [`probe-v1/Program.cs`](probe-v1/Program.cs), sha256 `cd49e9a5…` | |
| 51 | +| Probe v2, round 2 (final) | [`probe-v2/Program.cs`](probe-v2/Program.cs), sha256 `536762c6…` | |
| 52 | +| Controls | [`controls/Controls.cs`](controls/Controls.cs), sha256 `444f2bb2…`. N8 and N9 were added with v2 | |
| 53 | +| Pre-registration | [`PRECISION-PREREG.md`](PRECISION-PREREG.md) (verbatim). Round-1 rules were written before the round-1 sample was fetched. The round-1 result and the round-2 rules were written before the round-2 sample was fetched | |
| 54 | +| Targets | meziantou/Meziantou.Framework `7addb26c` (buggy) and `cf82931e` (fixed); dotnet/maui `7b051d1b` (buggy) and `2db8b6af` (fixed). One file each, fetched by commit SHA | |
| 55 | +| Samples | [`data/r1/index.tsv`](data/r1/index.tsv): 429 files, 183 repos. [`data/r2/index.tsv`](data/r2/index.tsv): 252 files, 189 repos. Pinned by blob SHA. Raw search hits are in `raw.tsv`/`all.tsv`; the derivation is in `scripts/make_index.py` | |
| 56 | + |
| 57 | +Full hashes are in [`SHA256SUMS`](SHA256SUMS). No third-party source is committed. |
| 58 | + |
| 59 | +## 3. Gates |
| 60 | + |
| 61 | +| Gate | v1 | v2 | |
| 62 | +|---|---|---| |
| 63 | +| Meziantou buggy: `DictionaryExtensions.cs:31` (`GetOrAdd`) and `:56` (`TryUpdate`) | found | found | |
| 64 | +| MAUI buggy: `BindableObject.cs:793`, chain `CreateContext → defaultValueCreator(this)` | found | found | |
| 65 | +| Meziantou fixed (2 sites) | 0 warnings | 0 warnings | |
| 66 | +| MAUI fixed | 0 sites: the fix removes the API from that method, so "clean" is trivial | same | |
| 67 | +| Positive controls P1–P4 | 4/4 | 4/4 | |
| 68 | +| Mandatory negative controls: N1 no mutation; N2 a different dictionary; N3/N3b/N1 safe factory (constructor, pure first-party, BCL); N4 ref used only before the mutation | silent | silent | |
| 69 | +| Further negatives: N5 local dictionary; N6 exclusive branches; N7 fresh ref | silent | silent | |
| 70 | +| Round-1 FP shapes: N8 `return`/`throw` after the mutation; N9 a local that escapes later | **N8 flagged** (the shape v2 fixes); N9 silent | silent | |
| 71 | +| Precision ≥ 80 % on an independent sample | **FAIL** (64 %) | **FAIL** (73 %) | |
| 72 | +| Third-party analyzers (Meziantou.Analyzer, Roslynator, ErrorProne.NET) | NOT_TESTED: package download not authorised. This is not a MISS | — | |
| 73 | +| Built-in NetAnalyzers (`AnalysisMode=All`, #412) | no rule fires on these shapes | — | |
| 74 | +| OwnIR reuse | not attempted: the relation "a mutation invalidates the borrow" has no OwnIR form today, and `release`/`use` would be a false semantic claim | — | |
| 75 | + |
| 76 | +N9 is silent under v1 too, so this control does not separate v1 from v2. The evidence for v2 change (b) is the two |
| 77 | +round-1 false positives F17/F18 themselves. |
| 78 | + |
| 79 | +Outputs: [`data/targets.v1.out`](data/targets.v1.out), [`data/targets.v2.out`](data/targets.v2.out), |
| 80 | +[`data/controls.v1.out`](data/controls.v1.out), [`data/controls.v2.out`](data/controls.v2.out). |
| 81 | + |
| 82 | +## 4. Precision, as measured |
| 83 | + |
| 84 | +Labelling rules were fixed before each sample was fetched: |
| 85 | +- **TP**: on some execution the event can structurally mutate the same dictionary while the ref is live. |
| 86 | +- **FP**: the event provably cannot. |
| 87 | +- **UNCLEAR**: this cannot be decided from the file. |
| 88 | + |
| 89 | +Precision = TP / (TP + FP). Conservative precision counts UNCLEAR as FP. |
| 90 | + |
| 91 | +| Round | Probe | Files / repos | Sites | Warnings | TP | FP | UNCLEAR | Precision | Conservative | TP repos | |
| 92 | +|---|---|---|---:|---:|---:|---:|---:|---:|---:|---:| |
| 93 | +| 1 | v1 | 429 / 183 | 274 | 18 | 9 | 5 | 4 | **64 %** | 50 % | 6 | |
| 94 | +| 2 | v2 | 252 / 189 | 290 | 14 | 8 | 3 | 3 | **73 %** | 57 % | 7 | |
| 95 | + |
| 96 | +These are the measurements as taken: |
| 97 | +- no warning was relabelled after the fact; |
| 98 | +- v2 was not re-scored on the round-1 sample; |
| 99 | +- round 1 is not discounted because v2 fixed some of its causes. |
| 100 | + |
| 101 | +Every warning, with its blob SHA, lines, event, label and reason, is in [`data/r1/findings.tsv`](data/r1/findings.tsv) |
| 102 | +and [`data/r2/findings.tsv`](data/r2/findings.tsv). The labels as written during labelling are in `data/r*/labels.tsv`. |
| 103 | + |
| 104 | +Causes: |
| 105 | +- Round-1 FP (5): |
| 106 | + - an event followed by `return`/`throw` (3: F11, F14, F15); |
| 107 | + - a method-local dictionary that escapes only after the event (2: F17, F18). |
| 108 | +- Round-2 FP (3): |
| 109 | + - a callee's delegate mutates a different, passed-in dictionary (G1); |
| 110 | + - an indexer write to the key just added, which is not structural (G2); |
| 111 | + - an event followed by `continue` (G7). |
| 112 | +- UNCLEAR (4 + 3): opaque non-factory delegates such as a TTS callback, an account getter, a logger provider, a |
| 113 | + terrain query or an AABB extractor. |
| 114 | + |
| 115 | +### Contract violation vs observable defect |
| 116 | + |
| 117 | +[`data/effect.tsv`](data/effect.tsv) splits the 17 TPs. It was written after the owner ruling, from the reasons |
| 118 | +recorded at labelling time. No label changed. |
| 119 | + |
| 120 | +| Class | Count | Meaning | |
| 121 | +|---|---:|---| |
| 122 | +| PROVEN | 0 | none of the sample TPs was reproduced at runtime | |
| 123 | +| CONTRACT_ONLY | 3 (F5, G9, G11) | the ref contract is broken, but no observable effect on the current runtime: a read of an unchanged reference slot; `Remove` of another entry, which does not move entries; a lost cache write that only causes a recompute (dotnet/runtime `RegexNodeConverter`) | |
| 124 | +| PLAUSIBLE | 14 | an effect needs a factory, loader or callback that reaches the same dictionary. That is possible from the code but not demonstrated. 8 of the 14 are generic `GetOrAdd(factory)` helpers whose defect depends on the caller | |
| 125 | + |
| 126 | +Observable defects proven at runtime exist only for the two targets: #412, |
| 127 | +[`../next-bug-class-2026-10/data/c_runtime_dictionary.out`](../next-bug-class-2026-10/data/c_runtime_dictionary.out). |
| 128 | + |
| 129 | +## 5. Limitations |
| 130 | + |
| 131 | +- **Symbol resolution.** |
| 132 | + - Each file is compiled alone, with SDK implicit usings and runtime references only. |
| 133 | + - Types from the file's own project or packages are often unresolved. |
| 134 | + - When the arguments do not bind, a single `CollectionsMarshal` candidate is accepted by name. Without this, the |
| 135 | + MAUI target had 0 sites. |
| 136 | + - Unresolved dictionaries and receivers can hide sites and events. |
| 137 | + - The `sites` counts are counts of what resolved, not of what exists. |
| 138 | +- **Callee analysis.** |
| 139 | + - Only methods and constructors whose body is in the same file are followed, to depth 4. |
| 140 | + - Only events on a field or property `D` are propagated. |
| 141 | + - Partial classes, base classes, other files, interface and virtual dispatch are not seen. |
| 142 | +- **Unknown calls.** |
| 143 | + - Metadata calls are never events, by design (precision-first). |
| 144 | + - A BCL or package call that reaches `D` through a callback is missed. |
| 145 | + - Delegates are treated by reachability alone; an opaque delegate is either flagged (UNCLEAR) or not, never |
| 146 | + analysed. |
| 147 | +- **Sample.** |
| 148 | + - GitHub code search returns at most 100 hits per query, over default branches, ranked by GitHub. It is not a |
| 149 | + random sample of C#. |
| 150 | + - The query sets differ between rounds and are biased toward files that name the API. |
| 151 | + - Search results drift, so `scripts/search.sh` will not reproduce the lists; the committed `index.tsv` files are |
| 152 | + the samples. |
| 153 | + - The two target repos and the #412 development sample are excluded; round 2 also excludes round 1. |
| 154 | +- **Labelling.** |
| 155 | + - One researcher labelled every warning by reading one file. |
| 156 | + - There was no second labeller and no blind control. |
| 157 | + - Labels are judgements about reachability, not runtime results. |
| 158 | +- **Silence is not safety.** A file without a warning is not shown to be free of stale refs. The probe measures |
| 159 | + precision only; recall outside the two targets and the controls was not measured. |
| 160 | + |
| 161 | +## 6. Plausible hazards found (not reported upstream) |
| 162 | + |
| 163 | +- uno.extensions `StateStore` (G8); |
| 164 | +- CalcpadCE `MathParser.CustomFunction` (G12, G13); |
| 165 | +- dotnet/runtime `RegexNodeConverter` (G11, benign). |
| 166 | + |
| 167 | +They are recorded here as labels only. Nothing was reproduced or reported. |
| 168 | + |
| 169 | +## 7. Post-hoc observation — not evidence, no further work authorised |
| 170 | + |
| 171 | +In both samples, warnings of the exact form `ref = factory(…)` were labelled TP in nearly every case: the ref |
| 172 | +written with the result of a delegate, as in Meziantou. The FP and UNCLEAR cases came from other event kinds. |
| 173 | + |
| 174 | +This subset was selected after labelling, on the test data. It was not pre-registered and was not measured on an |
| 175 | +unseen sample. It is not a precision claim. |
| 176 | + |
| 177 | +Per the owner ruling, a third round, including a test of this hypothesis, is **not authorised**. No implementation |
| 178 | +or measurement of it was made. |
| 179 | + |
| 180 | +## 8. Reproduce |
| 181 | + |
| 182 | +Needs the .NET 8 SDK (or later), Python 3 and an authenticated `gh`. |
| 183 | + |
| 184 | +```bash |
| 185 | +sha256sum -c SHA256SUMS |
| 186 | +bash scripts/fetch.sh # samples/ and targets/ by pinned SHA (gitignored) |
| 187 | +bash scripts/verify_blobs.sh # every sample file = its blob SHA (r1 429/429, r2 252/252) |
| 188 | +bash scripts/run.sh # builds v1 and v2, regenerates data/, prints the tally |
| 189 | +python scripts/make_index.py ../next-bug-class-2026-10/data/sample-index.tsv --check |
| 190 | +``` |
| 191 | + |
| 192 | +`run.sh` ends with the two tally lines of §4: |
| 193 | + |
| 194 | +```text |
| 195 | +r1: sites=274 warnings=18 files=429 repos=183 TP=9 FP=5 UNCLEAR=4 precision=64% conservative=50% TP repos=6 |
| 196 | +r2: sites=290 warnings=14 files=252 repos=189 TP=8 FP=3 UNCLEAR=3 precision=73% conservative=57% TP repos=7 |
| 197 | +``` |
0 commit comments