Skip to content

Commit 387a249

Browse files
reference: move GangRef from actor to reference (#421)
Summary: Pull Request resolved: #421 plain refactor: move `GangRef` from `hyperator::actor` to `hyperactor::reference` and re-export it as `hyperactor::GangRef`. Reviewed By: mariusae Differential Revision: D77738544 fbshipit-source-id: 7a0f16ef4b613a836125d528701f96c8c5ac9ceb
1 parent afbea3e commit 387a249

File tree

4 files changed

+58
-57
lines changed

4 files changed

+58
-57
lines changed

controller/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ use hyperactor::ActorId;
2424
use hyperactor::ActorRef;
2525
use hyperactor::Context;
2626
use hyperactor::GangId;
27+
use hyperactor::GangRef;
2728
use hyperactor::Handler;
2829
use hyperactor::Named;
2930
use hyperactor::actor::ActorHandle;
3031
use hyperactor::actor::ActorStatus;
31-
use hyperactor::actor::GangRef;
3232
use hyperactor::cap;
3333
use hyperactor::channel::ChannelAddr;
3434
use hyperactor::clock::Clock;

hyperactor/src/actor.rs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -623,62 +623,6 @@ pub trait Binds<A: Actor>: RemoteActor {
623623
/// is handled by a specific actor type.
624624
pub trait RemoteHandles<M: RemoteMessage>: RemoteActor {}
625625

626-
/// GangRefs are typed references to gangs.
627-
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Hash, Ord)]
628-
pub struct GangRef<A: RemoteActor> {
629-
gang_id: GangId,
630-
phantom: PhantomData<A>,
631-
}
632-
633-
impl<A: RemoteActor> GangRef<A> {
634-
/// Return an ActorRef corresponding with the provided rank in
635-
/// this gang. Does not check the validity of the rank, so the
636-
/// returned identifier is not guaranteed to refer to a valid rank.
637-
pub fn rank(&self, rank: Index) -> ActorRef<A> {
638-
let GangRef {
639-
gang_id: GangId(world_id, name),
640-
..
641-
} = self;
642-
ActorRef::attest(ActorId(ProcId(world_id.clone(), rank), name.clone(), 0))
643-
}
644-
645-
/// Return the gang ID.
646-
pub fn gang_id(&self) -> &GangId {
647-
&self.gang_id
648-
}
649-
}
650-
651-
impl<A: RemoteActor> Clone for GangRef<A> {
652-
fn clone(&self) -> Self {
653-
Self {
654-
gang_id: self.gang_id.clone(),
655-
phantom: PhantomData,
656-
}
657-
}
658-
}
659-
660-
// TODO: remove, replace with attest
661-
impl<A: RemoteActor> From<GangId> for GangRef<A> {
662-
fn from(gang_id: GangId) -> Self {
663-
Self {
664-
gang_id,
665-
phantom: PhantomData,
666-
}
667-
}
668-
}
669-
670-
impl<A: RemoteActor> From<GangRef<A>> for GangId {
671-
fn from(gang_ref: GangRef<A>) -> Self {
672-
gang_ref.gang_id
673-
}
674-
}
675-
676-
impl<'a, A: RemoteActor> From<&'a GangRef<A>> for &'a GangId {
677-
fn from(gang_ref: &'a GangRef<A>) -> Self {
678-
&gang_ref.gang_id
679-
}
680-
}
681-
682626
#[cfg(test)]
683627
mod tests {
684628
use std::sync::Mutex;

hyperactor/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ pub use proc::Instance;
156156
pub use reference::ActorId;
157157
pub use reference::ActorRef;
158158
pub use reference::GangId;
159+
pub use reference::GangRef;
159160
pub use reference::OncePortRef;
160161
pub use reference::PortId;
161162
pub use reference::PortRef;

hyperactor/src/reference.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,62 @@ fn chop<'a>(mut s: &'a str, delims: &'a [&'a str]) -> impl Iterator<Item = &'a s
11301130
})
11311131
}
11321132

1133+
/// GangRefs are typed references to gangs.
1134+
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Hash, Ord)]
1135+
pub struct GangRef<A: RemoteActor> {
1136+
gang_id: GangId,
1137+
phantom: PhantomData<A>,
1138+
}
1139+
1140+
impl<A: RemoteActor> GangRef<A> {
1141+
/// Return an ActorRef corresponding with the provided rank in
1142+
/// this gang. Does not check the validity of the rank, so the
1143+
/// returned identifier is not guaranteed to refer to a valid rank.
1144+
pub fn rank(&self, rank: Index) -> ActorRef<A> {
1145+
let GangRef {
1146+
gang_id: GangId(world_id, name),
1147+
..
1148+
} = self;
1149+
ActorRef::attest(ActorId(ProcId(world_id.clone(), rank), name.clone(), 0))
1150+
}
1151+
1152+
/// Return the gang ID.
1153+
pub fn gang_id(&self) -> &GangId {
1154+
&self.gang_id
1155+
}
1156+
}
1157+
1158+
impl<A: RemoteActor> Clone for GangRef<A> {
1159+
fn clone(&self) -> Self {
1160+
Self {
1161+
gang_id: self.gang_id.clone(),
1162+
phantom: PhantomData,
1163+
}
1164+
}
1165+
}
1166+
1167+
// TODO: remove, replace with attest
1168+
impl<A: RemoteActor> From<GangId> for GangRef<A> {
1169+
fn from(gang_id: GangId) -> Self {
1170+
Self {
1171+
gang_id,
1172+
phantom: PhantomData,
1173+
}
1174+
}
1175+
}
1176+
1177+
impl<A: RemoteActor> From<GangRef<A>> for GangId {
1178+
fn from(gang_ref: GangRef<A>) -> Self {
1179+
gang_ref.gang_id
1180+
}
1181+
}
1182+
1183+
impl<'a, A: RemoteActor> From<&'a GangRef<A>> for &'a GangId {
1184+
fn from(gang_ref: &'a GangRef<A>) -> Self {
1185+
&gang_ref.gang_id
1186+
}
1187+
}
1188+
11331189
#[cfg(test)]
11341190
mod tests {
11351191
use rand::seq::SliceRandom;

0 commit comments

Comments
 (0)