diff --git a/src/lib.rs b/src/lib.rs index 89cbde22..936792fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -222,9 +222,12 @@ pub fn readback_hvm_net( fn run_hvm(book: &::hvm::ast::Book, cmd: &str, run_opts: &RunOpts) -> Result { let out_path = ".out.hvm"; std::fs::write(out_path, hvm_book_show_pretty(book)).map_err(|x| x.to_string())?; - let mut process = std::process::Command::new(run_opts.hvm_path.clone()) - .arg(cmd) - .arg(out_path) + let mut command = std::process::Command::new(run_opts.hvm_path.clone()); + command.arg(cmd).arg(out_path); + if let Some(threads) = run_opts.threads { + command.env("HVM_THREADS", threads.to_string()); + } + let mut process = command .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::inherit()) .spawn() @@ -314,11 +317,14 @@ pub struct RunOpts { pub linear_readback: bool, pub pretty: bool, pub hvm_path: String, + /// Worker thread count for the parallel backends (run-c/run-cu), exported as + /// `HVM_THREADS` on the spawned `hvm` process. `None` keeps HVM's compiled TPC. + pub threads: Option, } impl Default for RunOpts { fn default() -> Self { - RunOpts { linear_readback: false, pretty: false, hvm_path: "hvm".to_string() } + RunOpts { linear_readback: false, pretty: false, hvm_path: "hvm".to_string(), threads: None } } } diff --git a/src/main.rs b/src/main.rs index 6b8d55d7..0227949f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -134,6 +134,12 @@ struct CliRunOpts { #[arg(short = 's', long = "stats", help = "Shows runtime stats and rewrite counts")] print_stats: bool, + + #[arg( + long = "threads", + help = "Worker thread count: sets HVM_THREADS on the spawned hvm (read by the C runtime; other runtimes ignore it)" + )] + threads: Option, } #[derive(Args, Debug, Clone)] @@ -327,7 +333,7 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> { Mode::RunC(RunArgs { pretty, run_opts, comp_opts, warn_opts, path, arguments }) | Mode::RunCu(RunArgs { pretty, run_opts, comp_opts, warn_opts, path, arguments }) | Mode::RunRs(RunArgs { pretty, run_opts, comp_opts, warn_opts, path, arguments }) => { - let CliRunOpts { linear, print_stats } = run_opts; + let CliRunOpts { linear, print_stats, threads } = run_opts; let diagnostics_cfg = set_warning_cfg_from_cli(DiagnosticsConfig::new(Severity::Allow, arg_verbose), warn_opts); @@ -336,7 +342,7 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> { compile_opts.check_for_strict(); - let run_opts = RunOpts { linear_readback: linear, pretty, hvm_path: hvm_bin }; + let run_opts = RunOpts { linear_readback: linear, pretty, hvm_path: hvm_bin, threads }; let book = load_book(&path, diagnostics_cfg)?; if let Some((term, stats, diags)) =