diff --git a/lib/src/types/array.rs b/lib/src/types/array.rs index f7c400225..839ce6ba7 100644 --- a/lib/src/types/array.rs +++ b/lib/src/types/array.rs @@ -8,6 +8,10 @@ use crate::symbols::{Symbol, SymbolTable}; use crate::types::{Struct, TypeValue}; use crate::wasm::WasmExport; +thread_local! { + static BUILTIN_METHODS: OnceCell> = const { OnceCell::new() }; +} + #[derive(Serialize, Deserialize)] pub(crate) enum Array { Integers(Vec), @@ -18,13 +22,9 @@ pub(crate) enum Array { } impl Array { - #[allow(clippy::declare_interior_mutable_const)] - const BUILTIN_METHODS: OnceCell> = OnceCell::new(); - pub fn builtin_methods() -> Rc { - #[allow(clippy::borrow_interior_mutable_const)] - Self::BUILTIN_METHODS - .get_or_init(|| { + BUILTIN_METHODS.with(|cell| { + cell.get_or_init(|| { let mut s = SymbolTable::new(); for (name, func) in WasmExport::get_methods("Array") { s.insert(name, Symbol::Func(Rc::new(func))); @@ -32,6 +32,7 @@ impl Array { Rc::new(s) }) .clone() + }) } pub fn deputy(&self) -> TypeValue { diff --git a/lib/src/types/map.rs b/lib/src/types/map.rs index de788b322..4253f880a 100644 --- a/lib/src/types/map.rs +++ b/lib/src/types/map.rs @@ -8,6 +8,10 @@ use crate::symbols::{Symbol, SymbolTable}; use crate::types::TypeValue; use crate::wasm::WasmExport; +thread_local! { + static BUILTIN_METHODS: OnceCell> = const { OnceCell::new() }; +} + #[derive(Serialize, Deserialize)] pub(crate) enum Map { /// A map that has integer keys. @@ -31,13 +35,9 @@ pub(crate) enum Map { } impl Map { - #[allow(clippy::declare_interior_mutable_const)] - const BUILTIN_METHODS: OnceCell> = OnceCell::new(); - pub fn builtin_methods() -> Rc { - #[allow(clippy::borrow_interior_mutable_const)] - Self::BUILTIN_METHODS - .get_or_init(|| { + BUILTIN_METHODS.with(|cell| { + cell.get_or_init(|| { let mut s = SymbolTable::new(); for (name, func) in WasmExport::get_methods("Map") { s.insert(name, Symbol::Func(Rc::new(func))); @@ -45,6 +45,7 @@ impl Map { Rc::new(s) }) .clone() + }) } pub fn deputy(&self) -> TypeValue { diff --git a/lib/src/types/mod.rs b/lib/src/types/mod.rs index 38b07dfc9..f62c7be45 100644 --- a/lib/src/types/mod.rs +++ b/lib/src/types/mod.rs @@ -17,6 +17,10 @@ pub(crate) use func::*; pub(crate) use map::*; pub(crate) use structure::*; +thread_local! { + static STRING_BUILTIN_METHODS: OnceCell> = const { OnceCell::new() }; +} + mod array; mod func; mod map; @@ -310,13 +314,9 @@ impl TypeValue { } } - #[allow(clippy::declare_interior_mutable_const)] - const STRING_BUILTIN_METHODS: OnceCell> = OnceCell::new(); - fn string_builtin_methods() -> Rc { - #[allow(clippy::borrow_interior_mutable_const)] - Self::STRING_BUILTIN_METHODS - .get_or_init(|| { + STRING_BUILTIN_METHODS.with(|cell| { + cell.get_or_init(|| { let mut s = SymbolTable::new(); for (name, func) in WasmExport::get_methods("RuntimeString") { s.insert(name, Symbol::Func(Rc::new(func))); @@ -324,6 +324,7 @@ impl TypeValue { Rc::new(s) }) .clone() + }) } /// Returns the symbol table associated to this [`TypeValue`].