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

@ -3,6 +3,7 @@
use crate::bid::{BidError, BidResult};
use crate::box_trait::NyashBox;
use crate::runtime::plugin_loader_v2::enabled::PluginLoaderV2;
use crate::runtime::get_global_ring0;
use std::env;
use std::sync::Arc;
@ -27,10 +28,10 @@ impl PluginLoaderV2 {
Ok(mid) => mid,
Err(e) => {
if dbg_on() {
eprintln!(
get_global_ring0().log.debug(&format!(
"[PluginLoaderV2] ERR: method resolve failed for {}.{}: {:?}",
box_type, method_name, e
);
));
}
return Err(BidError::InvalidMethod);
}
@ -43,7 +44,9 @@ impl PluginLoaderV2 {
// Optional C wrapper (Phase 22.2: design insertion point; default OFF)
if env::var("HAKO_PLUGIN_LOADER_C_WRAP").ok().as_deref() == Some("1") {
if should_trace_cwrap(box_type, method_name) {
eprintln!("[cwrap:invoke:{}.{}]", box_type, method_name);
get_global_ring0()
.log
.debug(&format!("[cwrap:invoke:{}.{}]", box_type, method_name));
}
// Future: route into a thin C shim here. For now, fall through to normal path.
}
@ -52,7 +55,9 @@ impl PluginLoaderV2 {
if env::var("HAKO_C_CORE_ENABLE").ok().as_deref() == Some("1")
&& should_route_ccore(box_type, method_name)
{
eprintln!("[c-core:invoke:{}.{}]", box_type, method_name);
get_global_ring0()
.log
.debug(&format!("[c-core:invoke:{}.{}]", box_type, method_name));
#[cfg(feature = "c-core")]
{
// MapBox.set: call C-core stub (no-op) with available info
@ -89,7 +94,9 @@ impl PluginLoaderV2 {
// Unified call trace (optional): plugin calls
if env::var("HAKO_CALL_TRACE").ok().as_deref() == Some("1") {
if should_trace_call(box_type, method_name) {
eprintln!("[call:{}.{}]", box_type, method_name);
get_global_ring0()
.log
.debug(&format!("[call:{}.{}]", box_type, method_name));
}
}
@ -98,18 +105,22 @@ impl PluginLoaderV2 {
&& env::var("HAKO_TLV_SHIM").ok().as_deref() == Some("1")
{
if should_trace_tlv_shim(box_type, method_name) {
eprintln!("[tlv/shim:{}.{}]", box_type, method_name);
get_global_ring0()
.log
.debug(&format!("[tlv/shim:{}.{}]", box_type, method_name));
if env::var("HAKO_TLV_SHIM_TRACE_DETAIL").ok().as_deref() == Some("1") {
eprintln!("[tlv/shim:detail argc={}]", args.len());
get_global_ring0()
.log
.debug(&format!("[tlv/shim:detail argc={}]", args.len()));
}
}
}
if dbg_on() {
eprintln!(
get_global_ring0().log.debug(&format!(
"[PluginLoaderV2] call {}.{}: type_id={} method_id={} instance_id={}",
box_type, method_name, type_id, method_id, instance_id
);
));
}
let (_code, out_len, out) = super::host_bridge::invoke_alloc(