Skip to content

Commit

Permalink
Remove once_cell (#2463)
Browse files Browse the repository at this point in the history
- **Fix**
- **Fix**
- **Fix**
- **Fix**
- **Fix**
- **Fix**
  • Loading branch information
raviqqe authored Aug 11, 2024
1 parent 2441a20 commit b7a7cc9
Show file tree
Hide file tree
Showing 34 changed files with 95 additions and 115 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion cmd/pen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ clap = { version = "4", features = ["cargo"] }
app = { path = "../../lib/app" }
indoc = "2"
infra = { path = "../../lib/infra" }
once_cell = "1"
url = "2"
34 changes: 17 additions & 17 deletions cmd/pen/src/application_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use once_cell::sync::Lazy;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

pub static APPLICATION_CONFIGURATION: Lazy<Arc<app::ApplicationConfiguration>> = Lazy::new(|| {
app::ApplicationConfiguration {
application_filename: "app".into(),
main_module_basename: "main".into(),
context_module_basename: "Context".into(),
main_module: app::MainModuleConfiguration {
source_main_function_name: "main".into(),
object_main_function_name: "_pen_main".into(),
main_context_type_name: "context".into(),
system_context_type_name: "Context".into(),
new_system_context_function_name: "UnsafeNew".into(),
},
}
.into()
});
pub static APPLICATION_CONFIGURATION: LazyLock<Arc<app::ApplicationConfiguration>> =
LazyLock::new(|| {
app::ApplicationConfiguration {
application_filename: "app".into(),
main_module_basename: "main".into(),
context_module_basename: "Context".into(),
main_module: app::MainModuleConfiguration {
source_main_function_name: "main".into(),
object_main_function_name: "_pen_main".into(),
main_context_type_name: "context".into(),
system_context_type_name: "Context".into(),
new_system_context_function_name: "UnsafeNew".into(),
},
}
.into()
});
7 changes: 3 additions & 4 deletions cmd/pen/src/compile_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use once_cell::sync::Lazy;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

pub const CROSS_COMPILE_TARGETS: &[&str] = &[
"i686-unknown-linux-musl",
Expand All @@ -8,8 +7,8 @@ pub const CROSS_COMPILE_TARGETS: &[&str] = &[
"wasm32-wasi",
];

pub static COMPILE_CONFIGURATION: Lazy<Arc<app::module_compiler::CompileConfiguration>> =
Lazy::new(|| {
pub static COMPILE_CONFIGURATION: LazyLock<Arc<app::module_compiler::CompileConfiguration>> =
LazyLock::new(|| {
app::module_compiler::CompileConfiguration {
fmm: app::module_compiler::FmmConfiguration {
allocate_function_name: "_pen_malloc".into(),
Expand Down
6 changes: 3 additions & 3 deletions cmd/pen/src/documentation_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::application_configuration::APPLICATION_CONFIGURATION;
use app::package_documentation_generator::DocumentationConfiguration;
use once_cell::sync::Lazy;
use std::sync::LazyLock;

pub static DOCUMENTATION_CONFIGURATION: Lazy<DocumentationConfiguration> =
Lazy::new(|| DocumentationConfiguration {
pub static DOCUMENTATION_CONFIGURATION: LazyLock<DocumentationConfiguration> =
LazyLock::new(|| DocumentationConfiguration {
language: "pen".into(),
private_names: [APPLICATION_CONFIGURATION
.main_module
Expand Down
6 changes: 3 additions & 3 deletions cmd/pen/src/test_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use once_cell::sync::Lazy;
use std::sync::LazyLock;

pub static TEST_CONFIGURATION: Lazy<app::TestConfiguration> =
Lazy::new(|| app::TestConfiguration {
pub static TEST_CONFIGURATION: LazyLock<app::TestConfiguration> =
LazyLock::new(|| app::TestConfiguration {
test_module_configuration: app::TestModuleConfiguration {
test_function_prefix: "_pen_test_".into(),
},
Expand Down
1 change: 0 additions & 1 deletion lib/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ hir_mir = { path = "../hir-mir" }
interface = { path = "../interface" }
mir = { path = "../mir" }
mir-fmm = { path = "../mir-fmm" }
once_cell = "1"
parse = { path = "../parse" }
petgraph = "0.6"
regex = "1"
Expand Down
4 changes: 2 additions & 2 deletions lib/app/src/common/package_id_calculator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use once_cell::sync::Lazy;
use regex::Regex;
use std::sync::LazyLock;

const REPLACEMENT_STRING: &str = "_";

static REPLACEMENT_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"[.:/]+").unwrap());
static REPLACEMENT_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[.:/]+").unwrap());

pub fn calculate(url: &url::Url) -> String {
REPLACEMENT_REGEX
Expand Down
1 change: 0 additions & 1 deletion lib/ast-hir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fnv = "1"
hir = { path = "../hir" }
interface = { path = "../interface" }
itertools = "0.13"
once_cell = "1"
position = { path = "../position" }
regex = "1"

Expand Down
7 changes: 3 additions & 4 deletions lib/ast-hir/src/string.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use once_cell::sync::Lazy;
use regex::bytes::{Captures, Regex};
use std::str;
use std::{str, sync::LazyLock};

static HEX_CHARACTER_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"\\x([0-9a-fA-F][0-9a-fA-F])").unwrap());
static HEX_CHARACTER_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\\x([0-9a-fA-F][0-9a-fA-F])").unwrap());

pub fn compile(string: &str) -> Vec<u8> {
HEX_CHARACTER_REGEX
Expand Down
1 change: 0 additions & 1 deletion lib/hir-mir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ test-info = { path = "../test-info" }

[dev-dependencies]
insta = "1"
once_cell = "1"
pretty_assertions = "1"
21 changes: 11 additions & 10 deletions lib/hir-mir/src/compile_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::{
};
use crate::number_type_configuration::NumberTypeConfiguration;
#[cfg(test)]
use once_cell::sync::Lazy;
use std::sync::LazyLock;

#[derive(Clone, Debug)]
pub struct CompileConfiguration {
Expand All @@ -25,12 +25,13 @@ pub struct CompileConfiguration {
}

#[cfg(test)]
pub static COMPILE_CONFIGURATION: Lazy<CompileConfiguration> = Lazy::new(|| CompileConfiguration {
list_type: LIST_TYPE_CONFIGURATION.clone(),
map_type: MAP_TYPE_CONFIGURATION.clone(),
number_type: NUMBER_TYPE_CONFIGURATION.clone(),
string_type: STRING_TYPE_CONFIGURATION.clone(),
debug_function_name: "debug".into(),
race_function_name: "race".into(),
spawn_function_name: "spawn".into(),
});
pub static COMPILE_CONFIGURATION: LazyLock<CompileConfiguration> =
LazyLock::new(|| CompileConfiguration {
list_type: LIST_TYPE_CONFIGURATION.clone(),
map_type: MAP_TYPE_CONFIGURATION.clone(),
number_type: NUMBER_TYPE_CONFIGURATION.clone(),
string_type: STRING_TYPE_CONFIGURATION.clone(),
debug_function_name: "debug".into(),
race_function_name: "race".into(),
spawn_function_name: "spawn".into(),
});
6 changes: 3 additions & 3 deletions lib/hir-mir/src/list_type_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(test)]
use once_cell::sync::Lazy;
use std::sync::LazyLock;

#[cfg(test)]
pub static LIST_TYPE_CONFIGURATION: Lazy<ListTypeConfiguration> =
Lazy::new(|| ListTypeConfiguration {
pub static LIST_TYPE_CONFIGURATION: LazyLock<ListTypeConfiguration> =
LazyLock::new(|| ListTypeConfiguration {
empty_function_name: "emptyList".into(),
concatenate_function_name: "concatenateLists".into(),
equal_function_name: "equalLists".into(),
Expand Down
12 changes: 6 additions & 6 deletions lib/hir-mir/src/map_type_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(test)]
use once_cell::sync::Lazy;
use std::sync::LazyLock;

#[cfg(test)]
pub static MAP_TYPE_CONFIGURATION: Lazy<MapTypeConfiguration> =
Lazy::new(|| MapTypeConfiguration {
pub static MAP_TYPE_CONFIGURATION: LazyLock<MapTypeConfiguration> =
LazyLock::new(|| MapTypeConfiguration {
context_function_name: "newMapContext".into(),
context_type_name: "mapContext".into(),
delete_function_name: "deleteMap".into(),
Expand All @@ -22,7 +22,7 @@ pub static MAP_TYPE_CONFIGURATION: Lazy<MapTypeConfiguration> =
});

#[cfg(test)]
pub static HASH_CONFIGURATION: Lazy<HashConfiguration> = Lazy::new(|| HashConfiguration {
pub static HASH_CONFIGURATION: LazyLock<HashConfiguration> = LazyLock::new(|| HashConfiguration {
combine_function_name: "combineHashes".into(),
number_hash_function_name: "hashNumber".into(),
string_hash_function_name: "hashString".into(),
Expand All @@ -31,8 +31,8 @@ pub static HASH_CONFIGURATION: Lazy<HashConfiguration> = Lazy::new(|| HashConfig
});

#[cfg(test)]
pub static MAP_TYPE_ITERATION_CONFIGURATION: Lazy<MapTypeIterationConfiguration> =
Lazy::new(|| MapTypeIterationConfiguration {
pub static MAP_TYPE_ITERATION_CONFIGURATION: LazyLock<MapTypeIterationConfiguration> =
LazyLock::new(|| MapTypeIterationConfiguration {
iterator_type_name: "mapIterator".into(),
iterate_function_name: "iterateMap".into(),
key_function_name: "mapIteratorKey".into(),
Expand Down
6 changes: 3 additions & 3 deletions lib/hir-mir/src/number_type_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(test)]
use once_cell::sync::Lazy;
use std::sync::LazyLock;

#[cfg(test)]
pub static NUMBER_TYPE_CONFIGURATION: Lazy<NumberTypeConfiguration> =
Lazy::new(|| NumberTypeConfiguration {
pub static NUMBER_TYPE_CONFIGURATION: LazyLock<NumberTypeConfiguration> =
LazyLock::new(|| NumberTypeConfiguration {
debug_function_name: "debugNumber".into(),
});

Expand Down
6 changes: 3 additions & 3 deletions lib/hir-mir/src/string_type_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(test)]
use once_cell::sync::Lazy;
use std::sync::LazyLock;

#[cfg(test)]
pub static STRING_TYPE_CONFIGURATION: Lazy<StringTypeConfiguration> =
Lazy::new(|| StringTypeConfiguration {
pub static STRING_TYPE_CONFIGURATION: LazyLock<StringTypeConfiguration> =
LazyLock::new(|| StringTypeConfiguration {
equal_function_name: "_equalStrings".into(),
});

Expand Down
1 change: 0 additions & 1 deletion lib/hir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ position = { path = "../position" }
serde = { version = "1", features = ["derive", "rc"] }

[dev-dependencies]
once_cell = "1"
pretty_assertions = "1"
1 change: 0 additions & 1 deletion lib/mir-fmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ edition = "2021"
fmm = { git = "https://github.com/raviqqe/fmm", branch = "main" }
fnv = "1"
mir = { path = "../mir" }
once_cell = "1"
plist = { git = "https://github.com/raviqqe/plist-rs", branch = "main" }

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions lib/mir-fmm/src/closure/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::{
reference_count::{self, REFERENCE_COUNT_FUNCTION_DEFINITION_OPTIONS},
type_, CompileError,
};
use once_cell::sync::Lazy;
use std::sync::LazyLock;

thread_local! {
static DUMMY_FUNCTION_TYPE: Lazy<mir::types::Function> =
Lazy::new(|| mir::types::Function::new(vec![], mir::types::Type::None));
static DUMMY_FUNCTION_TYPE: LazyLock<mir::types::Function> =
LazyLock::new(|| mir::types::Function::new(vec![], mir::types::Type::None));
}

pub fn compile(
Expand Down
15 changes: 8 additions & 7 deletions lib/mir-fmm/src/closure/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use super::{drop, sync};
use crate::{context::Context, CompileError};
use once_cell::sync::Lazy;
use std::sync::LazyLock;

static VARIABLE_DEFINITION_OPTIONS: Lazy<fmm::ir::VariableDefinitionOptions> = Lazy::new(|| {
fmm::ir::VariableDefinitionOptions::new()
.set_address_named(false)
.set_linkage(fmm::ir::Linkage::Internal)
.set_mutable(false)
});
static VARIABLE_DEFINITION_OPTIONS: LazyLock<fmm::ir::VariableDefinitionOptions> =
LazyLock::new(|| {
fmm::ir::VariableDefinitionOptions::new()
.set_address_named(false)
.set_linkage(fmm::ir::Linkage::Internal)
.set_mutable(false)
});

// We do not need to compile closure metadata for thunks in the middle of
// evaluation because of the following reasons.
Expand Down
6 changes: 3 additions & 3 deletions lib/mir-fmm/src/closure/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::{
reference_count::{self, REFERENCE_COUNT_FUNCTION_DEFINITION_OPTIONS},
type_, CompileError,
};
use once_cell::sync::Lazy;
use std::sync::LazyLock;

thread_local! {
static DUMMY_FUNCTION_TYPE: Lazy<mir::types::Function> =
Lazy::new(|| mir::types::Function::new(vec![], mir::types::Type::None));
static DUMMY_FUNCTION_TYPE: LazyLock<mir::types::Function> =
LazyLock::new(|| mir::types::Function::new(vec![], mir::types::Type::None));
}

pub fn compile(
Expand Down
4 changes: 2 additions & 2 deletions lib/mir-fmm/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(test)]
use once_cell::sync::Lazy;
use std::sync::LazyLock;

#[cfg(test)]
pub static CONFIGURATION: Lazy<Configuration> = Lazy::new(|| Configuration {
pub static CONFIGURATION: LazyLock<Configuration> = LazyLock::new(|| Configuration {
yield_function_name: "mir_yield".into(),
});

Expand Down
6 changes: 3 additions & 3 deletions lib/mir-fmm/src/entry_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use super::error::CompileError;
use crate::{
closure, context::Context, expression, reference_count, type_, yield_::yield_function_type,
};
use once_cell::sync::Lazy;
use std::sync::LazyLock;

const CLOSURE_NAME: &str = "_closure";

static ENTRY_FUNCTION_DEFINITION_OPTIONS: Lazy<fmm::ir::FunctionDefinitionOptions> =
Lazy::new(|| {
static ENTRY_FUNCTION_DEFINITION_OPTIONS: LazyLock<fmm::ir::FunctionDefinitionOptions> =
LazyLock::new(|| {
fmm::ir::FunctionDefinitionOptions::new()
.set_address_named(false)
.set_calling_convention(fmm::types::CallingConvention::Source)
Expand Down
6 changes: 3 additions & 3 deletions lib/mir-fmm/src/reference_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub mod string;
pub mod variant;

pub use expression::*;
use once_cell::sync::Lazy;
use std::sync::LazyLock;

pub(super) static REFERENCE_COUNT_FUNCTION_DEFINITION_OPTIONS: Lazy<
pub(super) static REFERENCE_COUNT_FUNCTION_DEFINITION_OPTIONS: LazyLock<
fmm::ir::FunctionDefinitionOptions,
> = Lazy::new(|| {
> = LazyLock::new(|| {
fmm::ir::FunctionDefinitionOptions::new()
.set_address_named(false)
.set_calling_convention(fmm::types::CallingConvention::Target)
Expand Down
Loading

0 comments on commit b7a7cc9

Please sign in to comment.