feat(phase21.5/22.1): MirBuilder JsonFrag refactor + FileBox ring-1 + registry tests
Phase 21.5 (AOT/LLVM Optimization Prep) - FileBox ring-1 (core-ro) provider: priority=-100, always available, no panic path - src/runner/modes/common_util/provider_registry.rs: CoreRoFileProviderFactory - Auto-registers at startup, eliminates fallback panic structurally - StringBox fast path prototypes (length/size optimization) - Performance benchmarks (C/Python/Hako comparison baseline) Phase 22.1 (JsonFrag Unification) - JsonFrag.last_index_of_from() for backward search (VM fallback) - Replace hand-written lastIndexOf in lower_loop_sum_bc_box.hako - SentinelExtractorBox for Break/Continue pattern extraction MirBuilder Refactor (Box → JsonFrag Migration) - 20+ lower_*_box.hako: Box-heavy → JsonFrag text assembly - MirBuilderMinBox: lightweight using set for dev env - Registry-only fast path with [registry:*] tag observation - pattern_util_box.hako: enhanced pattern matching Dev Environment & Testing - Dev toggles: SMOKES_DEV_PREINCLUDE=1 (point-enable), HAKO_MIR_BUILDER_SKIP_LOOPS=1 - phase2160: registry opt-in tests (array/map get/set/push/len) - content verification - phase2034: rc-dependent → token grep (grep -F based validation) - run_quick.sh: fast smoke testing harness - ENV documentation: docs/ENV_VARS.md Test Results ✅ quick phase2034: ALL GREEN (MirBuilder internal patterns) ✅ registry phase2160: ALL GREEN (array/map get/set/push/len) ✅ rc-dependent tests → content token verification complete ✅ PREINCLUDE policy: default OFF, point-enable only where needed Technical Notes - No INCLUDE by default (maintain minimalism) - FAIL_FAST=0 in Bring-up contexts only (explicit dev toggles) - Tag-based route observation ([mirbuilder/min:*], [registry:*]) - MIR structure validation (not just rc parity) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -13,6 +13,31 @@ impl MirInterpreter {
|
||||
if let Err(e) = crate::runtime::provider_lock::guard_before_new_box(box_type) {
|
||||
return Err(self.err_invalid(e));
|
||||
}
|
||||
|
||||
// Fast path (bench/profile-only): new StringBox("const") without registry roundtrip
|
||||
if std::env::var("NYASH_VM_FAST").ok().as_deref() == Some("1") && box_type == "StringBox" {
|
||||
if args.len() == 1 {
|
||||
let v0 = self.reg_load(args[0])?;
|
||||
let s_opt: Option<String> = match v0.clone() {
|
||||
VMValue::String(s) => Some(s),
|
||||
VMValue::BoxRef(b) => {
|
||||
if let Some(sb) = b.as_any().downcast_ref::<crate::boxes::basic::StringBox>() {
|
||||
Some(sb.value.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let Some(s) = s_opt {
|
||||
let boxed: Box<dyn crate::box_trait::NyashBox> = Box::new(crate::boxes::basic::StringBox::new(s));
|
||||
let created_vm = VMValue::from_nyash_box(boxed);
|
||||
self.regs.insert(dst, created_vm);
|
||||
if Self::box_trace_enabled() { self.box_trace_emit_new(box_type, args.len()); }
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
let converted = self.load_args_as_boxes(args)?;
|
||||
let reg = crate::runtime::unified_registry::get_global_unified_registry();
|
||||
let created = reg
|
||||
|
||||
@ -13,6 +13,17 @@ pub(super) fn try_handle_string_box(
|
||||
eprintln!("[vm-trace] try_handle_string_box(method={})", method);
|
||||
}
|
||||
let recv = this.reg_load(box_val)?;
|
||||
// Ultra-fast path: raw VM string receiver for length/size (no boxing at all)
|
||||
if (method == "length" || method == "size")
|
||||
&& std::env::var("NYASH_VM_FAST").ok().as_deref() == Some("1")
|
||||
{
|
||||
if let VMValue::String(ref raw) = recv {
|
||||
let use_cp = std::env::var("NYASH_STR_CP").ok().as_deref() == Some("1");
|
||||
let n = if use_cp { raw.chars().count() as i64 } else { raw.len() as i64 };
|
||||
this.write_result(dst, VMValue::Integer(n));
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
// Handle ONLY when the receiver is actually a string.
|
||||
// Do NOT coerce arbitrary boxes to StringBox (e.g., ArrayBox.length()).
|
||||
let sb_norm_opt: Option<crate::box_trait::StringBox> = match recv.clone() {
|
||||
@ -30,6 +41,13 @@ pub(super) fn try_handle_string_box(
|
||||
// Only handle known string methods here (receiver is confirmed string)
|
||||
match method {
|
||||
"length" | "size" => {
|
||||
// Bench/profile fast path: return VMValue::Integer directly (avoid boxing overhead)
|
||||
if std::env::var("NYASH_VM_FAST").ok().as_deref() == Some("1") {
|
||||
let use_cp = std::env::var("NYASH_STR_CP").ok().as_deref() == Some("1");
|
||||
let n = if use_cp { sb_norm.value.chars().count() as i64 } else { sb_norm.value.len() as i64 };
|
||||
this.write_result(dst, VMValue::Integer(n));
|
||||
return Ok(true);
|
||||
}
|
||||
let ret = sb_norm.length();
|
||||
this.write_result(dst, VMValue::from_nyash_box(ret));
|
||||
return Ok(true);
|
||||
|
||||
Reference in New Issue
Block a user