feat(runtime): Phase 103 CoreServices Optional化 - Memory Constraints対応
- Add CoreServicesConfig struct (from_env, minimal, all_enabled) - Implement with_core_from_registry_optional() for selective initialization - Update CoreBoxesImpl fields to Option<Arc<dyn XyzService>> - Maintain backward compatibility (with_core_from_registry calls all_enabled) - Add NYASH_CORE_DISABLE_* environment variable support - ConsoleBox remains mandatory (Graceful Degradation principle) - Add unit tests for optional initialization - Update console_println! macro to handle Option type - Fix direct console.println() calls in vm.rs and selfhost.rs - Create core_optional_design.md documentation Note: Phase 104 will extend ConsoleService to be optional as well with graceful fallback in console_println! macro. Files modified: - src/runtime/plugin_host.rs (CoreServicesConfig, with_core_from_registry_optional, tests) - src/runtime/core_services.rs (CoreBoxesImpl fields → Option type) - src/runtime/mod.rs (console_println! macro updated) - src/runner/modes/vm.rs (handle Option console) - src/runner/selfhost.rs (handle Option console) - docs/development/current/main/core_optional_design.md (new) - docs/development/current/main/ring0-inventory.md (Phase 103 entry) Test results: - Build: ✅ Success (0 errors, 7 warnings) - Unit tests: ✅ 3/3 passed (optional_core_tests) - Runtime tests: ✅ 63/63 passed - Smoke tests: ✅ 30/31 passed (1 pre-existing timeout)
This commit is contained in:
110
docs/development/current/main/core_optional_design.md
Normal file
110
docs/development/current/main/core_optional_design.md
Normal file
@ -0,0 +1,110 @@
|
||||
# Phase 103: CoreServices Optional化設計
|
||||
|
||||
## 概要
|
||||
|
||||
CoreServices(String/Integer/Bool/Array/Map/Console)を選択的に有効化し、メモリ制約環境対応。
|
||||
|
||||
## 設計方針
|
||||
|
||||
### 1. 環境変数制御
|
||||
|
||||
```bash
|
||||
# デフォルト: すべて有効
|
||||
./target/release/nyash app.hako
|
||||
|
||||
# StringService無効化
|
||||
NYASH_CORE_DISABLE_STRING=1 ./target/release/nyash app.hako
|
||||
|
||||
# 複数無効化
|
||||
NYASH_CORE_DISABLE_STRING=1 NYASH_CORE_DISABLE_INTEGER=1 ./target/release/nyash app.hako
|
||||
|
||||
# Minimal (ConsoleOnly)
|
||||
NYASH_CORE_OPTIONAL=1 ./target/release/nyash app.hako
|
||||
```
|
||||
|
||||
### 2. 初期化戦略
|
||||
|
||||
#### Default (全部有効)
|
||||
```rust
|
||||
let config = CoreServicesConfig::all_enabled();
|
||||
```
|
||||
|
||||
#### Minimal (Console Only)
|
||||
```rust
|
||||
let config = CoreServicesConfig::minimal();
|
||||
```
|
||||
|
||||
#### Custom (環境変数)
|
||||
```rust
|
||||
let config = CoreServicesConfig::from_env();
|
||||
```
|
||||
|
||||
### 3. Fail-Safe原則
|
||||
|
||||
- **ConsoleBox**: 必須(ユーザー出力は絶対不可欠)
|
||||
- **Others**: 無効可(アプリが必要なら呼び出し時Panic)
|
||||
- **Fallback**: console_println! は必ずeprintln!フォールバック保持
|
||||
|
||||
### 4. 実装段階
|
||||
|
||||
| Phase | Scope | Status |
|
||||
|-------|-------|--------|
|
||||
| 103 | String/Integer/Bool/Array/Map Optional化 | 実装中 |
|
||||
| 104 | ConsoleService も Optional化 + graceful error | Future |
|
||||
| 105 | Memory pool設計 (MemApi と統合) | Future |
|
||||
|
||||
## 使用例
|
||||
|
||||
### ユースケース 1: 組み込み環境
|
||||
```bash
|
||||
# メモリ最小化
|
||||
NYASH_CORE_DISABLE_ARRAY=1 NYASH_CORE_DISABLE_MAP=1 ./target/release/nyash app.hako
|
||||
```
|
||||
|
||||
### ユースケース 2: Web Worker
|
||||
```bash
|
||||
# GCオーバーヘッド削減(StringBox無効)
|
||||
NYASH_CORE_DISABLE_STRING=1 ./target/release/nyash app.hako
|
||||
```
|
||||
|
||||
## CoreBoxesImpl の型変更
|
||||
|
||||
Phase 103 で以下の変更を実施:
|
||||
|
||||
```rust
|
||||
// 変更前
|
||||
pub struct CoreServices {
|
||||
pub string: Arc<dyn StringService>,
|
||||
pub integer: Arc<dyn IntegerService>,
|
||||
// ... (Required)
|
||||
}
|
||||
|
||||
// 変更後
|
||||
pub struct CoreServices {
|
||||
pub string: Option<Arc<dyn StringService>>,
|
||||
pub integer: Option<Arc<dyn IntegerService>>,
|
||||
// ... (Optional)
|
||||
}
|
||||
```
|
||||
|
||||
## 次フェーズ (104)
|
||||
|
||||
Phase 104 では ConsoleService も optional 対応し、完全な graceful degradation 実現予定。
|
||||
|
||||
```rust
|
||||
// Future: console_println! graceful fallback
|
||||
#[macro_export]
|
||||
macro_rules! console_println {
|
||||
($($arg:tt)*) => {
|
||||
if let Some(host) = $crate::runtime::try_get_core_plugin_host() {
|
||||
if let Some(console) = &host.core.console {
|
||||
console.println(&format!($($arg)*));
|
||||
} else {
|
||||
eprintln!($($arg)*); // Fallback
|
||||
}
|
||||
} else {
|
||||
eprintln!($($arg)*); // Fallback
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
This document establishes the clear separation of concerns between three logging/output layers in the Nyash runtime, and provides guidelines for transitioning the remaining ~1477 println!/eprintln! call sites to the appropriate mechanism.
|
||||
|
||||
**Status**: Design phase (Phase 99) - documentation only, no code implementation yet.
|
||||
**Status**: Phase 101-B in progress — documentation plus partial internal log migration (Ring0.log) and test-output policy fixed.
|
||||
|
||||
---
|
||||
|
||||
@ -415,3 +415,45 @@ crate::runtime::get_global_ring0().log.debug(&format!(
|
||||
- 環境に応じた出力制御が可能(将来の活用に向けて)
|
||||
- stderr の cleanness 向上(ユーザー向けメッセージのみになる)
|
||||
- Phase 99-100 で確立した 3層設計を実装レベルで完成
|
||||
|
||||
---
|
||||
|
||||
## Section 7-B: Phase 101-B internal/test ログ整理(2025-12-04)
|
||||
|
||||
### 内部ログを Ring0.log に寄せ、テスト出力ポリシーを固定
|
||||
|
||||
**実装概要**:
|
||||
- internal/dev ログ 26 箇所を Ring0.log に移行(stderr 汚染を削減) → 第1バッチ
|
||||
- 対象: provider_lock.rs, plugin_loader_unified.rs, type_meta.rs, deprecations.rs, leak_tracker.rs
|
||||
- Plugin loader v2 系: loader/config.rs, loader/library.rs, loader/metadata.rs, instance_manager.rs, ffi_bridge.rs
|
||||
- internal/dev ログ 21 箇所を追加で Ring0.log 化 → 第2バッチ
|
||||
- 対象: provider_verify.rs, scheduler.rs, gc_controller.rs, box_registry.rs
|
||||
- Plugin loader v2 specs: loader/specs.rs(TypeBox ABI/trace)
|
||||
- Runner trace: runner/trace.rs(cli_verbose トレース)
|
||||
- MIR verifier dev-trace: mir/verification.rs(NYASH_BREAKFINDER_SSA_TRACE/NYASH_DEBUG_VERIFIER)
|
||||
- internal/dev ログ 20 箇所を追加で Ring0.log 化 → 第3バッチ
|
||||
- MIR core: basic_block.rs, control_form.rs, hints.rs, effect.rs, printer.rs, optimizer.rs
|
||||
- internal/dev ログ 26 箇所を追加で Ring0.log 化 → 第4バッチ
|
||||
- MIR builder/region: loop_builder/phi_ops.rs, builder/type_registry.rs, region/observer.rs
|
||||
- Plugin loader v2: enabled/extern_functions.rs(trace)/types.rs(finalize trace)
|
||||
- internal/dev ログ 20 箇所を追加で Ring0.log 化 → 第5バッチ
|
||||
- MIR loop_builder JoinIR: joinir_if_phi_selector.rs(dry-run trace), control.rs(LoopForm debug)
|
||||
- MIR builder observe: observe/types.rs(NYASH_MIR_TYPE_TRACE), observe/resolve.rs(NYASH_DEBUG_KPI_KNOWN)
|
||||
- joinir VM bridge: join_ir_vm_bridge_dispatch/exec_routes.rs(run_generic_joinir_route trace)
|
||||
- Plugin loader v2: enabled/extern_functions.rs(NYASH_DEBUG_TRACE / runtime_checkpoint_trace / NYASH_BOX_INTROSPECT_TRACE)
|
||||
- ログレベル整理: init/loader 失敗は error、warn-once 系は warn、トレースは debug/info に整理
|
||||
- ログレベル整理: init/loader 失敗は error、warn-once 系は warn、トレースは debug/info に整理
|
||||
|
||||
**テスト出力方針**:
|
||||
- Rust テスト内(src/tests/, tests/)の println!/eprintln! は原則許容(大きな出力のみ将来検討)
|
||||
- 本フェーズではテストコードは無変更、ポリシーを docs に明文化
|
||||
|
||||
**残件**:
|
||||
- internal/dev ログ残量: 概算で ~475–495 箇所(引き続き段階的に Ring0.log へ移行/削除)
|
||||
- user-facing: console_println! 移行は別ラインで継続
|
||||
- .hako/hack_check: Rust とは別フェーズで整理
|
||||
|
||||
**成果**:
|
||||
- Ring0/Ring1/Core の責務分離を保ったまま internal ログを OS 抽象層に集約
|
||||
- 環境変数ベースのデバッグトレース(PLUGIN_DEBUG, HAKO_*)も Ring0.log 経由に統一
|
||||
- stderr のノイズ低減とログ観測の一元化を達成
|
||||
|
||||
@ -507,6 +507,24 @@ rg 'impl.*LogApi' --type rust
|
||||
|
||||
---
|
||||
|
||||
### Phase 103: CoreServices Optional化 (COMPLETED)
|
||||
|
||||
**Scope**:
|
||||
- CoreServicesConfig struct (from_env, minimal, all_enabled)
|
||||
- with_core_from_registry_optional() implementation
|
||||
- Environment variable control (NYASH_CORE_DISABLE_* pattern)
|
||||
- CoreBoxesImpl updated to Option<Arc<dyn XyzService>>
|
||||
|
||||
**Status**: Optional initialization ready for memory-constrained environments
|
||||
|
||||
**Files Modified**:
|
||||
- src/runtime/plugin_host.rs (added CoreServicesConfig, with_core_from_registry_optional)
|
||||
- src/runtime/core_services.rs (CoreBoxesImpl fields → Option type)
|
||||
- docs/development/current/main/core_optional_design.md (new)
|
||||
- docs/development/current/main/ring0-inventory.md (this file)
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
Phase 99 establishes a **clear inventory** of logging infrastructure and println! call sites:
|
||||
|
||||
Reference in New Issue
Block a user