Skip to content

型別メソッドカバレッジ — 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|nil] にたためる。中優先度。
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|nil]。低優先度。
casecmp?🔲STRING_BINARY 追加で Constant[bool|nil]。低優先度。
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|nil]。中優先度。
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|nil 返却。低優先度。
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|nil]。中優先度。
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|Float](型推論済み)。
**NUMERIC_BINARY 追加で Constant[Integer|Float]。カタログでもカバー済みだが明示的に追加。
&, |, ^NUMERIC_BINARY 追加で Constant[Integer]。カタログでもカバー済み。
<<, >>NUMERIC_BINARY 追加で Constant[Integer]。カタログでもカバー済み。
~INTEGER_UNARY → Constant[Integer]
<=>, <, <=, >, >=, ==, !=NUMERIC_BINARY → Constant[Integer|bool]
-@, +@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|Integer]
-@, +@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_METHODSConstant[Integer|nil]
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** / & / | / ^ / << / >> → NUMERIC_BINARY
Float** → NUMERIC_BINARY
Array / Tuplevalues_at / + / compact / take → TUPLE_HANDLERS
bool=== → BOOL_BINARY
SetSetShape 不要で対応できる項目なし (size 確認程度)

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