From 4cc1b6854616ae5f4b2455aedcd3e1fe9251a6a1 Mon Sep 17 00:00:00 2001 From: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> Date: Fri, 16 Aug 2024 12:57:09 +0900 Subject: [PATCH] Remove lazy static (#33078) * remove from rand Mutex can be initialized in compile time. Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * remove from layout_2020 Mutex<()> can be initialize in compile time Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * remove from media `IS_MULTIPROCESS` doesn't be used. Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * remove lazy_static from dependencies Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * rewrite suppressed_leaks_for_asan.txt For all of lazy_static was replaced with LazyLock. Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> --------- Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> --- Cargo.lock | 3 --- Cargo.toml | 1 - components/layout_2020/Cargo.toml | 1 - components/layout_2020/tests/floats.rs | 5 +---- components/media/Cargo.toml | 1 - components/media/media_channel/mod.rs | 6 ------ components/rand/Cargo.toml | 1 - components/rand/lib.rs | 5 +---- support/suppressed_leaks_for_asan.txt | 4 ++-- 9 files changed, 4 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d549e83787..43f96c11179 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3712,7 +3712,6 @@ dependencies = [ "icu_segmenter", "ipc-channel", "itertools 0.13.0", - "lazy_static", "log", "net_traits", "parking_lot", @@ -4150,7 +4149,6 @@ dependencies = [ "euclid", "fnv", "ipc-channel", - "lazy_static", "log", "serde", "servo-media", @@ -6132,7 +6130,6 @@ dependencies = [ name = "servo_rand" version = "0.0.1" dependencies = [ - "lazy_static", "log", "rand", "rand_core", diff --git a/Cargo.toml b/Cargo.toml index b4a523bfce4..471fb040f96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,7 +72,6 @@ itertools = "0.13" tikv-jemalloc-sys = "0.6.0" tikv-jemallocator = "0.6.0" keyboard-types = "0.7" -lazy_static = "1.5" libc = "0.2" log = "0.4" malloc_size_of = { git = "https://github.com/servo/stylo", branch = "2024-07-16", features = ["servo"] } diff --git a/components/layout_2020/Cargo.toml b/components/layout_2020/Cargo.toml index cd3322f184e..0d124c5ca03 100644 --- a/components/layout_2020/Cargo.toml +++ b/components/layout_2020/Cargo.toml @@ -53,5 +53,4 @@ webrender_traits = { workspace = true } xi-unicode = { workspace = true } [dev-dependencies] -lazy_static = { workspace = true } quickcheck = "1" diff --git a/components/layout_2020/tests/floats.rs b/components/layout_2020/tests/floats.rs index 01d8f398aa7..0035bd265c9 100644 --- a/components/layout_2020/tests/floats.rs +++ b/components/layout_2020/tests/floats.rs @@ -17,13 +17,10 @@ use layout_2020::flow::float::{ PlacementInfo, }; use layout_2020::geom::{LogicalRect, LogicalVec2}; -use lazy_static::lazy_static; use quickcheck::{Arbitrary, Gen}; use style::values::computed::Clear; -lazy_static! { - static ref PANIC_HOOK_MUTEX: Mutex<()> = Mutex::new(()); -} +static PANIC_HOOK_MUTEX: Mutex<()> = Mutex::new(()); // Suppresses panic messages. Some tests need to fail and we don't want them to spam the console. // Note that, because the panic hook is process-wide, tests that are expected to fail might diff --git a/components/media/Cargo.toml b/components/media/Cargo.toml index 21ce8db2201..c272f02949c 100644 --- a/components/media/Cargo.toml +++ b/components/media/Cargo.toml @@ -14,7 +14,6 @@ path = "lib.rs" euclid = { workspace = true } fnv = { workspace = true } ipc-channel = { workspace = true } -lazy_static = { workspace = true } log = { workspace = true } serde = { workspace = true } servo-media = { workspace = true } diff --git a/components/media/media_channel/mod.rs b/components/media/media_channel/mod.rs index 4bcb652f12f..d01a80b7550 100644 --- a/components/media/media_channel/mod.rs +++ b/components/media/media_channel/mod.rs @@ -9,16 +9,10 @@ mod mpsc; use std::fmt; -use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; -use servo_config::opts; use crate::GLPlayerMsg; -lazy_static! { - static ref IS_MULTIPROCESS: bool = opts::multiprocess(); -} - #[derive(Deserialize, Serialize)] pub enum GLPlayerSender { Ipc(ipc::GLPlayerSender), diff --git a/components/rand/Cargo.toml b/components/rand/Cargo.toml index 8eb479cd612..f1054b7a2db 100644 --- a/components/rand/Cargo.toml +++ b/components/rand/Cargo.toml @@ -11,7 +11,6 @@ name = "servo_rand" path = "lib.rs" [dependencies] -lazy_static = { workspace = true } log = { workspace = true } rand = { workspace = true } rand_core = { workspace = true } diff --git a/components/rand/lib.rs b/components/rand/lib.rs index fafd8238307..0e0857f4129 100644 --- a/components/rand/lib.rs +++ b/components/rand/lib.rs @@ -6,7 +6,6 @@ use std::cell::RefCell; use std::rc::Rc; use std::sync::Mutex; -use lazy_static::lazy_static; use log::trace; /// A random number generator which shares one instance of an `OsRng`. /// @@ -26,9 +25,7 @@ use rand_isaac::isaac::IsaacCore; use uuid::{Builder, Uuid}; // The shared RNG which may hold on to a file descriptor -lazy_static! { - static ref OS_RNG: Mutex = Mutex::new(OsRng); -} +static OS_RNG: Mutex = Mutex::new(OsRng); // Generate 32K of data between reseedings const RESEED_THRESHOLD: u64 = 32_768; diff --git a/support/suppressed_leaks_for_asan.txt b/support/suppressed_leaks_for_asan.txt index d2b246866e6..71647c0578f 100644 --- a/support/suppressed_leaks_for_asan.txt +++ b/support/suppressed_leaks_for_asan.txt @@ -1,5 +1,5 @@ # intentional Box::leak, introduced here: https://github.com/servo/stylo/blob/f4cde5d89d03db92d111eaa4b4b34e622b6eecac/style/sharing/mod.rs#L481 leak:style::sharing::SHARING_CACHE_KEY::__init -# lazy_static never frees memory because it never runs destructors, see https://docs.rs/lazy_static/1.4.0/lazy_static/index.html#semantics -leak:lazy_static::lazy::Lazy*::get \ No newline at end of file +# std::sync::LazyLock never frees memory because it never runs destructors, see https://doc.rust-lang.org/std/sync/struct.LazyLock.html#examples +leak:std::sync::LazyLock \ No newline at end of file