Skip to content

Commit

Permalink
back to lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Arruda committed Jul 30, 2024
1 parent b467129 commit 5825bb2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions jyafn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 5 additions & 3 deletions jyafn/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -279,8 +279,10 @@ impl ResourceSymbols {

type LoadedExtensionVersions = HashMap<semver::Version, Arc<Extension>>;

static EXTENSIONS: LazyLock<RwLock<HashMap<String, LoadedExtensionVersions>>> =
LazyLock::new(RwLock::default);
lazy_static::lazy_static! {
static ref EXTENSIONS: RwLock<HashMap<String, LoadedExtensionVersions>> =
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
Expand Down
6 changes: 4 additions & 2 deletions jyafn/src/graph/compile/qbe_app.rs
Original file line number Diff line number Diff line change
@@ -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<Mutex<Option<PathBuf>>> = LazyLock::new(Mutex::default);
lazy_static::lazy_static! {
static ref CURRENT_QBE: Mutex<Option<PathBuf>> = Mutex::default();
}

#[cfg(unix)]
fn load() -> Result<PathBuf, io::Error> {
Expand Down
8 changes: 5 additions & 3 deletions jyafn/src/pfunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -148,8 +148,10 @@ impl PFunc {
}
}

/// All the known [`PFunc`]s.
static P_FUNCS: LazyLock<RwLock<HashMap<&'static str, PFunc>>> = LazyLock::new(|| RwLock::new(init()));
lazy_static::lazy_static! {
/// All the known [`PFunc`]s.
static ref P_FUNCS: RwLock<HashMap<&'static str, PFunc>> = RwLock::new(init());
}

/// Inscribes a new pure function.
///
Expand Down
2 changes: 1 addition & 1 deletion vendored/qbe-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
"Pedro Arruda <parruda@vio.com>",
]
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)"

Expand Down

0 comments on commit 5825bb2

Please sign in to comment.