Commit 1e7b3bd3
1e7b3bd38d34Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
docs(promote): record the 2b param-widening attempt and boundary findings
The poly-param widening makes the canonical function-arg overflow case (def mul(x,y)=x*y; mul(1e12,1e12)) promote correctly, but widening a param to poly surfaces ~25 poly<->int boundaries (assignment both ways, yield to an int block param, call args to other methods, comparisons, cvar init) because codegen assumes type consistency and inserts no coercion. Reverted to keep promote at its 972 baseline; documents the boundary buckets so the dedicated sweep can resume from a precise start.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 1e7b3bd38d34
- Parent
- 9c118627a9a5
docs/promote-mode-plan.mdmodifiedView file
@@ -43,7 +43,17 @@
4343
- **Increment 2a (48863f34)**: `sp_poly_add/sub/mul` が bigint operand を bigint 演算へ(全モード、`bigint+int`→0 bug 修正)+ **promote で int+int overflow→bigint 昇格**(`SP_INT_OVERFLOW_MODE_PROMOTE` #ifdef gate、default/wrap は wrap 維持)。→ **既に poly 型の値**は promote で runtime 昇格する。4444
4545
### 残: Increment 2b(本丸 big-bang)= int→poly widen under promote46-
**既に poly な値**は 2a で昇格するが、関数引数など**静的に int な slot** は poly でないので overflow しても昇格できない。最後の山は promote モードで該当 int slot を **poly に widen**する analyze 変更。これが all-or-nothing(部分 widen は promote suite の現 972 を割る)。widen 先が bigint(legacy)でなく **poly** な点が違い: 小さい値は unbox のまま、overflow 時だけ 2a の機構で box。46+
**既に poly な値**は 2a で昇格するが、関数引数など**静的に int な slot** は poly でないので overflow しても昇格できない。最後の山は promote モードで該当 int slot を **poly に widen**する analyze 変更。widen 先が bigint(legacy)でなく **poly** な点が違い: 小さい値は unbox のまま、overflow 時だけ 2a の機構で box。47+
48+
**2026-06-19 試行の知見(revert 済、master は 2a の promote 972 のまま):**49+
- `promote_widen_arith_params`(analyze.c の re-narrow 後 hook): `def` メソッド param のうち `+`/`-`/`*`/`**` の直接 operand を poly 化(block param・非 DefNode scope は除外)→ **c2 = `def mul(x,y)=x*y; mul(10^12,10^12)` が 1e24 で動いた**(MRI 一致)。50+
- しかし promote suite が **972→947(25 err/3 fail)**に退行。退行の本質: codegen は型一致を前提に coercion を挿入しないので、widen した poly param が int slot に出会う所が全部境界化:51+
- `mrb_int = sp_RbVal`(poly param → int local / cvar 代入、両方向)52+
- `yield x` で poly を int block param へ(`n = poly`)53+
- `sp_double(poly)`(別メソッド呼びの int param へ coercion 無し)54+
- `mrb_int == sp_RbVal`(比較)/ cvar init が非定数55+
- 伝播 pass を増やす(infer_block_params/ivar/cvar/param/return を post-widen で回す)と境界が**ずれるだけ**(whack-a-mole)。56+
- **結論**: 2b は「全 poly↔int 境界 site で coercion を挿入する codegen sweep」(代入両方向 / yield / call-arg / 比較 / cvar)を要する真の big-bang。専用セッションで境界バケツを 1 つずつ。あるいは sound な uniform widen(全 int→poly + 境界 coercion 完備)。c2 が動く事は確認済みなので方式自体は正しい、残りは境界網羅。4757
4858
### (参考)legacy 方式4959
legacy backend(`legacy/spinel_codegen.rb` L55, L3037-3203)は promote で全 int slot を `sp_Bigint*` に widen(method ABI = `(void*, sp_Bigint*...) -> sp_Bigint*`)。採用せず(上記理由)。