From e986e279b4b16336992887cc869e6d4312a0e004 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Thu, 25 Dec 2025 14:42:16 +0900 Subject: [PATCH] =?UTF-8?q?refactor(repl):=20Quiet=20Mode=20=E6=96=B9?= =?UTF-8?q?=E9=87=9D=E6=95=B4=E5=90=88=20-=20REPL=20=E5=B0=82=E7=94=A8?= =?UTF-8?q?=E3=83=95=E3=83=A9=E3=82=B0=E3=81=AB=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 方針整合修正(commit 1cec724ce の改善): - NYASH_QUIET_INTERNAL_LOGS 撤去(環境変数スパロー防止) - src/runner/repl/repl_runner.rs: quiet_internal_logs フラグ追加、環境変数操作削除 - src/mir/mod.rs: set_quiet_internal_logs() 公開 API 追加 - src/mir/builder/compilation_context.rs: quiet_internal_logs フラグ追加 - src/mir/builder/decls.rs: 環境変数直読み → context フラグ参照 アーキテクチャ: ✅ REPL 専用フラグで制御(file mode 無影響保証) ✅ ReplRunnerBox → MirCompiler → CompilationContext の明確な伝播経路 ✅ crate::config::env::cli_verbose() 既存 SSOT を活用 ルール遵守: ✅ 環境変数スパロー防止ポリシー(AGENTS.md 5.3) ✅ 隠しトグル禁止(新規環境変数なし) ✅ 既存の verbose 制御(NYASH_CLI_VERBOSE)に統一 機能保持: ✅ REPL 通常モード: 内部ログ抑制(clean output) ✅ REPL verbose モード: デバッグログ表示(--verbose) ✅ File mode 既定挙動: 不変(quiet_internal_logs 常に false) Test results: ✅ REPL quiet/verbose 動作確認 ✅ File mode regression: 154/154 pass(既定挙動不変) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/mir/builder/compilation_context.rs | 5 +++++ src/mir/builder/decls.rs | 2 +- src/mir/mod.rs | 5 +++++ src/runner/repl/repl_runner.rs | 22 ++++++++++++---------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/mir/builder/compilation_context.rs b/src/mir/builder/compilation_context.rs index 0497666c..49dded47 100644 --- a/src/mir/builder/compilation_context.rs +++ b/src/mir/builder/compilation_context.rs @@ -93,6 +93,10 @@ pub(crate) struct CompilationContext { /// Plugin method return type signatures loaded from nyash_box.toml pub plugin_method_sigs: HashMap<(String, String), MirType>, + + /// Phase 288: REPL mode での内部ログ抑制フラグ + /// REPL mode でのみ true、file mode では常に false + pub quiet_internal_logs: bool, } impl CompilationContext { @@ -114,6 +118,7 @@ impl CompilationContext { type_registry: TypeRegistry::new(), current_slot_registry: None, plugin_method_sigs: HashMap::new(), + quiet_internal_logs: false, // File mode: 常に false } } diff --git a/src/mir/builder/decls.rs b/src/mir/builder/decls.rs index 501d32ac..a404f16b 100644 --- a/src/mir/builder/decls.rs +++ b/src/mir/builder/decls.rs @@ -129,7 +129,7 @@ impl super::MirBuilder { } } // Phase 200-C: Store fn_body_ast for inline main() lowering - if std::env::var("NYASH_QUIET_INTERNAL_LOGS").ok().as_deref() != Some("1") { + if !self.comp_ctx.quiet_internal_logs { eprintln!( "[build_static_main_box] Storing fn_body_ast with {} nodes for inline main()", body.len() diff --git a/src/mir/mod.rs b/src/mir/mod.rs index 02325e6b..9dfd5cf1 100644 --- a/src/mir/mod.rs +++ b/src/mir/mod.rs @@ -131,6 +131,11 @@ impl MirCompiler { self.builder.repl_mode = repl_mode; } + /// Phase 288: REPL mode での内部ログ抑制フラグを設定 + pub fn set_quiet_internal_logs(&mut self, quiet: bool) { + self.builder.comp_ctx.quiet_internal_logs = quiet; + } + /// Compile AST to MIR module with verification pub fn compile_with_source( &mut self, diff --git a/src/runner/repl/repl_runner.rs b/src/runner/repl/repl_runner.rs index 9b36f0c7..b7ad2a1a 100644 --- a/src/runner/repl/repl_runner.rs +++ b/src/runner/repl/repl_runner.rs @@ -17,13 +17,20 @@ pub(super) struct ReplRunnerBox { #[allow(dead_code)] config: CliConfig, session: RefCell>, + /// REPL mode での内部ログ抑制フラグ + /// verbose が false の場合に true(REPL 専用) + quiet_internal_logs: bool, } impl ReplRunnerBox { pub(super) fn new(config: CliConfig) -> Self { + // REPL mode では verbose が false なら内部ログを抑制 + let quiet_internal_logs = !crate::config::env::cli_verbose(); + Self { config, session: RefCell::new(None), + quiet_internal_logs, } } @@ -99,11 +106,8 @@ impl ReplRunnerBox { use crate::mir::MirCompiler; use crate::backend::mir_interpreter::MirInterpreter; - // REPL mode では内部デバッグログを抑制(NYASH_CLI_VERBOSE=1 で無効化) - let verbose = std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1"); - if !verbose { - std::env::set_var("NYASH_QUIET_INTERNAL_LOGS", "1"); - } + // REPL mode では内部デバッグログを自動抑制 + // (quiet_internal_logs フラグで制御、環境変数操作不要) // Initialize session on first use { @@ -122,6 +126,9 @@ impl ReplRunnerBox { let mut compiler = MirCompiler::new(); compiler.set_repl_mode(true); + // MirCompiler に quiet フラグを渡す + compiler.set_quiet_internal_logs(self.quiet_internal_logs); + let mir_result = compiler.compile_with_source(ast, Some("")) .map_err(|e| format!("Compile error: {}", e))?; @@ -145,11 +152,6 @@ impl ReplRunnerBox { // Phase 288 P3: print() output already displayed via ExternCall // Expression auto-display deferred to Phase 288.1 - // 評価完了後に環境変数をクリーンアップ - if !verbose { - std::env::remove_var("NYASH_QUIET_INTERNAL_LOGS"); - } - Ok(String::new()) } }