Commit 38233dfe
38233dfe74c4Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
docs(promote): record range/string poly-arg coercion (912) and remaining one-off map
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 38233dfe74c4
- Parent
- 831caa0bf282
docs/promote-mode-plan.mdmodifiedView file
@@ -78,7 +78,9 @@
7878
- **★block-param widen 除外(0ed24068, 860→901、+41!)= 本セッション最大の勝因**: block-param 反復(`[1,2,3,4].filter_map{|x| x*2 if x.even?}`)は最大グループだった。**真因**: widen は block-param の scope local を poly 化するが、block emitter は use_shadow で param を element 型(int)に retype して body を再 infer する。だが **`even?` 等メソッド呼びの inference は receiver を cache から読むだけで再 infer しない**(`*` 演算子は operand を infer_type で更新する)ので、`x*2`=int / `x.even?`=poly に混在し、`mrb_int lv_x` shadow が外側 `sp_RbVal lv_x`(widen)を二重宣言。**解=block-param を widen から除外**(`is_block_param` skip、analyze.c:2275)。block-param は反復コレクションの element 型で型付くべきで、widen は害だけ。method param は引き続き widen(promote の本旨)。compile error と一致する output-mismatch FAIL も一掃。**当初は「analyze で型を一貫 poly 化」を想定したが、逆に「block-param は widen しない」が正解だった。**7979
- **poly→scalar unbox(29dbedea, 901→909)**: block-param を int に保ったことで、poly source(widen された yield 値・ivar・trampoline temp)を int block-param へ束縛する逆方向が必要に。emit_block_invoke の yield 束縛 + instance_exec の is_exec/tramp 束縛に `bt scalar && at poly → emit_unbox_text` arm を追加(box arm の対称)。yield/forward_args_block/block_forward_*/inlined_yield_self_locals/instance_exec_mixed_args 緑。8080
- **残 ERR=64 / FAIL=20(`/tmp/perr2.txt` の手法で再取得)**: **B4 builtin-arg coerce(~19)**= poly arg を builtin の int/typed param へ(`sp_bigint_new_int`/`sp_range_include`/`sp_str_sub_range(_r)`/user `<=>`=`_lt_set_gt`/`sp_collect_s` 等、call-arg site で散在 coerce)。**B6 残(poly→int 代入)**= まだ拾い切れてない束縛 site。**B1 残(int→poly 代入、8)**。**closure capture(front-end, 5)**=`unsupported closure capturing a non-integer variable`(widen で capture 変数が poly 化→closure が非 int capture 非対応、front-end 制限)。他に return mismatch(3)/invalid binary operands(4)/invalid initializer(2)/`unsupported p argument`(clamp)等。**FAIL=20** はコンパイル通るが出力差(例: `proc` が proc 戻り値で `6`→`0`)、別途調査。81-
- **次の一手**: (1) B4 builtin call-arg の中央 coerce(poly arg→int param=`sp_poly_to_i`、float=`sp_poly_to_f`、bigint=`.v.p`)。(2) closure-capture front-end(capture 変数 poly 対応 or widen 除外)。(3) FAIL=20 の出力差(proc 等)。手法=`/tmp/ptest.sh <name>`、`/tmp/perragg.sh`→`/tmp/perr2.txt`、`/tmp/ptest_lastc` に最後の cfile。81+
- **range/string builtin の poly arg coerce(17fa2d32, 909→912)**: `sp_range_include`(include?/case-as-value/when range-membership の 3 site)と string slice/index(`sp_str_sub_range[_r]`/`sp_str_char_at_or_nil`)の int 引数を poly のとき `sp_poly_to_i`(string 側は `emit_int_expr` で一律 coerce)。range/case/truncate_module_method 緑。**poly 経路のみ変化、default 不変**。82+
- **残 ERR=60 / FAIL=21**: B4 builtin-arg coerce の残り = **散在 one-off**(`sp_bigint_new_int(poly)`→本来 `sp_poly_as_bigint`、codegen_stmt.c:510/563/634 の bigint-cell arm / `sp_IntArray_index_poly` arg2 / user `<=>`=`sp_*__lt_set_gt`(構造的に `expected expression before sp_RbVal` も伴う)/ `sp_collect_s` / bound-method `.call` が raw arg を widen poly param へ=codegen_call の bound-method dispatch)。closure-capture front-end(5)。FAIL=21(出力差、proc 6→0 等)。83+
- **次の一手**: (1) 残 B4 one-off を `emit_int_expr`/`sp_poly_as_bigint` で個別 coerce(中央化できる site は emit_int_expr に寄せる)。(2) closure-capture front-end(capture 変数 poly 対応 or widen 除外)。(3) FAIL=21 の出力差(proc 等)。手法=`/tmp/ptest.sh <name>`、`/tmp/perragg.sh`→`/tmp/perr2.txt`、`/tmp/ptest_lastc` に最後の cfile。**poly→int は `emit_int_expr`、poly→float は `emit_float_expr`、poly→bigint は `sp_poly_as_bigint` が既存の中央ヘルパー。**8284
8385
### (参考)legacy 方式8486
legacy backend(`legacy/spinel_codegen.rb` L55, L3037-3203)は promote で全 int slot を `sp_Bigint*` に widen(method ABI = `(void*, sp_Bigint*...) -> sp_Bigint*`)。採用せず(上記理由)。