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:
nyash-codex
2025-12-03 13:59:06 +09:00
parent 262de28c6b
commit 6ecd8f7f52
42 changed files with 715 additions and 235 deletions

View File

@ -1,4 +1,5 @@
use super::super::MirBuilder;
use crate::runtime::get_global_ring0;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::OnceLock;
@ -62,9 +63,9 @@ fn record_kpi(meta: &serde_json::Value) {
} else {
0.0
};
eprintln!(
get_global_ring0().log.info(&format!(
"[NYASH-KPI] resolve.choose Known={} Total={} ({:.1}%)",
known, total, rate
);
));
}
}

View File

@ -5,6 +5,7 @@
//! TypeRegistry の移行なしに観測ラインを確保する小粒ガードだよ。
use crate::mir::{MirType, ValueId};
use crate::runtime::get_global_ring0;
use std::sync::OnceLock;
fn enabled() -> bool {
@ -15,20 +16,27 @@ fn enabled() -> bool {
/// Trace when a newbox/class origin is registered.
pub fn origin(event: &str, vid: ValueId, class: &str) {
if enabled() {
eprintln!("[type-trace] origin:{} %{}{}", event, vid.0, class);
get_global_ring0()
.log
.debug(&format!("[type-trace] origin:{} %{}{}", event, vid.0, class));
}
}
/// Trace when a concrete MirType is recorded.
pub fn ty(event: &str, vid: ValueId, ty: &MirType) {
if enabled() {
eprintln!("[type-trace] type:{} %{}{:?}", event, vid.0, ty);
get_global_ring0()
.log
.debug(&format!("[type-trace] type:{} %{}{:?}", event, vid.0, ty));
}
}
/// Trace propagation between ValueIds.
pub fn propagate(event: &str, src: ValueId, dst: ValueId) {
if enabled() {
eprintln!("[type-trace] propagate:{} %{} → %{}", event, src.0, dst.0);
get_global_ring0().log.debug(&format!(
"[type-trace] propagate:{} %{} → %{}",
event, src.0, dst.0
));
}
}

View File

@ -6,6 +6,7 @@
//! 🔄 戻せる: NYASH_TYPE_REGISTRY_TRACE=1 で詳細ログ
use crate::mir::{MirType, ValueId};
use crate::runtime::get_global_ring0;
use std::collections::HashMap;
/// 型情報追跡エントリ(デバッグ用)
@ -62,7 +63,9 @@ impl TypeRegistry {
timestamp: self.trace_log.len(),
};
self.trace_log.push(entry.clone());
eprintln!("[type-registry] {} {:?}", entry.source, vid);
get_global_ring0()
.log
.debug(&format!("[type-registry] {} {:?}", entry.source, vid));
}
}
@ -78,8 +81,10 @@ impl TypeRegistry {
source: format!("param:{}:{:?}", param_name, ty),
timestamp: self.trace_log.len(),
};
self.trace_log.push(entry.clone());
eprintln!("[type-registry] {} {:?}", entry.source, vid);
self.trace_log.push(entry.clone());
get_global_ring0()
.log
.debug(&format!("[type-registry] {} {:?}", entry.source, vid));
}
} else if self.trace_enabled {
let entry = TraceEntry {
@ -88,7 +93,9 @@ impl TypeRegistry {
timestamp: self.trace_log.len(),
};
self.trace_log.push(entry.clone());
eprintln!("[type-registry] {} {:?}", entry.source, vid);
get_global_ring0()
.log
.debug(&format!("[type-registry] {} {:?}", entry.source, vid));
}
}
@ -103,7 +110,9 @@ impl TypeRegistry {
timestamp: self.trace_log.len(),
};
self.trace_log.push(entry.clone());
eprintln!("[type-registry] {} {:?}", entry.source, vid);
get_global_ring0()
.log
.debug(&format!("[type-registry] {} {:?}", entry.source, vid));
}
}
@ -119,7 +128,9 @@ impl TypeRegistry {
timestamp: self.trace_log.len(),
};
self.trace_log.push(entry.clone());
eprintln!("[type-registry] {} {:?}", entry.source, vid);
get_global_ring0()
.log
.debug(&format!("[type-registry] {} {:?}", entry.source, vid));
}
}
@ -142,7 +153,9 @@ impl TypeRegistry {
timestamp: self.trace_log.len(),
};
self.trace_log.push(entry.clone());
eprintln!("[type-registry] {} {:?}", entry.source, dst);
get_global_ring0()
.log
.debug(&format!("[type-registry] {} {:?}", entry.source, dst));
}
}
@ -156,7 +169,9 @@ impl TypeRegistry {
timestamp: self.trace_log.len(),
};
self.trace_log.push(entry.clone());
eprintln!("[type-registry] {} {:?}", entry.source, dst);
get_global_ring0()
.log
.debug(&format!("[type-registry] {} {:?}", entry.source, dst));
}
}
}
@ -192,17 +207,19 @@ impl TypeRegistry {
// フォールバック: コンテキスト名(警告付き)
if let Some(ctx) = fallback_context {
if self.trace_enabled {
eprintln!(
get_global_ring0().log.warn(&format!(
"[type-registry] WARNING: fallback to context '{}' for %{}",
ctx, vid.0
);
));
}
return ctx.to_string();
}
// 最終フォールバック: UnknownBox
if self.trace_enabled {
eprintln!("[type-registry] WARNING: UnknownBox for %{}", vid.0);
get_global_ring0()
.log
.warn(&format!("[type-registry] WARNING: UnknownBox for %{}", vid.0));
}
"UnknownBox".to_string()
}