From e98db36f31d7d421b2016092a268d878ec2ba83d Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 12 Sep 2024 12:18:29 -0600 Subject: [PATCH] Use Arc instead of Rc in GenericFoo structs --- .../src/casm_contract_class.rs | 20 +++++++++---------- .../src/deprecated_compiled_class.rs | 18 ++++++++--------- .../src/sierra_contract_class.rs | 16 +++++++-------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/starknet-os-types/src/casm_contract_class.rs b/crates/starknet-os-types/src/casm_contract_class.rs index cb3a4ec2..9acabdc3 100644 --- a/crates/starknet-os-types/src/casm_contract_class.rs +++ b/crates/starknet-os-types/src/casm_contract_class.rs @@ -1,5 +1,5 @@ use std::cell::OnceCell; -use std::rc::Rc; +use std::sync::Arc; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -16,9 +16,9 @@ pub type BlockifierCasmClass = blockifier::execution::contract_class::ContractCl /// Fields are boxed in an RC for cheap cloning. #[derive(Debug, Clone)] pub struct GenericCasmContractClass { - blockifier_contract_class: OnceCell>, - cairo_lang_contract_class: OnceCell>, - serialized_class: OnceCell>>, + blockifier_contract_class: OnceCell>, + cairo_lang_contract_class: OnceCell>, + serialized_class: OnceCell>>, class_hash: OnceCell, } @@ -40,7 +40,7 @@ impl GenericCasmContractClass { Self { blockifier_contract_class: OnceCell::new(), cairo_lang_contract_class: OnceCell::new(), - serialized_class: OnceCell::from(Rc::new(serialized_class)), + serialized_class: OnceCell::from(Arc::new(serialized_class)), class_hash: OnceCell::new(), } } @@ -62,7 +62,7 @@ impl GenericCasmContractClass { if let Some(serialized_class) = &self.serialized_class.get() { let cairo_lang_class = cairo_lang_contract_class_from_bytes(serialized_class)?; self.cairo_lang_contract_class - .set(Rc::new(cairo_lang_class.clone())) + .set(Arc::new(cairo_lang_class.clone())) .expect("cairo-lang class is already set"); return blockifier_contract_class_from_cairo_lang_class(cairo_lang_class); } @@ -71,13 +71,13 @@ impl GenericCasmContractClass { } pub fn get_cairo_lang_contract_class(&self) -> Result<&CairoLangCasmClass, ContractClassError> { self.cairo_lang_contract_class - .get_or_try_init(|| self.build_cairo_lang_class().map(Rc::new)) + .get_or_try_init(|| self.build_cairo_lang_class().map(Arc::new)) .map(|boxed| boxed.as_ref()) } pub fn get_blockifier_contract_class(&self) -> Result<&BlockifierCasmClass, ContractClassError> { self.blockifier_contract_class - .get_or_try_init(|| self.build_blockifier_class().map(Rc::new)) + .get_or_try_init(|| self.build_blockifier_class().map(Arc::new)) .map(|boxed| boxed.as_ref()) } @@ -130,7 +130,7 @@ impl From for GenericCasmContractClass { fn from(cairo_lang_class: CairoLangCasmClass) -> Self { Self { blockifier_contract_class: Default::default(), - cairo_lang_contract_class: OnceCell::from(Rc::new(cairo_lang_class)), + cairo_lang_contract_class: OnceCell::from(Arc::new(cairo_lang_class)), serialized_class: Default::default(), class_hash: Default::default(), } @@ -140,7 +140,7 @@ impl From for GenericCasmContractClass { impl From for GenericCasmContractClass { fn from(blockifier_class: BlockifierCasmClass) -> Self { Self { - blockifier_contract_class: OnceCell::from(Rc::new(blockifier_class)), + blockifier_contract_class: OnceCell::from(Arc::new(blockifier_class)), cairo_lang_contract_class: Default::default(), serialized_class: Default::default(), class_hash: Default::default(), diff --git a/crates/starknet-os-types/src/deprecated_compiled_class.rs b/crates/starknet-os-types/src/deprecated_compiled_class.rs index 4c0a5c08..499e2262 100644 --- a/crates/starknet-os-types/src/deprecated_compiled_class.rs +++ b/crates/starknet-os-types/src/deprecated_compiled_class.rs @@ -1,5 +1,5 @@ use std::cell::OnceCell; -use std::rc::Rc; +use std::sync::Arc; use pathfinder_gateway_types::class_hash::compute_class_hash; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -20,9 +20,9 @@ pub type BlockifierDeprecatedClass = blockifier::execution::contract_class::Cont /// Fields are boxed in an RC for cheap cloning. #[derive(Debug, Clone)] pub struct GenericDeprecatedCompiledClass { - blockifier_contract_class: OnceCell>, - starknet_api_contract_class: OnceCell>, - starknet_core_contract_class: OnceCell>, + blockifier_contract_class: OnceCell>, + starknet_api_contract_class: OnceCell>, + starknet_core_contract_class: OnceCell>, serialized_class: OnceCell>, class_hash: OnceCell, } @@ -56,13 +56,13 @@ impl GenericDeprecatedCompiledClass { pub fn get_starknet_api_contract_class(&self) -> Result<&StarknetApiDeprecatedClass, ContractClassError> { self.starknet_api_contract_class - .get_or_try_init(|| self.build_starknet_api_class().map(Rc::new)) + .get_or_try_init(|| self.build_starknet_api_class().map(Arc::new)) .map(|boxed| boxed.as_ref()) } pub fn get_blockifier_contract_class(&self) -> Result<&BlockifierDeprecatedClass, ContractClassError> { self.blockifier_contract_class - .get_or_try_init(|| self.build_blockifier_class().map(Rc::new)) + .get_or_try_init(|| self.build_blockifier_class().map(Arc::new)) .map(|boxed| boxed.as_ref()) } @@ -128,7 +128,7 @@ impl From for GenericDeprecatedCompiledClass { fn from(starknet_api_class: StarknetApiDeprecatedClass) -> Self { Self { blockifier_contract_class: Default::default(), - starknet_api_contract_class: OnceCell::from(Rc::new(starknet_api_class)), + starknet_api_contract_class: OnceCell::from(Arc::new(starknet_api_class)), starknet_core_contract_class: Default::default(), serialized_class: Default::default(), class_hash: Default::default(), @@ -151,7 +151,7 @@ impl TryFrom for GenericDeprecatedCompile impl From for GenericDeprecatedCompiledClass { fn from(blockifier_class: BlockifierDeprecatedClass) -> Self { Self { - blockifier_contract_class: OnceCell::from(Rc::new(blockifier_class)), + blockifier_contract_class: OnceCell::from(Arc::new(blockifier_class)), starknet_api_contract_class: Default::default(), starknet_core_contract_class: Default::default(), serialized_class: Default::default(), @@ -165,7 +165,7 @@ impl From for GenericDeprecatedCompiledClass { Self { blockifier_contract_class: Default::default(), starknet_api_contract_class: Default::default(), - starknet_core_contract_class: OnceCell::from(Rc::new(starknet_core_class)), + starknet_core_contract_class: OnceCell::from(Arc::new(starknet_core_class)), serialized_class: Default::default(), class_hash: Default::default(), } diff --git a/crates/starknet-os-types/src/sierra_contract_class.rs b/crates/starknet-os-types/src/sierra_contract_class.rs index b8e9ec77..06a7ce99 100644 --- a/crates/starknet-os-types/src/sierra_contract_class.rs +++ b/crates/starknet-os-types/src/sierra_contract_class.rs @@ -1,5 +1,5 @@ use std::cell::OnceCell; -use std::rc::Rc; +use std::sync::Arc; use cairo_vm::Felt252; use pathfinder_gateway_types::class_hash::compute_class_hash; @@ -20,11 +20,11 @@ pub type StarknetCoreSierraContractClass = starknet_core::types::FlattenedSierra /// contract class types in Starknet and provides utility methods. /// Operations are implemented as lazily as possible, i.e. we only convert /// between different types if strictly necessary. -/// Fields are boxed in an RC for cheap cloning. +/// Fields are boxed in an Arc for cheap cloning. #[derive(Debug, Clone)] pub struct GenericSierraContractClass { - cairo_lang_contract_class: OnceCell>, - starknet_core_contract_class: OnceCell>, + cairo_lang_contract_class: OnceCell>, + starknet_core_contract_class: OnceCell>, serialized_class: OnceCell>, class_hash: OnceCell, } @@ -58,13 +58,13 @@ impl GenericSierraContractClass { } pub fn get_cairo_lang_contract_class(&self) -> Result<&CairoLangSierraContractClass, ContractClassError> { self.cairo_lang_contract_class - .get_or_try_init(|| self.build_cairo_lang_class().map(Rc::new)) + .get_or_try_init(|| self.build_cairo_lang_class().map(Arc::new)) .map(|boxed| boxed.as_ref()) } pub fn get_starknet_core_contract_class(&self) -> Result<&StarknetCoreSierraContractClass, ContractClassError> { self.starknet_core_contract_class - .get_or_try_init(|| self.build_starknet_core_class().map(Rc::new)) + .get_or_try_init(|| self.build_starknet_core_class().map(Arc::new)) .map(|boxed| boxed.as_ref()) } @@ -194,7 +194,7 @@ impl<'de> Deserialize<'de> for GenericSierraContractClass { impl From for GenericSierraContractClass { fn from(cairo_lang_class: CairoLangSierraContractClass) -> Self { Self { - cairo_lang_contract_class: OnceCell::from(Rc::new(cairo_lang_class)), + cairo_lang_contract_class: OnceCell::from(Arc::new(cairo_lang_class)), starknet_core_contract_class: Default::default(), serialized_class: Default::default(), class_hash: Default::default(), @@ -206,7 +206,7 @@ impl From for GenericSierraContractClass { fn from(starknet_core_class: StarknetCoreSierraContractClass) -> Self { Self { cairo_lang_contract_class: Default::default(), - starknet_core_contract_class: OnceCell::from(Rc::new(starknet_core_class)), + starknet_core_contract_class: OnceCell::from(Arc::new(starknet_core_class)), serialized_class: Default::default(), class_hash: Default::default(), }