Skip to content

Commit

Permalink
refactor(hydroflow_plus): split up location module and store location…
Browse files Browse the repository at this point in the history
…s directly in streams (#1523)
  • Loading branch information
shadaj authored Nov 5, 2024
1 parent 534fe97 commit d9634f2
Show file tree
Hide file tree
Showing 21 changed files with 1,168 additions and 1,245 deletions.
6 changes: 3 additions & 3 deletions hydroflow_plus/src/builder/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use stageleft::Quoted;
use super::built::build_inner;
use crate::deploy::{ExternalSpec, LocalDeploy, Node, RegisterPort};
use crate::ir::HfPlusLeaf;
use crate::location::{
ExternalBincodeSink, ExternalBincodeStream, ExternalBytesPort, ExternalProcess, Location,
LocationId,
use crate::location::external_process::{
ExternalBincodeSink, ExternalBincodeStream, ExternalBytesPort,
};
use crate::location::{ExternalProcess, Location, LocationId};
use crate::{Cluster, ClusterSpec, Deploy, HfCompiled, Process, ProcessSpec};

pub struct DeployFlow<'a, D: LocalDeploy<'a>> {
Expand Down
75 changes: 1 addition & 74 deletions hydroflow_plus/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ use std::collections::HashMap;
use std::marker::PhantomData;
use std::rc::Rc;

use internal::TokenStream;
use proc_macro2::Span;
use quote::quote;
use runtime_support::FreeVariable;
use stageleft::*;

use super::staging_util::get_this_crate;
use crate::ir::HfPlusLeaf;
use crate::location::{Cluster, ExternalProcess, Process};
use crate::{ClusterId, RuntimeContext};
use crate::RuntimeContext;

pub mod built;
pub mod deploy;
Expand All @@ -32,74 +27,6 @@ pub struct FlowStateInner {

pub type FlowState = Rc<RefCell<FlowStateInner>>;

pub struct ClusterIds<'a, C> {
pub(crate) id: usize,
pub(crate) _phantom: PhantomData<&'a mut &'a C>,
}

impl<C> Clone for ClusterIds<'_, C> {
fn clone(&self) -> Self {
*self
}
}

impl<C> Copy for ClusterIds<'_, C> {}

impl<'a, C> FreeVariable<&'a Vec<ClusterId<C>>> for ClusterIds<'a, C> {
fn to_tokens(self) -> (Option<TokenStream>, Option<TokenStream>)
where
Self: Sized,
{
let ident = syn::Ident::new(
&format!("__hydroflow_plus_cluster_ids_{}", self.id),
Span::call_site(),
);
let root = get_this_crate();
let c_type = quote_type::<C>();
(
None,
Some(
quote! { unsafe { ::std::mem::transmute::<_, &::std::vec::Vec<#root::ClusterId<#c_type>>>(#ident) } },
),
)
}
}

impl<'a, C> Quoted<'a, &'a Vec<ClusterId<C>>> for ClusterIds<'a, C> {}

pub(crate) struct ClusterSelfId<'a, C> {
pub(crate) id: usize,
pub(crate) _phantom: PhantomData<&'a mut &'a C>,
}

impl<C> Clone for ClusterSelfId<'_, C> {
fn clone(&self) -> Self {
*self
}
}

impl<C> Copy for ClusterSelfId<'_, C> {}

impl<C> FreeVariable<ClusterId<C>> for ClusterSelfId<'_, C> {
fn to_tokens(self) -> (Option<TokenStream>, Option<TokenStream>)
where
Self: Sized,
{
let ident = syn::Ident::new(
&format!("__hydroflow_plus_cluster_self_id_{}", self.id),
Span::call_site(),
);
let root = get_this_crate();
let c_type: syn::Type = quote_type::<C>();
(
None,
Some(quote! { #root::ClusterId::<#c_type>::from_raw(#ident) }),
)
}
}

impl<'a, C> Quoted<'a, ClusterId<C>> for ClusterSelfId<'a, C> {}

pub struct FlowBuilder<'a> {
flow_state: FlowState,
nodes: RefCell<Vec<usize>>,
Expand Down
12 changes: 3 additions & 9 deletions hydroflow_plus/src/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::marker::PhantomData;

use crate::builder::FlowState;
use crate::location::{Location, LocationId};
use crate::location::Location;

pub struct TickCycle {}

Expand All @@ -16,18 +15,13 @@ pub trait CycleComplete<'a, T> {
pub trait CycleCollection<'a, T>: CycleComplete<'a, T> {
type Location: Location<'a>;

fn create_source(ident: syn::Ident, flow_state: FlowState, l: LocationId) -> Self;
fn create_source(ident: syn::Ident, location: Self::Location) -> Self;
}

pub trait CycleCollectionWithInitial<'a, T>: CycleComplete<'a, T> {
type Location: Location<'a>;

fn create_source(
ident: syn::Ident,
flow_state: FlowState,
initial: Self,
l: LocationId,
) -> Self;
fn create_source(ident: syn::Ident, initial: Self, location: Self::Location) -> Self;
}

/// Represents a forward reference in the graph that will be fulfilled
Expand Down
4 changes: 2 additions & 2 deletions hydroflow_plus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ pub mod runtime_support {
}

pub mod stream;
pub use stream::{Bounded, Stream, Tick, Unbounded};
pub use stream::{Bounded, Stream, Unbounded};

pub mod singleton;
pub use singleton::{Optional, Singleton};

pub mod location;
pub use location::{Cluster, ClusterId, Location, Process};
pub use location::{Cluster, ClusterId, Location, Process, Tick};

pub mod deploy;
pub use deploy::{ClusterSpec, Deploy, ProcessSpec};
Expand Down
Loading

0 comments on commit d9634f2

Please sign in to comment.