From 0bd3a2d2230cbef24210f71a3ea83d82d1cc7244 Mon Sep 17 00:00:00 2001 From: Shadaj Laddad Date: Fri, 8 Nov 2024 09:32:50 -0800 Subject: [PATCH] refactor(hydroflow_plus)!: eliminate remaining `Hf` name prefixes (#1554) --- hydroflow_plus/src/builder/built.rs | 8 ++++---- hydroflow_plus/src/builder/compiled.rs | 20 ++++++++++---------- hydroflow_plus/src/builder/deploy.rs | 6 +++--- hydroflow_plus/src/cycle.rs | 12 ++++++------ hydroflow_plus/src/location/mod.rs | 8 ++++---- hydroflow_plus/src/location/tick.rs | 22 +++++++++++----------- hydroflow_plus/src/optional.rs | 20 +++++++++++++------- hydroflow_plus/src/singleton.rs | 15 ++++++++++----- hydroflow_plus/src/stream.rs | 10 +++++----- 9 files changed, 66 insertions(+), 55 deletions(-) diff --git a/hydroflow_plus/src/builder/built.rs b/hydroflow_plus/src/builder/built.rs index 9beb37b6da4a..997c5388d373 100644 --- a/hydroflow_plus/src/builder/built.rs +++ b/hydroflow_plus/src/builder/built.rs @@ -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; @@ -62,10 +62,10 @@ pub(crate) fn build_inner(ir: &mut Vec) -> BTreeMap BuiltFlow<'a> { - pub fn compile_no_network>(mut self) -> HfCompiled<'a, D::GraphId> { + pub fn compile_no_network>(mut self) -> CompiledFlow<'a, D::GraphId> { self.used = true; - HfCompiled { + CompiledFlow { hydroflow_ir: build_inner(&mut self.ir), extra_stmts: BTreeMap::new(), _phantom: PhantomData, @@ -130,7 +130,7 @@ impl<'a> BuiltFlow<'a> { self.into_deploy().with_cluster(cluster, spec) } - pub fn compile + 'a>(self, env: &D::CompileEnv) -> HfCompiled<'a, D::GraphId> { + pub fn compile + 'a>(self, env: &D::CompileEnv) -> CompiledFlow<'a, D::GraphId> { self.into_deploy::().compile(env) } diff --git a/hydroflow_plus/src/builder/compiled.rs b/hydroflow_plus/src/builder/compiled.rs index 0d16884e0166..ce92789763a3 100644 --- a/hydroflow_plus/src/builder/compiled.rs +++ b/hydroflow_plus/src/builder/compiled.rs @@ -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, pub(super) extra_stmts: BTreeMap>, pub(super) _phantom: PhantomData<&'a mut &'a ID>, } -impl HfCompiled<'_, ID> { +impl CompiledFlow<'_, ID> { pub fn hydroflow_ir(&self) -> &BTreeMap { &self.hydroflow_ir } @@ -24,8 +24,8 @@ impl 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 { @@ -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 { @@ -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> for HfCompiled<'a, ()> { +impl<'a> FreeVariable> for CompiledFlow<'a, ()> { fn to_tokens(mut self) -> (Option, Option) { let hydroflow_crate = proc_macro_crate::crate_name("hydroflow_plus") .expect("hydroflow_plus should be present in `Cargo.toml`"); @@ -109,14 +109,14 @@ impl<'a> FreeVariable> 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> for HfBuiltWithId<'a> { +impl<'a> FreeVariable> for CompiledFlowWithId<'a> { fn to_tokens(self) -> (Option, Option) { (None, Some(self.tokens)) } diff --git a/hydroflow_plus/src/builder/deploy.rs b/hydroflow_plus/src/builder/deploy.rs index 8cdaf5b9e1b9..07353dd0fd77 100644 --- a/hydroflow_plus/src/builder/deploy.rs +++ b/hydroflow_plus/src/builder/deploy.rs @@ -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::{ @@ -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(); @@ -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, diff --git a/hydroflow_plus/src/cycle.rs b/hydroflow_plus/src/cycle.rs index 5f6bb98dd55a..3a7709d56a77 100644 --- a/hydroflow_plus/src/cycle.rs +++ b/hydroflow_plus/src/cycle.rs @@ -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; @@ -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) diff --git a/hydroflow_plus/src/location/mod.rs b/hydroflow_plus/src/location/mod.rs index 8908f5827647..061dfd1016cb 100644 --- a/hydroflow_plus/src/location/mod.rs +++ b/hydroflow_plus/src/location/mod.rs @@ -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}; @@ -178,9 +178,9 @@ pub trait Location<'a>: Clone { ))) } - fn forward_ref>( + fn forward_ref>( &self, - ) -> (HfForwardRef<'a, S>, S) + ) -> (ForwardRef<'a, S>, S) where Self: NoTick, { @@ -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, }, diff --git a/hydroflow_plus/src/location/tick.rs b/hydroflow_plus/src/location/tick.rs index d974eb14acca..3e9e8074baf3 100644 --- a/hydroflow_plus/src/location/tick.rs +++ b/hydroflow_plus/src/location/tick.rs @@ -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}; @@ -82,9 +82,9 @@ impl<'a, L: Location<'a>> Tick { ) } - pub fn forward_ref>( + pub fn forward_ref>( &self, - ) -> (HfForwardRef<'a, S>, S) + ) -> (ForwardRef<'a, S>, S) where L: NoTick, { @@ -107,7 +107,7 @@ impl<'a, L: Location<'a>> Tick { let ident = syn::Ident::new(&format!("cycle_{}", next_id), Span::call_site()); ( - HfForwardRef { + ForwardRef { ident: ident.clone(), _phantom: PhantomData, }, @@ -115,9 +115,9 @@ impl<'a, L: Location<'a>> Tick { ) } - pub fn cycle + DeferTick>( + pub fn cycle + DeferTick>( &self, - ) -> (HfCycle<'a, S>, S) + ) -> (TickCycle<'a, S>, S) where L: NoTick, { @@ -140,7 +140,7 @@ impl<'a, L: Location<'a>> Tick { let ident = syn::Ident::new(&format!("cycle_{}", next_id), Span::call_site()); ( - HfCycle { + TickCycle { ident: ident.clone(), _phantom: PhantomData, }, @@ -149,11 +149,11 @@ impl<'a, L: Location<'a>> Tick { } 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, { @@ -176,7 +176,7 @@ impl<'a, L: Location<'a>> Tick { let ident = syn::Ident::new(&format!("cycle_{}", next_id), Span::call_site()); ( - HfCycle { + TickCycle { ident: ident.clone(), _phantom: PhantomData, }, diff --git a/hydroflow_plus/src/optional.rs b/hydroflow_plus/src/optional.rs index 1494f8a667f7..e5530352bd02 100644 --- a/hydroflow_plus/src/optional.rs +++ b/hydroflow_plus/src/optional.rs @@ -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}; @@ -43,7 +43,9 @@ impl<'a, T, L: Location<'a>> DeferTick for Optional, Bounded> { } } -impl<'a, T, L: Location<'a>> CycleCollection<'a, TickCycle> for Optional, Bounded> { +impl<'a, T, L: Location<'a>> CycleCollection<'a, TickCycleMarker> + for Optional, Bounded> +{ type Location = Tick; fn create_source(ident: syn::Ident, location: Tick) -> Self { @@ -58,7 +60,7 @@ impl<'a, T, L: Location<'a>> CycleCollection<'a, TickCycle> for Optional> CycleComplete<'a, TickCycle> for Optional, Bounded> { +impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycleMarker> for Optional, Bounded> { fn complete(self, ident: syn::Ident) { self.location .flow_state() @@ -74,7 +76,9 @@ impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycle> for Optional> CycleCollection<'a, ForwardRef> for Optional, Bounded> { +impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRefMarker> + for Optional, Bounded> +{ type Location = Tick; fn create_source(ident: syn::Ident, location: Tick) -> Self { @@ -89,7 +93,7 @@ impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRef> for Optional> CycleComplete<'a, ForwardRef> for Optional, Bounded> { +impl<'a, T, L: Location<'a>> CycleComplete<'a, ForwardRefMarker> for Optional, Bounded> { fn complete(self, ident: syn::Ident) { self.location .flow_state() @@ -105,7 +109,9 @@ impl<'a, T, L: Location<'a>> CycleComplete<'a, ForwardRef> for Optional + NoTick, B> CycleCollection<'a, ForwardRef> for Optional { +impl<'a, T, L: Location<'a> + NoTick, B> CycleCollection<'a, ForwardRefMarker> + for Optional +{ type Location = L; fn create_source(ident: syn::Ident, location: L) -> Self { @@ -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 { +impl<'a, T, L: Location<'a> + NoTick, B> CycleComplete<'a, ForwardRefMarker> for Optional { fn complete(self, ident: syn::Ident) { self.location .flow_state() diff --git a/hydroflow_plus/src/singleton.rs b/hydroflow_plus/src/singleton.rs index 394aae8c0fa2..b068d1d9bd1f 100644 --- a/hydroflow_plus/src/singleton.rs +++ b/hydroflow_plus/src/singleton.rs @@ -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}; @@ -47,7 +48,7 @@ impl<'a, T, L: Location<'a>> DeferTick for Singleton, Bounded> { } } -impl<'a, T, L: Location<'a>> CycleCollectionWithInitial<'a, TickCycle> +impl<'a, T, L: Location<'a>> CycleCollectionWithInitial<'a, TickCycleMarker> for Singleton, Bounded> { type Location = Tick; @@ -67,7 +68,7 @@ impl<'a, T, L: Location<'a>> CycleCollectionWithInitial<'a, TickCycle> } } -impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycle> for Singleton, Bounded> { +impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycleMarker> for Singleton, Bounded> { fn complete(self, ident: syn::Ident) { self.location .flow_state() @@ -83,7 +84,9 @@ impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycle> for Singleton> CycleCollection<'a, ForwardRef> for Singleton, Bounded> { +impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRefMarker> + for Singleton, Bounded> +{ type Location = Tick; fn create_source(ident: syn::Ident, location: Tick) -> Self { @@ -98,7 +101,9 @@ impl<'a, T, L: Location<'a>> CycleCollection<'a, ForwardRef> for Singleton> CycleComplete<'a, ForwardRef> for Singleton, Bounded> { +impl<'a, T, L: Location<'a>> CycleComplete<'a, ForwardRefMarker> + for Singleton, Bounded> +{ fn complete(self, ident: syn::Ident) { self.location .flow_state() diff --git a/hydroflow_plus/src/stream.rs b/hydroflow_plus/src/stream.rs index 81c8f1ec0573..aa1193e2e859 100644 --- a/hydroflow_plus/src/stream.rs +++ b/hydroflow_plus/src/stream.rs @@ -13,7 +13,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::{DebugInstantiate, HfPlusLeaf, HfPlusNode, TeeNode}; use crate::location::cluster::ClusterSelfId; use crate::location::external_process::{ExternalBincodeStream, ExternalBytesPort}; @@ -57,7 +57,7 @@ impl<'a, T, L: Location<'a>> DeferTick for Stream, Bounded> { } } -impl<'a, T, L: Location<'a>> CycleCollection<'a, TickCycle> for Stream, Bounded> { +impl<'a, T, L: Location<'a>> CycleCollection<'a, TickCycleMarker> for Stream, Bounded> { type Location = Tick; fn create_source(ident: syn::Ident, location: Tick) -> Self { @@ -72,7 +72,7 @@ impl<'a, T, L: Location<'a>> CycleCollection<'a, TickCycle> for Stream> CycleComplete<'a, TickCycle> for Stream, Bounded> { +impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycleMarker> for Stream, Bounded> { fn complete(self, ident: syn::Ident) { self.location .flow_state() @@ -88,7 +88,7 @@ impl<'a, T, L: Location<'a>> CycleComplete<'a, TickCycle> for Stream, } } -impl<'a, T, L: Location<'a> + NoTick, B> CycleCollection<'a, ForwardRef> for Stream { +impl<'a, T, L: Location<'a> + NoTick, B> CycleCollection<'a, ForwardRefMarker> for Stream { type Location = L; fn create_source(ident: syn::Ident, location: L) -> Self { @@ -103,7 +103,7 @@ impl<'a, T, L: Location<'a> + NoTick, B> CycleCollection<'a, ForwardRef> for Str } } -impl<'a, T, L: Location<'a> + NoTick, B> CycleComplete<'a, ForwardRef> for Stream { +impl<'a, T, L: Location<'a> + NoTick, B> CycleComplete<'a, ForwardRefMarker> for Stream { fn complete(self, ident: syn::Ident) { self.location .flow_state()