chore: Phase 25.1 完了 - LoopForm v2/Stage1 CLI/環境変数削減 + Phase 26-D からの変更

Phase 25.1 完了成果:
-  LoopForm v2 テスト・ドキュメント・コメント完備
  - 4ケース(A/B/C/D)完全テストカバレッジ
  - 最小再現ケース作成(SSAバグ調査用)
  - SSOT文書作成(loopform_ssot.md)
  - 全ソースに [LoopForm] コメントタグ追加

-  Stage-1 CLI デバッグ環境構築
  - stage1_cli.hako 実装
  - stage1_bridge.rs ブリッジ実装
  - デバッグツール作成(stage1_debug.sh/stage1_minimal.sh)
  - アーキテクチャ改善提案文書

-  環境変数削減計画策定
  - 25変数の完全調査・分類
  - 6段階削減ロードマップ(25→5、80%削減)
  - 即時削除可能変数特定(NYASH_CONFIG/NYASH_DEBUG)

Phase 26-D からの累積変更:
- PHI実装改善(ExitPhiBuilder/HeaderPhiBuilder等)
- MIRビルダーリファクタリング
- 型伝播・最適化パス改善
- その他約300ファイルの累積変更

🎯 技術的成果:
- SSAバグ根本原因特定(条件分岐内loop変数変更)
- Region+next_iパターン適用完了(UsingCollectorBox等)
- LoopFormパターン文書化・テスト化完了
- セルフホスティング基盤強化

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: ChatGPT <noreply@openai.com>
Co-Authored-By: Task Assistant <task@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-21 06:25:17 +09:00
parent baf028a94f
commit f9d100ce01
366 changed files with 14322 additions and 5236 deletions

View File

@ -18,7 +18,9 @@ pub(crate) fn execute_file_with_backend(runner: &NyashRunner, filename: &str) {
if runner.try_run_selfhost_pipeline(filename) {
return;
} else {
crate::cli_v!("[ny-compiler] fallback to default path (MVP unavailable for this input)");
crate::cli_v!(
"[ny-compiler] fallback to default path (MVP unavailable for this input)"
);
}
}
@ -31,7 +33,11 @@ pub(crate) fn execute_file_with_backend(runner: &NyashRunner, filename: &str) {
// Try schema v1 first (preferred by emitter)
match crate::runner::json_v1_bridge::try_parse_v1_to_module(&text) {
Ok(Some(module)) => {
crate::cli_v!("[mir-json] schema=v1 executing {} (len={})", path, text.len());
crate::cli_v!(
"[mir-json] schema=v1 executing {} (len={})",
path,
text.len()
);
let rc = runner.execute_mir_module_quiet_exit(&module);
std::process::exit(rc);
}
@ -40,7 +46,11 @@ pub(crate) fn execute_file_with_backend(runner: &NyashRunner, filename: &str) {
if text.contains("\"functions\"") && text.contains("\"blocks\"") {
match crate::runner::mir_json_v0::parse_mir_v0_to_module(&text) {
Ok(module) => {
crate::cli_v!("[mir-json] schema=v0 executing {} (len={})", path, text.len());
crate::cli_v!(
"[mir-json] schema=v0 executing {} (len={})",
path,
text.len()
);
let rc = runner.execute_mir_module_quiet_exit(&module);
std::process::exit(rc);
}
@ -77,7 +87,10 @@ pub(crate) fn execute_file_with_backend(runner: &NyashRunner, filename: &str) {
};
match json_v0_bridge::parse_source_v0_to_module(&code) {
Ok(module) => {
crate::cli_v!("🚀 Hakorune MIR Interpreter - (parser=ny) Executing file: {} 🚀", filename);
crate::cli_v!(
"🚀 Hakorune MIR Interpreter - (parser=ny) Executing file: {} 🚀",
filename
);
runner.execute_mir_module(&module);
return;
}
@ -100,10 +113,14 @@ pub(crate) fn execute_file_with_backend(runner: &NyashRunner, filename: &str) {
};
let ast = match NyashParser::parse_from_string(&code) {
Ok(ast) => ast,
Err(e) => {
eprintln!("❌ Parse error in {}: {}", filename, e);
process::exit(1);
}
Err(e) => {
crate::runner::modes::common_util::diag::print_parse_error_with_context(
filename,
&code,
&e,
);
process::exit(1);
}
};
// Optional macro expansion dump (no-op expansion for now)
let ast2 = if crate::r#macro::enabled() {
@ -120,16 +137,28 @@ pub(crate) fn execute_file_with_backend(runner: &NyashRunner, filename: &str) {
if runner.config.dump_expanded_ast_json {
let code = match fs::read_to_string(filename) {
Ok(content) => content,
Err(e) => { eprintln!("❌ Error reading file {}: {}", filename, e); process::exit(1); }
Err(e) => {
eprintln!("❌ Error reading file {}: {}", filename, e);
process::exit(1);
}
};
let ast = match NyashParser::parse_from_string(&code) {
Ok(ast) => ast,
Err(e) => { eprintln!("❌ Parse error in {}: {}", filename, e); process::exit(1); }
Err(e) => {
crate::runner::modes::common_util::diag::print_parse_error_with_context(
filename,
&code,
&e,
);
process::exit(1);
}
};
let expanded = if crate::r#macro::enabled() {
let a = crate::r#macro::maybe_expand_and_dump(&ast, false);
crate::runner::modes::macro_child::normalize_core_pass(&a)
} else { ast };
} else {
ast
};
let j = crate::r#macro::ast_json::ast_to_json(&expanded);
println!("{}", j.to_string());
return;
@ -137,7 +166,10 @@ pub(crate) fn execute_file_with_backend(runner: &NyashRunner, filename: &str) {
// MIR dump/verify
if groups.debug.dump_mir || groups.debug.verify_mir {
crate::cli_v!("🚀 Hakorune MIR Compiler - Processing file: {} 🚀", filename);
crate::cli_v!(
"🚀 Hakorune MIR Compiler - Processing file: {} 🚀",
filename
);
runner.execute_mir_mode(filename);
return;
}
@ -171,25 +203,36 @@ pub(crate) fn execute_file_with_backend(runner: &NyashRunner, filename: &str) {
// Backend selection
match groups.backend.backend.as_str() {
"mir" => {
crate::cli_v!("🚀 Hakorune MIR Interpreter - Executing file: {} 🚀", filename);
crate::cli_v!(
"🚀 Hakorune MIR Interpreter - Executing file: {} 🚀",
filename
);
runner.execute_mir_mode(filename);
}
"vm" => {
crate::cli_v!("🚀 Hakorune VM Backend - Executing file: {} 🚀", filename);
// Route to primary VM path by default. Fallback is a last resort and must be explicitly enabled.
let force_fallback = std::env::var("NYASH_VM_USE_FALLBACK").ok().as_deref() == Some("1");
let force_fallback =
std::env::var("NYASH_VM_USE_FALLBACK").ok().as_deref() == Some("1");
let route_trace = std::env::var("NYASH_VM_ROUTE_TRACE").ok().as_deref() == Some("1");
if force_fallback {
if route_trace { eprintln!("[vm-route] choose=fallback reason=env:NYASH_VM_USE_FALLBACK=1"); }
if route_trace {
eprintln!("[vm-route] choose=fallback reason=env:NYASH_VM_USE_FALLBACK=1");
}
runner.execute_vm_fallback_interpreter(filename);
} else {
if route_trace { eprintln!("[vm-route] choose=vm"); }
if route_trace {
eprintln!("[vm-route] choose=vm");
}
runner.execute_vm_mode(filename);
}
}
#[cfg(feature = "cranelift-jit")]
"jit-direct" => {
crate::cli_v!("⚡ Hakorune JIT-Direct Backend - Executing file: {} ⚡", filename);
crate::cli_v!(
"⚡ Hakorune JIT-Direct Backend - Executing file: {} ⚡",
filename
);
#[cfg(feature = "cranelift-jit")]
{
// Use independent JIT-direct runner method (no VM execute loop)
@ -269,10 +312,18 @@ impl NyashRunner {
}
}
// Global fallbacks when signature is missing or imprecise
if let Some(ib) = result.as_any().downcast_ref::<IntegerBox>() { return to_rc(ib.value); }
if let Some(bb) = result.as_any().downcast_ref::<BoolBox>() { return if bb.value { 1 } else { 0 }; }
if let Some(fb) = result.as_any().downcast_ref::<FloatBox>() { return to_rc(fb.value as i64); }
if let Some(_sb) = result.as_any().downcast_ref::<StringBox>() { return 0; }
if let Some(ib) = result.as_any().downcast_ref::<IntegerBox>() {
return to_rc(ib.value);
}
if let Some(bb) = result.as_any().downcast_ref::<BoolBox>() {
return if bb.value { 1 } else { 0 };
}
if let Some(fb) = result.as_any().downcast_ref::<FloatBox>() {
return to_rc(fb.value as i64);
}
if let Some(_sb) = result.as_any().downcast_ref::<StringBox>() {
return 0;
}
0
}
Err(_) => 1,