forked from hydro-project/hydro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hydroflow_plus)!: separate singletons into their own types (hydr…
- Loading branch information
Showing
9 changed files
with
689 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,28 @@ | ||
use std::marker::PhantomData; | ||
|
||
use crate::builder::FlowLeaves; | ||
use crate::ir::{HfPlusLeaf, HfPlusNode}; | ||
use crate::location::{Location, LocationId}; | ||
use crate::stream::{NoTick, Tick}; | ||
use crate::Stream; | ||
|
||
pub trait CycleCollection<'a> { | ||
type Location: Location; | ||
|
||
fn create_source(ident: syn::Ident, ir_leaves: FlowLeaves<'a>, l: LocationId) -> Self; | ||
|
||
fn complete(self, ident: syn::Ident); | ||
} | ||
|
||
/// Represents a fixpoint cycle in the graph that will be fulfilled | ||
/// by a stream that is not yet known. | ||
/// | ||
/// See [`Stream`] for an explainer on the type parameters. | ||
pub struct HfCycle<'a, T, W, C, N: Location> { | ||
/// See [`crate::FlowBuilder`] for an explainer on the type parameters. | ||
pub struct HfCycle<'a, S: CycleCollection<'a>> { | ||
pub(crate) ident: syn::Ident, | ||
pub(crate) location_kind: LocationId, | ||
pub(crate) ir_leaves: FlowLeaves<'a>, | ||
pub(crate) _phantom: PhantomData<(N, &'a mut &'a (), T, W, C)>, | ||
} | ||
|
||
impl<'a, T, W, N: Location> HfCycle<'a, T, W, Tick, N> { | ||
pub fn complete(self, stream: Stream<'a, T, W, Tick, N>) { | ||
let ident = self.ident; | ||
|
||
self.ir_leaves.borrow_mut().as_mut().expect("Attempted to add a cycle to a flow that has already been finalized. No cycles can be added after the flow has been compiled.").push(HfPlusLeaf::CycleSink { | ||
ident, | ||
location_kind: self.location_kind, | ||
input: Box::new(stream.ir_node.into_inner()), | ||
}); | ||
} | ||
pub(crate) _phantom: PhantomData<(&'a mut &'a (), S)>, | ||
} | ||
|
||
impl<'a, T, W, N: Location> HfCycle<'a, T, W, NoTick, N> { | ||
pub fn complete(self, stream: Stream<'a, T, W, NoTick, N>) { | ||
impl<'a, S: CycleCollection<'a>> HfCycle<'a, S> { | ||
pub fn complete(self, stream: S) { | ||
let ident = self.ident; | ||
|
||
self.ir_leaves.borrow_mut().as_mut().expect("Attempted to add a cycle to a flow that has already been finalized. No cycles can be added after the flow has been compiled.").push(HfPlusLeaf::CycleSink { | ||
ident, | ||
location_kind: self.location_kind, | ||
input: Box::new(HfPlusNode::Unpersist( | ||
Box::new(stream.ir_node.into_inner()) | ||
)), | ||
}); | ||
S::complete(stream, ident) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.