From 5825bb2a974fcc78cff724cd5583e345181029a7 Mon Sep 17 00:00:00 2001 From: Pedro Arruda Date: Tue, 30 Jul 2024 16:44:03 -0300 Subject: [PATCH] back to lazy_static --- Cargo.lock | 1 + jyafn/Cargo.toml | 1 + jyafn/src/extension.rs | 8 +++++--- jyafn/src/graph/compile/qbe_app.rs | 6 ++++-- jyafn/src/pfunc.rs | 8 +++++--- vendored/qbe-rs/Cargo.toml | 2 +- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65ce315..0feef83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -707,6 +707,7 @@ dependencies = [ "hashbrown 0.14.5", "home", "jyafn-qbe 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", "libloading", "rand", "scopeguard", diff --git a/jyafn/Cargo.toml b/jyafn/Cargo.toml index a467dfb..cba2678 100644 --- a/jyafn/Cargo.toml +++ b/jyafn/Cargo.toml @@ -36,3 +36,4 @@ thiserror = "1.0.58" thread_local = "1.1.8" typetag = "0.2.16" zip = { version = "2.1.3", default-features = false, features = ["deflate"] } +lazy_static = "1.5.0" diff --git a/jyafn/src/extension.rs b/jyafn/src/extension.rs index 758cb93..7548557 100644 --- a/jyafn/src/extension.rs +++ b/jyafn/src/extension.rs @@ -6,7 +6,7 @@ use serde_with::{serde_as, DisplayFromStr}; use std::collections::HashMap; use std::ffi::{c_char, CStr, CString}; use std::path::{Path, PathBuf}; -use std::sync::{Arc, LazyLock, RwLock}; +use std::sync::{Arc, RwLock}; use crate::layout::{Layout, Struct}; use crate::{Context, Error}; @@ -279,8 +279,10 @@ impl ResourceSymbols { type LoadedExtensionVersions = HashMap>; -static EXTENSIONS: LazyLock>> = - LazyLock::new(RwLock::default); +lazy_static::lazy_static! { + static ref EXTENSIONS: RwLock> = + RwLock::default(); +} /// An extension is a wrapper over a shared object comforming to a given interface. This /// can be used to create extra "resources" that can be accessed from jyafn. It's useful diff --git a/jyafn/src/graph/compile/qbe_app.rs b/jyafn/src/graph/compile/qbe_app.rs index 9ece619..0eb665d 100644 --- a/jyafn/src/graph/compile/qbe_app.rs +++ b/jyafn/src/graph/compile/qbe_app.rs @@ -1,11 +1,13 @@ use rand::random; use std::path::PathBuf; -use std::sync::{LazyLock, Mutex}; +use std::sync::Mutex; use std::{env, fs, io}; const BIN: &[u8] = include_bytes!("../../../../vendored/qbe/qbe"); -static CURRENT_QBE: LazyLock>> = LazyLock::new(Mutex::default); +lazy_static::lazy_static! { + static ref CURRENT_QBE: Mutex> = Mutex::default(); +} #[cfg(unix)] fn load() -> Result { diff --git a/jyafn/src/pfunc.rs b/jyafn/src/pfunc.rs index 6efb948..0e4b18d 100644 --- a/jyafn/src/pfunc.rs +++ b/jyafn/src/pfunc.rs @@ -2,7 +2,7 @@ use chrono::prelude::*; use special_fun::FloatSpecial; -use std::{collections::HashMap, sync::LazyLock}; +use std::collections::HashMap; use std::ops::Rem; use std::sync::RwLock; @@ -148,8 +148,10 @@ impl PFunc { } } -/// All the known [`PFunc`]s. -static P_FUNCS: LazyLock>> = LazyLock::new(|| RwLock::new(init())); +lazy_static::lazy_static! { + /// All the known [`PFunc`]s. + static ref P_FUNCS: RwLock> = RwLock::new(init()); +} /// Inscribes a new pure function. /// diff --git a/vendored/qbe-rs/Cargo.toml b/vendored/qbe-rs/Cargo.toml index 20ace89..5cfe9d2 100644 --- a/vendored/qbe-rs/Cargo.toml +++ b/vendored/qbe-rs/Cargo.toml @@ -7,7 +7,7 @@ authors = [ "Pedro Arruda ", ] license = "MIT OR Apache-2.0" -repository = "https://github.com/viodotcom/jyafn/vendored/qbe-rs" +repository = "https://github.com/viodotcom/jyafn" keywords = ["qbe", "compiler", "ir"] description = "QBE IR for Rust (forked from https://github.com/garritfra/qbe-rs for jyafn)"