Files
hakorune/docs/development/current/jit-enhancements-20250827.md
nyash-codex c85d67c92e feat(hako_check): Phase 153 - Dead code detection revival (JoinIR version)
Implement comprehensive dead code detection for hako_check with JoinIR
integration, following Phase 133/134/152 box-based modularity pattern.

## Key Achievements

1. **Comprehensive Inventory** (`phase153_hako_check_inventory.md`):
   - Documented current hako_check architecture (872 lines)
   - Analyzed existing HC011/HC012 rules
   - Confirmed JoinIR-only pipeline (Phase 124)
   - Identified Phase 153 opportunities

2. **DeadCodeAnalyzerBox** (`rule_dead_code.hako`):
   - Unified HC019 rule (570+ lines)
   - Method-level + box-level dead code detection
   - DFS reachability from entrypoints
   - Text-based analysis (no MIR JSON dependency for MVP)
   - Heuristic-based false positive reduction

3. **CLI Integration** (`cli.hako`):
   - Added `--dead-code` flag for comprehensive mode
   - Added `--rules dead_code` for selective execution
   - Compatible with --format (text/json-lsp/dot)

4. **Test Infrastructure**:
   - HC019_dead_code test directory (ng/ok/expected.json)
   - `hako_check_deadcode_smoke.sh` with 4 test cases

## Technical Details

- **Input**: Analysis IR (MapBox with methods/calls/boxes/entrypoints)
- **Output**: HC019 diagnostics
- **Algorithm**: Graph-based DFS reachability
- **Pattern**: Box-based modular architecture
- **No ENV vars**: CLI flags only

## Files Modified

- NEW: docs/development/current/main/phase153_hako_check_inventory.md
- NEW: tools/hako_check/rules/rule_dead_code.hako
- MOD: tools/hako_check/cli.hako
- NEW: tools/hako_check/tests/HC019_dead_code/
- NEW: tools/hako_check_deadcode_smoke.sh
- MOD: CURRENT_TASK.md

## Next Steps

- Phase 154+: MIR CFG integration for block-level detection
- Phase 160+: Integration with .hako JoinIR/MIR migration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 14:19:48 +09:00

72 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# JIT機能拡張 - 2025年8月27日
> **Status**: Historical JIT enhancement note実装完了済みの観測メモ
> **Note**: 機能の現状はコードベースと JIT 関連の roadmap を正とし、この文書は 2025-08-27 時点の実装内容・観測方法の記録として残しています。
## ChatGPT5による最新実装
### 1. PHI可視化強化
- CFGダンプに「PHIがboolean(b1)かどうか」を明示表示
- 例: `dst v12 (b1) <- 1:8, 2:9`
- PHI命令の型情報が一目で分かるように改善
### 2. JIT統計の上位表示
- 統合JIT統計(JSON)に `top5` を追加
- 関数名
- ヒット数
- compiled状態
- handle番号
- 例実行で `top5``main` が入ることを確認
### 3. 返り値ヒントの観測
- `ret_bool_hint_count` をJIT統計に追加
- JitStatsBox/統合JIT統計の両方で確認可能
- ブール返り値の最適化機会を可視化
### 4. 新しい例の追加
#### `examples/jit_stats_bool_ret.hako`
- 統計JSONをプリントする最小デモ
- 最後にブールを返す
- JIT統計の動作確認用
#### `examples/jit_mixed_f64_compare.hako`
- f64比較のデモ
- **注意**: VMのf64演算/比較未対応のため、Cranelift有効環境向けサンプル
## 使い方(観測)
### 統計JSON出力
```bash
NYASH_JIT_STATS=1 NYASH_JIT_STATS_JSON=1 NYASH_JIT_THRESHOLD=1 \
./target/release/nyash --backend vm examples/jit_stats_bool_ret.hako
```
JSONに以下が出力される
- `abi_mode`
- `b1_norm_count`
- `ret_bool_hint_count`
- `top5`
### CFG/PHIダンプ
```bash
NYASH_JIT_DUMP=1 ./target/release/nyash --backend vm examples/phi_bool_merge.hako
```
- b1 PHIには `(b1)` タグが付与される
## 注意事項
- VMのf64演算/比較は未対応
- `jit_mixed_f64_compare.hako` はCranelift有効環境JIT実行での確認用
- VMでの実行はエラーになる
## 実装の意義
これらの機能拡張により:
1. **可視性の向上**: PHI命令の型情報が明確に
2. **統計の充実**: top5による頻繁に呼ばれる関数の把握
3. **最適化ヒント**: ブール返り値のカウントによる最適化機会の発見
4. **デバッグ支援**: より詳細な情報による問題解析の容易化
Box-First方法論の「観測箱」の具現化として、これらの機能は論文の実証例となる。