Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,12 @@ pub fn readback_hvm_net(
fn run_hvm(book: &::hvm::ast::Book, cmd: &str, run_opts: &RunOpts) -> Result<String, String> {
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()
Expand Down Expand Up @@ -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<usize>,
}

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

Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
}

#[derive(Args, Debug, Clone)]
Expand Down Expand Up @@ -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);
Expand All @@ -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)) =
Expand Down