Skip to content

Commit 21797fd

Browse files
committed
linera-execution: remove unnecessary Arc
1 parent 9d7d08c commit 21797fd

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ custom_debug_derive = "0.6.1"
7171
dashmap = "5.5.3"
7272
derive_more = "1.0.0"
7373
dirs = "5.0.1"
74+
dyn-clone = "1.0.17"
7475
ed25519-dalek = { version = "2.1.1", features = ["batch", "serde"] }
7576
either = "1.10.0"
7677
ethers = { version = "2.0.14", features = ["solc"] }

examples/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linera-chain/src/unit_tests/chain_tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#![allow(clippy::large_futures)]
55

6-
use std::{collections::BTreeMap, iter, sync::Arc};
6+
use std::{collections::BTreeMap, iter};
77

88
use assert_matches::assert_matches;
99
use linera_base::{
@@ -184,11 +184,11 @@ async fn test_application_permissions() {
184184
// Create a mock application.
185185
let app_description = make_app_description();
186186
let application_id = ApplicationId::from(&app_description);
187-
let application = Arc::new(MockApplication::default());
187+
let application = MockApplication::default();
188188
let extra = &chain.context().extra();
189189
extra
190190
.user_contracts()
191-
.insert(application_id, application.clone());
191+
.insert(application_id, application.clone().into());
192192
let contract_blob = Blob::new_contract_bytecode(Bytecode::new(b"contract".into()).compress());
193193
extra.add_blob(contract_blob);
194194
let service_blob = Blob::new_service_bytecode(Bytecode::new(b"service".into()).compress());

linera-execution/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ clap.workspace = true
4343
custom_debug_derive.workspace = true
4444
dashmap.workspace = true
4545
derive_more = { workspace = true, features = ["display"] }
46+
dyn-clone.workspace = true
4647
futures.workspace = true
4748
linera-base.workspace = true
4849
linera-views.workspace = true

linera-execution/src/lib.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,49 @@ const MAX_EVENT_KEY_LEN: usize = 64;
8181
const MAX_STREAM_NAME_LEN: usize = 64;
8282

8383
/// An implementation of [`UserContractModule`].
84-
pub type UserContractCode = Arc<dyn UserContractModule + Send + Sync + 'static>;
84+
pub type UserContractCode = Box<dyn UserContractModule + Send + Sync>;
8585

8686
/// An implementation of [`UserServiceModule`].
87-
pub type UserServiceCode = Arc<dyn UserServiceModule + Send + Sync + 'static>;
87+
pub type UserServiceCode = Box<dyn UserServiceModule + Send + Sync>;
8888

8989
/// An implementation of [`UserContract`].
90-
pub type UserContractInstance = Box<dyn UserContract + 'static>;
90+
pub type UserContractInstance = Box<dyn UserContract>;
9191

9292
/// An implementation of [`UserService`].
93-
pub type UserServiceInstance = Box<dyn UserService + 'static>;
93+
pub type UserServiceInstance = Box<dyn UserService>;
9494

9595
/// A factory trait to obtain a [`UserContract`] from a [`UserContractModule`]
96-
pub trait UserContractModule {
96+
pub trait UserContractModule: dyn_clone::DynClone {
9797
fn instantiate(
9898
&self,
9999
runtime: ContractSyncRuntimeHandle,
100100
) -> Result<UserContractInstance, ExecutionError>;
101101
}
102102

103+
impl<T: UserContractModule + Send + Sync + 'static> From<T> for UserContractCode {
104+
fn from(module: T) -> Self {
105+
Box::new(module)
106+
}
107+
}
108+
109+
dyn_clone::clone_trait_object!(UserContractModule);
110+
103111
/// A factory trait to obtain a [`UserService`] from a [`UserServiceModule`]
104-
pub trait UserServiceModule {
112+
pub trait UserServiceModule: dyn_clone::DynClone {
105113
fn instantiate(
106114
&self,
107115
runtime: ServiceSyncRuntimeHandle,
108116
) -> Result<UserServiceInstance, ExecutionError>;
109117
}
110118

119+
impl<T: UserServiceModule + Send + Sync + 'static> From<T> for UserServiceCode {
120+
fn from(module: T) -> Self {
121+
Box::new(module)
122+
}
123+
}
124+
125+
dyn_clone::clone_trait_object!(UserServiceModule);
126+
111127
/// A type for errors happening during execution.
112128
#[derive(Error, Debug)]
113129
pub enum ExecutionError {

linera-execution/src/test_utils/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ where
7575
for (id, mock_application) in &mock_applications {
7676
extra
7777
.user_contracts()
78-
.insert(*id, Arc::new(mock_application.clone()));
78+
.insert(*id, mock_application.clone().into());
7979
extra
8080
.user_services()
81-
.insert(*id, Arc::new(mock_application.clone()));
81+
.insert(*id, mock_application.clone().into());
8282
}
8383

8484
Ok(mock_applications.into_iter())

linera-storage/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ pub trait Storage: Sized {
301301
let contract_bytecode =
302302
linera_base::task::spawn_blocking(move || compressed_contract_bytecode.decompress())
303303
.await??;
304-
Ok(Arc::new(
305-
WasmContractModule::new(contract_bytecode, wasm_runtime).await?,
306-
))
304+
Ok(WasmContractModule::new(contract_bytecode, wasm_runtime)
305+
.await?
306+
.into())
307307
}
308308

309309
#[cfg(not(with_wasm_runtime))]
@@ -340,9 +340,9 @@ pub trait Storage: Sized {
340340
let service_bytecode =
341341
linera_base::task::spawn_blocking(move || compressed_service_bytecode.decompress())
342342
.await??;
343-
Ok(Arc::new(
344-
WasmServiceModule::new(service_bytecode, wasm_runtime).await?,
345-
))
343+
Ok(WasmServiceModule::new(service_bytecode, wasm_runtime)
344+
.await?
345+
.into())
346346
}
347347

348348
#[cfg(not(with_wasm_runtime))]

0 commit comments

Comments
 (0)