feat(phase91): PluginHost/CoreServices skeleton complete
Phase 91 完了: Ring1-Core 構造の明確化 **実装内容**: - CoreServices 定義(6つの Service trait) - StringService, IntegerService, BoolService - ArrayService, MapService, ConsoleService - PluginHost 構造体(Ring0 ⇔ CoreServices 橋渡し) - NyashPlugin trait(プラグインシステム標準IF) - PluginRegistry skeleton **Phase 87 整合性**: - CoreServices は core_required (6個) を完全カバー - String, Integer, Bool, Array, Map, Console - CoreBoxId との対応表をドキュメント化 **設計原則確立**: - Ring1-Core 構造明確化 - core_required は必ず揃う(型レベル保証) - Fail-Fast 設計(ensure_initialized) - 既存影響ゼロ(新規ファイルのみ) **テスト結果**: - 5件追加(全て合格) - ビルド成功 - 既存テストに影響なし **次のステップ**: Phase 92 (UnifiedBoxRegistry との統合) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -239,3 +239,127 @@ Phase 85 の調査結果を完全反映:
|
||||
|
||||
すべて1ファイルで完結するため、Phase 84-4-B のような分散ハードコード問題は完全解消。
|
||||
|
||||
---
|
||||
|
||||
## 6. CoreBoxCategory enum(Phase 87)
|
||||
|
||||
### 6.1 役割
|
||||
|
||||
CoreBoxId の分類を型安全に表現する enum。Phase 85 調査結果を完全に反映。
|
||||
|
||||
```rust
|
||||
pub enum CoreBoxCategory {
|
||||
CoreRequired, // 必須: 起動時に全て揃っていなければならない (6個)
|
||||
CoreOptional, // オプション: 無くても起動できるが、標準機能として提供 (9個)
|
||||
Special, // 特殊: 言語実装に直結(Function/Result/Method/Missing)
|
||||
}
|
||||
```
|
||||
|
||||
### 6.2 Phase 85 対応表
|
||||
|
||||
| Category | 個数 | Box 一覧 |
|
||||
|----------|------|---------|
|
||||
| CoreRequired | 6 | String, Integer, Bool, Array, Map, Console |
|
||||
| CoreOptional | 9 | Float, Null, File, Path, Regex, Math, Time, Json, Toml |
|
||||
| Special | 4 | Function, Result, Method, Missing |
|
||||
|
||||
### 6.3 実装効果
|
||||
|
||||
- **is_core_required() の簡略化**: `category() == CoreBoxCategory::CoreRequired`
|
||||
- **Phase 92 CoreServices 設計**: core_required (6個) のみを CoreServices に含める根拠
|
||||
- **型安全な分類**: 文字列比較 → enum 比較で完全型安全
|
||||
|
||||
---
|
||||
|
||||
## 7. Phase 87 完了チェックリスト
|
||||
|
||||
### 7.1 実装完了 ✅
|
||||
|
||||
- [x] CoreBoxId enum 定義(19個)
|
||||
- [x] CoreMethodId enum 定義(30個)
|
||||
- [x] CoreBoxCategory enum 定義(3カテゴリ)
|
||||
- [x] is_reserved_type() リファクタリング
|
||||
- [x] infer_boxcall_return_type() リファクタリング(67%削減)
|
||||
- [x] テスト 11件追加
|
||||
- [x] Phase 85 調査結果の完全反映
|
||||
|
||||
### 7.2 Phase 92 への橋渡し準備 ✅
|
||||
|
||||
- [x] core_required (6個) の確定
|
||||
- [x] CoreBoxCategory による分類体系確立
|
||||
- [x] SSOT(Single Source of Truth)確立
|
||||
|
||||
### 7.3 今後の展開
|
||||
|
||||
Phase 92 では、CoreServices の実装時に CoreBoxCategory::CoreRequired (6個) のみを対象とすることで、**「core_required は必ず揃う」**という設計原則を型レベルで保証する。
|
||||
|
||||
---
|
||||
|
||||
## 8. Phase 91: PluginHost/CoreServices 実装(2025-12-03)
|
||||
|
||||
### 8.1 PluginHost アーキテクチャ
|
||||
|
||||
**構造**:
|
||||
```rust
|
||||
pub struct PluginHost {
|
||||
pub ring0: Arc<Ring0Context>, // Phase 88-90 実装済み
|
||||
pub core: CoreServices, // Phase 91 skeleton
|
||||
pub optional: HashMap<String, Arc<dyn Any>>,
|
||||
}
|
||||
```
|
||||
|
||||
**役割**:
|
||||
- Ring0Context(OS API)と CoreServices(Box 実装)の橋渡し
|
||||
- core_required Box の初期化保証
|
||||
- optional/user プラグインの管理
|
||||
|
||||
### 8.2 CoreServices: Ring1-Core の顔
|
||||
|
||||
**定義**:
|
||||
```rust
|
||||
pub struct CoreServices {
|
||||
pub string: Arc<dyn StringService>,
|
||||
pub integer: Arc<dyn IntegerService>,
|
||||
pub bool: Arc<dyn BoolService>,
|
||||
pub array: Arc<dyn ArrayService>,
|
||||
pub map: Arc<dyn MapService>,
|
||||
pub console: Arc<dyn ConsoleService>,
|
||||
}
|
||||
```
|
||||
|
||||
**Phase 87 CoreBoxId との対応**:
|
||||
|
||||
| CoreBoxId | CoreBoxCategory | CoreServices | 実装状況 |
|
||||
|-----------|----------------|--------------|---------|
|
||||
| String | CoreRequired | ✅ string | Phase 91 skeleton |
|
||||
| Integer | CoreRequired | ✅ integer | Phase 91 skeleton |
|
||||
| Bool | CoreRequired | ✅ bool | Phase 91 skeleton |
|
||||
| Array | CoreRequired | ✅ array | Phase 91 skeleton |
|
||||
| Map | CoreRequired | ✅ map | Phase 91 skeleton |
|
||||
| Console | CoreRequired | ✅ console | Phase 91 skeleton |
|
||||
|
||||
**設計原則**:
|
||||
- core_required (6個) は全て CoreServices に含まれる
|
||||
- 起動時に全フィールドが初期化されていなければ panic
|
||||
- Phase 92 で UnifiedBoxRegistry から自動生成予定
|
||||
|
||||
### 8.3 NyashPlugin trait
|
||||
|
||||
**定義**:
|
||||
```rust
|
||||
pub trait NyashPlugin: Send + Sync {
|
||||
fn descriptor(&self) -> PluginDescriptor;
|
||||
fn register(&self, host: &mut PluginRegistry);
|
||||
}
|
||||
```
|
||||
|
||||
**用途**:
|
||||
- プラグインの基本情報(名前、バージョン、capabilities)
|
||||
- Phase 92 以降で既存プラグインシステムと統合予定
|
||||
|
||||
### 8.4 Phase 92 以降の計画
|
||||
|
||||
- UnifiedBoxRegistry から CoreServices への自動変換
|
||||
- PluginHost.optional への optional/user プラグイン登録
|
||||
- 既存 Box 実装と Service trait の接続
|
||||
|
||||
|
||||
67
src/runtime/core_services.rs
Normal file
67
src/runtime/core_services.rs
Normal file
@ -0,0 +1,67 @@
|
||||
//! Phase 91: CoreServices 定義
|
||||
//!
|
||||
//! Ring1-Core: core_required Box の Service trait 群。
|
||||
//! Phase 87 CoreBoxId の core_required (6個) 全てをカバー。
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
/// StringBox Service trait
|
||||
pub trait StringService: Send + Sync {
|
||||
// Phase 92 以降で実装
|
||||
}
|
||||
|
||||
/// IntegerBox Service trait
|
||||
pub trait IntegerService: Send + Sync {
|
||||
// Phase 92 以降で実装
|
||||
}
|
||||
|
||||
/// BoolBox Service trait
|
||||
pub trait BoolService: Send + Sync {
|
||||
// Phase 92 以降で実装
|
||||
}
|
||||
|
||||
/// ArrayBox Service trait
|
||||
pub trait ArrayService: Send + Sync {
|
||||
// Phase 92 以降で実装
|
||||
}
|
||||
|
||||
/// MapBox Service trait
|
||||
pub trait MapService: Send + Sync {
|
||||
// Phase 92 以降で実装
|
||||
}
|
||||
|
||||
/// ConsoleBox Service trait
|
||||
pub trait ConsoleService: Send + Sync {
|
||||
// Phase 92 以降で実装
|
||||
}
|
||||
|
||||
/// CoreServices: core_required Box の集合
|
||||
///
|
||||
/// Phase 85 設計原則:
|
||||
/// - core_required は必ず全て揃っていなければならない
|
||||
/// - 起動時に全フィールドが初期化されていることを保証
|
||||
///
|
||||
/// Phase 87 CoreBoxId との対応:
|
||||
/// - String → string
|
||||
/// - Integer → integer
|
||||
/// - Bool → bool
|
||||
/// - Array → array
|
||||
/// - Map → map
|
||||
/// - Console → console
|
||||
pub struct CoreServices {
|
||||
pub string: Arc<dyn StringService>,
|
||||
pub integer: Arc<dyn IntegerService>,
|
||||
pub bool: Arc<dyn BoolService>,
|
||||
pub array: Arc<dyn ArrayService>,
|
||||
pub map: Arc<dyn MapService>,
|
||||
pub console: Arc<dyn ConsoleService>,
|
||||
}
|
||||
|
||||
impl CoreServices {
|
||||
/// 全フィールドが初期化されているか検証
|
||||
/// Phase 92 以降で各 Service の初期化を検証
|
||||
pub fn ensure_initialized(&self) {
|
||||
// Phase 91 では trait が空なので何もしない
|
||||
// Phase 92 以降で各 Service の初期化を検証
|
||||
}
|
||||
}
|
||||
@ -4,8 +4,10 @@
|
||||
|
||||
pub mod box_registry;
|
||||
pub mod core_box_ids; // Phase 87: CoreBoxId/CoreMethodId 型安全enum
|
||||
pub mod core_services; // Phase 91: CoreServices trait 定義
|
||||
pub mod deprecations;
|
||||
pub mod gc;
|
||||
pub mod plugin_host; // Phase 91: PluginHost skeleton
|
||||
pub mod ring0; // Phase 88: Ring0Context - OS API 抽象化レイヤー
|
||||
pub mod gc_controller;
|
||||
pub mod gc_mode;
|
||||
|
||||
163
src/runtime/plugin_host.rs
Normal file
163
src/runtime/plugin_host.rs
Normal file
@ -0,0 +1,163 @@
|
||||
//! Phase 91: PluginHost/CoreServices skeleton
|
||||
//!
|
||||
//! Ring1-Core(Box 実装層)の構造定義。
|
||||
//! Phase 92 で UnifiedBoxRegistry と接続予定。
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
use std::any::Any;
|
||||
|
||||
/// Plugin の基本情報
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PluginDescriptor {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub capabilities: Vec<String>, // "json", "http", "cli" など
|
||||
}
|
||||
|
||||
/// Nyash Plugin の trait
|
||||
pub trait NyashPlugin: Send + Sync {
|
||||
fn descriptor(&self) -> PluginDescriptor;
|
||||
fn register(&self, host: &mut PluginRegistry);
|
||||
}
|
||||
|
||||
/// Plugin 登録レジストリ(skeleton のみ、Phase 92 で実装)
|
||||
pub struct PluginRegistry {
|
||||
_placeholder: (),
|
||||
}
|
||||
|
||||
impl PluginRegistry {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
_placeholder: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use super::core_services::CoreServices;
|
||||
use super::ring0::Ring0Context;
|
||||
|
||||
/// PluginHost: Ring0Context と CoreServices の橋渡し
|
||||
pub struct PluginHost {
|
||||
pub ring0: Arc<Ring0Context>,
|
||||
pub core: CoreServices,
|
||||
pub optional: HashMap<String, Arc<dyn Any>>,
|
||||
}
|
||||
|
||||
impl PluginHost {
|
||||
/// Phase 91: skeleton のみ(core は未実装)
|
||||
/// Phase 92 以降で from_registry() を実装予定
|
||||
#[allow(dead_code)]
|
||||
pub fn new_skeleton(ring0: Arc<Ring0Context>) -> Self {
|
||||
// ダミー実装(Phase 92 で削除)
|
||||
unimplemented!("Phase 92 で from_registry() 実装後に削除")
|
||||
}
|
||||
|
||||
/// core_required が全て揃っているか検証
|
||||
pub fn ensure_core_initialized(&self) {
|
||||
self.core.ensure_initialized();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::runtime::core_services::*;
|
||||
|
||||
#[test]
|
||||
fn test_plugin_descriptor() {
|
||||
let desc = PluginDescriptor {
|
||||
name: "test_plugin".to_string(),
|
||||
version: "1.0.0".to_string(),
|
||||
capabilities: vec!["json".to_string()],
|
||||
};
|
||||
assert_eq!(desc.name, "test_plugin");
|
||||
assert_eq!(desc.version, "1.0.0");
|
||||
assert_eq!(desc.capabilities.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_plugin_registry_creation() {
|
||||
let _registry = PluginRegistry::new();
|
||||
// panic しないことを確認
|
||||
}
|
||||
|
||||
// ダミー Service 実装
|
||||
struct DummyStringService;
|
||||
impl StringService for DummyStringService {}
|
||||
|
||||
struct DummyIntegerService;
|
||||
impl IntegerService for DummyIntegerService {}
|
||||
|
||||
struct DummyBoolService;
|
||||
impl BoolService for DummyBoolService {}
|
||||
|
||||
struct DummyArrayService;
|
||||
impl ArrayService for DummyArrayService {}
|
||||
|
||||
struct DummyMapService;
|
||||
impl MapService for DummyMapService {}
|
||||
|
||||
struct DummyConsoleService;
|
||||
impl ConsoleService for DummyConsoleService {}
|
||||
|
||||
#[test]
|
||||
fn test_core_services_all_fields() {
|
||||
let services = CoreServices {
|
||||
string: Arc::new(DummyStringService),
|
||||
integer: Arc::new(DummyIntegerService),
|
||||
bool: Arc::new(DummyBoolService),
|
||||
array: Arc::new(DummyArrayService),
|
||||
map: Arc::new(DummyMapService),
|
||||
console: Arc::new(DummyConsoleService),
|
||||
};
|
||||
services.ensure_initialized();
|
||||
// panic しないことを確認(Phase 92 で検証ロジック追加予定)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_core_services_coverage() {
|
||||
// Phase 87 CoreBoxId の core_required (6個) 全てをカバーすることを検証
|
||||
let services = CoreServices {
|
||||
string: Arc::new(DummyStringService),
|
||||
integer: Arc::new(DummyIntegerService),
|
||||
bool: Arc::new(DummyBoolService),
|
||||
array: Arc::new(DummyArrayService),
|
||||
map: Arc::new(DummyMapService),
|
||||
console: Arc::new(DummyConsoleService),
|
||||
};
|
||||
|
||||
// Phase 87 core_required (6個) と一致することを確認
|
||||
// String, Integer, Bool, Array, Map, Console
|
||||
let _string = &services.string;
|
||||
let _integer = &services.integer;
|
||||
let _bool = &services.bool;
|
||||
let _array = &services.array;
|
||||
let _map = &services.map;
|
||||
let _console = &services.console;
|
||||
|
||||
// 全フィールドが存在することを確認
|
||||
}
|
||||
|
||||
struct DummyPlugin;
|
||||
impl NyashPlugin for DummyPlugin {
|
||||
fn descriptor(&self) -> PluginDescriptor {
|
||||
PluginDescriptor {
|
||||
name: "dummy".to_string(),
|
||||
version: "0.1.0".to_string(),
|
||||
capabilities: vec![],
|
||||
}
|
||||
}
|
||||
fn register(&self, _host: &mut PluginRegistry) {
|
||||
// ダミー実装
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_plugin_trait_implementation() {
|
||||
let plugin = DummyPlugin;
|
||||
let desc = plugin.descriptor();
|
||||
assert_eq!(desc.name, "dummy");
|
||||
assert_eq!(desc.version, "0.1.0");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user