mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Mutex::new() is now const
This commit is contained in:
parent
8b53a13f0e
commit
e92ceb7282
9 changed files with 31 additions and 45 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -3356,7 +3356,6 @@ name = "roc_builtins"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dunce",
|
"dunce",
|
||||||
"lazy_static",
|
|
||||||
"roc_collections",
|
"roc_collections",
|
||||||
"roc_module",
|
"roc_module",
|
||||||
"roc_region",
|
"roc_region",
|
||||||
|
@ -3826,7 +3825,6 @@ name = "roc_module"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"lazy_static",
|
|
||||||
"roc_collections",
|
"roc_collections",
|
||||||
"roc_error_macros",
|
"roc_error_macros",
|
||||||
"roc_ident",
|
"roc_ident",
|
||||||
|
@ -4815,7 +4813,6 @@ dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"indoc",
|
"indoc",
|
||||||
"insta",
|
"insta",
|
||||||
"lazy_static",
|
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"roc_builtins",
|
"roc_builtins",
|
||||||
"roc_can",
|
"roc_can",
|
||||||
|
|
|
@ -12,7 +12,6 @@ roc_region = { path = "../region" }
|
||||||
roc_module = { path = "../module" }
|
roc_module = { path = "../module" }
|
||||||
roc_target = { path = "../roc_target" }
|
roc_target = { path = "../roc_target" }
|
||||||
roc_utils = { path = "../../utils" }
|
roc_utils = { path = "../../utils" }
|
||||||
lazy_static = "1.4.0"
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
# dunce can be removed once ziglang/zig#5109 is fixed
|
# dunce can be removed once ziglang/zig#5109 is fixed
|
||||||
|
|
|
@ -69,6 +69,14 @@ impl std::fmt::Debug for SmallStringInterner {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SmallStringInterner {
|
impl SmallStringInterner {
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
buffer: Vec::new(),
|
||||||
|
lengths: Vec::new(),
|
||||||
|
offsets: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_capacity(capacity: usize) -> Self {
|
pub fn with_capacity(capacity: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
// guess: the average symbol length is 5
|
// guess: the average symbol length is 5
|
||||||
|
|
|
@ -6,14 +6,18 @@ pub struct VecMap<K, V> {
|
||||||
|
|
||||||
impl<K, V> Default for VecMap<K, V> {
|
impl<K, V> Default for VecMap<K, V> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<K, V> VecMap<K, V> {
|
||||||
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
keys: Vec::new(),
|
keys: Vec::new(),
|
||||||
values: Vec::new(),
|
values: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<K, V> VecMap<K, V> {
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
debug_assert_eq!(self.keys.len(), self.values.len());
|
debug_assert_eq!(self.keys.len(), self.values.len());
|
||||||
self.keys.len()
|
self.keys.len()
|
||||||
|
|
|
@ -12,7 +12,6 @@ roc_ident = { path = "../ident" }
|
||||||
roc_collections = { path = "../collections" }
|
roc_collections = { path = "../collections" }
|
||||||
roc_error_macros = {path = "../../error_macros"}
|
roc_error_macros = {path = "../../error_macros"}
|
||||||
bumpalo = { version = "3.11.0", features = ["collections"] }
|
bumpalo = { version = "3.11.0", features = ["collections"] }
|
||||||
lazy_static = "1.4.0"
|
|
||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
snafu = { version = "0.7.1", features = ["backtraces"] }
|
snafu = { version = "0.7.1", features = ["backtraces"] }
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,3 @@ pub mod ident;
|
||||||
pub mod low_level;
|
pub mod low_level;
|
||||||
pub mod module_err;
|
pub mod module_err;
|
||||||
pub mod symbol;
|
pub mod symbol;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
|
||||||
|
|
|
@ -246,29 +246,13 @@ fn fallback_debug_fmt(symbol: Symbol, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "`{:?}.{:?}`", module_id, ident_id)
|
write!(f, "`{:?}.{:?}`", module_id, ident_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is only here to prevent clippy from complaining about an unused
|
/// This is used in Debug builds only, to let us have a Debug instance
|
||||||
// #[macro_use] on lazy_statc in --release builds, because as of January 2020,
|
/// which displays not only the Module ID, but also the Module Name which
|
||||||
// we only use lazy_static in the debug configuration. If we ever start using
|
/// corresponds to that ID.
|
||||||
// lazy_static in release builds, this do-nothing macro invocation will be safe to delete!
|
///
|
||||||
//
|
|
||||||
// There's probably also a way to get clippy to stop complaining about the unused
|
|
||||||
// #[macro_use] but it didn't seem worth the effort since probably someday we'll
|
|
||||||
// end up using it in release builds anyway. Right? ...Right?
|
|
||||||
lazy_static! {}
|
|
||||||
|
|
||||||
#[cfg(any(debug_assertions, feature = "debug-symbols"))]
|
#[cfg(any(debug_assertions, feature = "debug-symbols"))]
|
||||||
lazy_static! {
|
static DEBUG_MODULE_ID_NAMES: std::sync::Mutex<roc_collections::SmallStringInterner> =
|
||||||
/// This is used in Debug builds only, to let us have a Debug instance
|
std::sync::Mutex::new(roc_collections::SmallStringInterner::new());
|
||||||
/// which displays not only the Module ID, but also the Module Name which
|
|
||||||
/// corresponds to that ID.
|
|
||||||
///
|
|
||||||
static ref DEBUG_MODULE_ID_NAMES: std::sync::Mutex<roc_collections::SmallStringInterner> =
|
|
||||||
// This stores a u32 key instead of a ModuleId key so that if there's
|
|
||||||
// a problem with ModuleId's Debug implementation, logging this for diagnostic
|
|
||||||
// purposes won't recursively trigger ModuleId's Debug instance in the course of printing
|
|
||||||
// this out.
|
|
||||||
std::sync::Mutex::new(roc_collections::SmallStringInterner::with_capacity(10));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct Interns {
|
pub struct Interns {
|
||||||
|
@ -338,18 +322,16 @@ pub fn get_module_ident_ids_mut<'a>(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This is used in Debug builds only, to let us have a Debug instance
|
||||||
|
/// which displays not only the Module ID, but also the Module Name which
|
||||||
|
/// corresponds to that ID.
|
||||||
#[cfg(any(debug_assertions, feature = "debug-symbols"))]
|
#[cfg(any(debug_assertions, feature = "debug-symbols"))]
|
||||||
lazy_static! {
|
static DEBUG_IDENT_IDS_BY_MODULE_ID: std::sync::Mutex<roc_collections::VecMap<u32, IdentIds>> =
|
||||||
/// This is used in Debug builds only, to let us have a Debug instance
|
|
||||||
/// which displays not only the Module ID, but also the Module Name which
|
|
||||||
/// corresponds to that ID.
|
|
||||||
static ref DEBUG_IDENT_IDS_BY_MODULE_ID: std::sync::Mutex<roc_collections::VecMap<u32, IdentIds>> =
|
|
||||||
// This stores a u32 key instead of a ModuleId key so that if there's
|
// This stores a u32 key instead of a ModuleId key so that if there's
|
||||||
// a problem with ModuleId's Debug implementation, logging this for diagnostic
|
// a problem with ModuleId's Debug implementation, logging this for diagnostic
|
||||||
// purposes won't recursively trigger ModuleId's Debug instance in the course of printing
|
// purposes won't recursively trigger ModuleId's Debug instance in the course of printing
|
||||||
// this out.
|
// this out.
|
||||||
std::sync::Mutex::new(roc_collections::VecMap::default());
|
std::sync::Mutex::new(roc_collections::VecMap::new());
|
||||||
}
|
|
||||||
|
|
||||||
/// A globally unique ID that gets assigned to each module as it is loaded.
|
/// A globally unique ID that gets assigned to each module as it is loaded.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
|
|
|
@ -26,7 +26,6 @@ roc_region = { path = "../region" }
|
||||||
roc_solve = { path = "../solve" }
|
roc_solve = { path = "../solve" }
|
||||||
roc_debug_flags = { path = "../debug_flags" }
|
roc_debug_flags = { path = "../debug_flags" }
|
||||||
bumpalo = { version = "3.11.0", features = ["collections"] }
|
bumpalo = { version = "3.11.0", features = ["collections"] }
|
||||||
lazy_static = "1.4.0"
|
|
||||||
indoc = "1.0.7"
|
indoc = "1.0.7"
|
||||||
ven_pretty = { path = "../../vendor/pretty" }
|
ven_pretty = { path = "../../vendor/pretty" }
|
||||||
pretty_assertions = "1.3.0"
|
pretty_assertions = "1.3.0"
|
||||||
|
|
|
@ -23,9 +23,10 @@ thread_local! {
|
||||||
// Even if Cargo uses many threads, these tests won't go any faster. But that's fine, they're quick.
|
// Even if Cargo uses many threads, these tests won't go any faster. But that's fine, they're quick.
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref COMPILER: Instance = init_compiler();
|
static ref COMPILER: Instance = init_compiler();
|
||||||
static ref TEST_MUTEX: Mutex<()> = Mutex::new(());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TEST_MUTEX: Mutex<()> = Mutex::new(());
|
||||||
|
|
||||||
/// Load the compiler .wasm file and get it ready to execute
|
/// Load the compiler .wasm file and get it ready to execute
|
||||||
/// THIS FUNCTION TAKES 4 SECONDS TO RUN
|
/// THIS FUNCTION TAKES 4 SECONDS TO RUN
|
||||||
fn init_compiler() -> Instance {
|
fn init_compiler() -> Instance {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue