コンテンツにスキップ

型別メソッドカバレッジ — ConstantFolding / ShapeDispatch / ExpressionTyper 監査

2026-05-22生成。Ruby 4.0の"".methods - Object.new.methods等から型ごとに固有メソッドを抽出し、現在の精度カバレッジを分類する。


記号意味
ConstantFolding(invoke_unary/invoke_binary)またはShapeDispatch / ExpressionTyperブロックフォールドで実装済み
🔷別ティア処理済み(BlockFolding / LiteralStringFolding / RBSで十分精度が出る)
🔲未実装だが精度向上の価値あり
🚫非対象(破壊的変更・Enumerator生成・精度向上がnegligible)

Constant[String]STRING_UNARY / STRING_BINARYで処理。
特殊ケース: %try_fold_string_formatchars/bytes/lines/splittry_fold_string_array_unary/_binary
<</concat / +(リテラル文字列連結)→ LiteralStringFolding

メソッド状態備考
%try_fold_string_format — Tuple / HashShape引数対応。
*STRING_BINARY — Constant["ab"] * 3Constant["ababab"]
+STRING_BINARY。リテラル連結はLiteralStringFoldingも担当。
<<🔷LiteralStringFoldingでliteral-string精度維持。破壊的変更。
<=>STRING_BINARY → Constant[Integer]
<, <=, >, >=, ==, !=STRING_BINARY → Constant[bool]
[] / slice🔲整数インデックスまたはRange引数で`Constant[String
ascii_only?🔲STRING_UNARY追加でConstant[bool]。低優先度。
b🚫BINARYエンコーディングで複製。精度向上なし。
bytesizeSTRING_UNARY → Constant[Integer]
bytestry_fold_string_array_unaryTuple[Constant[Integer]…]
capitalizeSTRING_UNARY → Constant[String]
capitalize!🚫破壊的変更。
casecmp🔲STRING_BINARY追加で`Constant[Integer
casecmp?🔲STRING_BINARY追加で`Constant[bool
center🔲STRING_BINARY追加でConstant[String]。中優先度。
charstry_fold_string_array_unaryTuple[Constant[String]…]
chompSTRING_UNARY → Constant[String]
chomp!🚫破壊的変更。
chop🔲STRING_UNARY追加でConstant[String]。中優先度。
chop!🚫破壊的変更。
chr🔲STRING_UNARY追加でConstant[String](最初の1文字)。中優先度。
clear🚫破壊的変更。
concat🔷LiteralStringFoldingでliteral-string精度維持。
count🔲STRING_BINARY追加でConstant[Integer](文字数カウント)。低優先度。
delete🔲STRING_BINARY追加でConstant[String]。低優先度。
delete!🚫破壊的変更。
delete_prefixSTRING_BINARY追加でConstant[String]高優先度
delete_prefix!🚫破壊的変更。
delete_suffixSTRING_BINARY追加でConstant[String]高優先度
delete_suffix!🚫破壊的変更。
downcaseSTRING_UNARY → Constant[String]
downcase!🚫破壊的変更。
dump🔲STRING_UNARY追加でConstant[String]。低優先度。
each_byte / each_char / each_line / each_codepoint🚫反復子 / Enumerator。
empty?STRING_UNARY → Constant[bool]
encode🔲エンコーディング引数あり。中優先度。
encode!🚫破壊的変更。
encoding🔲STRING_UNARY追加でConstant[Encoding]。低優先度。
end_with?STRING_BINARY追加でConstant[bool]高優先度
force_encoding🚫破壊的変更(エンコーディング変更)。
gsub🔲Regexp引数で複雑。低優先度。
gsub!🚫破壊的変更。
hashSTRING_UNARY → Constant[Integer]
hex🔲STRING_UNARY追加でConstant[Integer]。中優先度。
include?STRING_BINARY追加でConstant[bool]高優先度
index🔲STRING_BINARY追加で`Constant[Integer
insert🚫破壊的変更。
inspectSTRING_UNARY → Constant[String]
intern / to_symSTRING_UNARY → Constant[Symbol]
length / sizeSTRING_UNARY → Constant[Integer]
linestry_fold_string_array_unaryTuple[Constant[String]…]
ljust🔲STRING_BINARY追加でConstant[String]。中優先度。
lstripSTRING_UNARY → Constant[String]
lstrip!🚫破壊的変更。
match🔲Regexp引数、`MatchData
match?🔲STRING_BINARY追加でConstant[bool]。中優先度。
next / succ🔲STRING_UNARY追加でConstant[String]。中優先度。
next! / succ!🚫破壊的変更。
oct🔲STRING_UNARY追加でConstant[Integer]。中優先度。
ordSTRING_UNARY追加でConstant[Integer](最初のコードポイント)。高優先度
prepend🚫破壊的変更。
replace🚫破壊的変更。
reverseSTRING_UNARY → Constant[String]
reverse!🚫破壊的変更。
rindex🔲STRING_BINARY追加で`Constant[Integer
rjust🔲STRING_BINARY追加でConstant[String]。中優先度。
rstripSTRING_UNARY → Constant[String]
rstrip!🚫破壊的変更。
scantry_fold_string_array_binaryTuple[Constant[String]…]
scrub🔲STRING_UNARY追加でConstant[String]。低優先度。
splittry_fold_string_array_unary / _binary対応。
squeeze🔲STRING_UNARY追加でConstant[String]。低優先度。
start_with?STRING_BINARY追加でConstant[bool]高優先度
stripSTRING_UNARY → Constant[String]
strip!🚫破壊的変更。
sub🔲Regexp引数で複雑。低優先度。
sub!🚫破壊的変更。
swapcaseSTRING_UNARY → Constant[String]
swapcase!🚫破壊的変更。
to_c🔲STRING_UNARY追加でConstant[Complex]。低優先度。
to_fSTRING_UNARY追加でConstant[Float]高優先度
to_iSTRING_UNARY追加でConstant[Integer]高優先度
to_r🔲STRING_UNARY追加でConstant[Rational]。低優先度。
to_s / to_strSTRING_UNARY → Constant[String]
tr🔲文字置換。低優先度。
tr!🚫破壊的変更。
undump🔲STRING_UNARY追加でConstant[String]。低優先度。
unicode_normalize🔲STRING_UNARY追加でConstant[String]。低優先度。
upcaseSTRING_UNARY → Constant[String]
upcase!🚫破壊的変更。
upto🚫Enumerator。
valid_encoding?🔲STRING_UNARY追加でConstant[bool]。低優先度。

1-2. 実装チェックリスト(優先度順)

Section titled “1-2. 実装チェックリスト(優先度順)”
高優先度(Constant[String] / Constant[bool] への折りたたみで頻用パターンをカバー):
[x] start_with? → STRING_BINARY に追加 → Constant[bool]
[x] end_with? → STRING_BINARY に追加 → Constant[bool]
[x] include? → STRING_BINARY に追加 → Constant[bool]
[x] delete_prefix → STRING_BINARY に追加 → Constant[String]
[x] delete_suffix → STRING_BINARY に追加 → Constant[String]
[x] to_i → STRING_UNARY に追加 → Constant[Integer]
[x] to_f → STRING_UNARY に追加 → Constant[Float]
[x] ord → STRING_UNARY に追加 → Constant[Integer]
中優先度:
[x] chr → STRING_UNARY に追加 → Constant[String]
[x] hex → STRING_UNARY に追加 → Constant[Integer]
[x] oct → STRING_UNARY に追加 → Constant[Integer]
[x] next / succ → STRING_UNARY に追加 → Constant[String]
[x] chop → STRING_UNARY に追加 → Constant[String]
[x] match? → STRING_BINARY に追加 → Constant[bool]
[x] index → STRING_BINARY に追加 → Constant[Integer|nil]
[x] rindex → STRING_BINARY に追加 → Constant[Integer|nil]
[x] center → STRING_BINARY に追加 → Constant[String](幅ブローアップガード付き)
[x] ljust / rjust → STRING_BINARY に追加 → Constant[String](同上)
低優先度:
[ ] casecmp / casecmp? → STRING_BINARY
[ ] count (文字カウント) → STRING_BINARY
[ ] delete → STRING_BINARY
[ ] ascii_only? → STRING_UNARY
[ ] encoding → STRING_UNARY
[ ] squeeze → STRING_UNARY
[ ] valid_encoding? → STRING_UNARY
[ ] [] / slice → 専用ハンドラ(整数インデックス / Range 引数)

実装ファイル: lib/rigor/inference/method_dispatcher/constant_folding.rbSTRING_UNARY / STRING_BINARY


Constant[Integer]INTEGER_UNARY / NUMERIC_BINARYで処理。
IntegerRange向け専用ハンドラ群は別途shape_dispatch.rbに存在。

メソッド状態備考
+, -, *, /, %NUMERIC_BINARY → `Constant[Integer
**NUMERIC_BINARY追加で`Constant[Integer
&, `, ^`
<<, >>NUMERIC_BINARY追加でConstant[Integer]。カタログでもカバー済み。
~INTEGER_UNARY → Constant[Integer]
<=>, <, <=, >, >=, ==, !=NUMERIC_BINARY → `Constant[Integer
-@, +@INTEGER_UNARY。
abs / magnitudeINTEGER_UNARY → Constant[Integer]
bit_lengthINTEGER_UNARY → Constant[Integer]
between?try_fold_ternary(catalog経由)→ Constant[bool]
ceilINTEGER_UNARY(引数なし)→ Constant[Integer]
chrINTEGER_UNARY → Constant[String]
clamptry_fold_ternary(catalog経由)→ Constant[Integer]
coerce🚫内部用。精度向上なし。
digitstry_fold_integer_array_unaryTuple[Constant[Integer]…]
divmodtry_fold_divmodTuple[Constant[Integer], Constant[Integer]]
even?INTEGER_UNARY → Constant[bool]
fdivNUMERIC_BINARY → Constant[Float]
floorINTEGER_UNARY(引数なし)→ Constant[Integer]
gcdNUMERIC_BINARY → Constant[Integer]
gcdlcm🔲INTEGER_BINARY追加でTuple[Constant[Integer], Constant[Integer]]。低優先度。
hashINTEGER_UNARY → Constant[Integer]
inspect / to_sINTEGER_UNARY → Constant[String]
integer?🔲INTEGER_UNARY追加でConstant[true]。低優先度(常にtrue)。
lcmNUMERIC_BINARY → Constant[Integer]
negative? / positive? / zero?INTEGER_UNARY → Constant[bool]
next / succINTEGER_UNARY → Constant[Integer]
odd?INTEGER_UNARY → Constant[bool]
pow🔲**の別名(ただしpow(exp, mod)は剰余乗算)。低優先度。
predINTEGER_UNARY → Constant[Integer]
rationalize / to_r🔲INTEGER_UNARY追加でConstant[Rational]。低優先度。
roundINTEGER_UNARY(引数なし)→ Constant[Integer]
size🔲プラットフォーム依存バイト幅。低優先度。
to_c🔲INTEGER_UNARY追加でConstant[Complex]。低優先度。
to_fINTEGER_UNARY → Constant[Float]
to_i / to_intINTEGER_UNARY → Constant[Integer]
truncateINTEGER_UNARY(引数なし)→ Constant[Integer]
upto / downto / times🚫反復子。

2-2. 実装チェックリスト(優先度順)

Section titled “2-2. 実装チェックリスト(優先度順)”
高優先度(式で多用・Constant[Integer] 精度の核心):
[x] ** → NUMERIC_BINARY → Constant[Integer|Float]
[x] & → NUMERIC_BINARY → Constant[Integer]
[x] | → NUMERIC_BINARY → Constant[Integer]
[x] ^ → NUMERIC_BINARY → Constant[Integer]
[x] << → NUMERIC_BINARY → Constant[Integer]
[x] >> → NUMERIC_BINARY → Constant[Integer]
中優先度:
[x] floor / ceil / round / truncate (引数なし) → INTEGER_UNARY → Constant[Integer]
[x] chr → INTEGER_UNARY → Constant[String]
[x] digits (引数なし) → try_fold_integer_array_unary → Tuple[Constant[Integer]…]
[x] gcd / lcm → NUMERIC_BINARY → Constant[Integer]
[x] divmod → try_fold_divmod → Tuple[Constant[Integer], Constant[Integer]]
[x] fdiv → NUMERIC_BINARY → Constant[Float]
[x] between? → try_fold_ternary(catalog 経由)→ Constant[bool]
[x] clamp → try_fold_ternary(catalog 経由)→ Constant[Integer]
低優先度:
[ ] rationalize / to_r → INTEGER_UNARY
[ ] gcdlcm → INTEGER_BINARY
[ ] pow(exp, mod) → 専用ハンドラ(3 引数形式)

実装ファイル: constant_folding.rbINTEGER_UNARY拡張、またはNUMERIC_BINARYへのキー追加。
invoke_binaryConstant[Integer] op Constant[Integer]のとき自動評価するので定数に追加するだけで折りたたみが機能する


Constant[Float]FLOAT_UNARY / NUMERIC_BINARYで処理。

メソッド状態備考
+, -, *, /, %NUMERIC_BINARY。
**NUMERIC_BINARY追加でConstant[Float]高優先度
<=>, <, <=, >, >=, ==, !=NUMERIC_BINARY → `Constant[bool
-@, +@FLOAT_UNARY。
abs / magnitudeFLOAT_UNARY → Constant[Float]
between?try_fold_ternary(catalog経由)→ Constant[bool]
ceilFLOAT_UNARY(引数なし)→ Constant[Integer]
ceil(n)🔲小数点指定形式の専用ハンドラ → Constant[Float]。低優先度。
clamptry_fold_ternary(catalog経由)→ Constant[Float]
coerce🚫内部用。
divmodtry_fold_divmodTuple[Constant[Integer], Constant[Float]]
fdivNUMERIC_BINARY → Constant[Float]
finite?FLOAT_UNARY → Constant[bool]
floorFLOAT_UNARY(引数なし)→ Constant[Integer]
floor(n)🔲小数点指定形式 → Constant[Float]。低優先度。
hashFLOAT_UNARY → Constant[Integer]
infinite?FLOAT_UNARY → Constant[Integer](-1/0/1)。
inspect / to_sFLOAT_UNARY → Constant[String]
modulo🔷%の別名 → NUMERIC_BINARYで処理。
nan?FLOAT_UNARY → Constant[bool]
negative? / positive? / zero?FLOAT_UNARY → Constant[bool]
next_floatFLOAT_UNARY → Constant[Float]
prev_floatFLOAT_UNARY → Constant[Float]
rationalize / to_r🔲FLOAT_UNARY追加でConstant[Rational]。低優先度。
roundFLOAT_UNARY(引数なし)→ Constant[Integer]
round(n)🔲小数点指定形式 → Constant[Float]。低優先度。
to_c🔲FLOAT_UNARY追加でConstant[Complex]。低優先度。
to_fFLOAT_UNARY → Constant[Float]
to_i / to_int / truncateFLOAT_UNARY → Constant[Integer]

3-2. 実装チェックリスト(優先度順)

Section titled “3-2. 実装チェックリスト(優先度順)”
高優先度:
[x] ** → NUMERIC_BINARY → Constant[Float]
中優先度:
[x] divmod → try_fold_divmod → Tuple[Constant[Integer], Constant[Float]]
[x] between? → try_fold_ternary(catalog 経由)→ Constant[bool]
[x] clamp → try_fold_ternary(catalog 経由)→ Constant[Float]
低優先度:
[ ] ceil(n) / floor(n) / round(n) → 小数点 n 指定形式専用ハンドラ
[x] next_float / prev_float → FLOAT_UNARY
[x] fdiv → NUMERIC_BINARY
[ ] rationalize / to_r / to_c → FLOAT_UNARY

実装ファイル: constant_folding.rbFLOAT_UNARY拡張 / NUMERIC_BINARY追加。


Constant[true] / Constant[false]BOOL_UNARY / BOOL_BINARYで処理。
カバレッジはほぼ完全。

(true.methods - Object.new.methods).sort[:&, :^, :|](TrueClass / FalseClass共通)。

メソッド状態備考
&BOOL_UNARY(引数なし形式)・BOOL_BINARY → Constant[bool]
``
^同上。
!BOOL_UNARY → Constant[bool](論理反転)。
==, !=BOOL_BINARY → Constant[bool]
to_s / inspect / hashBOOL_UNARY → 各Constant型。
===BOOL_BINARY追加でConstant[bool]。低優先度(==と等価な場面がほとんど)。
低優先度(現状カバレッジほぼ完全):
[x] === → BOOL_BINARY に追加 → Constant[bool]

Type::Tupleshape_dispatch.rbTUPLE_HANDLERSexpression_typer.rbPER_ELEMENT_TUPLE_METHODSで処理。

メソッド状態備考
[] / fetchtuple_lookup / tuple_fetch — 整数インデックスで位置別型を返す。
+(連結)Tuple + Tuple → 新しいTuple。高優先度tuple_concat実装。
-(差集合)🔲差集合 → 型が複雑。低優先度。
*(繰り返し)🔲Tuple * n → 繰り返しTuple。低優先度。
<< / push / append🚫破壊的変更(形状変化)。
<=>🔷RBS Integer?で十分。
all?tuple_all? — ブロックなしで要素型確認。BlockFoldingでブロックあり対応。
any?tuple_any? — ブロックなしで要素型確認。
assoc🔲先頭要素マッチ。低優先度。
bsearch🚫複雑な二分探索。
chain🚫Enumerator。
chunk / chunk_while🚫Enumerable。
collect / mapPER_ELEMENT_TUPLE_METHODS — ブロック毎要素適用で新Tuple。
combination / permutation🚫Enumerable。
compactConstant[nil]エントリーを除去したTuple。高優先度tuple_compact実装。
counttuple_count — ブロックなしでConstant[Integer]
cycle🚫Enumerable。
deconstruct🔲パターンマッチ用 — to_aと等価。低優先度。
delete / delete_at / delete_if🚫破壊的変更。
detect / findPER_ELEMENT_TUPLE_METHODS — ブロック毎要素で要素型を返す。
digtuple_dig — 入れ子Tuple / HashShapeを掘る。
drop🔲drop(n) → n要素以降の部分Tuple。中優先度。
drop_while🔷BlockFolding FILTER_KEEP_ON_FALSEY
each / each_with_index / each_with_object🚫反復子。
empty?tuple_empty?Constant[bool]
entries🔷to_aの別名 → RBS経由。
fetchtuple_fetch → 位置別型。
fill🚫破壊的変更。
filter / select🔷BlockFolding FILTER_KEEP_ON_TRUTHY / FALSEY
filter_mapPER_ELEMENT_TUPLE_METHODSnil除去後のUnion Tuple。
firsttuple_first → 先頭n要素(Tupleまたは単一型)。
flat_map / collect_concatPER_ELEMENT_TUPLE_METHODS — 単一ネスト除去。
flatten🔲入れ子Tupleを再帰展開。中優先度。
include?tuple_include?Constant[bool](Constant引数のとき)。
index / find_indexPER_ELEMENT_TUPLE_METHODS → `Constant[Integer
insert🚫破壊的変更。
intersection🔲集合交差。低優先度。
join🔲Tuple要素をStringに連結。中優先度(すべてConstantのときConstant[String])。
keep_if🚫破壊的変更。
lasttuple_last → 末尾n要素。
length / sizetuple_sizeConstant[Integer]
max / mintuple_max / tuple_min → 要素型のUnion。
max_by / min_by🔲ブロックあり形式。BlockFolding非対応。中優先度。
minmax🔲Tuple[min, max]形式。中優先度。
none?tuple_none?Constant[bool]
pack🔲バイナリパッキング → Constant[String]。低優先度。
pop / shift🚫破壊的変更。
product🚫複雑な直積Tuple。
push / unshift🚫破壊的変更。
rassoc🔲低優先度。
reject🔷BlockFolding FILTER_KEEP_ON_FALSEY
repeated_combination / repeated_permutation🚫Enumerable。
reversetuple_reverse → 要素逆順のTuple。
reverse!🚫破壊的変更。
rotate🔲rotate(n) → 回転後のTuple。中優先度。
sample / shuffle🚫非決定論的。
slice🔲values_atと類似。専用ハンドラ。中優先度。
sorttuple_sort → 要素型でソートしたTuple。
sort!🚫破壊的変更。
sort_by🔲ブロックあり。低優先度。
sumtuple_sum → 要素型のUnion。
taketake(n) → 先頭n要素の部分Tuple。高優先度tuple_take実装。
take_while🔷BlockFolding FILTER_KEEP_ON_TRUTHY
tally🔲Hash[elem_type, Integer]。低優先度。
to_atuple_to_a → self。
to_htuple_to_h → HashShape(Tuple[Tuple[K,V]…]形式)。
transpose🔲2次元Tupleの行列転置。低優先度。
union🔲集合和(dedup)。低優先度。
uniq🔲Tuple要素の重複除去。低優先度。
values_atvalues_at(*indices) → 位置指定Tuple。高優先度tuple_values_at実装。
ziptuple_zip → 要素ペアTuple。

5-2. 実装チェックリスト(優先度順)

Section titled “5-2. 実装チェックリスト(優先度順)”
高優先度:
[x] values_at(*indices) → TUPLE_HANDLERS → Tuple[T[i1], T[i2], …]
[x] + (Tuple + Tuple) → TUPLE_HANDLERS → 連結 Tuple
[x] compact → TUPLE_HANDLERS → nil エントリ除去 Tuple
[x] take(n) → TUPLE_HANDLERS → 先頭 n 要素 Tuple
中優先度:
[ ] drop(n) → TUPLE_HANDLERS → n 以降の部分 Tuple
[ ] rotate(n) → TUPLE_HANDLERS → 回転後 Tuple
[ ] flatten → TUPLE_HANDLERS → 1 段ネスト展開(depth=1 限定で実用十分)
[ ] join → TUPLE_HANDLERS → すべて Constant のとき Constant[String]
[ ] slice → TUPLE_HANDLERS → values_at の Range / 2 引数形式
低優先度:
[ ] uniq → TUPLE_HANDLERS → Union 縮小 Tuple
[ ] minmax → TUPLE_HANDLERS → Tuple[min_type, max_type]
[ ] max_by / min_by → ExpressionTyper ブロックフォールド追加

実装ファイル:

  • TUPLE_HANDLERSへの追加: lib/rigor/inference/method_dispatcher/shape_dispatch.rb
  • ブロック系追加: lib/rigor/inference/expression_typer.rbPER_ELEMENT_TUPLE_METHODS

現状、SetはNominal[Set]としてRBSから型を取得。SetShapeキャリアは存在しない。

観点内容
現在の精度RBS Set[T]経由。include?bool返却(Constant[bool]にならない)。
SetShapeがない理由Setのリテラル構文がRubyにない(Set[1, 2, 3]Set.new呼び出し)ため形状を静的に確定しにくい。
精度向上できる範囲SetのSIZE_RETURNING_NOMINALSへの登録でsize/length/countがIntegerRangeを返す(ShapeDispatch側)。それ以上はSetShapeなしでは難しい。
現時点で対応可能(SetShape 不要):
[ ] size / length / count → SIZE_RETURNING_NOMINALS に Set が登録済か確認
(登録済みであれば ✅ — shape_dispatch.rb の SIZE_RETURNING_NOMINALS を参照)
将来的な SetShape 導入時に対応:
[ ] include? / member? → Constant[bool]
[ ] empty? → Constant[bool]
[ ] subset? / superset? → Constant[bool]
[ ] + / | / & / - → 新 Set 型

SetShape導入は現サイクルでは対象外。需要が出た時点でADR化を検討。


2026-05-22時点の高優先度タスクは全件実装済み。

状態実装(2026-05-22)
Stringstart_with? / end_with? / include? / delete_prefix / delete_suffix → STRING_BINARY
Stringto_i / to_f / ord → STRING_UNARY
Integer** / & / `
Float** → NUMERIC_BINARY
Array / Tuplevalues_at / + / compact / take → TUPLE_HANDLERS
bool=== → BOOL_BINARY
SetSetShape不要で対応できる項目なし(size確認程度)

© 2026 TypedDuck. Licensed under CC BY-SA 4.0.