Commit e9e3d43d
e9e3d43d23d3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
docs(promote): record leading-splat masgn (860) and the block-param iteration analyze-level blocker
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- e9e3d43d23d3
- Parent
- c7663cecf992
docs/promote-mode-plan.mdmodifiedView file
@@ -73,9 +73,11 @@
7373
- **instance_exec/instance_eval block-param(dbc46864, +16)**: lifted block の `lv_<param> = <arg>` 束縛が int arg を poly slot へ。numbered/requireds(直接 arg・auto-splat 要素・trampoline arg)/keyword の 4 経路で slot poly なら `emit_boxed`。codegen_call.c:5268+。7474
- **(a..b).each fusion(07e55f26, +3)**: loop var を int 直駆動。poly counter は fresh `mrb_int` で駆動し毎 iter `lv_i=sp_box_int(_tc)`(emit_for と同パターン)。codegen_call.c:10749。7575
- **masgn target boxing(694f3f89, +7)**: scalar-RHS local(+typed-zero rest default)/tuple-element local・cvar/typed-array destructure get/trailing rights get を box。codegen_stmt.c。76+
- **leading-splat masgn(91c022ce, +1)**: `*xs, last=[..]` の post-splat fixed target を temp 経由 box。splat_destructure 緑。codegen_stmt.c:3672。(promote 860 到達)7677
- **★決定的洞察**: widen pass は `scope->locals[].type`/`ivar_types`/`cvar_types` だけ書き換え、**node-type cache は更新しない**。ゆえに `comp_ntype(c, target_node)` は **widen 前のスカラ型(int 等)を返す**。slot が poly かは必ず `scope_local(scope, name)->type`(or ivar/cvar の type 配列)で判定すること。rvalue を box する型は `comp_ntype(value)`(真の値型)で取る。この non-update のおかげで rest default の typed-zero(`default_value(int)="0"`)も復元でき、`emit_boxed_text(int,"0")`=`sp_box_int(0)` で quirk 一致。7778
- **残 ERR=101 の内訳(first-error 集計 `/tmp/perr_lines.txt` の手法で再取得可)**: B1 assign-poly の未カバー site = **leading-splat masgn**(`*xs, last=`、trailing を temp 経由で bind)+ **rightward pattern**(`expr => a,b` は MultiWriteNode でなく MatchRequiredNode の別経路)。**B4 builtin-arg coerce(~29)**= poly arg を builtin の int/typed param へ(`sp_IntArray_push`/`sp_poly_to_i`/`sp_poly_to_s`/`sp_bigint_new_int`/`sp_range_include`/user `<=>` 等、call-arg site で coerce、最も散在)。他に return mismatch・invalid binary operands・closure capture(front-end)・float coerce が少数。FAIL=33 は別途(コンパイルは通るが出力差)。78-
- **次の一手**: B4(builtin call-arg coerce)が次の塊。`compile_typed_call_args` 相当の call-arg emission で poly arg→int param に `sp_poly_to_i`、float param に `sp_poly_to_f`、bigint へは `.v.p` を挿す中央 coerce を入れると散在分が一気に閉じる見込み。並行で leading-splat/rightward の 2 site。手法=`/tmp/ptest.sh <name>`(単体 promote compile+diff)、`/tmp/perragg.sh`(全 ERR 並列 first-error 集計)。79+
- **★次の大物 = ブロック反復 block-param(analyze レベル、codegen boxing では直せない)**: `[1,2,3,4].filter_map{|x| x*2 if x.even?}` 系。widen は block-param の scope local を poly 化するが、**最終 infer_type pass(analyze.c:2296 の全 node 再 infer)が typed-array 反復の block-param を element 型(int)に再導出して widen を打ち消す**。一方 `even?` 等一部の codegen 経路は scope local(poly)を読む → **同一 body 内で同じ `x` が int(`sp_int_mul`)と poly(`sp_poly_to_i`)に混在**し、反復束縛も `mrb_int lv_x__bp = Array_get(...)`(element 型 decl)が外側 `sp_RbVal lv_x__bp`(widen slot)を **shadow 二重宣言**。codegen で decl を poly 化すると body の `sp_int_mul(poly,..)` が新たに壊れる(=codegen 単独で不可)。**正解は analyze 側で block-param 型解決を widen と一貫させる**(typed-array 反復 param も promote で poly に固定、final infer で上書きさせない)。**inference 変更=default/optcarrot 回帰リスク**ゆえ専用に慎重に。each/map/select/filter_map/reduce 系の最大グループ(sample 10 中 4 がこの shadow pattern)。80+
- **次の一手(codegen 級)**: B4(builtin call-arg coerce、genuine な poly arg→int builtin param のみ)。`compile_typed_call_args` 相当の call-arg emission で poly arg→int param に `sp_poly_to_i`、float→`sp_poly_to_f`、bigint→`.v.p` を挿す中央 coerce。並行で rightward pattern(`expr=>a,b`=MatchRequiredNode 別経路)。手法=`/tmp/ptest.sh <name>`(単体 promote compile+diff)、`/tmp/perragg.sh`(全 ERR 並列 first-error 集計→`/tmp/perr_lines.txt`)。7981
8082
### (参考)legacy 方式8183
legacy backend(`legacy/spinel_codegen.rb` L55, L3037-3203)は promote で全 int slot を `sp_Bigint*` に widen(method ABI = `(void*, sp_Bigint*...) -> sp_Bigint*`)。採用せず(上記理由)。