refactor(repl): Quiet Mode 方針整合 - REPL 専用フラグに統一

方針整合修正(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 <noreply@anthropic.com>
This commit is contained in:
2025-12-25 14:42:16 +09:00
parent 1cec724ce0
commit e986e279b4
4 changed files with 23 additions and 11 deletions

View File

@ -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
}
}

View File

@ -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()

View File

@ -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,

View File

@ -17,13 +17,20 @@ pub(super) struct ReplRunnerBox {
#[allow(dead_code)]
config: CliConfig,
session: RefCell<Option<ReplSessionBox>>,
/// REPL mode での内部ログ抑制フラグ
/// verbose が false の場合に trueREPL 専用)
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("<repl>"))
.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())
}
}