Skip to content
Merged
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
5 changes: 3 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 crates/hir_ty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ expect-test = "1.0"
tracing = "0.1"
tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
tracing-tree = { version = "0.1.4" }
once_cell = { version = "1.5.0", features = ["unstable"] }
7 changes: 4 additions & 3 deletions crates/hir_ty/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use hir_def::{
AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId,
};
use hir_expand::{db::AstDatabase, InFile};
use stdx::{format_to, RacyFlag};
use once_cell::race::OnceBool;
use stdx::format_to;
use syntax::{
algo,
ast::{self, AstNode},
Expand All @@ -40,8 +41,8 @@ use crate::{
// `env UPDATE_EXPECT=1 cargo test -p hir_ty` to update the snapshots.

fn setup_tracing() -> Option<tracing::subscriber::DefaultGuard> {
static ENABLE: RacyFlag = RacyFlag::new();
if !ENABLE.get(|| env::var("CHALK_DEBUG").is_ok()) {
static ENABLE: OnceBool = OnceBool::new();
if !ENABLE.get_or_init(|| env::var("CHALK_DEBUG").is_ok()) {
return None;
}

Expand Down
30 changes: 1 addition & 29 deletions crates/stdx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! Missing batteries for standard libraries.
use std::{
sync::atomic::{AtomicUsize, Ordering},
time::Instant,
};
use std::time::Instant;

mod macros;
pub mod panic_context;
Expand Down Expand Up @@ -150,31 +147,6 @@ where
left
}

pub struct RacyFlag(AtomicUsize);

impl RacyFlag {
pub const fn new() -> RacyFlag {
RacyFlag(AtomicUsize::new(!0))
}

pub fn get(&self, init: impl FnMut() -> bool) -> bool {
let mut init = Some(init);
self.get_impl(&mut || init.take().map_or(false, |mut f| f()))
}

fn get_impl(&self, init: &mut dyn FnMut() -> bool) -> bool {
match self.0.load(Ordering::Relaxed) {
0 => false,
1 => true,
_ => {
let res = init();
self.0.store(if res { 1 } else { 0 }, Ordering::Relaxed);
res
}
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down