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

@ -4,7 +4,9 @@ use std::{fs, process};
/// Execute using PyVM only (no Rust VM runtime). Emits MIR(JSON) and invokes tools/pyvm_runner.py.
pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
if crate::config::env::env_bool("NYASH_PYVM_TRACE") { eprintln!("[pyvm] entry"); }
if crate::config::env::env_bool("NYASH_PYVM_TRACE") {
eprintln!("[pyvm] entry");
}
// Read the file
let code = match fs::read_to_string(filename) {
Ok(content) => content,
@ -16,7 +18,9 @@ pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
// Using handling: AST-prelude collection (legacy inlining removed)
let mut code = if crate::config::env::enable_using() {
match crate::runner::modes::common_util::resolve::resolve_prelude_paths_profiled(runner, &code, filename) {
match crate::runner::modes::common_util::resolve::resolve_prelude_paths_profiled(
runner, &code, filename,
) {
Ok((clean, paths)) => {
if !paths.is_empty() && !crate::config::env::using_ast_enabled() {
eprintln!("❌ using: AST prelude merge is disabled in this profile. Enable NYASH_USING_AST=1 or remove 'using' lines.");
@ -25,9 +29,14 @@ pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
// PyVM pipeline currently does not merge prelude ASTs here; rely on main/common path for that.
clean
}
Err(e) => { eprintln!("{}", e); process::exit(1); }
Err(e) => {
eprintln!("{}", e);
process::exit(1);
}
}
} else { code };
} else {
code
};
// Dev sugar pre-expand: line-head @name[:T] = expr → local name[:T] = expr
code = crate::runner::modes::common_util::resolve::preexpand_at_local(&code);
@ -42,31 +51,76 @@ pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
while let Some(c) = it.next() {
if in_line {
out.push(c);
if c == '\n' { in_line = false; }
if c == '\n' {
in_line = false;
}
continue;
}
if in_block {
out.push(c);
if c == '*' && matches!(it.peek(), Some('/')) { out.push('/'); it.next(); in_block = false; }
if c == '*' && matches!(it.peek(), Some('/')) {
out.push('/');
it.next();
in_block = false;
}
continue;
}
if in_str {
out.push(c);
if c == '\\' { if let Some(nc) = it.next() { out.push(nc); } continue; }
if c == '"' { in_str = false; }
if c == '\\' {
if let Some(nc) = it.next() {
out.push(nc);
}
continue;
}
if c == '"' {
in_str = false;
}
continue;
}
match c {
'"' => { in_str = true; out.push(c); }
'/' => {
match it.peek() { Some('/') => { out.push('/'); out.push('/'); it.next(); in_line = true; }, Some('*') => { out.push('/'); out.push('*'); it.next(); in_block = true; }, _ => out.push('/') }
'"' => {
in_str = true;
out.push(c);
}
'/' => match it.peek() {
Some('/') => {
out.push('/');
out.push('/');
it.next();
in_line = true;
}
Some('*') => {
out.push('/');
out.push('*');
it.next();
in_block = true;
}
_ => out.push('/'),
},
'#' => {
in_line = true;
out.push('#');
}
'#' => { in_line = true; out.push('#'); }
'|' => {
if matches!(it.peek(), Some('|')) { out.push_str(" or "); it.next(); } else if matches!(it.peek(), Some('>')) { out.push('|'); out.push('>'); it.next(); } else { out.push('|'); }
if matches!(it.peek(), Some('|')) {
out.push_str(" or ");
it.next();
} else if matches!(it.peek(), Some('>')) {
out.push('|');
out.push('>');
it.next();
} else {
out.push('|');
}
}
'&' => {
if matches!(it.peek(), Some('&')) { out.push_str(" and "); it.next(); } else { out.push('&'); }
if matches!(it.peek(), Some('&')) {
out.push_str(" and ");
it.next();
} else {
out.push('&');
}
}
_ => out.push(c),
}
@ -79,13 +133,17 @@ pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
if crate::config::env::env_bool("NYASH_PYVM_DUMP_CODE") {
eprintln!("[pyvm-code]\n{}", code);
}
let ast = match NyashParser::parse_from_string(&code) {
Ok(ast) => ast,
Err(e) => {
eprintln!("❌ Parse error in {}: {}", filename, e);
process::exit(1);
}
};
let ast = match NyashParser::parse_from_string(&code) {
Ok(ast) => ast,
Err(e) => {
crate::runner::modes::common_util::diag::print_parse_error_with_context(
filename,
&code,
&e,
);
process::exit(1);
}
};
let ast = crate::r#macro::maybe_expand_and_dump(&ast, false);
let ast = crate::runner::modes::macro_child::normalize_core_pass(&ast);
@ -101,8 +159,11 @@ pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
// Optional: VM-only escape analysis elision pass retained for parity with VM path
if crate::config::env::env_bool("NYASH_VM_ESCAPE_ANALYSIS") {
let removed = nyash_rust::mir::passes::escape::escape_elide_barriers_vm(&mut compile_result.module);
if removed > 0 { crate::cli_v!("[PyVM] escape_elide_barriers: removed {} barriers", removed); }
let removed =
nyash_rust::mir::passes::escape::escape_elide_barriers_vm(&mut compile_result.module);
if removed > 0 {
crate::cli_v!("[PyVM] escape_elide_barriers: removed {} barriers", removed);
}
}
// Optional: delegate to Ny selfhost executor (Stage 0 scaffold: no-op)
@ -111,12 +172,16 @@ pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
let tmp_dir = std::path::Path::new("tmp");
let _ = std::fs::create_dir_all(tmp_dir);
let mir_json_path = tmp_dir.join("nyash_selfhost_mir.json");
if let Err(e) = crate::runner::mir_json_emit::emit_mir_json_for_harness_bin(&compile_result.module, &mir_json_path) {
if let Err(e) = crate::runner::mir_json_emit::emit_mir_json_for_harness_bin(
&compile_result.module,
&mir_json_path,
) {
eprintln!("❌ Selfhost MIR JSON emit error: {}", e);
process::exit(1);
}
// Resolve nyash executable and runner path
let exe = std::env::current_exe().unwrap_or_else(|_| std::path::PathBuf::from("target/release/nyash"));
let exe = std::env::current_exe()
.unwrap_or_else(|_| std::path::PathBuf::from("target/release/nyash"));
let runner = std::path::Path::new("apps/selfhost-runtime/runner.hako");
if !runner.exists() {
eprintln!("❌ Selfhost runner missing: {}", runner.display());
@ -124,7 +189,8 @@ pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
}
let mut cmd = std::process::Command::new(&exe);
crate::runner::child_env::apply_core_wrapper_env(&mut cmd);
cmd.arg("--backend").arg("vm")
cmd.arg("--backend")
.arg("vm")
.arg(runner)
.arg("--")
.arg(mir_json_path.display().to_string());
@ -139,14 +205,25 @@ pub fn execute_pyvm_only(runner: &NyashRunner, filename: &str) {
// Avoid recursive selfhost delegation inside the child.
.env_remove("NYASH_SELFHOST_EXEC")
.status()
.unwrap_or_else(|e| { eprintln!("❌ spawn selfhost runner failed: {}", e); std::process::exit(1); });
.unwrap_or_else(|e| {
eprintln!("❌ spawn selfhost runner failed: {}", e);
std::process::exit(1);
});
let code = status.code().unwrap_or(1);
process::exit(code);
}
// Delegate to common PyVM harness
match crate::runner::modes::common_util::pyvm::run_pyvm_harness_lib(&compile_result.module, "pyvm") {
Ok(code) => { process::exit(code); }
Err(e) => { eprintln!("❌ PyVM error: {}", e); process::exit(1); }
match crate::runner::modes::common_util::pyvm::run_pyvm_harness_lib(
&compile_result.module,
"pyvm",
) {
Ok(code) => {
process::exit(code);
}
Err(e) => {
eprintln!("❌ PyVM error: {}", e);
process::exit(1);
}
}
}