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:
141
src/cli/args.rs
141
src/cli/args.rs
@ -1,7 +1,7 @@
|
||||
use super::utils::parse_debug_fuel;
|
||||
use super::CliConfig;
|
||||
use clap::{Arg, ArgMatches, Command};
|
||||
use serde_json;
|
||||
use super::CliConfig;
|
||||
use super::utils::parse_debug_fuel;
|
||||
|
||||
pub fn parse() -> CliConfig {
|
||||
let argv: Vec<String> = std::env::args().collect();
|
||||
@ -13,10 +13,7 @@ pub fn parse() -> CliConfig {
|
||||
}
|
||||
// Provide HEX-escaped JSON as an alternate robust path for multiline/special bytes
|
||||
// Each arg is encoded as lowercase hex of its UTF-8 bytes
|
||||
let hex_args: Vec<String> = script_args
|
||||
.iter()
|
||||
.map(|s| hex_encode_utf8(s))
|
||||
.collect();
|
||||
let hex_args: Vec<String> = script_args.iter().map(|s| hex_encode_utf8(s)).collect();
|
||||
if let Ok(hex_json) = serde_json::to_string(&hex_args) {
|
||||
std::env::set_var("NYASH_SCRIPT_ARGS_HEX_JSON", hex_json);
|
||||
}
|
||||
@ -118,8 +115,12 @@ fn hex_encode_utf8(s: &str) -> String {
|
||||
}
|
||||
|
||||
pub fn from_matches(matches: &ArgMatches) -> CliConfig {
|
||||
if matches.get_flag("stage3") { std::env::set_var("NYASH_NY_COMPILER_STAGE3", "1"); }
|
||||
if let Some(a) = matches.get_one::<String>("ny-compiler-args") { std::env::set_var("NYASH_NY_COMPILER_CHILD_ARGS", a); }
|
||||
if matches.get_flag("stage3") {
|
||||
std::env::set_var("NYASH_NY_COMPILER_STAGE3", "1");
|
||||
}
|
||||
if let Some(a) = matches.get_one::<String>("ny-compiler-args") {
|
||||
std::env::set_var("NYASH_NY_COMPILER_CHILD_ARGS", a);
|
||||
}
|
||||
let cfg = CliConfig {
|
||||
file: matches.get_one::<String>("file").cloned(),
|
||||
debug_fuel: parse_debug_fuel(matches.get_one::<String>("debug-fuel").unwrap()),
|
||||
@ -134,7 +135,11 @@ pub fn from_matches(matches: &ArgMatches) -> CliConfig {
|
||||
compile_native: matches.get_flag("compile-native") || matches.get_flag("aot"),
|
||||
output_file: matches.get_one::<String>("output").cloned(),
|
||||
benchmark: matches.get_flag("benchmark"),
|
||||
iterations: matches.get_one::<String>("iterations").unwrap().parse().unwrap_or(10),
|
||||
iterations: matches
|
||||
.get_one::<String>("iterations")
|
||||
.unwrap()
|
||||
.parse()
|
||||
.unwrap_or(10),
|
||||
vm_stats: matches.get_flag("vm-stats"),
|
||||
vm_stats_json: matches.get_flag("vm-stats-json"),
|
||||
jit_exec: matches.get_flag("jit-exec"),
|
||||
@ -145,7 +150,9 @@ pub fn from_matches(matches: &ArgMatches) -> CliConfig {
|
||||
jit_events_compile: matches.get_flag("jit-events-compile"),
|
||||
jit_events_runtime: matches.get_flag("jit-events-runtime"),
|
||||
jit_events_path: matches.get_one::<String>("jit-events-path").cloned(),
|
||||
jit_threshold: matches.get_one::<String>("jit-threshold").and_then(|s| s.parse::<u32>().ok()),
|
||||
jit_threshold: matches
|
||||
.get_one::<String>("jit-threshold")
|
||||
.and_then(|s| s.parse::<u32>().ok()),
|
||||
jit_phi_min: matches.get_flag("jit-phi-min"),
|
||||
jit_hostcall: matches.get_flag("jit-hostcall"),
|
||||
jit_handle_debug: matches.get_flag("jit-handle-debug"),
|
||||
@ -158,7 +165,10 @@ pub fn from_matches(matches: &ArgMatches) -> CliConfig {
|
||||
run_task: matches.get_one::<String>("run-task").cloned(),
|
||||
load_ny_plugins: matches.get_flag("load-ny-plugins"),
|
||||
gc_mode: matches.get_one::<String>("gc").cloned(),
|
||||
parser_ny: matches.get_one::<String>("parser").map(|s| s == "ny").unwrap_or(false),
|
||||
parser_ny: matches
|
||||
.get_one::<String>("parser")
|
||||
.map(|s| s == "ny")
|
||||
.unwrap_or(false),
|
||||
ny_parser_pipe: matches.get_flag("ny-parser-pipe"),
|
||||
json_file: matches.get_one::<String>("json-file").cloned(),
|
||||
mir_json_file: matches.get_one::<String>("mir-json-file").cloned(),
|
||||
@ -168,7 +178,10 @@ pub fn from_matches(matches: &ArgMatches) -> CliConfig {
|
||||
build_aot: matches.get_one::<String>("build-aot").cloned(),
|
||||
build_profile: matches.get_one::<String>("build-profile").cloned(),
|
||||
build_target: matches.get_one::<String>("build-target").cloned(),
|
||||
cli_usings: matches.get_many::<String>("using").map(|v| v.cloned().collect()).unwrap_or_else(|| Vec::new()),
|
||||
cli_usings: matches
|
||||
.get_many::<String>("using")
|
||||
.map(|v| v.cloned().collect())
|
||||
.unwrap_or_else(|| Vec::new()),
|
||||
emit_mir_json: matches.get_one::<String>("emit-mir-json").cloned(),
|
||||
program_json_to_mir: matches.get_one::<String>("program-json-to-mir").cloned(),
|
||||
emit_exe: matches.get_one::<String>("emit-exe").cloned(),
|
||||
@ -179,42 +192,94 @@ pub fn from_matches(matches: &ArgMatches) -> CliConfig {
|
||||
macro_ctx_json: matches.get_one::<String>("macro-ctx-json").cloned(),
|
||||
};
|
||||
|
||||
if cfg.cli_verbose { std::env::set_var("NYASH_CLI_VERBOSE", "1"); }
|
||||
if cfg.vm_stats { std::env::set_var("NYASH_VM_STATS", "1"); }
|
||||
if cfg.vm_stats_json { std::env::set_var("NYASH_VM_STATS_JSON", "1"); }
|
||||
if cfg.jit_exec { std::env::set_var("NYASH_JIT_EXEC", "1"); }
|
||||
if cfg.jit_stats { std::env::set_var("NYASH_JIT_STATS", "1"); }
|
||||
if cfg.jit_stats_json { std::env::set_var("NYASH_JIT_STATS_JSON", "1"); }
|
||||
if cfg.jit_dump { std::env::set_var("NYASH_JIT_DUMP", "1"); }
|
||||
if cfg.jit_events { std::env::set_var("NYASH_JIT_EVENTS", "1"); }
|
||||
if cfg.jit_events_compile { std::env::set_var("NYASH_JIT_EVENTS_COMPILE", "1"); }
|
||||
if cfg.jit_events_runtime { std::env::set_var("NYASH_JIT_EVENTS_RUNTIME", "1"); }
|
||||
if let Some(p) = &cfg.jit_events_path { std::env::set_var("NYASH_JIT_EVENTS_PATH", p); }
|
||||
if let Some(t) = cfg.jit_threshold { std::env::set_var("NYASH_JIT_THRESHOLD", t.to_string()); }
|
||||
if cfg.jit_phi_min { std::env::set_var("NYASH_JIT_PHI_MIN", "1"); }
|
||||
if cfg.jit_hostcall { std::env::set_var("NYASH_JIT_HOSTCALL", "1"); }
|
||||
if cfg.jit_handle_debug { std::env::set_var("NYASH_JIT_HANDLE_DEBUG", "1"); }
|
||||
if cfg.jit_native_f64 { std::env::set_var("NYASH_JIT_NATIVE_F64", "1"); }
|
||||
if cfg.jit_native_bool { std::env::set_var("NYASH_JIT_NATIVE_BOOL", "1"); }
|
||||
if cfg.jit_only { std::env::set_var("NYASH_JIT_ONLY", "1"); }
|
||||
if cfg.jit_direct { std::env::set_var("NYASH_JIT_DIRECT", "1"); }
|
||||
if let Some(gc) = &cfg.gc_mode { std::env::set_var("NYASH_GC_MODE", gc); }
|
||||
if cfg.cli_verbose {
|
||||
std::env::set_var("NYASH_CLI_VERBOSE", "1");
|
||||
}
|
||||
if cfg.vm_stats {
|
||||
std::env::set_var("NYASH_VM_STATS", "1");
|
||||
}
|
||||
if cfg.vm_stats_json {
|
||||
std::env::set_var("NYASH_VM_STATS_JSON", "1");
|
||||
}
|
||||
if cfg.jit_exec {
|
||||
std::env::set_var("NYASH_JIT_EXEC", "1");
|
||||
}
|
||||
if cfg.jit_stats {
|
||||
std::env::set_var("NYASH_JIT_STATS", "1");
|
||||
}
|
||||
if cfg.jit_stats_json {
|
||||
std::env::set_var("NYASH_JIT_STATS_JSON", "1");
|
||||
}
|
||||
if cfg.jit_dump {
|
||||
std::env::set_var("NYASH_JIT_DUMP", "1");
|
||||
}
|
||||
if cfg.jit_events {
|
||||
std::env::set_var("NYASH_JIT_EVENTS", "1");
|
||||
}
|
||||
if cfg.jit_events_compile {
|
||||
std::env::set_var("NYASH_JIT_EVENTS_COMPILE", "1");
|
||||
}
|
||||
if cfg.jit_events_runtime {
|
||||
std::env::set_var("NYASH_JIT_EVENTS_RUNTIME", "1");
|
||||
}
|
||||
if let Some(p) = &cfg.jit_events_path {
|
||||
std::env::set_var("NYASH_JIT_EVENTS_PATH", p);
|
||||
}
|
||||
if let Some(t) = cfg.jit_threshold {
|
||||
std::env::set_var("NYASH_JIT_THRESHOLD", t.to_string());
|
||||
}
|
||||
if cfg.jit_phi_min {
|
||||
std::env::set_var("NYASH_JIT_PHI_MIN", "1");
|
||||
}
|
||||
if cfg.jit_hostcall {
|
||||
std::env::set_var("NYASH_JIT_HOSTCALL", "1");
|
||||
}
|
||||
if cfg.jit_handle_debug {
|
||||
std::env::set_var("NYASH_JIT_HANDLE_DEBUG", "1");
|
||||
}
|
||||
if cfg.jit_native_f64 {
|
||||
std::env::set_var("NYASH_JIT_NATIVE_F64", "1");
|
||||
}
|
||||
if cfg.jit_native_bool {
|
||||
std::env::set_var("NYASH_JIT_NATIVE_BOOL", "1");
|
||||
}
|
||||
if cfg.jit_only {
|
||||
std::env::set_var("NYASH_JIT_ONLY", "1");
|
||||
}
|
||||
if cfg.jit_direct {
|
||||
std::env::set_var("NYASH_JIT_DIRECT", "1");
|
||||
}
|
||||
if let Some(gc) = &cfg.gc_mode {
|
||||
std::env::set_var("NYASH_GC_MODE", gc);
|
||||
}
|
||||
|
||||
if matches.get_flag("run-tests") {
|
||||
std::env::set_var("NYASH_RUN_TESTS", "1");
|
||||
if let Some(filter) = matches.get_one::<String>("test-filter") { std::env::set_var("NYASH_TEST_FILTER", filter); }
|
||||
if let Some(filter) = matches.get_one::<String>("test-filter") {
|
||||
std::env::set_var("NYASH_TEST_FILTER", filter);
|
||||
}
|
||||
if let Some(entry) = matches.get_one::<String>("test-entry") {
|
||||
let v = entry.as_str();
|
||||
if v == "wrap" || v == "override" { std::env::set_var("NYASH_TEST_ENTRY", v); }
|
||||
if v == "wrap" || v == "override" {
|
||||
std::env::set_var("NYASH_TEST_ENTRY", v);
|
||||
}
|
||||
}
|
||||
if let Some(ret) = matches.get_one::<String>("test-return") {
|
||||
let v = ret.as_str();
|
||||
if v == "tests" || v == "original" { std::env::set_var("NYASH_TEST_RETURN", v); }
|
||||
if v == "tests" || v == "original" {
|
||||
std::env::set_var("NYASH_TEST_RETURN", v);
|
||||
}
|
||||
}
|
||||
}
|
||||
if matches.get_flag("macro-preexpand") { std::env::set_var("NYASH_MACRO_SELFHOST_PRE_EXPAND", "1"); }
|
||||
if matches.get_flag("macro-preexpand-auto") { std::env::set_var("NYASH_MACRO_SELFHOST_PRE_EXPAND", "auto"); }
|
||||
if matches.get_flag("macro-top-level-allow") { std::env::set_var("NYASH_MACRO_TOPLEVEL_ALLOW", "1"); }
|
||||
if matches.get_flag("macro-preexpand") {
|
||||
std::env::set_var("NYASH_MACRO_SELFHOST_PRE_EXPAND", "1");
|
||||
}
|
||||
if matches.get_flag("macro-preexpand-auto") {
|
||||
std::env::set_var("NYASH_MACRO_SELFHOST_PRE_EXPAND", "auto");
|
||||
}
|
||||
if matches.get_flag("macro-top-level-allow") {
|
||||
std::env::set_var("NYASH_MACRO_TOPLEVEL_ALLOW", "1");
|
||||
}
|
||||
if let Some(p) = matches.get_one::<String>("macro-profile") {
|
||||
match p.as_str() {
|
||||
"dev" | "ci-fast" | "strict" => {
|
||||
|
||||
@ -6,7 +6,6 @@ mod args;
|
||||
mod groups;
|
||||
mod utils;
|
||||
|
||||
|
||||
/// Command-line configuration structure
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CliConfig {
|
||||
@ -69,14 +68,22 @@ pub struct CliConfig {
|
||||
pub macro_ctx_json: Option<String>,
|
||||
}
|
||||
|
||||
pub use groups::{BackendConfig, BuildConfig, CliGroups, DebugConfig, EmitConfig, InputConfig, JitConfig, ParserPipeConfig};
|
||||
pub use groups::{
|
||||
BackendConfig, BuildConfig, CliGroups, DebugConfig, EmitConfig, InputConfig, JitConfig,
|
||||
ParserPipeConfig,
|
||||
};
|
||||
|
||||
impl CliConfig {
|
||||
pub fn parse() -> Self { args::parse() }
|
||||
pub fn parse() -> Self {
|
||||
args::parse()
|
||||
}
|
||||
|
||||
pub fn as_groups(&self) -> CliGroups {
|
||||
CliGroups {
|
||||
input: InputConfig { file: self.file.clone(), cli_usings: self.cli_usings.clone() },
|
||||
input: InputConfig {
|
||||
file: self.file.clone(),
|
||||
cli_usings: self.cli_usings.clone(),
|
||||
},
|
||||
debug: DebugConfig {
|
||||
debug_fuel: self.debug_fuel,
|
||||
dump_ast: self.dump_ast,
|
||||
|
||||
@ -6,4 +6,3 @@ pub fn parse_debug_fuel(value: &str) -> Option<usize> {
|
||||
value.parse::<usize>().ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user