From e5cac9651139396353d1164010c7e5ec48465add Mon Sep 17 00:00:00 2001 From: Daniel Alley Date: Sun, 26 Jan 2020 23:25:28 -0500 Subject: [PATCH] Replace lazy_static! macro with once_cell --- Cargo.lock | 10 ++++++++-- derive/Cargo.toml | 2 +- derive/src/compile_bytecode.rs | 9 ++++----- vm/Cargo.toml | 2 +- vm/src/lib.rs | 2 -- vm/src/vm.rs | 5 ++--- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9001fea6e..6169f706f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -888,6 +888,11 @@ dependencies = [ "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "once_cell" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "opaque-debug" version = "0.2.3" @@ -1310,8 +1315,8 @@ dependencies = [ name = "rustpython-derive" version = "0.1.1" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustpython-bytecode 0.1.1", @@ -1361,7 +1366,6 @@ dependencies = [ "indexmap 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "is-macro 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lexical 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1376,6 +1380,7 @@ dependencies = [ "num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "pwd 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2303,6 +2308,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2885278d5fe2adc2f75ced642d52d879bffaceb5a2e0b1d4309ffdfb239b454" "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" +"checksum once_cell 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" "checksum paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "423a519e1c6e828f1e73b720f9d9ed2fa643dce8a7737fb43235ce0b41eeaa49" diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 3242ab804..bbadcc3d9 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -17,4 +17,4 @@ proc-macro2 = "1.0" rustpython-compiler = { path = "../compiler", version = "0.1.1" } rustpython-bytecode = { path = "../bytecode", version = "0.1.1" } maplit = "1.0" -lazy_static = "1" +once_cell = "1.3.1" diff --git a/derive/src/compile_bytecode.rs b/derive/src/compile_bytecode.rs index c89debd1d..e4382ee01 100644 --- a/derive/src/compile_bytecode.rs +++ b/derive/src/compile_bytecode.rs @@ -14,6 +14,7 @@ //! ``` use crate::{extract_spans, Diagnostic}; +use once_cell::sync::Lazy; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; use rustpython_bytecode::bytecode::{CodeObject, FrozenModule}; @@ -25,11 +26,9 @@ use std::path::{Path, PathBuf}; use syn::parse::{Parse, ParseStream, Result as ParseResult}; use syn::{self, parse2, Lit, LitByteStr, LitStr, Meta, Token}; -lazy_static::lazy_static! { - static ref CARGO_MANIFEST_DIR: PathBuf = PathBuf::from( - env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not present"), - ); -} +static CARGO_MANIFEST_DIR: Lazy = Lazy::new(|| { + PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not present")) +}); enum CompilationSourceKind { File(PathBuf), diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 7bfbaf23a..ccfd9f8b5 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -46,7 +46,7 @@ rustc_version_runtime = "0.1.*" statrs = "0.12.0" caseless = "0.2.1" chrono = { version = "=0.4.9", features = ["wasmbind"] } -lazy_static = "^1.0.1" +once_cell = "1.3.1" lexical = "4" itertools = "0.8" hex = "0.4.0" diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 444d87ccc..910439ad7 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -20,8 +20,6 @@ extern crate flamer; #[macro_use] extern crate bitflags; -#[macro_use] -extern crate lazy_static; extern crate lexical; #[macro_use] extern crate log; diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 38762ca77..3c44c9f22 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -15,6 +15,7 @@ use std::sync::{Mutex, MutexGuard}; use arr_macro::arr; use num_bigint::BigInt; use num_traits::ToPrimitive; +use once_cell::sync::Lazy; #[cfg(feature = "rustpython-compiler")] use rustpython_compiler::{compile, error::CompileError}; @@ -1322,9 +1323,7 @@ impl Default for VirtualMachine { } } -lazy_static! { - static ref REPR_GUARDS: Mutex> = { Mutex::new(HashSet::new()) }; -} +static REPR_GUARDS: Lazy>> = Lazy::new(Mutex::default); pub struct ReprGuard { id: usize,