Files
hakorune/src/runtime/mod.rs

90 lines
3.6 KiB
Rust
Raw Normal View History

//! Nyashランタイムモジュール
//!
//! プラグインシステムとBox管理の中核
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;
pub mod gc_trace;
pub mod global_hooks;
pub mod leak_tracker;
pub mod nyash_runtime;
pub mod observe; // Lightweight observability flags (OOB etc.)
pub mod plugin_config;
pub mod plugin_ffi_common;
pub mod plugin_loader_unified;
pub mod plugin_loader_v2;
pub mod provider_lock;
pub mod provider_verify;
pub mod scheduler;
pub mod semantics;
pub mod unified_registry; // Deprecation warnings with warn-once guards
// pub mod plugin_box; // legacy - 古いPluginBox
// pub mod plugin_loader; // legacy - Host VTable使用
pub mod extern_registry; // ExternCall (env.*) 登録・診断用レジストリ
pub mod host_api; // C ABI: plugins -> host 逆呼び出しAPITLSでVMに橋渡し
pub mod host_handles; // C ABI(TLV) 向け HostHandle レジストリ(ユーザー/内蔵Box受け渡し
pub mod modules_registry;
pub mod type_box_abi; // Phase 12: Nyash ABI (vtable) 雛形
pub mod type_meta;
pub mod type_registry; // Phase 12: TypeId→TypeBox 解決(雛形) // env.modules minimal registry
#[cfg(test)]
mod tests;
pub use box_registry::{get_global_registry, BoxFactoryRegistry, BoxProvider};
pub use core_box_ids::{CoreBoxCategory, CoreBoxId, CoreMethodId}; // Phase 87: 型安全enum
pub use plugin_config::PluginConfig;
pub use ring0::{get_global_ring0, init_global_ring0, Ring0Context}; // Phase 88: Ring0 公開 API
pub use plugin_host::CoreInitError; // Phase 92: CoreServices 初期化エラー
pub use plugin_loader_unified::{
get_global_plugin_host, init_global_plugin_host, MethodHandle, PluginBoxType, PluginHost,
PluginLibraryHandle,
};
pub use plugin_loader_v2::{get_global_loader_v2, init_global_loader_v2, PluginLoaderV2};
pub mod cache_versions;
pub use gc::{BarrierKind, GcHooks};
pub use nyash_runtime::{NyashRuntime, NyashRuntimeBuilder};
pub use scheduler::{Scheduler, SingleThreadScheduler};
pub use unified_registry::{
get_global_unified_registry, init_global_unified_registry, register_user_defined_factory,
};
// pub use plugin_box::PluginBox; // legacy
// Use unified plugin loader (formerly v2)
// pub use plugin_loader::{PluginLoaderV2 as PluginLoader, get_global_loader_v2 as get_global_loader}; // legacy
feat(phase93): with_core_from_registry implementation complete Phase 93 完了: UnifiedBoxRegistry 統合実装 & 起動パス統合 **実装内容**: - with_core_from_registry() 実装 - UnifiedBoxRegistry.has_type() で core Box の存在確認 - 不足時は CoreInitError::MissingService を返す - ダミー Service 実装で CoreServices を構築 - ダミー Service 実装を pub に - DummyStringService, DummyIntegerService 等を公開 - Phase 94 の実変換までの橋渡し - CoreServices::dummy() ヘルパー追加 - フォールバック用ダミー実装 - initialize_runtime() 実装(環境変数制御) - NYASH_USE_PLUGIN_HOST=1 で PluginHost 有効化 - 環境変数なしで従来通り動作(後方互換性) - selfhost に PluginHost 初期化追加 - CoreInitError 発生時は fail-fast - 既存ロジックは変更なし **Fail-Fast 設計**: - 起動時に core Box 不足を即座に検出 - CoreInitError で明示的なエラーメッセージ - デバッグ容易(ランタイムエラーではなく起動時エラー) **テスト結果**: - test_with_core_from_registry_missing_box 追加 - 7件全て成功 - ビルド成功(1分4秒) - 526 passed(既存36失敗は Phase 93 と無関係) **動作確認**: - 環境変数なし: 従来通り動作 ✅ - NYASH_USE_PLUGIN_HOST=1: PluginHost 初期化成功 ✅ - selfhost: fail-fast 動作確認済み ✅ **ドキュメント更新**: - Section 10 追加(77行) - 段階的展開戦略、Fail-Fast 設計を文書化 **次のステップ**: Phase 94 (実際の Box → Service 変換) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 08:42:45 +09:00
/// Runtime 初期化Phase 93: 実装完了)
///
feat(phase93): with_core_from_registry implementation complete Phase 93 完了: UnifiedBoxRegistry 統合実装 & 起動パス統合 **実装内容**: - with_core_from_registry() 実装 - UnifiedBoxRegistry.has_type() で core Box の存在確認 - 不足時は CoreInitError::MissingService を返す - ダミー Service 実装で CoreServices を構築 - ダミー Service 実装を pub に - DummyStringService, DummyIntegerService 等を公開 - Phase 94 の実変換までの橋渡し - CoreServices::dummy() ヘルパー追加 - フォールバック用ダミー実装 - initialize_runtime() 実装(環境変数制御) - NYASH_USE_PLUGIN_HOST=1 で PluginHost 有効化 - 環境変数なしで従来通り動作(後方互換性) - selfhost に PluginHost 初期化追加 - CoreInitError 発生時は fail-fast - 既存ロジックは変更なし **Fail-Fast 設計**: - 起動時に core Box 不足を即座に検出 - CoreInitError で明示的なエラーメッセージ - デバッグ容易(ランタイムエラーではなく起動時エラー) **テスト結果**: - test_with_core_from_registry_missing_box 追加 - 7件全て成功 - ビルド成功(1分4秒) - 526 passed(既存36失敗は Phase 93 と無関係) **動作確認**: - 環境変数なし: 従来通り動作 ✅ - NYASH_USE_PLUGIN_HOST=1: PluginHost 初期化成功 ✅ - selfhost: fail-fast 動作確認済み ✅ **ドキュメント更新**: - Section 10 追加(77行) - 段階的展開戦略、Fail-Fast 設計を文書化 **次のステップ**: Phase 94 (実際の Box → Service 変換) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 08:42:45 +09:00
/// 環境変数 NYASH_USE_PLUGIN_HOST=1 で PluginHost を有効化。
pub fn initialize_runtime(ring0: std::sync::Arc<Ring0Context>) -> Result<plugin_host::PluginHost, CoreInitError> {
use crate::box_factory::UnifiedBoxRegistry;
feat(phase93): with_core_from_registry implementation complete Phase 93 完了: UnifiedBoxRegistry 統合実装 & 起動パス統合 **実装内容**: - with_core_from_registry() 実装 - UnifiedBoxRegistry.has_type() で core Box の存在確認 - 不足時は CoreInitError::MissingService を返す - ダミー Service 実装で CoreServices を構築 - ダミー Service 実装を pub に - DummyStringService, DummyIntegerService 等を公開 - Phase 94 の実変換までの橋渡し - CoreServices::dummy() ヘルパー追加 - フォールバック用ダミー実装 - initialize_runtime() 実装(環境変数制御) - NYASH_USE_PLUGIN_HOST=1 で PluginHost 有効化 - 環境変数なしで従来通り動作(後方互換性) - selfhost に PluginHost 初期化追加 - CoreInitError 発生時は fail-fast - 既存ロジックは変更なし **Fail-Fast 設計**: - 起動時に core Box 不足を即座に検出 - CoreInitError で明示的なエラーメッセージ - デバッグ容易(ランタイムエラーではなく起動時エラー) **テスト結果**: - test_with_core_from_registry_missing_box 追加 - 7件全て成功 - ビルド成功(1分4秒) - 526 passed(既存36失敗は Phase 93 と無関係) **動作確認**: - 環境変数なし: 従来通り動作 ✅ - NYASH_USE_PLUGIN_HOST=1: PluginHost 初期化成功 ✅ - selfhost: fail-fast 動作確認済み ✅ **ドキュメント更新**: - Section 10 追加(77行) - 段階的展開戦略、Fail-Fast 設計を文書化 **次のステップ**: Phase 94 (実際の Box → Service 変換) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 08:42:45 +09:00
let registry = UnifiedBoxRegistry::with_env_policy();
feat(phase93): with_core_from_registry implementation complete Phase 93 完了: UnifiedBoxRegistry 統合実装 & 起動パス統合 **実装内容**: - with_core_from_registry() 実装 - UnifiedBoxRegistry.has_type() で core Box の存在確認 - 不足時は CoreInitError::MissingService を返す - ダミー Service 実装で CoreServices を構築 - ダミー Service 実装を pub に - DummyStringService, DummyIntegerService 等を公開 - Phase 94 の実変換までの橋渡し - CoreServices::dummy() ヘルパー追加 - フォールバック用ダミー実装 - initialize_runtime() 実装(環境変数制御) - NYASH_USE_PLUGIN_HOST=1 で PluginHost 有効化 - 環境変数なしで従来通り動作(後方互換性) - selfhost に PluginHost 初期化追加 - CoreInitError 発生時は fail-fast - 既存ロジックは変更なし **Fail-Fast 設計**: - 起動時に core Box 不足を即座に検出 - CoreInitError で明示的なエラーメッセージ - デバッグ容易(ランタイムエラーではなく起動時エラー) **テスト結果**: - test_with_core_from_registry_missing_box 追加 - 7件全て成功 - ビルド成功(1分4秒) - 526 passed(既存36失敗は Phase 93 と無関係) **動作確認**: - 環境変数なし: 従来通り動作 ✅ - NYASH_USE_PLUGIN_HOST=1: PluginHost 初期化成功 ✅ - selfhost: fail-fast 動作確認済み ✅ **ドキュメント更新**: - Section 10 追加(77行) - 段階的展開戦略、Fail-Fast 設計を文書化 **次のステップ**: Phase 94 (実際の Box → Service 変換) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 08:42:45 +09:00
// Phase 93: 環境変数で有効化(段階的展開)
let use_plugin_host = std::env::var("NYASH_USE_PLUGIN_HOST")
.ok()
.and_then(|v| if v == "1" { Some(()) } else { None })
.is_some();
feat(phase93): with_core_from_registry implementation complete Phase 93 完了: UnifiedBoxRegistry 統合実装 & 起動パス統合 **実装内容**: - with_core_from_registry() 実装 - UnifiedBoxRegistry.has_type() で core Box の存在確認 - 不足時は CoreInitError::MissingService を返す - ダミー Service 実装で CoreServices を構築 - ダミー Service 実装を pub に - DummyStringService, DummyIntegerService 等を公開 - Phase 94 の実変換までの橋渡し - CoreServices::dummy() ヘルパー追加 - フォールバック用ダミー実装 - initialize_runtime() 実装(環境変数制御) - NYASH_USE_PLUGIN_HOST=1 で PluginHost 有効化 - 環境変数なしで従来通り動作(後方互換性) - selfhost に PluginHost 初期化追加 - CoreInitError 発生時は fail-fast - 既存ロジックは変更なし **Fail-Fast 設計**: - 起動時に core Box 不足を即座に検出 - CoreInitError で明示的なエラーメッセージ - デバッグ容易(ランタイムエラーではなく起動時エラー) **テスト結果**: - test_with_core_from_registry_missing_box 追加 - 7件全て成功 - ビルド成功(1分4秒) - 526 passed(既存36失敗は Phase 93 と無関係) **動作確認**: - 環境変数なし: 従来通り動作 ✅ - NYASH_USE_PLUGIN_HOST=1: PluginHost 初期化成功 ✅ - selfhost: fail-fast 動作確認済み ✅ **ドキュメント更新**: - Section 10 追加(77行) - 段階的展開戦略、Fail-Fast 設計を文書化 **次のステップ**: Phase 94 (実際の Box → Service 変換) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 08:42:45 +09:00
if use_plugin_host {
let plugin_host = plugin_host::PluginHost::with_core_from_registry(ring0, &registry)?;
plugin_host.ensure_core_initialized();
Ok(plugin_host)
} else {
// フォールバックPhase 94 で削除予定)
let core = core_services::CoreServices::dummy();
Ok(plugin_host::PluginHost {
ring0,
core,
optional: std::collections::HashMap::new(),
})
}
}