Skip to content

Commit e15c632

Browse files
pzhan9meta-codesync[bot]
authored andcommitted
Put ActorError's fields in Box (#1469)
Summary: Pull Request resolved: #1469 As title. Same motivation as D82982701. Reviewed By: pablorfb-meta Differential Revision: D84162324 fbshipit-source-id: ca3d85cdb5acc5936019176bb458f93c1f1af910
1 parent f22982d commit e15c632

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

hyperactor/src/actor.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ where
310310
/// with the ID of the actor being served.
311311
#[derive(Debug)]
312312
pub struct ActorError {
313-
pub(crate) actor_id: ActorId,
314-
pub(crate) kind: ActorErrorKind,
313+
pub(crate) actor_id: Box<ActorId>,
314+
pub(crate) kind: Box<ActorErrorKind>,
315315
}
316316

317317
/// The kinds of actor serving errors.
@@ -362,14 +362,17 @@ pub enum ActorErrorKind {
362362

363363
impl ActorError {
364364
/// Create a new actor server error with the provided id and kind.
365-
pub(crate) fn new(actor_id: ActorId, kind: ActorErrorKind) -> Self {
366-
Self { actor_id, kind }
365+
pub(crate) fn new(actor_id: &ActorId, kind: ActorErrorKind) -> Self {
366+
Self {
367+
actor_id: Box::new(actor_id.clone()),
368+
kind: Box::new(kind),
369+
}
367370
}
368371

369372
/// Passthrough this error.
370373
fn passthrough(&self) -> Self {
371374
ActorError::new(
372-
self.actor_id.clone(),
375+
&self.actor_id,
373376
ActorErrorKind::Passthrough(anyhow::anyhow!("{}", self.kind)),
374377
)
375378
}
@@ -390,25 +393,28 @@ impl std::error::Error for ActorError {
390393

391394
impl From<MailboxError> for ActorError {
392395
fn from(inner: MailboxError) -> Self {
393-
Self::new(inner.actor_id().clone(), ActorErrorKind::from(inner))
396+
Self {
397+
actor_id: Box::new(inner.actor_id().clone()),
398+
kind: Box::new(ActorErrorKind::from(inner)),
399+
}
394400
}
395401
}
396402

397403
impl From<MailboxSenderError> for ActorError {
398404
fn from(inner: MailboxSenderError) -> Self {
399-
Self::new(
400-
inner.location().actor_id().clone(),
401-
ActorErrorKind::from(inner),
402-
)
405+
Self {
406+
actor_id: Box::new(inner.location().actor_id().clone()),
407+
kind: Box::new(ActorErrorKind::from(inner)),
408+
}
403409
}
404410
}
405411

406412
impl From<ActorSupervisionEvent> for ActorError {
407413
fn from(inner: ActorSupervisionEvent) -> Self {
408-
Self::new(
409-
inner.actor_id.clone(),
410-
ActorErrorKind::UnhandledSupervisionEvent(inner),
411-
)
414+
Self {
415+
actor_id: Box::new(inner.actor_id.clone()),
416+
kind: Box::new(ActorErrorKind::UnhandledSupervisionEvent(inner)),
417+
}
412418
}
413419
}
414420

@@ -609,7 +615,6 @@ impl<A: Actor> ActorHandle<A> {
609615
}
610616

611617
/// Signal the actor to drain its current messages and then stop.
612-
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `ActorError`.
613618
pub fn drain_and_stop(&self) -> Result<(), ActorError> {
614619
tracing::info!("ActorHandle::drain_and_stop called: {}", self.actor_id());
615620
self.cell.signal(Signal::DrainAndStop)

hyperactor/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#![feature(anonymous_lifetime_in_impl_trait)]
5858
#![feature(assert_matches)]
5959
#![feature(associated_type_defaults)]
60+
#![feature(box_patterns)]
6061
#![feature(btree_cursors)]
6162
#![feature(const_type_id)]
6263
#![feature(error_reporter)]

hyperactor/src/proc.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,6 @@ impl<A: Actor> Instance<A> {
10061006
}
10071007

10081008
/// Signal the actor to stop.
1009-
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `ActorError`.
10101009
pub fn stop(&self) -> Result<(), ActorError> {
10111010
tracing::info!("Instance::stop called, {}", self.cell.actor_id());
10121011
self.cell.signal(Signal::DrainAndStop)
@@ -1033,7 +1032,6 @@ impl<A: Actor> Instance<A> {
10331032
}
10341033

10351034
/// Send a message to the actor itself with a delay usually to trigger some event.
1036-
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `ActorError`.
10371035
pub fn self_message_with_delay<M>(&self, message: M, delay: Duration) -> Result<(), ActorError>
10381036
where
10391037
M: Message,
@@ -1096,7 +1094,7 @@ impl<A: Actor> Instance<A> {
10961094
let (actor_status, event) = match result {
10971095
Ok(_) => (ActorStatus::Stopped, None),
10981096
Err(ActorError {
1099-
kind: ActorErrorKind::UnhandledSupervisionEvent(event),
1097+
kind: box ActorErrorKind::UnhandledSupervisionEvent(event),
11001098
..
11011099
}) => (event.actor_status.clone(), Some(event)),
11021100
Err(err) => (
@@ -1167,7 +1165,7 @@ impl<A: Actor> Instance<A> {
11671165
let backtrace = panic_handler::take_panic_backtrace()
11681166
.unwrap_or_else(|e| format!("Cannot take backtrace due to: {:?}", e));
11691167
Err(ActorError::new(
1170-
self.self_id().clone(),
1168+
self.self_id(),
11711169
ActorErrorKind::Panic(anyhow::anyhow!("{}\n{}", err_msg, backtrace)),
11721170
))
11731171
}
@@ -1221,7 +1219,7 @@ impl<A: Actor> Instance<A> {
12211219
actor
12221220
.init(self)
12231221
.await
1224-
.map_err(|err| ActorError::new(self.self_id().clone(), ActorErrorKind::Init(err)))?;
1222+
.map_err(|err| ActorError::new(self.self_id(), ActorErrorKind::Init(err)))?;
12251223
let need_drain;
12261224
'messages: loop {
12271225
self.change_status(ActorStatus::Idle);
@@ -1237,7 +1235,7 @@ impl<A: Actor> Instance<A> {
12371235
for supervision_event in supervision_event_receiver.drain() {
12381236
self.handle_supervision_event(actor, supervision_event).await?;
12391237
}
1240-
return Err(ActorError::new(self.self_id().clone(), ActorErrorKind::Processing(err)));
1238+
return Err(ActorError::new(self.self_id(), ActorErrorKind::Processing(err)));
12411239
}
12421240
}
12431241
signal = signal_receiver.recv() => {
@@ -1269,7 +1267,7 @@ impl<A: Actor> Instance<A> {
12691267
while let Ok(work) = work_rx.try_recv() {
12701268
if let Err(err) = work.handle(actor, self).await {
12711269
return Err(ActorError::new(
1272-
self.self_id().clone(),
1270+
self.self_id(),
12731271
ActorErrorKind::Processing(err),
12741272
));
12751273
}
@@ -1664,7 +1662,6 @@ impl InstanceCell {
16641662
}
16651663

16661664
/// Send a signal to the actor.
1667-
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `ActorError`.
16681665
pub fn signal(&self, signal: Signal) -> Result<(), ActorError> {
16691666
if let Some((signal_port, _)) = &self.inner.actor_loop {
16701667
signal_port.send(signal).map_err(ActorError::from)

hyperactor_multiprocess/src/system_actor.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ impl World {
570570
world_id.name().starts_with(SHADOW_PREFIX)
571571
}
572572

573-
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `CastError`.
574573
fn get_port_ref_from_host(
575574
&self,
576575
host_id: &HostId,
@@ -584,7 +583,6 @@ impl World {
584583
}
585584

586585
/// Adds procs to the world.
587-
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `SystemActorError`.
588586
fn add_proc(
589587
&mut self,
590588
proc_id: ProcId,
@@ -654,7 +652,6 @@ impl World {
654652
Ok(())
655653
}
656654

657-
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `SystemActorError`.
658655
fn get_hosts_to_procs(&mut self) -> Result<HashMap<HostId, Vec<ProcId>>, SystemActorError> {
659656
// A map from host ID to scheduled proc IDs on this host.
660657
let mut host_proc_map: HashMap<HostId, Vec<ProcId>> = HashMap::new();

0 commit comments

Comments
 (0)