From cbf2d8ffc82a4589f35e4f63a443c6dbb0ce0d9c Mon Sep 17 00:00:00 2001 From: Declan Tsien Date: Sun, 14 Apr 2024 10:24:34 +0800 Subject: [PATCH] Replace lazy_static with std LazyLock --- Cargo.lock | 15 ------ Cargo.toml | 1 - crates/codegen/Cargo.toml | 1 - crates/codegen/lib.rs | 10 ++-- crates/colors/Cargo.toml | 1 - crates/colors/lib.rs | 8 +-- crates/emacs-sys/Cargo.toml | 1 - crates/emacs-sys/src/lib.rs | 1 + crates/emacs-sys/src/sys.rs | 2 +- crates/emacs-sys/src/vector.rs | 11 ++-- crates/font/Cargo.toml | 1 - crates/font/src/lib.rs | 54 +++++++++++--------- crates/git/Cargo.toml | 1 - crates/git/src/lib.rs | 1 + crates/js/Cargo.toml | 1 - crates/js/src/lib.rs | 1 + crates/lisp-async/Cargo.toml | 1 - crates/lisp-async/src/lib.rs | 1 + crates/lisp-doc/Cargo.toml | 1 - crates/lisp-doc/docfile.rs | 20 ++++---- crates/lisp-doc/lib.rs | 3 +- crates/lisp-macros/Cargo.toml | 1 - crates/lisp-macros/lib.rs | 57 ++++++++++----------- crates/lsp-json/Cargo.toml | 1 - crates/lsp-json/src/lib.rs | 1 + crates/ng-module/Cargo.toml | 1 - crates/ng-module/src/lib.rs | 1 + crates/webrender/Cargo.toml | 1 - crates/webrender/src/image/cache.rs | 13 ++--- crates/webrender/src/lib.rs | 1 + crates/winit/Cargo.toml | 1 - crates/winit/src/term.rs | 78 ++++++++++++++--------------- 32 files changed, 131 insertions(+), 161 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0446163939a..2c52dfa8f03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -688,7 +688,6 @@ dependencies = [ "anyhow", "cargo-files-core", "cargo_metadata 0.18.1", - "lazy_static", "libc", "regex", "thiserror", @@ -703,9 +702,6 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "colors" version = "0.1.0" -dependencies = [ - "lazy_static", -] [[package]] name = "combine" @@ -1003,7 +999,6 @@ dependencies = [ "gtk", "gtk-sys", "image", - "lazy_static", "libc", "log", "memoffset", @@ -1190,7 +1185,6 @@ dependencies = [ "font-index", "font-loader", "fxhash", - "lazy_static", "libc", "lisp-macros", "lisp-util", @@ -1592,7 +1586,6 @@ dependencies = [ "codegen", "emacs-sys", "git2", - "lazy_static", "libc", "lisp-macros", "lisp-util", @@ -2112,7 +2105,6 @@ dependencies = [ "codegen", "emacs-sys", "futures", - "lazy_static", "libc", "lisp-macros", "lisp-util", @@ -2252,7 +2244,6 @@ dependencies = [ "crossbeam", "emacs-sys", "futures", - "lazy_static", "libc", "lisp-macros", "lisp-util", @@ -2264,7 +2255,6 @@ version = "0.1.0" dependencies = [ "anyhow", "darling", - "lazy_static", "libc", "lisp-util", "regex", @@ -2276,7 +2266,6 @@ version = "0.1.0" dependencies = [ "darling", "emacs-sys", - "lazy_static", "lisp-util", "proc-macro2", "quote", @@ -2340,7 +2329,6 @@ version = "0.1.0" dependencies = [ "codegen", "emacs-sys", - "lazy_static", "libc", "lisp-async", "lisp-macros", @@ -2531,7 +2519,6 @@ version = "0.1.0" dependencies = [ "codegen", "emacs-sys", - "lazy_static", "libc", "lisp-macros", "lisp-util", @@ -4535,7 +4522,6 @@ dependencies = [ "font", "gleam", "image", - "lazy_static", "libc", "lisp-macros", "lisp-util", @@ -4899,7 +4885,6 @@ dependencies = [ "core-foundation", "emacs-sys", "font", - "lazy_static", "libc", "lisp-macros", "lisp-util", diff --git a/Cargo.toml b/Cargo.toml index 847664ee44a..1b0ea72d84d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,7 +88,6 @@ gleam = "0.15" winit = { version = "0.29", default-features = false, features = ["rwh_06"]} arboard = "3.3" euclid = "0.22" -lazy_static = "1.4" tokio = "1" regex = "1.10" syn = "2" diff --git a/crates/codegen/Cargo.toml b/crates/codegen/Cargo.toml index 7fb8004c9b9..643d5a60679 100644 --- a/crates/codegen/Cargo.toml +++ b/crates/codegen/Cargo.toml @@ -6,7 +6,6 @@ version = "0.1.0" edition = "2021" [dependencies] -lazy_static = "1.4" libc = "0.2" regex = "1.10" cargo_metadata = { version = "0.18", optional = false } diff --git a/crates/codegen/lib.rs b/crates/codegen/lib.rs index 7576c334240..ca316efca34 100644 --- a/crates/codegen/lib.rs +++ b/crates/codegen/lib.rs @@ -1,5 +1,5 @@ -#[macro_use] -extern crate lazy_static; +#![feature(lazy_cell)] + mod data; mod error; use data::package_targets; @@ -11,6 +11,7 @@ pub use data::with_root_crate; use data::with_root_crate_checked; pub use data::Package; pub use error::BuildError; +use std::sync::LazyLock; use std::env; use std::ffi::OsStr; @@ -248,9 +249,8 @@ impl<'a> ModuleParser<'a> { } fn parse_gc_protected_static(&mut self, line: &str) -> Result { - lazy_static! { - static ref RE: Regex = Regex::new(r#"GC_protected_static!\((.+), .+\);"#).unwrap(); - } + static RE: LazyLock = + LazyLock::new(|| Regex::new(r#"GC_protected_static!\((.+), .+\);"#).unwrap()); match RE.captures(line) { Some(caps) => { diff --git a/crates/colors/Cargo.toml b/crates/colors/Cargo.toml index 8286475f9fc..3bc459a79b4 100644 --- a/crates/colors/Cargo.toml +++ b/crates/colors/Cargo.toml @@ -7,4 +7,3 @@ edition = "2021" path = "lib.rs" [dependencies] -lazy_static = "1.4.0" \ No newline at end of file diff --git a/crates/colors/lib.rs b/crates/colors/lib.rs index 9b90eb72f77..9106b9339fa 100644 --- a/crates/colors/lib.rs +++ b/crates/colors/lib.rs @@ -1,8 +1,8 @@ -use lazy_static::lazy_static; +#![feature(lazy_cell)] use std::collections::HashMap; +use std::sync::LazyLock; include!(concat!(env!("OUT_DIR"), "/colors.rs")); -lazy_static! { - pub static ref COLOR_MAP: HashMap<&'static str, (u8, u8, u8)> = init_color(); -} +pub static COLOR_MAP: LazyLock> = + LazyLock::new(|| init_color()); diff --git a/crates/emacs-sys/Cargo.toml b/crates/emacs-sys/Cargo.toml index abf30161318..3a7cea66019 100644 --- a/crates/emacs-sys/Cargo.toml +++ b/crates/emacs-sys/Cargo.toml @@ -9,7 +9,6 @@ path = "src/lib.rs" [dependencies] libc = "0.2.153" -lazy_static = "1.4.0" log = "0.4" memoffset = "0.9" raw-window-handle = { workspace = true, optional = true } diff --git a/crates/emacs-sys/src/lib.rs b/crates/emacs-sys/src/lib.rs index 4938a72a1e4..eeab727992c 100755 --- a/crates/emacs-sys/src/lib.rs +++ b/crates/emacs-sys/src/lib.rs @@ -13,6 +13,7 @@ #![feature(never_type)] #![feature(stmt_expr_attributes)] #![feature(async_closure)] +#![feature(lazy_cell)] #[cfg(all(glutin, surfman, winit))] compile_error!("You cannot specify both `glutin` and `surfman` features for winit window system"); diff --git a/crates/emacs-sys/src/sys.rs b/crates/emacs-sys/src/sys.rs index 59c5f5bb316..8a8137de334 100755 --- a/crates/emacs-sys/src/sys.rs +++ b/crates/emacs-sys/src/sys.rs @@ -64,7 +64,7 @@ extern "C" { ) -> LispObject; } -// In order to use `lazy_static!` with LispSubr, it must be Sync. Raw +// In order to use `LazyLock` with LispSubr, it must be Sync. Raw // pointers are not Sync, but it isn't a problem to define Sync if we // never mutate LispSubr values. If we do, we will need to create // these objects at runtime, perhaps using forget(). diff --git a/crates/emacs-sys/src/vector.rs b/crates/emacs-sys/src/vector.rs index bf7bed9aa31..b7ff8b4d6e0 100644 --- a/crates/emacs-sys/src/vector.rs +++ b/crates/emacs-sys/src/vector.rs @@ -4,7 +4,6 @@ use libc::ptrdiff_t; use std::mem; use crate::bindings::VECTORP; -use lazy_static::lazy_static; use crate::bindings::pvec_type; use crate::bindings::Lisp_Type; @@ -22,6 +21,7 @@ use crate::sys::Lisp_Vectorlike; use crate::sys::PSEUDOVECTOR_FLAG; use crate::terminal::TerminalRef; use crate::window::WindowRef; +use std::sync::LazyLock; pub type LispVectorlikeRef = ExternalPtr; #[allow(dead_code)] @@ -236,11 +236,10 @@ macro_rules! impl_vectorlike_ref { impl_vectorlike_ref! { LispVectorRef, LispVecIterator, ptrdiff_t::max_value() } -lazy_static! { - pub static ref HEADER_SIZE: usize = - memoffset::offset_of!(crate::bindings::Lisp_Vector, contents); - pub static ref WORD_SIZE: usize = ::std::mem::size_of::(); -} +pub static HEADER_SIZE: LazyLock = + LazyLock::new(|| memoffset::offset_of!(crate::bindings::Lisp_Vector, contents)); +pub static WORD_SIZE: LazyLock = + LazyLock::new(|| ::std::mem::size_of::()); pub trait LVector { fn vectorp(self) -> bool; diff --git a/crates/font/Cargo.toml b/crates/font/Cargo.toml index f5470a8d841..3287134c18c 100644 --- a/crates/font/Cargo.toml +++ b/crates/font/Cargo.toml @@ -11,7 +11,6 @@ webrender_api.workspace = true emacs-sys.path = "../emacs-sys" lisp-macros.path = "../lisp-macros" lisp-util.path = "../lisp-util" -lazy_static = "1.4" log.workspace = true libc.workspace = true parking_lot.workspace = true diff --git a/crates/font/src/lib.rs b/crates/font/src/lib.rs index 53bcc370853..7c3a0736094 100644 --- a/crates/font/src/lib.rs +++ b/crates/font/src/lib.rs @@ -1,4 +1,5 @@ #![feature(concat_idents)] +#![feature(lazy_cell)] #[macro_use] extern crate emacs_sys; @@ -31,7 +32,9 @@ use font_index::FontEntry; pub use font_index::FontId; use font_index::FontIndex; use std::mem::ManuallyDrop; -use std::sync::OnceLock; +use std::sync::LazyLock; +use std::sync::Mutex; +use swash::shape::ShapeContext; use swash::text::Language; use swash::text::Script; use swash::Attributes; @@ -73,29 +76,32 @@ pub type FontRef = ExternalPtr; pub struct FontDriver(pub font_driver); unsafe impl Sync for FontDriver {} -static FONT_DRIVER: OnceLock = OnceLock::new(); +static FONT_DRIVER: LazyLock = LazyLock::new(|| { + log::trace!("FONT_DRIVER is being created..."); + let mut font_driver = font_driver::default(); + + font_driver.type_ = Qswash; + font_driver.case_sensitive = true; + font_driver.get_cache = Some(get_cache); + font_driver.list = Some(list); + font_driver.match_ = Some(match_); + font_driver.list_family = Some(list_family); + font_driver.open_font = Some(open_font); + font_driver.close_font = Some(close_font); + font_driver.encode_char = Some(encode_char); + font_driver.has_char = Some(has_char); + font_driver.text_extents = Some(text_extents); + font_driver.draw = Some(draw); + font_driver.shape = Some(shape); + + FontDriver(font_driver) +}); +//shapecontext per thread +static SHAPE_CONTEXT: LazyLock> = + LazyLock::new(|| Mutex::new(ShapeContext::new())); impl FontDriver { fn global() -> &'static FontDriver { - FONT_DRIVER.get_or_init(|| { - log::trace!("FONT_DRIVER is being created..."); - let mut font_driver = font_driver::default(); - - font_driver.type_ = Qswash; - font_driver.case_sensitive = true; - font_driver.get_cache = Some(get_cache); - font_driver.list = Some(list); - font_driver.match_ = Some(match_); - font_driver.list_family = Some(list_family); - font_driver.open_font = Some(open_font); - font_driver.close_font = Some(close_font); - font_driver.encode_char = Some(encode_char); - font_driver.has_char = Some(has_char); - font_driver.text_extents = Some(text_extents); - font_driver.draw = Some(draw); - font_driver.shape = Some(shape); - - FontDriver(font_driver) - }) + &FONT_DRIVER } } @@ -685,7 +691,6 @@ pub extern "C" fn shape(lgstring: LispObject, direction: LispObject) -> LispObje use swash::shape::cluster::Glyph; use swash::shape::cluster::GlyphCluster; use swash::shape::Direction; - use swash::shape::ShapeContext; let font = lgstring.lgstring_font(); let font = unsafe { CHECK_FONT_GET_OBJECT(font) }; @@ -711,8 +716,7 @@ pub extern "C" fn shape(lgstring: LispObject, direction: LispObject) -> LispObje }; let source = source.as_str(); - //TODO shapecontext per thread - let mut context = ShapeContext::new(); + let mut context = SHAPE_CONTEXT.lock().expect("SHAPE_CONTEXT lock() failed"); let mut shaper_builder = context.builder(&font); /* If the caller didn't provide a meaningful DIRECTION, let Swash diff --git a/crates/git/Cargo.toml b/crates/git/Cargo.toml index bdedfe048ba..a2204779db3 100644 --- a/crates/git/Cargo.toml +++ b/crates/git/Cargo.toml @@ -15,7 +15,6 @@ openssl = { version = "0.10", features = ["vendored"] } openssl-sys = { version = "0.9" } git2 = "0.18" libc.workspace = true -lazy_static.workspace = true [build-dependencies] codegen = { path = "../codegen" } \ No newline at end of file diff --git a/crates/git/src/lib.rs b/crates/git/src/lib.rs index b5200cd1b35..486181a5c15 100755 --- a/crates/git/src/lib.rs +++ b/crates/git/src/lib.rs @@ -1,4 +1,5 @@ #![feature(concat_idents)] +#![feature(lazy_cell)] #[macro_use] extern crate emacs_sys; diff --git a/crates/js/Cargo.toml b/crates/js/Cargo.toml index f9d9b2f6538..0531b49fe0e 100644 --- a/crates/js/Cargo.toml +++ b/crates/js/Cargo.toml @@ -13,7 +13,6 @@ lisp-macros.path = "../lisp-macros" lisp-util.path = "../lisp-util" lsp-json.path = "../lsp-json" libc.workspace = true -lazy_static.workspace = true futures = "0.3" # deno_core = { git = "https://github.com/emacs-ng/deno", branch = "emacs-ng" } # deno_runtime = { git = "https://github.com/emacs-ng/deno", branch = "emacs-ng" } diff --git a/crates/js/src/lib.rs b/crates/js/src/lib.rs index fd04e760205..b0871fd677a 100755 --- a/crates/js/src/lib.rs +++ b/crates/js/src/lib.rs @@ -2,6 +2,7 @@ #![feature(concat_idents)] #![feature(async_closure)] #![feature(maybe_uninit_extra)] +#![feature(lazy_cell)] extern crate futures; extern crate serde_json; diff --git a/crates/lisp-async/Cargo.toml b/crates/lisp-async/Cargo.toml index 7c7afa2dd14..682ea792f5f 100644 --- a/crates/lisp-async/Cargo.toml +++ b/crates/lisp-async/Cargo.toml @@ -13,7 +13,6 @@ emacs-sys.path = "../emacs-sys" lisp-macros.path = "../lisp-macros" lisp-util.path = "../lisp-util" libc.workspace = true -lazy_static.workspace = true crossbeam = "0.8" futures = "0.3" diff --git a/crates/lisp-async/src/lib.rs b/crates/lisp-async/src/lib.rs index fe1ab409526..d0d94484d37 100755 --- a/crates/lisp-async/src/lib.rs +++ b/crates/lisp-async/src/lib.rs @@ -1,6 +1,7 @@ #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] #![feature(concat_idents)] #![feature(async_closure)] +#![feature(lazy_cell)] #[macro_use] extern crate emacs_sys; diff --git a/crates/lisp-doc/Cargo.toml b/crates/lisp-doc/Cargo.toml index dd79a82f140..3ef4f7647a1 100644 --- a/crates/lisp-doc/Cargo.toml +++ b/crates/lisp-doc/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" lisp-util.path = "../lisp-util" darling = "0.20" anyhow = "1.0" -lazy_static.workspace = true libc.workspace = true regex.workspace = true diff --git a/crates/lisp-doc/docfile.rs b/crates/lisp-doc/docfile.rs index f5235e110e1..a03296240e6 100644 --- a/crates/lisp-doc/docfile.rs +++ b/crates/lisp-doc/docfile.rs @@ -16,6 +16,7 @@ use std::io::BufRead; use std::io::BufReader; use std::mem; use std::ptr; +use std::sync::LazyLock; use lisp_util::parse_lisp_fn; @@ -243,11 +244,11 @@ pub fn scan_rust_file1( ); } } else if line.starts_with("def_lisp_sym!(") { - lazy_static! { - static ref RE: Regex = Regex::new(r#"def_lisp_sym!\((.+?),\s+"(.+?)"\);"#) + static RE: LazyLock = LazyLock::new(|| { + Regex::new(r#"def_lisp_sym!\((.+?),\s+"(.+?)"\);"#) .map_err(|e| format_err!("Failed to create regext: {:?}", e)) - .unwrap(); - } + .unwrap() + }); let caps = RE.captures(line).ok_or(format_err!("No Regex captures"))?; let name = CString::new(&caps[1])?; let value = CString::new(&caps[2])?; @@ -255,12 +256,11 @@ pub fn scan_rust_file1( } else if line.starts_with("defvar_") { // defvar_lisp!(f_Vpost_self_insert_hook, "post-self-insert-hook", Qnil); // defvar_kboard!(Vlast_command_, "last-command"); - lazy_static! { - static ref RE: Regex = - Regex::new(r#"defvar_(.+?)!\((.+?),\s+"(.+?)"(?:,\s+(.+?))?\);"#) - .map_err(|e| format_err!("Failed to create regext: {:?}", e)) - .unwrap(); - } + static RE: LazyLock = LazyLock::new(|| { + Regex::new(r#"defvar_(.+?)!\((.+?),\s+"(.+?)"(?:,\s+(.+?))?\);"#) + .map_err(|e| format_err!("Failed to create regext: {:?}", e)) + .unwrap() + }); for caps in RE.captures_iter(line) { if generate_globals != 0 { let kindstr = &caps[1]; diff --git a/crates/lisp-doc/lib.rs b/crates/lisp-doc/lib.rs index 87b8bed1046..b8d985b0d0f 100755 --- a/crates/lisp-doc/lib.rs +++ b/crates/lisp-doc/lib.rs @@ -1,9 +1,8 @@ #![allow(non_upper_case_globals)] #![allow(non_snake_case)] +#![feature(lazy_cell)] #![cfg_attr(feature = "strict", deny(warnings))] -#[macro_use] -extern crate lazy_static; extern crate libc; extern crate lisp_util; extern crate regex; diff --git a/crates/lisp-macros/Cargo.toml b/crates/lisp-macros/Cargo.toml index 5e27e7908ab..ddcc991dc46 100644 --- a/crates/lisp-macros/Cargo.toml +++ b/crates/lisp-macros/Cargo.toml @@ -14,6 +14,5 @@ syn = { workspace = true, features = ["full"] } lisp-util.path = "../lisp-util" emacs-sys.path = "../emacs-sys" regex.workspace = true -lazy_static.workspace = true proc-macro2.workspace = true darling = "0.20" diff --git a/crates/lisp-macros/lib.rs b/crates/lisp-macros/lib.rs index c969e76b7a9..b7a963c22f0 100755 --- a/crates/lisp-macros/lib.rs +++ b/crates/lisp-macros/lib.rs @@ -1,9 +1,10 @@ +#![feature(lazy_cell)] #![recursion_limit = "256"] -use lazy_static::lazy_static; use proc_macro::TokenStream; use quote::quote; use regex::Regex; +use std::sync::LazyLock; mod function; @@ -65,7 +66,6 @@ pub fn lisp_fn(attr_ts: TokenStream, fn_ts: TokenStream) -> TokenStream { let sname = concat_idents("S", &cname); let fname = concat_idents("F", &cname); let srname = concat_idents("SR", &cname); - let lazy_include = concat_idents("_LS_", &cname); let rname = function.name; let min_args = lisp_fn_args.min; let mut windows_header = quote! {}; @@ -120,36 +120,33 @@ pub fn lisp_fn(attr_ts: TokenStream, fn_ts: TokenStream) -> TokenStream { emacs_sys::lisp::LispObject::from(ret) } - use lazy_static::lazy_static as #lazy_include; - #[no_mangle] pub static mut #srname: std::mem::MaybeUninit = std::mem::MaybeUninit::::uninit(); - #lazy_include! { - pub static ref #sname: emacs_sys::lisp::LispSubrRef = { - let mut subr = emacs_sys::bindings::Aligned_Lisp_Subr::default(); - unsafe { - let mut subr_ref = subr.s.as_mut(); - subr_ref.header = emacs_sys::bindings::vectorlike_header { - size: ((emacs_sys::bindings::pvec_type::PVEC_SUBR as libc::ptrdiff_t) - << emacs_sys::bindings::More_Lisp_Bits::PSEUDOVECTOR_AREA_BITS) - #windows_header, - }; - subr_ref.function = emacs_sys::bindings::Lisp_Subr__bindgen_ty_1 { - #functype: (Some(self::#fname)) - }; - subr_ref.min_args = #min_args; - subr_ref.max_args = #max_args; - subr_ref.symbol_name = (#symbol_name).as_ptr() as *const libc::c_char; - *subr_ref.intspec.string.as_mut() = #intspec; - subr_ref.doc = 0; - - std::ptr::copy_nonoverlapping(&subr, #srname.as_mut_ptr(), 1); - emacs_sys::lisp::ExternalPtr::new(#srname.as_mut_ptr()) - } - }; - } + pub static #sname: std::sync::LazyLock + = std::sync::LazyLock::new(|| { + let mut subr = emacs_sys::bindings::Aligned_Lisp_Subr::default(); + unsafe { + let mut subr_ref = subr.s.as_mut(); + subr_ref.header = emacs_sys::bindings::vectorlike_header { + size: ((emacs_sys::bindings::pvec_type::PVEC_SUBR as libc::ptrdiff_t) + << emacs_sys::bindings::More_Lisp_Bits::PSEUDOVECTOR_AREA_BITS) + #windows_header, + }; + subr_ref.function = emacs_sys::bindings::Lisp_Subr__bindgen_ty_1 { + #functype: (Some(self::#fname)) + }; + subr_ref.min_args = #min_args; + subr_ref.max_args = #max_args; + subr_ref.symbol_name = (#symbol_name).as_ptr() as *const libc::c_char; + *subr_ref.intspec.string.as_mut() = #intspec; + subr_ref.doc = 0; + + std::ptr::copy_nonoverlapping(&subr, #srname.as_mut_ptr(), 1); + emacs_sys::lisp::ExternalPtr::new(#srname.as_mut_ptr()) + } + }); }; // we could put #fn_item into the quoted code above, but doing so @@ -186,9 +183,7 @@ struct CByteLiteral<'a>(&'a str); impl<'a> quote::ToTokens for CByteLiteral<'a> { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - lazy_static! { - static ref RE: Regex = Regex::new(r#"["\\]"#).unwrap(); - } + static RE: LazyLock = LazyLock::new(|| Regex::new(r#"["\\]"#).unwrap()); let s = RE.replace_all(self.0, |caps: ®ex::Captures| { format!("\\x{:x}", u32::from(caps[0].chars().next().unwrap())) }); diff --git a/crates/lsp-json/Cargo.toml b/crates/lsp-json/Cargo.toml index ebb10a73f2c..c2bb9c58d68 100644 --- a/crates/lsp-json/Cargo.toml +++ b/crates/lsp-json/Cargo.toml @@ -13,7 +13,6 @@ emacs-sys.path = "../emacs-sys" lisp-macros.path = "../lisp-macros" lisp-util.path = "../lisp-util" libc.workspace = true -lazy_static.workspace = true lsp-server = "0.7" serde_json = { version = "1.0", features = ["preserve_order"] } diff --git a/crates/lsp-json/src/lib.rs b/crates/lsp-json/src/lib.rs index 1ccdaf4c83e..a93ede2a074 100755 --- a/crates/lsp-json/src/lib.rs +++ b/crates/lsp-json/src/lib.rs @@ -1,6 +1,7 @@ #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] #![feature(concat_idents)] #![feature(async_closure)] +#![feature(lazy_cell)] #[macro_use] extern crate serde_json; diff --git a/crates/ng-module/Cargo.toml b/crates/ng-module/Cargo.toml index aa6e8a9ce0b..eac22c10ba1 100644 --- a/crates/ng-module/Cargo.toml +++ b/crates/ng-module/Cargo.toml @@ -12,7 +12,6 @@ emacs-sys.path = "../emacs-sys" lisp-macros.path = "../lisp-macros" lisp-util.path = "../lisp-util" libc.workspace = true -lazy_static.workspace = true [build-dependencies] codegen = { path = "../codegen" } \ No newline at end of file diff --git a/crates/ng-module/src/lib.rs b/crates/ng-module/src/lib.rs index d332a8b9b8e..3ff329ff1fa 100755 --- a/crates/ng-module/src/lib.rs +++ b/crates/ng-module/src/lib.rs @@ -1,4 +1,5 @@ #![feature(concat_idents)] +#![feature(lazy_cell)] extern crate emacs_sys; #[macro_use] diff --git a/crates/webrender/Cargo.toml b/crates/webrender/Cargo.toml index 2146f878741..477245ac792 100644 --- a/crates/webrender/Cargo.toml +++ b/crates/webrender/Cargo.toml @@ -15,7 +15,6 @@ lisp-macros.path = "../lisp-macros" lisp-util.path = "../lisp-util" log.workspace = true libc.workspace = true -lazy_static = "1.4" gleam.workspace = true image.workspace = true bit-vec = "0.6.3" diff --git a/crates/webrender/src/image/cache.rs b/crates/webrender/src/image/cache.rs index a56c6a4c996..70a3af55d6f 100644 --- a/crates/webrender/src/image/cache.rs +++ b/crates/webrender/src/image/cache.rs @@ -29,7 +29,7 @@ use std::io::BufRead; use std::io::Cursor; use std::io::Seek; use std::sync::Arc; -use std::sync::OnceLock; +use std::sync::LazyLock; use std::time::Duration; use webrender::api::ImageData; use webrender::api::ImageDescriptor; @@ -338,16 +338,11 @@ impl ImageSource { /// TODO We plan implement spec(rotate/scale) using WebRender transform pub struct ImageCache(FastHashMap); -static IMAGE_CACHE: OnceLock>> = OnceLock::new(); +static IMAGE_CACHE: LazyLock>> = + LazyLock::new(|| Arc::new(Mutex::new(ImageCache(FastHashMap::default())))); impl ImageCache { - pub fn new() -> Arc> { - Arc::new(Mutex::new(Self(FastHashMap::default()))) - } pub fn global() -> &'static Arc> { - IMAGE_CACHE.get_or_init(|| { - log::trace!("image cache is being created..."); - Self::new() - }) + &IMAGE_CACHE } fn cache_mut(p: P) -> Option where diff --git a/crates/webrender/src/lib.rs b/crates/webrender/src/lib.rs index 7f76448fa58..c4c0d97bad9 100644 --- a/crates/webrender/src/lib.rs +++ b/crates/webrender/src/lib.rs @@ -1,6 +1,7 @@ #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] #![feature(concat_idents)] #![allow(non_upper_case_globals)] +#![feature(lazy_cell)] #[macro_use] extern crate emacs_sys; diff --git a/crates/winit/Cargo.toml b/crates/winit/Cargo.toml index 2cebbe43185..c0467b9d6f0 100644 --- a/crates/winit/Cargo.toml +++ b/crates/winit/Cargo.toml @@ -17,7 +17,6 @@ colors = { path = "../colors" } webrender_api = { workspace = true} log.workspace = true libc.workspace = true -lazy_static = "1.4" app_units = "0.7" bit-vec = "0.6.3" raw-window-handle.workspace = true diff --git a/crates/winit/src/term.rs b/crates/winit/src/term.rs index 097edb9aa77..1116bbf92c0 100644 --- a/crates/winit/src/term.rs +++ b/crates/winit/src/term.rs @@ -34,7 +34,7 @@ use libc::fd_set; use libc::sigset_t; use libc::timespec; use std::ptr; -use std::sync::OnceLock; +use std::sync::LazyLock; use std::time::Duration; use winit::event::ElementState; use winit::event::Event; @@ -167,46 +167,46 @@ struct RedisplayInterface(pub redisplay_interface); unsafe impl Sync for RedisplayInterface {} unsafe impl Send for RedisplayInterface {} -static REDISPLAY_INTERFACE: OnceLock = OnceLock::new(); +static REDISPLAY_INTERFACE: LazyLock = LazyLock::new(|| { + log::trace!("REDISPLAY_INTERFACE is being created..."); + let frame_parm_handlers = Box::new(get_frame_parm_handlers()); + + let interface = redisplay_interface { + frame_parm_handlers: (Box::into_raw(frame_parm_handlers)) as *mut Option<_>, + produce_glyphs: Some(gui_produce_glyphs), + write_glyphs: Some(gui_write_glyphs), + insert_glyphs: Some(gui_insert_glyphs), + clear_end_of_line: Some(gui_clear_end_of_line), + scroll_run_hook: Some(wr_scroll_run), + after_update_window_line_hook: Some(wr_after_update_window_line), + update_window_begin_hook: Some(wr_update_window_begin), + update_window_end_hook: Some(wr_update_window_end), + flush_display: Some(wr_flush_display), + clear_window_mouse_face: Some(gui_clear_window_mouse_face), + get_glyph_overhangs: Some(gui_get_glyph_overhangs), + fix_overlapping_area: Some(gui_fix_overlapping_area), + draw_fringe_bitmap: Some(wr_draw_fringe_bitmap), + define_fringe_bitmap: None, + destroy_fringe_bitmap: None, + compute_glyph_string_overhangs: None, + draw_glyph_string: Some(wr_draw_glyph_string), + define_frame_cursor: Some(winit_define_frame_cursor), + clear_frame_area: Some(wr_clear_frame_area), + clear_under_internal_border: None, + draw_window_cursor: Some(wr_draw_window_cursor), + draw_vertical_window_border: Some(wr_draw_vertical_window_border), + draw_window_divider: Some(wr_draw_window_divider), + shift_glyphs_for_insert: None, /* Never called; see comment in xterm.c. */ + show_hourglass: None, + hide_hourglass: None, + default_font_parameter: None, + }; + + RedisplayInterface(interface) +}); impl RedisplayInterface { fn global() -> &'static RedisplayInterface { - REDISPLAY_INTERFACE.get_or_init(|| { - log::trace!("REDISPLAY_INTERFACE is being created..."); - let frame_parm_handlers = Box::new(get_frame_parm_handlers()); - - let interface = redisplay_interface { - frame_parm_handlers: (Box::into_raw(frame_parm_handlers)) as *mut Option<_>, - produce_glyphs: Some(gui_produce_glyphs), - write_glyphs: Some(gui_write_glyphs), - insert_glyphs: Some(gui_insert_glyphs), - clear_end_of_line: Some(gui_clear_end_of_line), - scroll_run_hook: Some(wr_scroll_run), - after_update_window_line_hook: Some(wr_after_update_window_line), - update_window_begin_hook: Some(wr_update_window_begin), - update_window_end_hook: Some(wr_update_window_end), - flush_display: Some(wr_flush_display), - clear_window_mouse_face: Some(gui_clear_window_mouse_face), - get_glyph_overhangs: Some(gui_get_glyph_overhangs), - fix_overlapping_area: Some(gui_fix_overlapping_area), - draw_fringe_bitmap: Some(wr_draw_fringe_bitmap), - define_fringe_bitmap: None, - destroy_fringe_bitmap: None, - compute_glyph_string_overhangs: None, - draw_glyph_string: Some(wr_draw_glyph_string), - define_frame_cursor: Some(winit_define_frame_cursor), - clear_frame_area: Some(wr_clear_frame_area), - clear_under_internal_border: None, - draw_window_cursor: Some(wr_draw_window_cursor), - draw_vertical_window_border: Some(wr_draw_vertical_window_border), - draw_window_divider: Some(wr_draw_window_divider), - shift_glyphs_for_insert: None, /* Never called; see comment in xterm.c. */ - show_hourglass: None, - hide_hourglass: None, - default_font_parameter: None, - }; - - RedisplayInterface(interface) - }) + &REDISPLAY_INTERFACE } }