fix(selfhost): Phase 28.2 Ny compiler child process fixes

- Use --stage-b flag for file-based compilation (Stage-A expects source
  content, not path; Stage-B uses FileBox to read files)
- Remove redundant env overrides that conflicted with
  apply_selfhost_compiler_env() settings
- Re-enable plugins in selfhost compiler env (NYASH_DISABLE_PLUGINS=0)
  so compiler.hako can use FileBox to read source files

Note: Pipeline infrastructure now works, but compiler.hako has a MIR
SSA bug (undefined ValueId(374)) that needs separate investigation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-25 07:49:47 +09:00
parent 22575aa1db
commit 6726ee246d
2 changed files with 19 additions and 11 deletions

View File

@ -57,7 +57,7 @@ pub fn apply_core_wrapper_env(cmd: &mut std::process::Command) {
/// Apply environment for selfhost/Ny compiler processes (ParserBox/EmitterBox/MirBuilderBox).
/// - Inherits core restrictions from apply_core_wrapper_env()
/// - Re-enables `using` file resolution for module loading (lang.compiler.parser.box, etc.)
/// - Keeps plugin/toml restrictions to avoid side effects
/// - Re-enables plugins (compiler.hako needs FileBox to read source files)
pub fn apply_selfhost_compiler_env(cmd: &mut std::process::Command) {
// Phase 25.1b: Start with core wrapper restrictions
apply_core_wrapper_env(cmd);
@ -67,6 +67,10 @@ pub fn apply_selfhost_compiler_env(cmd: &mut std::process::Command) {
// (nyash.toml [modules] mapping is primary, but file fallback ensures robustness)
cmd.env("HAKO_ALLOW_USING_FILE", "1");
// Phase 28.2 fix: Re-enable plugins for selfhost compiler child process.
// compiler.hako needs FileBox to read source files via `new FileBox(path).read()`.
// Without plugins, the [plugin/missing] warning fires and file I/O fails.
cmd.env("NYASH_DISABLE_PLUGINS", "0");
// Note: NYASH_USING_AST stays 0 (AST-based using not needed for basic module resolution)
// Note: NYASH_DISABLE_PLUGINS stays 1 (avoid plugin side effects in nested compilation)
}

View File

@ -227,8 +227,15 @@ impl NyashRunner {
extra_owned.push("--".to_string());
extra_owned.push("--min-json".to_string());
}
// Phase 28.2 fix: Use Stage-B compiler for file-based compilation.
// Stage-A (_compile_source_to_json_v0) expects source CONTENT, not path.
// Stage-B (StageBMain._do_compile_stage_b) reads files via FileBox.
extra_owned.push("--".to_string());
extra_owned.push("--read-tmp".to_string());
extra_owned.push("--stage-b".to_string());
// Pass source file path to compiler.hako
extra_owned.push("--".to_string());
extra_owned.push("--source".to_string());
extra_owned.push("tmp/ny_parser_input.ny".to_string());
if crate::config::env::ny_compiler_stage3() {
extra_owned.push("--".to_string());
extra_owned.push("--stage3".to_string());
@ -258,20 +265,17 @@ impl NyashRunner {
}
let extra: Vec<&str> = extra_owned.iter().map(|s| s.as_str()).collect();
let timeout_ms: u64 = crate::config::env::ny_compiler_timeout_ms();
// Phase 28.2 fix: Don't override HAKO_ALLOW_USING_FILE here.
// apply_selfhost_compiler_env() already sets HAKO_ALLOW_USING_FILE=1 to enable
// module resolution for `using lang.compiler.parser.box`, etc.
// The extra envs here previously overrode it back to "0", breaking module loading.
if let Some(line) = child::run_ny_program_capture_json(
&exe,
parser_prog,
timeout_ms,
&extra,
&["NYASH_USE_NY_COMPILER", "NYASH_CLI_VERBOSE"],
&[
("NYASH_JSON_ONLY", "1"),
("NYASH_DISABLE_PLUGINS", "1"),
("NYASH_SKIP_TOML_ENV", "1"),
("NYASH_USING_AST", "0"),
("NYASH_ALLOW_USING_FILE", "0"),
("HAKO_ALLOW_USING_FILE", "0"),
],
&[], // rely on apply_selfhost_compiler_env() for env setup
) {
// Phase 28.2: observation log - JSON received
if verbose_level >= 2 {