Skip to content

Commit

Permalink
refactor(hydroflow_plus)!: eliminate remaining Hf name prefixes (#1554
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shadaj authored Nov 8, 2024
1 parent baedf23 commit 0bd3a2d
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 55 deletions.
8 changes: 4 additions & 4 deletions hydroflow_plus/src/builder/built.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::marker::PhantomData;

use hydroflow_lang::graph::{eliminate_extra_unions_tees, HydroflowGraph};

use super::compiled::HfCompiled;
use super::compiled::CompiledFlow;
use super::deploy::{DeployFlow, DeployResult};
use crate::deploy::{ClusterSpec, Deploy, ExternalSpec, IntoProcessSpec, LocalDeploy};
use crate::ir::HfPlusLeaf;
Expand Down Expand Up @@ -62,10 +62,10 @@ pub(crate) fn build_inner(ir: &mut Vec<HfPlusLeaf>) -> BTreeMap<usize, Hydroflow
}

impl<'a> BuiltFlow<'a> {
pub fn compile_no_network<D: LocalDeploy<'a>>(mut self) -> HfCompiled<'a, D::GraphId> {
pub fn compile_no_network<D: LocalDeploy<'a>>(mut self) -> CompiledFlow<'a, D::GraphId> {
self.used = true;

HfCompiled {
CompiledFlow {
hydroflow_ir: build_inner(&mut self.ir),
extra_stmts: BTreeMap::new(),
_phantom: PhantomData,
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<'a> BuiltFlow<'a> {
self.into_deploy().with_cluster(cluster, spec)
}

pub fn compile<D: Deploy<'a> + 'a>(self, env: &D::CompileEnv) -> HfCompiled<'a, D::GraphId> {
pub fn compile<D: Deploy<'a> + 'a>(self, env: &D::CompileEnv) -> CompiledFlow<'a, D::GraphId> {
self.into_deploy::<D>().compile(env)
}

Expand Down
20 changes: 10 additions & 10 deletions hydroflow_plus/src/builder/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use quote::quote;
use stageleft::runtime_support::FreeVariable;
use stageleft::Quoted;

pub struct HfCompiled<'a, ID> {
pub struct CompiledFlow<'a, ID> {
pub(super) hydroflow_ir: BTreeMap<usize, HydroflowGraph>,
pub(super) extra_stmts: BTreeMap<usize, Vec<syn::Stmt>>,
pub(super) _phantom: PhantomData<&'a mut &'a ID>,
}

impl<ID> HfCompiled<'_, ID> {
impl<ID> CompiledFlow<'_, ID> {
pub fn hydroflow_ir(&self) -> &BTreeMap<usize, HydroflowGraph> {
&self.hydroflow_ir
}
Expand All @@ -24,8 +24,8 @@ impl<ID> HfCompiled<'_, ID> {
}
}

impl<'a> HfCompiled<'a, usize> {
pub fn with_dynamic_id(self, id: impl Quoted<'a, usize>) -> HfBuiltWithId<'a> {
impl<'a> CompiledFlow<'a, usize> {
pub fn with_dynamic_id(self, id: impl Quoted<'a, usize>) -> CompiledFlowWithId<'a> {
let hydroflow_crate = proc_macro_crate::crate_name("hydroflow_plus")
.expect("hydroflow_plus should be present in `Cargo.toml`");
let root = match hydroflow_crate {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'a> HfCompiled<'a, usize> {

let conditioned_tokens: TokenStream = conditioned_tokens.unwrap();
let id = id.splice_untyped();
HfBuiltWithId {
CompiledFlowWithId {
tokens: syn::parse_quote!({
let __given_id = #id;
#conditioned_tokens else {
Expand All @@ -80,9 +80,9 @@ impl<'a> HfCompiled<'a, usize> {
}
}

impl<'a> Quoted<'a, Hydroflow<'a>> for HfCompiled<'a, ()> {}
impl<'a> Quoted<'a, Hydroflow<'a>> for CompiledFlow<'a, ()> {}

impl<'a> FreeVariable<Hydroflow<'a>> for HfCompiled<'a, ()> {
impl<'a> FreeVariable<Hydroflow<'a>> for CompiledFlow<'a, ()> {
fn to_tokens(mut self) -> (Option<TokenStream>, Option<TokenStream>) {
let hydroflow_crate = proc_macro_crate::crate_name("hydroflow_plus")
.expect("hydroflow_plus should be present in `Cargo.toml`");
Expand All @@ -109,14 +109,14 @@ impl<'a> FreeVariable<Hydroflow<'a>> for HfCompiled<'a, ()> {
}
}

pub struct HfBuiltWithId<'a> {
pub struct CompiledFlowWithId<'a> {
tokens: TokenStream,
_phantom: PhantomData<&'a mut &'a ()>,
}

impl<'a> Quoted<'a, Hydroflow<'a>> for HfBuiltWithId<'a> {}
impl<'a> Quoted<'a, Hydroflow<'a>> for CompiledFlowWithId<'a> {}

impl<'a> FreeVariable<Hydroflow<'a>> for HfBuiltWithId<'a> {
impl<'a> FreeVariable<Hydroflow<'a>> for CompiledFlowWithId<'a> {
fn to_tokens(self) -> (Option<TokenStream>, Option<TokenStream>) {
(None, Some(self.tokens))
}
Expand Down
6 changes: 3 additions & 3 deletions hydroflow_plus/src/builder/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde::Serialize;
use stageleft::Quoted;

use super::built::build_inner;
use super::compiled::HfCompiled;
use super::compiled::CompiledFlow;
use crate::deploy::{ExternalSpec, IntoProcessSpec, LocalDeploy, Node, RegisterPort};
use crate::ir::HfPlusLeaf;
use crate::location::external_process::{
Expand Down Expand Up @@ -72,7 +72,7 @@ impl<'a, D: LocalDeploy<'a>> DeployFlow<'a, D> {
}

impl<'a, D: Deploy<'a>> DeployFlow<'a, D> {
pub fn compile(mut self, env: &D::CompileEnv) -> HfCompiled<'a, D::GraphId> {
pub fn compile(mut self, env: &D::CompileEnv) -> CompiledFlow<'a, D::GraphId> {
self.used = true;

let mut seen_tees: HashMap<_, _> = HashMap::new();
Expand All @@ -91,7 +91,7 @@ impl<'a, D: Deploy<'a>> DeployFlow<'a, D> {

let extra_stmts = self.extra_stmts(env);

HfCompiled {
CompiledFlow {
hydroflow_ir: build_inner(&mut flow_state_networked),
extra_stmts,
_phantom: PhantomData,
Expand Down
12 changes: 6 additions & 6 deletions hydroflow_plus/src/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::marker::PhantomData;

use crate::location::Location;

pub enum ForwardRef {}
pub enum TickCycle {}
pub enum ForwardRefMarker {}
pub enum TickCycleMarker {}

pub trait DeferTick {
fn defer_tick(self) -> Self;
Expand All @@ -29,24 +29,24 @@ pub trait CycleCollectionWithInitial<'a, T>: CycleComplete<'a, T> {
/// by a stream that is not yet known.
///
/// See [`crate::FlowBuilder`] for an explainer on the type parameters.
pub struct HfForwardRef<'a, S: CycleComplete<'a, ForwardRef>> {
pub struct ForwardRef<'a, S: CycleComplete<'a, ForwardRefMarker>> {
pub(crate) ident: syn::Ident,
pub(crate) _phantom: PhantomData<(&'a mut &'a (), S)>,
}

impl<'a, S: CycleComplete<'a, ForwardRef>> HfForwardRef<'a, S> {
impl<'a, S: CycleComplete<'a, ForwardRefMarker>> ForwardRef<'a, S> {
pub fn complete(self, stream: S) {
let ident = self.ident;
S::complete(stream, ident)
}
}

pub struct HfCycle<'a, S: CycleComplete<'a, TickCycle> + DeferTick> {
pub struct TickCycle<'a, S: CycleComplete<'a, TickCycleMarker> + DeferTick> {
pub(crate) ident: syn::Ident,
pub(crate) _phantom: PhantomData<(&'a mut &'a (), S)>,
}

impl<'a, S: CycleComplete<'a, TickCycle> + DeferTick> HfCycle<'a, S> {
impl<'a, S: CycleComplete<'a, TickCycleMarker> + DeferTick> TickCycle<'a, S> {
pub fn complete_next_tick(self, stream: S) {
let ident = self.ident;
S::complete(stream.defer_tick(), ident)
Expand Down
8 changes: 4 additions & 4 deletions hydroflow_plus/src/location/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use proc_macro2::Span;
use stageleft::{q, Quoted};

use super::builder::FlowState;
use crate::cycle::{CycleCollection, ForwardRef, HfForwardRef};
use crate::cycle::{CycleCollection, ForwardRef, ForwardRefMarker};
use crate::ir::{HfPlusNode, HfPlusSource};
use crate::{Singleton, Stream, Unbounded};

Expand Down Expand Up @@ -178,9 +178,9 @@ pub trait Location<'a>: Clone {
)))
}

fn forward_ref<S: CycleCollection<'a, ForwardRef, Location = Self>>(
fn forward_ref<S: CycleCollection<'a, ForwardRefMarker, Location = Self>>(
&self,
) -> (HfForwardRef<'a, S>, S)
) -> (ForwardRef<'a, S>, S)
where
Self: NoTick,
{
Expand All @@ -203,7 +203,7 @@ pub trait Location<'a>: Clone {
let ident = syn::Ident::new(&format!("cycle_{}", next_id), Span::call_site());

(
HfForwardRef {
ForwardRef {
ident: ident.clone(),
_phantom: PhantomData,
},
Expand Down
22 changes: 11 additions & 11 deletions hydroflow_plus/src/location/tick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use stageleft::{q, Quoted};
use super::{Cluster, Location, LocationId, Process};
use crate::builder::FlowState;
use crate::cycle::{
CycleCollection, CycleCollectionWithInitial, DeferTick, ForwardRef, HfCycle, HfForwardRef,
TickCycle,
CycleCollection, CycleCollectionWithInitial, DeferTick, ForwardRef, ForwardRefMarker,
TickCycle, TickCycleMarker,
};
use crate::ir::{HfPlusNode, HfPlusSource};
use crate::{Bounded, Optional, Singleton, Stream};
Expand Down Expand Up @@ -82,9 +82,9 @@ impl<'a, L: Location<'a>> Tick<L> {
)
}

pub fn forward_ref<S: CycleCollection<'a, ForwardRef, Location = Self>>(
pub fn forward_ref<S: CycleCollection<'a, ForwardRefMarker, Location = Self>>(
&self,
) -> (HfForwardRef<'a, S>, S)
) -> (ForwardRef<'a, S>, S)
where
L: NoTick,
{
Expand All @@ -107,17 +107,17 @@ impl<'a, L: Location<'a>> Tick<L> {
let ident = syn::Ident::new(&format!("cycle_{}", next_id), Span::call_site());

(
HfForwardRef {
ForwardRef {
ident: ident.clone(),
_phantom: PhantomData,
},
S::create_source(ident, self.clone()),
)
}

pub fn cycle<S: CycleCollection<'a, TickCycle, Location = Self> + DeferTick>(
pub fn cycle<S: CycleCollection<'a, TickCycleMarker, Location = Self> + DeferTick>(
&self,
) -> (HfCycle<'a, S>, S)
) -> (TickCycle<'a, S>, S)
where
L: NoTick,
{
Expand All @@ -140,7 +140,7 @@ impl<'a, L: Location<'a>> Tick<L> {
let ident = syn::Ident::new(&format!("cycle_{}", next_id), Span::call_site());

(
HfCycle {
TickCycle {
ident: ident.clone(),
_phantom: PhantomData,
},
Expand All @@ -149,11 +149,11 @@ impl<'a, L: Location<'a>> Tick<L> {
}

pub fn cycle_with_initial<
S: CycleCollectionWithInitial<'a, TickCycle, Location = Self> + DeferTick,
S: CycleCollectionWithInitial<'a, TickCycleMarker, Location = Self> + DeferTick,
>(
&self,
initial: S,
) -> (HfCycle<'a, S>, S)
) -> (TickCycle<'a, S>, S)
where
L: NoTick,
{
Expand All @@ -176,7 +176,7 @@ impl<'a, L: Location<'a>> Tick<L> {
let ident = syn::Ident::new(&format!("cycle_{}", next_id), Span::call_site());

(
HfCycle {
TickCycle {
ident: ident.clone(),
_phantom: PhantomData,
},
Expand Down
20 changes: 13 additions & 7 deletions hydroflow_plus/src/optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use stageleft::{q, IntoQuotedMut, Quoted};
use syn::parse_quote;

use crate::builder::FLOW_USED_MESSAGE;
use crate::cycle::{CycleCollection, CycleComplete, DeferTick, ForwardRef, TickCycle};
use crate::cycle::{CycleCollection, CycleComplete, DeferTick, ForwardRefMarker, TickCycleMarker};
use crate::ir::{HfPlusLeaf, HfPlusNode, HfPlusSource, TeeNode};
use crate::location::{check_matching_location, LocationId, NoTick};
use crate::{Bounded, Location, Singleton, Stream, Tick, Unbounded};
Expand Down Expand Up @@ -43,7 +43,9 @@ impl<'a, T, L: Location<'a>> DeferTick for Optional<T, Tick<L>, Bounded> {
}
}

impl<'a, T, L: Location<'a>> CycleCollection<'a, TickCycle> for Optional<T, Tick<L>, Bounded> {
impl<'a, T, L: Location<'a>> CycleCollection<'a, TickCycleMarker>
for Optional<T, Tick<L>, Bounded>
{
type Location = Tick<L>;

fn create_source(ident: syn::Ident, location: Tick<L>) -> Self {
Expand All @@ -58,7 +60,7 @@ impl<'a, T, L: Location<'a>> CycleCollection<'a, TickCycle> for Optional<T, Tick
}
}

impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycle> for Optional<T, Tick<L>, Bounded> {
impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycleMarker> for Optional<T, Tick<L>, Bounded> {
fn complete(self, ident: syn::Ident) {
self.location
.flow_state()
Expand All @@ -74,7 +76,9 @@ impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycle> for Optional<T, Tick<L
}
}

impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRef> for Optional<T, Tick<L>, Bounded> {
impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRefMarker>
for Optional<T, Tick<L>, Bounded>
{
type Location = Tick<L>;

fn create_source(ident: syn::Ident, location: Tick<L>) -> Self {
Expand All @@ -89,7 +93,7 @@ impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRef> for Optional<T, Tic
}
}

impl<'a, T, L: Location<'a>> CycleComplete<'a, ForwardRef> for Optional<T, Tick<L>, Bounded> {
impl<'a, T, L: Location<'a>> CycleComplete<'a, ForwardRefMarker> for Optional<T, Tick<L>, Bounded> {
fn complete(self, ident: syn::Ident) {
self.location
.flow_state()
Expand All @@ -105,7 +109,9 @@ impl<'a, T, L: Location<'a>> CycleComplete<'a, ForwardRef> for Optional<T, Tick<
}
}

impl<'a, T, L: Location<'a> + NoTick, B> CycleCollection<'a, ForwardRef> for Optional<T, L, B> {
impl<'a, T, L: Location<'a> + NoTick, B> CycleCollection<'a, ForwardRefMarker>
for Optional<T, L, B>
{
type Location = L;

fn create_source(ident: syn::Ident, location: L) -> Self {
Expand All @@ -120,7 +126,7 @@ impl<'a, T, L: Location<'a> + NoTick, B> CycleCollection<'a, ForwardRef> for Opt
}
}

impl<'a, T, L: Location<'a> + NoTick, B> CycleComplete<'a, ForwardRef> for Optional<T, L, B> {
impl<'a, T, L: Location<'a> + NoTick, B> CycleComplete<'a, ForwardRefMarker> for Optional<T, L, B> {
fn complete(self, ident: syn::Ident) {
self.location
.flow_state()
Expand Down
15 changes: 10 additions & 5 deletions hydroflow_plus/src/singleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use stageleft::{q, IntoQuotedMut, Quoted};

use crate::builder::FLOW_USED_MESSAGE;
use crate::cycle::{
CycleCollection, CycleCollectionWithInitial, CycleComplete, DeferTick, ForwardRef, TickCycle,
CycleCollection, CycleCollectionWithInitial, CycleComplete, DeferTick, ForwardRefMarker,
TickCycleMarker,
};
use crate::ir::{HfPlusLeaf, HfPlusNode, TeeNode};
use crate::location::{check_matching_location, Location, LocationId, NoTick, Tick};
Expand Down Expand Up @@ -47,7 +48,7 @@ impl<'a, T, L: Location<'a>> DeferTick for Singleton<T, Tick<L>, Bounded> {
}
}

impl<'a, T, L: Location<'a>> CycleCollectionWithInitial<'a, TickCycle>
impl<'a, T, L: Location<'a>> CycleCollectionWithInitial<'a, TickCycleMarker>
for Singleton<T, Tick<L>, Bounded>
{
type Location = Tick<L>;
Expand All @@ -67,7 +68,7 @@ impl<'a, T, L: Location<'a>> CycleCollectionWithInitial<'a, TickCycle>
}
}

impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycle> for Singleton<T, Tick<L>, Bounded> {
impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycleMarker> for Singleton<T, Tick<L>, Bounded> {
fn complete(self, ident: syn::Ident) {
self.location
.flow_state()
Expand All @@ -83,7 +84,9 @@ impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycle> for Singleton<T, Tick<
}
}

impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRef> for Singleton<T, Tick<L>, Bounded> {
impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRefMarker>
for Singleton<T, Tick<L>, Bounded>
{
type Location = Tick<L>;

fn create_source(ident: syn::Ident, location: Tick<L>) -> Self {
Expand All @@ -98,7 +101,9 @@ impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRef> for Singleton<T, Ti
}
}

impl<'a, T, L: Location<'a>> CycleComplete<'a, ForwardRef> for Singleton<T, Tick<L>, Bounded> {
impl<'a, T, L: Location<'a>> CycleComplete<'a, ForwardRefMarker>
for Singleton<T, Tick<L>, Bounded>
{
fn complete(self, ident: syn::Ident) {
self.location
.flow_state()
Expand Down
Loading

0 comments on commit 0bd3a2d

Please sign in to comment.