Skip to content

Commit fa1f55a

Browse files
authored
Merge pull request #2043 from s7tya/remove-lazy-static
remove lazy_static
2 parents 9528dd0 + 8e96f31 commit fa1f55a

File tree

13 files changed

+73
-86
lines changed

13 files changed

+73
-86
lines changed

Cargo.lock

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ chrono = "0.4"
99
clap = "4.1"
1010
env_logger = "0.10"
1111
hashbrown = "0.14"
12-
lazy_static = "1"
1312
log = "0.4"
1413
reqwest = "0.11"
1514
serde = "1"

collector/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ anyhow = { workspace = true }
1111
chrono = { workspace = true, features = ["serde"] }
1212
clap = { workspace = true, features = ["derive"] }
1313
env_logger = { workspace = true }
14-
lazy_static = { workspace = true }
1514
log = { workspace = true }
1615
reqwest = { workspace = true, features = ["blocking", "json"] }
1716
serde = { workspace = true, features = ["derive"] }

collector/src/compile/execute/mod.rs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::path::{Path, PathBuf};
2020
use std::pin::Pin;
2121
use std::process::{self, Command};
2222
use std::str;
23+
use std::sync::LazyLock;
2324

2425
pub mod bencher;
2526
mod etw_parser;
@@ -366,44 +367,42 @@ impl<'a> CargoProcess<'a> {
366367
}
367368
}
368369

369-
lazy_static::lazy_static! {
370-
static ref FAKE_RUSTC: PathBuf = {
371-
let mut fake_rustc = env::current_exe().unwrap();
372-
fake_rustc.pop();
373-
fake_rustc.push("rustc-fake");
374-
fake_rustc
375-
};
376-
static ref FAKE_RUSTDOC: PathBuf = {
377-
let mut fake_rustdoc = env::current_exe().unwrap();
378-
fake_rustdoc.pop();
379-
fake_rustdoc.push("rustdoc-fake");
380-
// link from rustc-fake to rustdoc-fake
381-
if !fake_rustdoc.exists() {
382-
#[cfg(unix)]
383-
use std::os::unix::fs::symlink;
384-
#[cfg(windows)]
385-
use std::os::windows::fs::symlink_file as symlink;
386-
387-
symlink(&*FAKE_RUSTC, &fake_rustdoc).expect("failed to make symbolic link");
388-
}
389-
fake_rustdoc
390-
};
391-
static ref FAKE_CLIPPY: PathBuf = {
392-
let mut fake_clippy = env::current_exe().unwrap();
393-
fake_clippy.pop();
394-
fake_clippy.push("clippy-fake");
395-
// link from rustc-fake to rustdoc-fake
396-
if !fake_clippy.exists() {
397-
#[cfg(unix)]
398-
use std::os::unix::fs::symlink;
399-
#[cfg(windows)]
400-
use std::os::windows::fs::symlink_file as symlink;
401-
402-
symlink(&*FAKE_RUSTC, &fake_clippy).expect("failed to make symbolic link");
403-
}
404-
fake_clippy
405-
};
406-
}
370+
static FAKE_RUSTC: LazyLock<PathBuf> = LazyLock::new(|| {
371+
let mut fake_rustc = env::current_exe().unwrap();
372+
fake_rustc.pop();
373+
fake_rustc.push("rustc-fake");
374+
fake_rustc
375+
});
376+
static FAKE_RUSTDOC: LazyLock<PathBuf> = LazyLock::new(|| {
377+
let mut fake_rustdoc = env::current_exe().unwrap();
378+
fake_rustdoc.pop();
379+
fake_rustdoc.push("rustdoc-fake");
380+
// link from rustc-fake to rustdoc-fake
381+
if !fake_rustdoc.exists() {
382+
#[cfg(unix)]
383+
use std::os::unix::fs::symlink;
384+
#[cfg(windows)]
385+
use std::os::windows::fs::symlink_file as symlink;
386+
387+
symlink(&*FAKE_RUSTC, &fake_rustdoc).expect("failed to make symbolic link");
388+
}
389+
fake_rustdoc
390+
});
391+
static FAKE_CLIPPY: LazyLock<PathBuf> = LazyLock::new(|| {
392+
let mut fake_clippy = env::current_exe().unwrap();
393+
fake_clippy.pop();
394+
fake_clippy.push("clippy-fake");
395+
// link from rustc-fake to rustdoc-fake
396+
if !fake_clippy.exists() {
397+
#[cfg(unix)]
398+
use std::os::unix::fs::symlink;
399+
#[cfg(windows)]
400+
use std::os::windows::fs::symlink_file as symlink;
401+
402+
symlink(&*FAKE_RUSTC, &fake_clippy).expect("failed to make symbolic link");
403+
}
404+
fake_clippy
405+
});
407406

408407
/// Used to indicate if we need to retry a run.
409408
pub enum Retry {

database/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ chrono = { workspace = true, features = ["serde"] }
1010
clap = { workspace = true, features = ["cargo"] }
1111
env_logger = { workspace = true }
1212
hashbrown = { workspace = true, features = ["serde"] }
13-
lazy_static = { workspace = true }
1413
log = { workspace = true }
1514
reqwest = { workspace = true }
1615
serde = { workspace = true, features = ["derive"] }

intern/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ edition = "2021"
66

77
[dependencies]
88
hashbrown = { workspace = true }
9-
lazy_static = { workspace = true }
109
serde = { workspace = true, features = ["derive"] }
1110

1211
bumpalo = "3.2"

intern/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::alloc::Layout;
88
use std::fmt;
99
use std::ptr;
1010
use std::ptr::NonNull;
11-
use std::sync::Arc;
11+
use std::sync::{Arc, LazyLock};
1212

1313
#[allow(clippy::missing_safety_doc)]
1414
pub trait InternString {
@@ -132,10 +132,13 @@ macro_rules! intern {
132132
};
133133
}
134134

135-
lazy_static::lazy_static! {
136-
static ref INTERNED: (ArcSwap<HashSet<ArenaStr>>, Mutex<(HashSet<ArenaStr>, Bump)>)
137-
= (ArcSwap::new(Arc::new(HashSet::new())), Mutex::new((HashSet::new(), Bump::new())));
138-
}
135+
static INTERNED: LazyLock<(ArcSwap<HashSet<ArenaStr>>, Mutex<(HashSet<ArenaStr>, Bump)>)> =
136+
LazyLock::new(|| {
137+
(
138+
ArcSwap::new(Arc::new(HashSet::new())),
139+
Mutex::new((HashSet::new(), Bump::new())),
140+
)
141+
});
139142

140143
pub fn preloaded<T: InternString>(value: &str) -> Option<T> {
141144
let set = INTERNED.0.load();

site/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
[package]
2-
authors = ["Mark-Simulacrum <[email protected]>", "Nicholas Cameron <[email protected]>", "The rustc-perf contributors"]
2+
authors = [
3+
"Mark-Simulacrum <[email protected]>",
4+
"Nicholas Cameron <[email protected]>",
5+
"The rustc-perf contributors",
6+
]
37
name = "site"
48
version = "0.1.0"
59
edition = "2021"
@@ -9,7 +13,6 @@ anyhow = { workspace = true }
913
chrono = { workspace = true }
1014
env_logger = { workspace = true }
1115
hashbrown = { workspace = true, features = ["serde"] }
12-
lazy_static = { workspace = true }
1316
log = { workspace = true }
1417
reqwest = { workspace = true, features = ["blocking", "json"] }
1518
serde = { workspace = true, features = ["rc"] }
@@ -41,7 +44,10 @@ mime = "0.3"
4144
prometheus = { version = "0.13", default-features = false }
4245
uuid = { version = "1.3.0", features = ["v4"] }
4346
tera = { version = "1.19", default-features = false }
44-
rust-embed = { version = "6.6.0", features = ["include-exclude", "interpolate-folder-path"] }
47+
rust-embed = { version = "6.6.0", features = [
48+
"include-exclude",
49+
"interpolate-folder-path",
50+
] }
4551
humansize = "2"
4652
lru = "0.12.0"
4753
ruzstd = "0.7.0"

site/src/benchmark_metadata/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::LazyLock;
2+
13
use hashbrown::HashMap;
24
use rust_embed::RustEmbed;
35

@@ -23,9 +25,8 @@ pub struct CompileBenchmarkMetadata {
2325
struct EmbeddedCompileBenchmarks;
2426

2527
pub fn get_compile_benchmarks_metadata() -> &'static HashMap<String, CompileBenchmarkMetadata> {
26-
lazy_static::lazy_static! {
27-
static ref METADATA: HashMap<String, CompileBenchmarkMetadata> = load_compile_benchmark_metadata();
28-
}
28+
static METADATA: LazyLock<HashMap<String, CompileBenchmarkMetadata>> =
29+
LazyLock::new(load_compile_benchmark_metadata);
2930
&METADATA
3031
}
3132

site/src/github.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod comparison_summary;
33

44
use crate::api::github::Commit;
55
use crate::load::{MissingReason, SiteCtxt, TryCommit};
6+
use std::sync::LazyLock;
67
use std::time::Duration;
78

89
use serde::Deserialize;
@@ -195,12 +196,10 @@ pub struct UnrolledCommit<'a> {
195196
pub sha: Option<String>,
196197
}
197198

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

205204
// Gets the pr number for the associated rollup PR message. Returns None if this is not a rollup PR
206205
pub async fn rollup_pr_number(

site/src/load.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::collections::{HashMap, HashSet};
22
use std::fs;
33
use std::ops::RangeInclusive;
4-
use std::sync::Arc;
4+
use std::sync::{Arc, LazyLock};
55
use std::time::Instant;
66

77
use arc_swap::{ArcSwap, Guard};
88
use chrono::{Duration, Utc};
9-
use lazy_static::lazy_static;
109
use log::error;
1110
use parking_lot::Mutex;
1211
use regex::Regex;
@@ -218,10 +217,6 @@ impl SiteCtxt {
218217
.text()
219218
.await?;
220219

221-
lazy_static! {
222-
static ref VERSION_REGEX: Regex = Regex::new(r"(\d+\.\d+.\d+)").unwrap();
223-
}
224-
225220
let conn = self.conn().await;
226221

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

299293
let mut parts = line.rsplit('/');
300294
let name = parts.next();

site/src/request_handlers/dashboard.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use std::sync::Arc;
2-
3-
use lazy_static::lazy_static;
1+
use std::sync::{Arc, LazyLock};
42

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

80-
lazy_static! {
81-
static ref STABLE_BENCHMARKS: Vec<String> = get_stable_benchmark_names();
82-
}
78+
static STABLE_BENCHMARKS: LazyLock<Vec<String>> = LazyLock::new(get_stable_benchmark_names);
8379

8480
let compile_benchmark_query = selector::CompileBenchmarkQuery::default()
8581
.benchmark(selector::Selector::Subset(STABLE_BENCHMARKS.clone()))

site/src/server.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::net::SocketAddr;
55
use std::path::Path;
66
use std::str::FromStr;
77
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
8-
use std::sync::Arc;
8+
use std::sync::{Arc, LazyLock};
99
use std::time::Instant;
1010
use std::{fmt, str};
1111

@@ -257,9 +257,7 @@ impl Server {
257257
}
258258

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

264262
let last = *LAST_UPDATE.lock();
265263
if let Some(last) = last {
@@ -603,10 +601,9 @@ where
603601
}
604602
}
605603

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

611608
/// Handle the case where the path is to a static file
612609
async fn handle_fs_path(

0 commit comments

Comments
 (0)