Skip to content

Commit

Permalink
Merge pull request #1019 from Armael/ncores
Browse files Browse the repository at this point in the history
setup: allow configuring the number of cores used by why3
  • Loading branch information
Armael authored Jun 4, 2024
2 parents 1d38909 + 2bc013c commit 917bcee
Show file tree
Hide file tree
Showing 19 changed files with 2,188 additions and 2,012 deletions.
3 changes: 2 additions & 1 deletion cargo-creusot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ fn main() -> Result<()> {
Ok(())
}
Setup(SetupSubCommand::Status) => setup::status(),
Setup(SetupSubCommand::Install { external, no_check_version }) => {
Setup(SetupSubCommand::Install { provers_parallelism, external, no_check_version }) => {
let extflag =
|name| setup::ExternalFlag { check_version: !no_check_version.contains(&name) };
let managedflag = |name, mname| setup::ManagedFlag {
check_version: !no_check_version.contains(&name),
external: external.contains(&mname),
};
let flags = setup::InstallFlags {
provers_parallelism,
why3: extflag(SetupTool::Why3),
altergo: extflag(SetupTool::AltErgo),
z3: managedflag(SetupTool::Z3, SetupManagedTool::Z3),
Expand Down
3 changes: 2 additions & 1 deletion ci/creusot-config-dummy.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = 2
version = 3
provers_parallelism = 1

[why3]
path = "why3"
Expand Down
10 changes: 10 additions & 0 deletions creusot-args/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,22 @@ pub enum SetupTool {
CVC5,
}

fn default_provers_parallelism() -> usize {
match std::thread::available_parallelism() {
Ok(n) => n.get(),
Err(_) => 1,
}
}

#[derive(Debug, Parser, Clone)]
pub enum SetupSubCommand {
/// Show the current status of the Creusot installation
Status,
/// Setup Creusot or update an existing installation
Install {
/// Maximum number of provers to run in parallel
#[arg(long, default_value_t = default_provers_parallelism())]
provers_parallelism: usize,
/// Look-up <TOOL> from PATH instead of using the built-in version
#[arg(long, value_name = "TOOL")]
external: Vec<SetupManagedTool>,
Expand Down
4 changes: 3 additions & 1 deletion creusot-setup/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::{
// identifies a version of the config file.
// the goal is to avoid silently mis-interpreting a past or future version of
// the config file whenever its format changes.
pub const CURRENT_CONFIG_VERSION: i64 = 2;
// NOTE: update ci/creusot-config-dummy.toml whenever you change this.
pub const CURRENT_CONFIG_VERSION: i64 = 3;

// bump CURRENT_CONFIG_VERSION if you change this definition
#[derive(Serialize, Deserialize)]
Expand All @@ -29,6 +30,7 @@ pub enum ManagedTool {
// bump CURRENT_CONFIG_VERSION if you change this definition
#[derive(Serialize, Deserialize)]
pub struct Config {
pub provers_parallelism: usize,
pub why3: ExternalTool,
pub altergo: ExternalTool,
pub z3: ManagedTool,
Expand Down
9 changes: 8 additions & 1 deletion creusot-setup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ pub struct ManagedFlag {
}

pub struct InstallFlags {
pub provers_parallelism: usize,
pub why3: ExternalFlag,
pub altergo: ExternalFlag,
pub z3: ManagedFlag,
Expand Down Expand Up @@ -234,6 +235,7 @@ pub fn install(flags: InstallFlags) -> anyhow::Result<()> {
// build the corresponding configuration

let config = Config {
provers_parallelism: std::cmp::max(1, flags.provers_parallelism),
why3: external_tool(WHY3, flags.why3)?,
altergo: external_tool(ALTERGO, flags.altergo)?,
z3: managed_tool(Z3.bin, flags.z3)?,
Expand Down Expand Up @@ -290,7 +292,12 @@ fn apply_config(paths: &CfgPaths, cfg: &Config) -> anyhow::Result<()> {
}

// generate the corresponding .why3.conf
generate_why3_conf(&cfg.why3.path, &paths.bin_subdir, &paths.why3_config_file)?;
generate_why3_conf(
cfg.provers_parallelism,
&cfg.why3.path,
&paths.bin_subdir,
&paths.why3_config_file,
)?;

// write the config file to disk
cfg.write_to_file(&paths.config_file)
Expand Down
9 changes: 6 additions & 3 deletions creusot-setup/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,18 @@ fn detect_why3_version(why3: &Path) -> Option<String> {
}

pub fn generate_why3_conf(
provers_parallelism: usize,
why3_path: &Path,
bin_dir: &Path,
dest_file: &Path,
) -> anyhow::Result<()> {
println!("Generating a fresh why3 configuration...");
// create or empty the destination file to avoid getting a warning from why3
// because it doesn't exist
{
let _ = fs::File::create(&dest_file);
use std::io::Write;
let mut f = fs::File::create(&dest_file)?;
writeln!(&mut f, "[main]")?;
writeln!(&mut f, "magic = {WHY3_CONFIG_MAGIC_NUMBER}")?;
writeln!(&mut f, "running_provers_max = {provers_parallelism}")?;
}
let status = Command::new(why3_path)
.arg("-C")
Expand Down
1 change: 1 addition & 0 deletions creusot-setup/src/tools_versions_urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// tools without binary releases
pub const WHY3_VERSION: &'static str = "1.7.2";
pub const WHY3_CONFIG_MAGIC_NUMBER: &'static str = "14";
pub const ALTERGO_VERSION: &'static str = "2.5.3";
// tools with binary releases
pub const Z3_VERSION: &'static str = "4.12.4";
Expand Down
329 changes: 144 additions & 185 deletions creusot/tests/should_succeed/heapsort_generic/why3session.xml

Large diffs are not rendered by default.

Binary file modified creusot/tests/should_succeed/heapsort_generic/why3shapes.gz
Binary file not shown.
Loading

0 comments on commit 917bcee

Please sign in to comment.