Phase A リファクタリング: String.length デバッグ基盤の強化
## 実装内容(振る舞い変更なし)
A-1: Hostcall シンボルの定数化
- 直書き文字列を SYM_* 定数に統一
- nyash.handle.of / nyash.string.len_h / nyash.console.birth_h
A-2: string_len ヘルパー抽出(共通化)
- src/jit/lower/core/string_len.rs 新設
- emit_len_with_fallback_{param,local_handle,literal} を移設
- 二段フォールバック(string.len_h → any.length_h)の集約
A-3: 観測の統一
- import 呼び出しトレース機能を追加(NYASH_JIT_TRACE_IMPORT=1)
- CraneliftBuilder/ObjectBuilder の emit_host_call に構造化イベント
- observe::lower_hostcall で len_h/any.length_h の追跡
## 今後の道筋(CURRENT_TASK.md に記載)
- P0: フェイルセーフ(NYASH_LEN_FORCE_BRIDGE=1)
- P1: シンボル解決の可視化
- P2: リテラル最優先の安定化
- P3: Return 材化の後方走査
バグは手強いけど、デバッグ基盤が整ったにゃ!
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -426,6 +426,22 @@ impl IRBuilder for CraneliftBuilder {
|
||||
}
|
||||
fn emit_host_call(&mut self, symbol: &str, _argc: usize, has_ret: bool) {
|
||||
use cranelift_codegen::ir::{AbiParam, Signature, types};
|
||||
// Structured lower event for import call
|
||||
{
|
||||
let mut arg_types: Vec<&'static str> = Vec::new();
|
||||
for _ in 0.._argc { arg_types.push("I64"); }
|
||||
crate::jit::events::emit_lower(
|
||||
serde_json::json!({
|
||||
"id": symbol,
|
||||
"decision": "allow",
|
||||
"reason": "import_call",
|
||||
"argc": _argc,
|
||||
"arg_types": arg_types,
|
||||
"ret": if has_ret { "I64" } else { "Void" }
|
||||
}),
|
||||
"hostcall","<jit>"
|
||||
);
|
||||
}
|
||||
let call_conv = self.module.isa().default_call_conv();
|
||||
let mut sig = Signature::new(call_conv);
|
||||
// Collect up to _argc i64 values from stack (right-to-left)
|
||||
@ -440,6 +456,22 @@ impl IRBuilder for CraneliftBuilder {
|
||||
}
|
||||
fn emit_host_call_typed(&mut self, symbol: &str, params: &[ParamKind], has_ret: bool, ret_is_f64: bool) {
|
||||
use cranelift_codegen::ir::{AbiParam, Signature, types};
|
||||
// Structured lower event for typed import call
|
||||
{
|
||||
let mut arg_types: Vec<&'static str> = Vec::new();
|
||||
for k in params { arg_types.push(match k { ParamKind::I64 | ParamKind::B1 => "I64", ParamKind::F64 => "F64" }); }
|
||||
crate::jit::events::emit_lower(
|
||||
serde_json::json!({
|
||||
"id": symbol,
|
||||
"decision": "allow",
|
||||
"reason": "import_call_typed",
|
||||
"argc": params.len(),
|
||||
"arg_types": arg_types,
|
||||
"ret": if has_ret { if ret_is_f64 { "F64" } else { "I64" } } else { "Void" }
|
||||
}),
|
||||
"hostcall","<jit>"
|
||||
);
|
||||
}
|
||||
let mut args: Vec<cranelift_codegen::ir::Value> = Vec::new();
|
||||
let take_n = params.len().min(self.value_stack.len());
|
||||
for _ in 0..take_n { if let Some(v) = self.value_stack.pop() { args.push(v); } }
|
||||
|
||||
Reference in New Issue
Block a user