Skip to content

Commit

Permalink
Update toolchain (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilehmann authored Feb 9, 2023
1 parent 0151c14 commit 30b099f
Show file tree
Hide file tree
Showing 31 changed files with 232 additions and 69 deletions.
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"flux",
"flux-bin",
"flux-common",
"flux-config",
"flux-desugar",
"flux-driver",
"flux-errors",
Expand Down
8 changes: 4 additions & 4 deletions flux-bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[package]
edition = "2021"
name = "flux-bin"
version = "0.1.0"
edition = "2021"

[[bin]]
doctest = false
name = "cargo-flux"
test = false
doctest = false

[[bin]]
doctest = false
name = "rustc-flux"
test = false
doctest = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
flux-common = { path = "../flux-common" }
anyhow = "1.0.68"
dirs = "4.0.0"
flux-config = { path = "../flux-config" }
rust-toolchain-file = "0.1.0"
2 changes: 1 addition & 1 deletion flux-bin/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{env, ffi::OsString, fs, path::PathBuf};

use anyhow::{anyhow, Result};
use flux_common::config;
use flux_config as config;

#[cfg(target_os = "windows")]
pub const LIB_PATH: &str = "PATH";
Expand Down
5 changes: 1 addition & 4 deletions flux-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
config = "0.12"
once_cell = "1.9"
serde = { version = "1.0", features = ["derive"] }
toml = "0.5"
flux-config = { path = "../flux-config" }

[package.metadata.rust-analyzer]
rustc_private = true
3 changes: 1 addition & 2 deletions flux-common/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{fs::File, path::PathBuf};

use flux_config as config;
use rustc_hash::FxHashMap;

use crate::config;

pub struct QueryCache {
entries: FxHashMap<String, u64>,
}
Expand Down
3 changes: 1 addition & 2 deletions flux-common/src/dbg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use std::{
io::{self, Write},
};

use flux_config as config;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::TyCtxt;

use crate::config;

pub fn writer_for_item(
tcx: TyCtxt,
def_id: DefId,
Expand Down
2 changes: 1 addition & 1 deletion flux-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(rustc_private, try_trait_v2, try_blocks, never_type, once_cell)]

extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_hash;
extern crate rustc_hir;
Expand All @@ -9,7 +10,6 @@ extern crate rustc_span;
extern crate serde_json;

pub mod cache;
pub mod config;
pub mod dbg;
pub mod format;
pub mod index;
Expand Down
11 changes: 11 additions & 0 deletions flux-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
edition = "2021"
name = "flux-config"
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
config = "0.12"
serde = { version = "1.0", features = ["derive"] }
toml = "0.5"
161 changes: 161 additions & 0 deletions flux-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#![feature(once_cell)]

use std::{io::Read, path::PathBuf, sync::LazyLock};

use config::{Environment, File};
use serde::Deserialize;
pub use toml::Value;

const FLUX_ENV_VAR_PREFIX: &str = "FLUX";
const FLUX_CONFIG_ENV_VAR: &str = "FLUX_CONFIG";

#[derive(Debug, Deserialize, Copy, Clone)]
#[serde(rename_all = "lowercase")]
pub enum AssertBehavior {
Ignore,
Assume,
Check,
}

pub fn check_def() -> &'static str {
&CONFIG.check_def
}

pub fn dump_timings() -> bool {
CONFIG.dump_timings
}

pub fn dump_checker_trace() -> bool {
CONFIG.dump_checker_trace
}

pub fn dump_mir() -> bool {
CONFIG.dump_mir
}

pub fn dump_constraint() -> bool {
CONFIG.dump_constraint
}

pub fn dump_fhir() -> bool {
CONFIG.dump_fhir
}

pub fn pointer_width() -> u64 {
CONFIG.pointer_width
}

pub fn assert_behavior() -> AssertBehavior {
CONFIG.check_asserts
}

pub fn log_dir() -> &'static PathBuf {
&CONFIG.log_dir
}

pub fn is_cache_enabled() -> bool {
CONFIG.cache
}

pub fn cache_path() -> PathBuf {
log_dir().join(&CONFIG.cache_file)
}

pub fn driver_path() -> Option<&'static PathBuf> {
CONFIG.driver_path.as_ref()
}

impl std::str::FromStr for AssertBehavior {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"ignore" => Ok(AssertBehavior::Ignore),
"assume" => Ok(AssertBehavior::Assume),
"check" => Ok(AssertBehavior::Check),
_ => Err(()),
}
}
}

#[derive(Debug)]
pub struct CrateConfig {
pub log_dir: PathBuf,
pub dump_constraint: bool,
pub dump_checker_trace: bool,
pub check_asserts: AssertBehavior,
}

#[derive(Deserialize)]
struct Config {
driver_path: Option<PathBuf>,
log_dir: PathBuf,
dump_constraint: bool,
dump_checker_trace: bool,
dump_timings: bool,
dump_fhir: bool,
check_asserts: AssertBehavior,
dump_mir: bool,
pointer_width: u64,
check_def: String,
cache: bool,
cache_file: String,
}

static CONFIG: LazyLock<Config> = LazyLock::new(|| {
fn build() -> Result<Config, config::ConfigError> {
let mut config_builder = config::Config::builder()
.set_default("driver_path", None::<String>)?
.set_default("log_dir", "./log/")?
.set_default("dump_constraint", false)?
.set_default("dump_checker_trace", false)?
.set_default("dump_timings", false)?
.set_default("dump_mir", false)?
.set_default("dump_fhir", false)?
.set_default("check_asserts", "assume")?
.set_default("pointer_width", 64)?
.set_default("check_def", "")?
.set_default("cache", false)?
.set_default("cache_file", "cache.json")?;
// Config comes first, enviroment settings override it.
if let Some(config_path) = CONFIG_PATH.as_ref() {
config_builder = config_builder.add_source(File::from(config_path.to_path_buf()));
};
config_builder
.add_source(Environment::with_prefix(FLUX_ENV_VAR_PREFIX).ignore_empty(true))
.build()?
.try_deserialize()
}
build().unwrap()
});

pub static CONFIG_PATH: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
if let Ok(file) = std::env::var(FLUX_CONFIG_ENV_VAR) {
return Some(PathBuf::from(file));
}

// find config file in current or parent directories
let mut path = std::env::current_dir().unwrap();
loop {
for name in ["flux.toml", ".flux.toml"] {
let file = path.join(name);
if file.exists() {
return Some(file);
}
}
if !path.pop() {
return None;
}
}
});

pub static CONFIG_FILE: LazyLock<Value> = LazyLock::new(|| {
if let Some(path) = &*CONFIG_PATH {
let mut file = std::fs::File::open(path).unwrap();
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
toml::from_str(&contents).unwrap()
} else {
toml::from_str("").unwrap()
}
});
1 change: 1 addition & 0 deletions flux-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.1.0"

[dependencies]
flux-common = { path = "../flux-common" }
flux-config = { path = "../flux-config" }
flux-desugar = { path = "../flux-desugar" }
flux-errors = { path = "../flux-errors" }
flux-fixpoint = { path = "../flux-fixpoint" }
Expand Down
5 changes: 3 additions & 2 deletions flux-driver/src/callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use flux_common::{cache::QueryCache, config, dbg, iter::IterExt};
use flux_common::{cache::QueryCache, dbg, iter::IterExt};
use flux_config as config;
use flux_desugar as desugar;
use flux_errors::FluxSession;
use flux_metadata::CStore;
Expand Down Expand Up @@ -53,7 +54,7 @@ impl Callbacks for FluxCallbacks {
return Compilation::Stop;
}

queries.global_ctxt().unwrap().peek_mut().enter(|tcx| {
queries.global_ctxt().unwrap().enter(|tcx| {
if !is_tool_registered(tcx) {
return;
}
Expand Down
6 changes: 2 additions & 4 deletions flux-driver/src/collector.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::{collections::HashMap, path::PathBuf};

use flux_common::{
config::{self, AssertBehavior, CrateConfig},
iter::IterExt,
};
use flux_common::iter::IterExt;
use flux_config::{self as config, AssertBehavior, CrateConfig};
use flux_errors::{FluxSession, ResultExt};
use flux_middle::{const_eval::scalar_int_to_rty_constant, rty::Constant};
use flux_syntax::{
Expand Down
1 change: 1 addition & 0 deletions flux-errors/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(rustc_private, never_type)]

extern crate rustc_data_structures;
extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_session;
extern crate rustc_span;
Expand Down
1 change: 1 addition & 0 deletions flux-fixpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.1.0"

[dependencies]
flux-common = { path = "../flux-common" }
flux-config = { path = "../flux-config" }
itertools = "0.10"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion flux-fixpoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub use constraint::{
BinOp, Const, Constant, Constraint, Expr, Func, FuncSort, KVid, Name, Pred, Proj, Qualifier,
Sign, Sort, UifDef, UnOp,
};
use flux_common::{cache::QueryCache, config, format::PadAdapter};
use flux_common::{cache::QueryCache, format::PadAdapter};
use flux_config as config;
use itertools::Itertools;
use serde::{de, Deserialize};

Expand Down
Loading

0 comments on commit 30b099f

Please sign in to comment.