Skip to content

remove lazy_static #2043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
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
4 changes: 0 additions & 4 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ chrono = "0.4"
clap = "4.1"
env_logger = "0.10"
hashbrown = "0.14"
lazy_static = "1"
log = "0.4"
reqwest = "0.11"
serde = "1"
Expand Down
1 change: 0 additions & 1 deletion collector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ anyhow = { workspace = true }
chrono = { workspace = true, features = ["serde"] }
clap = { workspace = true, features = ["derive"] }
env_logger = { workspace = true }
lazy_static = { workspace = true }
log = { workspace = true }
reqwest = { workspace = true, features = ["blocking", "json"] }
serde = { workspace = true, features = ["derive"] }
Expand Down
75 changes: 37 additions & 38 deletions collector/src/compile/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::process::{self, Command};
use std::str;
use std::sync::LazyLock;

pub mod bencher;
mod etw_parser;
Expand Down Expand Up @@ -366,44 +367,42 @@ impl<'a> CargoProcess<'a> {
}
}

lazy_static::lazy_static! {
static ref FAKE_RUSTC: PathBuf = {
let mut fake_rustc = env::current_exe().unwrap();
fake_rustc.pop();
fake_rustc.push("rustc-fake");
fake_rustc
};
static ref FAKE_RUSTDOC: PathBuf = {
let mut fake_rustdoc = env::current_exe().unwrap();
fake_rustdoc.pop();
fake_rustdoc.push("rustdoc-fake");
// link from rustc-fake to rustdoc-fake
if !fake_rustdoc.exists() {
#[cfg(unix)]
use std::os::unix::fs::symlink;
#[cfg(windows)]
use std::os::windows::fs::symlink_file as symlink;

symlink(&*FAKE_RUSTC, &fake_rustdoc).expect("failed to make symbolic link");
}
fake_rustdoc
};
static ref FAKE_CLIPPY: PathBuf = {
let mut fake_clippy = env::current_exe().unwrap();
fake_clippy.pop();
fake_clippy.push("clippy-fake");
// link from rustc-fake to rustdoc-fake
if !fake_clippy.exists() {
#[cfg(unix)]
use std::os::unix::fs::symlink;
#[cfg(windows)]
use std::os::windows::fs::symlink_file as symlink;

symlink(&*FAKE_RUSTC, &fake_clippy).expect("failed to make symbolic link");
}
fake_clippy
};
}
static FAKE_RUSTC: LazyLock<PathBuf> = LazyLock::new(|| {
let mut fake_rustc = env::current_exe().unwrap();
fake_rustc.pop();
fake_rustc.push("rustc-fake");
fake_rustc
});
static FAKE_RUSTDOC: LazyLock<PathBuf> = LazyLock::new(|| {
let mut fake_rustdoc = env::current_exe().unwrap();
fake_rustdoc.pop();
fake_rustdoc.push("rustdoc-fake");
// link from rustc-fake to rustdoc-fake
if !fake_rustdoc.exists() {
#[cfg(unix)]
use std::os::unix::fs::symlink;
#[cfg(windows)]
use std::os::windows::fs::symlink_file as symlink;

symlink(&*FAKE_RUSTC, &fake_rustdoc).expect("failed to make symbolic link");
}
fake_rustdoc
});
static FAKE_CLIPPY: LazyLock<PathBuf> = LazyLock::new(|| {
let mut fake_clippy = env::current_exe().unwrap();
fake_clippy.pop();
fake_clippy.push("clippy-fake");
// link from rustc-fake to rustdoc-fake
if !fake_clippy.exists() {
#[cfg(unix)]
use std::os::unix::fs::symlink;
#[cfg(windows)]
use std::os::windows::fs::symlink_file as symlink;

symlink(&*FAKE_RUSTC, &fake_clippy).expect("failed to make symbolic link");
}
fake_clippy
});

/// Used to indicate if we need to retry a run.
pub enum Retry {
Expand Down
1 change: 0 additions & 1 deletion database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ chrono = { workspace = true, features = ["serde"] }
clap = { workspace = true, features = ["cargo"] }
env_logger = { workspace = true }
hashbrown = { workspace = true, features = ["serde"] }
lazy_static = { workspace = true }
log = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true, features = ["derive"] }
Expand Down
1 change: 0 additions & 1 deletion intern/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"

[dependencies]
hashbrown = { workspace = true }
lazy_static = { workspace = true }
serde = { workspace = true, features = ["derive"] }

bumpalo = "3.2"
Expand Down
13 changes: 8 additions & 5 deletions intern/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::alloc::Layout;
use std::fmt;
use std::ptr;
use std::ptr::NonNull;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

#[allow(clippy::missing_safety_doc)]
pub trait InternString {
Expand Down Expand Up @@ -132,10 +132,13 @@ macro_rules! intern {
};
}

lazy_static::lazy_static! {
static ref INTERNED: (ArcSwap<HashSet<ArenaStr>>, Mutex<(HashSet<ArenaStr>, Bump)>)
= (ArcSwap::new(Arc::new(HashSet::new())), Mutex::new((HashSet::new(), Bump::new())));
}
static INTERNED: LazyLock<(ArcSwap<HashSet<ArenaStr>>, Mutex<(HashSet<ArenaStr>, Bump)>)> =
LazyLock::new(|| {
(
ArcSwap::new(Arc::new(HashSet::new())),
Mutex::new((HashSet::new(), Bump::new())),
)
});

pub fn preloaded<T: InternString>(value: &str) -> Option<T> {
let set = INTERNED.0.load();
Expand Down
12 changes: 9 additions & 3 deletions site/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[package]
authors = ["Mark-Simulacrum <[email protected]>", "Nicholas Cameron <[email protected]>", "The rustc-perf contributors"]
authors = [
"Mark-Simulacrum <[email protected]>",
"Nicholas Cameron <[email protected]>",
"The rustc-perf contributors",
]
name = "site"
version = "0.1.0"
edition = "2021"
Expand All @@ -9,7 +13,6 @@ anyhow = { workspace = true }
chrono = { workspace = true }
env_logger = { workspace = true }
hashbrown = { workspace = true, features = ["serde"] }
lazy_static = { workspace = true }
log = { workspace = true }
reqwest = { workspace = true, features = ["blocking", "json"] }
serde = { workspace = true, features = ["rc"] }
Expand Down Expand Up @@ -41,7 +44,10 @@ mime = "0.3"
prometheus = { version = "0.13", default-features = false }
uuid = { version = "1.3.0", features = ["v4"] }
tera = { version = "1.19", default-features = false }
rust-embed = { version = "6.6.0", features = ["include-exclude", "interpolate-folder-path"] }
rust-embed = { version = "6.6.0", features = [
"include-exclude",
"interpolate-folder-path",
] }
humansize = "2"
lru = "0.12.0"
ruzstd = "0.7.0"
Expand Down
7 changes: 4 additions & 3 deletions site/src/benchmark_metadata/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::LazyLock;

use hashbrown::HashMap;
use rust_embed::RustEmbed;

Expand All @@ -23,9 +25,8 @@ pub struct CompileBenchmarkMetadata {
struct EmbeddedCompileBenchmarks;

pub fn get_compile_benchmarks_metadata() -> &'static HashMap<String, CompileBenchmarkMetadata> {
lazy_static::lazy_static! {
static ref METADATA: HashMap<String, CompileBenchmarkMetadata> = load_compile_benchmark_metadata();
}
static METADATA: LazyLock<HashMap<String, CompileBenchmarkMetadata>> =
LazyLock::new(load_compile_benchmark_metadata);
&METADATA
}

Expand Down
11 changes: 5 additions & 6 deletions site/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod comparison_summary;

use crate::api::github::Commit;
use crate::load::{MissingReason, SiteCtxt, TryCommit};
use std::sync::LazyLock;
use std::time::Duration;

use serde::Deserialize;
Expand Down Expand Up @@ -195,12 +196,10 @@ pub struct UnrolledCommit<'a> {
pub sha: Option<String>,
}

lazy_static::lazy_static! {
static ref ROLLUP_PR_NUMBER: regex::Regex =
regex::Regex::new(r"^Auto merge of #(\d+)").unwrap();
static ref ROLLEDUP_PR_NUMBER: regex::Regex =
regex::Regex::new(r"^Rollup merge of #(\d+)").unwrap();
}
static ROLLUP_PR_NUMBER: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r"^Auto merge of #(\d+)").unwrap());
static ROLLEDUP_PR_NUMBER: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r"^Rollup merge of #(\d+)").unwrap());

// Gets the pr number for the associated rollup PR message. Returns None if this is not a rollup PR
pub async fn rollup_pr_number(
Expand Down
12 changes: 3 additions & 9 deletions site/src/load.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::collections::{HashMap, HashSet};
use std::fs;
use std::ops::RangeInclusive;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};
use std::time::Instant;

use arc_swap::{ArcSwap, Guard};
use chrono::{Duration, Utc};
use lazy_static::lazy_static;
use log::error;
use parking_lot::Mutex;
use regex::Regex;
Expand Down Expand Up @@ -218,10 +217,6 @@ impl SiteCtxt {
.text()
.await?;

lazy_static! {
static ref VERSION_REGEX: Regex = Regex::new(r"(\d+\.\d+.\d+)").unwrap();
}

let conn = self.conn().await;

let index = self.index.load();
Expand Down Expand Up @@ -292,9 +287,8 @@ impl SiteCtxt {
/// Parses an artifact tag like `1.63.0` or `beta-2022-08-19` from a line taken from
/// `https://static.rust-lang.org/manifests.txt`.
fn parse_published_artifact_tag(line: &str) -> Option<String> {
lazy_static! {
static ref VERSION_REGEX: Regex = Regex::new(r"(\d+\.\d+.\d+)").unwrap();
}
static VERSION_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(\d+\.\d+.\d+)").unwrap());

let mut parts = line.rsplit('/');
let name = parts.next();
Expand Down
8 changes: 2 additions & 6 deletions site/src/request_handlers/dashboard.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::sync::Arc;

use lazy_static::lazy_static;
use std::sync::{Arc, LazyLock};

use crate::api::{dashboard, ServerResult};
use crate::benchmark_metadata::get_stable_benchmark_names;
Expand Down Expand Up @@ -77,9 +75,7 @@ pub async fn handle_dashboard(ctxt: Arc<SiteCtxt>) -> ServerResult<dashboard::Re
.collect::<Vec<_>>(),
);

lazy_static! {
static ref STABLE_BENCHMARKS: Vec<String> = get_stable_benchmark_names();
}
static STABLE_BENCHMARKS: LazyLock<Vec<String>> = LazyLock::new(get_stable_benchmark_names);

let compile_benchmark_query = selector::CompileBenchmarkQuery::default()
.benchmark(selector::Selector::Subset(STABLE_BENCHMARKS.clone()))
Expand Down
13 changes: 5 additions & 8 deletions site/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::net::SocketAddr;
use std::path::Path;
use std::str::FromStr;
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
use std::sync::Arc;
use std::sync::{Arc, LazyLock};
use std::time::Instant;
use std::{fmt, str};

Expand Down Expand Up @@ -257,9 +257,7 @@ impl Server {
}

async fn handle_push(&self, _req: Request) -> Response {
lazy_static::lazy_static! {
static ref LAST_UPDATE: Mutex<Option<Instant>> = Mutex::new(None);
}
static LAST_UPDATE: LazyLock<Mutex<Option<Instant>>> = LazyLock::new(|| Mutex::new(None));

let last = *LAST_UPDATE.lock();
if let Some(last) = last {
Expand Down Expand Up @@ -603,10 +601,9 @@ where
}
}

lazy_static::lazy_static! {
static ref VERSION_UUID: Uuid = Uuid::new_v4(); // random UUID used as ETag for cache revalidation
static ref TEMPLATES: ResourceResolver = ResourceResolver::new().expect("Cannot load resources");
}
static VERSION_UUID: LazyLock<Uuid> = LazyLock::new(Uuid::new_v4); // random UUID used as ETag for cache revalidation
static TEMPLATES: LazyLock<ResourceResolver> =
LazyLock::new(|| ResourceResolver::new().expect("Cannot load resources"));

/// Handle the case where the path is to a static file
async fn handle_fs_path(
Expand Down
Loading