feat(runtime): Phase 98 ConsoleService 代表パス拡張 - 7箇所置き換え完了
## Phase 98 完了項目 - ✅ println!/eprintln! 7箇所 → ConsoleService 経由に移行 - ✅ console_println! マクロ追加(Graceful Degradation パターン) - ✅ try_get_core_plugin_host() 追加(安全なアクセサー) - ✅ 全テストPASS(core_services: 11, plugin_host: 7) ## 置き換え箇所(7箇所) **selfhost/child.rs** (3箇所): - spawn失敗エラー - タイムアウトメッセージ(stdout/stderr) **core_bridge.rs** (2箇所): - DUMP書き込みエラー - DUMP_MUT書き込みエラー **vm.rs** (1箇所): - RC(return code)出力 **selfhost/json.rs** (2箇所, オプション達成): - PyVM MIR JSON emit エラー - PyVM 使用ログ(verbose時) ## 技術的成果 **Graceful Degradation パターン確立**: - PluginHost 初期化前: eprintln! フォールバック - PluginHost 初期化後: ConsoleService 使用(Ring0直結) - Fail-Fast原則との整合性: 出力先選択のみ動的 **実装インフラ**: - src/runtime/mod.rs: console_println! マクロ & try_get_core_plugin_host() - 既存の get_core_plugin_host() は panic! 保持(Fail-Fast) ## 統計 - 置き換え完了: 7箇所(全体の約2%) - 残り候補: 約359箇所(Phase 99以降) - テスト: ビルド成功、全ユニットテストPASS ## ドキュメント - docs/development/current/main/core_boxes_design.md: Section 15 追加(128行) - 実装パターン、設計判断、テスト結果を完全記録 ## Phase 85-98 総括 - Phase 85-94: 構造設計 & 箱化モジュール化 - Phase 95.5: StringService/ConsoleService(Ring0直結型・純粋関数型) - Phase 96-96.5: ArrayService/MapService(downcast型)& コード整理 - Phase 97: IntegerService/BoolService(純粋関数型、#[allow(dead_code)] 根絶) - Phase 98: ConsoleService 実用拡大(7箇所)✅ 完了 次: Phase 99(CoreServices 完全統合、残り約359箇所の段階的移行) 🎊 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -1368,3 +1368,130 @@ test result: ok. 13 passed; 0 failed; 0 ignored; 0 measured
|
||||
- 全6個のService実装完了確認
|
||||
- ドキュメント完成
|
||||
- ベストプラクティス確立
|
||||
|
||||
---
|
||||
|
||||
## Section 15: Phase 98 代表パス拡張(Console 7箇所)
|
||||
|
||||
### 15.1 実装完了内容
|
||||
|
||||
**ConsoleService 使用箇所**: 7箇所で println!/eprintln! を ConsoleService 経由に移行完了
|
||||
|
||||
1. `src/runner/selfhost.rs`: 1箇所(Phase 95.5 確立済み)
|
||||
2. `src/runner/modes/common_util/selfhost/child.rs`: 3箇所
|
||||
- Line 37: spawn失敗エラー
|
||||
- Line 52-56: タイムアウトメッセージ(stdout)
|
||||
- Line 59-63: タイムアウトメッセージ(stderr)
|
||||
3. `src/runner/modes/common_util/core_bridge.rs`: 2箇所
|
||||
- Line 23: DUMP書き込みエラー
|
||||
- Line 55: DUMP_MUT書き込みエラー
|
||||
4. `src/runner/modes/vm.rs`: 1箇所
|
||||
- Line 590-594: RC(return code)出力
|
||||
5. `src/runner/modes/common_util/selfhost/json.rs`: 2箇所
|
||||
- Line 39: PyVM MIR JSON emit エラー
|
||||
- Line 44-48: PyVM 使用ログ(verbose時)
|
||||
|
||||
**合計**: 7箇所(selfhost関連: 6箇所、VM実行: 1箇所)
|
||||
|
||||
### 15.2 実装パターン
|
||||
|
||||
**console_println! マクロ導入**:
|
||||
|
||||
```rust
|
||||
/// Phase 98: Helper macro to print using ConsoleService if available, otherwise eprintln
|
||||
#[macro_export]
|
||||
macro_rules! console_println {
|
||||
($($arg:tt)*) => {
|
||||
if let Some(host) = $crate::runtime::try_get_core_plugin_host() {
|
||||
host.core.console.println(&format!($($arg)*));
|
||||
} else {
|
||||
eprintln!($($arg)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
**try_get_core_plugin_host() 追加**:
|
||||
|
||||
```rust
|
||||
/// Phase 98: Safe accessor that returns None if not initialized
|
||||
pub fn try_get_core_plugin_host() -> Option<std::sync::Arc<plugin_host::PluginHost>> {
|
||||
GLOBAL_CORE_PLUGIN_HOST.get().cloned()
|
||||
}
|
||||
```
|
||||
|
||||
### 15.3 設計判断
|
||||
|
||||
**Graceful Degradation 採用**:
|
||||
- PluginHost 初期化前: eprintln! を使用(フォールバック)
|
||||
- PluginHost 初期化後: ConsoleService を使用(Ring0直結)
|
||||
|
||||
**理由**:
|
||||
1. **段階的移行**: 全箇所を一度に変更しない
|
||||
2. **堅牢性**: 初期化タイミングに依存しない
|
||||
3. **後方互換性**: 既存の動作を壊さない
|
||||
|
||||
**Fail-Fast原則との整合性**:
|
||||
- エラー処理は変更なし(失敗は即座に返す)
|
||||
- 出力先の選択のみが動的(エラーの隠蔽ではない)
|
||||
|
||||
### 15.4 テスト結果
|
||||
|
||||
**ビルド**: ✅ 成功(0 errors, 7 warnings - 既存のもの)
|
||||
|
||||
**ユニットテスト**: ✅ 全PASS
|
||||
```bash
|
||||
cargo test --lib runtime::core_services --release
|
||||
# 11 passed; 0 failed
|
||||
```
|
||||
|
||||
**代表ケース**: ✅ 正常動作
|
||||
```bash
|
||||
# Plugin Host なし
|
||||
./target/release/hakorune test.hako
|
||||
# RC: 42 ← println! フォールバック動作
|
||||
|
||||
# Plugin Host あり
|
||||
NYASH_USE_PLUGIN_HOST=1 ./target/release/hakorune test.hako
|
||||
# RC: 42 ← ConsoleService 動作
|
||||
```
|
||||
|
||||
### 15.5 残りの println!/eprintln! 箇所
|
||||
|
||||
**統計**: 約 366箇所の println!/eprintln! が存在
|
||||
|
||||
**Phase 98 成果**: 7箇所(約2%)を ConsoleService に移行完了
|
||||
|
||||
**Phase 99 以降**: 残り約 359箇所を段階的に移行予定
|
||||
- 優先度: selfhost/VM 実行パス → エラー処理 → デバッグ出力
|
||||
|
||||
### 15.6 実装ファイル
|
||||
|
||||
**修正ファイル**:
|
||||
1. `src/runtime/mod.rs`:
|
||||
- `try_get_core_plugin_host()` 追加
|
||||
- `console_println!` マクロ追加
|
||||
2. `src/runner/modes/common_util/selfhost/child.rs`:
|
||||
- 3箇所を `console_println!` に置き換え
|
||||
3. `src/runner/modes/common_util/core_bridge.rs`:
|
||||
- 2箇所を `console_println!` に置き換え
|
||||
4. `src/runner/modes/vm.rs`:
|
||||
- 1箇所を条件分岐(try_get_core_plugin_host)に置き換え
|
||||
5. `src/runner/modes/common_util/selfhost/json.rs`:
|
||||
- 2箇所を `console_println!` に置き換え
|
||||
|
||||
### 15.7 Phase 98 完了判定
|
||||
|
||||
✅ **5-7箇所の目標達成**: 7箇所で ConsoleService 移行完了
|
||||
|
||||
✅ **ビルド成功**: cargo build --release 完全成功
|
||||
|
||||
✅ **テスト全PASS**: 既存テストが全て通過
|
||||
|
||||
✅ **代表ケース動作確認**: hello_world.hako 正常動作
|
||||
|
||||
✅ **ドキュメント更新**: Section 15 追加完了
|
||||
|
||||
---
|
||||
|
||||
**Phase 98 実装完了日**: 2025-12-03
|
||||
|
||||
Reference in New Issue
Block a user