Skip to content

Commit 33ed71d

Browse files
on-keydayclaude
andcommitted
docs: separate what side tables fix from what they do not
I had been treating "move it to a side table" as the answer to everything in the union section, and attributing costs to it that belong elsewhere. Two claims were wrong. The identifier patching in the generators does not come from where the view is stored. generate.h:469 maps a union field's ident to (*prefix.name()), a dereference of what a generated getter returns, because the field may be absent; code needing the bare name strips the wrapper. A generator emits that for as long as unions exist. And the invariant and the null padding go away because the duplication goes away - branches become the single source - not because the view moved off the node. Those are separable: you could stop duplicating and still keep the view on the node. The section now splits the three symptoms by cause: duplication, doing the derivation in the parser, and unions themselves. Storing analysis results in a side table is a consequence of the first two, not a cause of any of them, and reading it the other way makes it look like it solves the third as well. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 81a2c91 commit 33ed71d

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

rebrgen/docs/draft/ast_prototype_analysis.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,31 @@ if (ast::as<ast::UnionType>(field->field_type)) {
350350
}
351351
```
352352

353-
つまり合成 Field が構造体のメンバ列に居ることの代償を、各生成器が
354-
**飛ばす処理と直す処理**で払っている。side table へ移せばメンバ列に現れないので、
355-
この 2 つがどちらも要らなくなる。逆に、型から辿る経路 (`union_fields`) は
356-
side table への写像に置き換わるだけで役目が変わらない。
353+
この手術は union フィールドのアクセスが getter 呼び出しに写されていることに由来する:
357354

358-
**「区別する必要がなかった」のではなく、型で区別できたので印を足さずに済んでいた**
359-
というのが実態に近い。
355+
```cpp
356+
// generate.h:469
357+
str.map_ident(union_field->ident, "(*", prefix, "." + union_field->ident->ident + "())");
358+
```
359+
360+
union フィールドは存在しないことがあるので、アクセスがポインタ / optional を返す
361+
getter に写る。`(*x.name())` がその形で、素のメンバ名が要る文脈で包みを剥がしている。
362+
**union がある限り生成器はこれを描く。** 構造をどう変えても消えない。
363+
364+
#### 何が何の対価かを分ける
365+
366+
この節の前半 (§1-9 冒頭) で挙げた問題は 3 つあり、原因が別々である。混ぜないこと。
367+
368+
| 症状 | 原因 | 消すには |
369+
| --- | --- | --- |
370+
| `conds.size() == structs.size()` の不変条件、`get_null_cache` の null padding | 導出ビューが構文を**複製**している | 複製をやめる (branches を正本にする)。置き場所は関係ない |
371+
| parser が合成 Ident / Field を scope に push する | 導出を**parser でやっている** | 導出を後段へ移す。ビューの形は関係ない |
372+
| 生成器の getter 化と `(*...)` の剥がし、メンバ列での場合分け | union という**機能そのもの** | 消えない |
373+
374+
**解析結果を side table に置くこと (軸1) はこのどれの直接の原因でもない。**
375+
複製をやめる / 導出を後段へ移す、をやった結果として「導出ビューをどこに置くか」が問われ、
376+
その答えの候補が side table である、という順序になる。逆向きに
377+
「side table にすれば解決する」と読むと、3 行目まで解決するかのように見えてしまう。
360378

361379
---
362380

0 commit comments

Comments
 (0)