-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hydroflow_lang): add
batch()
, checking of flo [un]windowing ops (
- Loading branch information
1 parent
9ace9a9
commit c9e4f94
Showing
13 changed files
with
287 additions
and
29 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
hydroflow/tests/compile-fail/surface_loop_missing_unwindowing.rs
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
fn main() { | ||
let mut df = hydroflow::hydroflow_syntax! { | ||
a = source_iter(0..10); | ||
loop { | ||
b = a -> batch(); | ||
} | ||
b -> null(); | ||
}; | ||
df.run_available(); | ||
} |
11 changes: 11 additions & 0 deletions
11
hydroflow/tests/compile-fail/surface_loop_missing_unwindowing.stderr
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
warning: `loop` blocks are not yet supported. | ||
--> tests/compile-fail/surface_loop_missing_unwindowing.rs:4:9 | ||
| | ||
4 | loop { | ||
| ^^^^ | ||
|
||
error: Operator `null(...)` exiting a loop context must be an un-windowing operator, but is not. | ||
--> tests/compile-fail/surface_loop_missing_unwindowing.rs:7:14 | ||
| | ||
7 | b -> null(); | ||
| ^^^^^^ |
9 changes: 9 additions & 0 deletions
9
hydroflow/tests/compile-fail/surface_loop_missing_windowing.rs
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() { | ||
let mut df = hydroflow::hydroflow_syntax! { | ||
a = source_iter(0..10); | ||
loop { | ||
a -> null(); | ||
} | ||
}; | ||
df.run_available(); | ||
} |
11 changes: 11 additions & 0 deletions
11
hydroflow/tests/compile-fail/surface_loop_missing_windowing.stderr
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
warning: `loop` blocks are not yet supported. | ||
--> tests/compile-fail/surface_loop_missing_windowing.rs:4:9 | ||
| | ||
4 | loop { | ||
| ^^^^ | ||
|
||
error: Operator `null(...)` entering a loop context must be a windowing operator, but is not. | ||
--> tests/compile-fail/surface_loop_missing_windowing.rs:5:18 | ||
| | ||
5 | a -> null(); | ||
| ^^^^^^ |
11 changes: 11 additions & 0 deletions
11
hydroflow/tests/compile-fail/surface_loop_multiple_window.rs
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn main() { | ||
let mut df = hydroflow::hydroflow_syntax! { | ||
a = source_iter(0..10); | ||
loop { | ||
loop { | ||
a -> batch() -> null(); | ||
} | ||
} | ||
}; | ||
df.run_available(); | ||
} |
17 changes: 17 additions & 0 deletions
17
hydroflow/tests/compile-fail/surface_loop_multiple_window.stderr
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: `loop` blocks are not yet supported. | ||
--> tests/compile-fail/surface_loop_multiple_window.rs:4:9 | ||
| | ||
4 | loop { | ||
| ^^^^ | ||
|
||
warning: `loop` blocks are not yet supported. | ||
--> tests/compile-fail/surface_loop_multiple_window.rs:5:13 | ||
| | ||
5 | loop { | ||
| ^^^^ | ||
|
||
error: Operator input edge may not cross multiple loop contexts. | ||
--> tests/compile-fail/surface_loop_multiple_window.rs:6:22 | ||
| | ||
6 | a -> batch() -> null(); | ||
| ^^^^^^^ |
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
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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use quote::quote_spanned; | ||
|
||
use super::{ | ||
FloType, OperatorCategory, OperatorConstraints, OperatorWriteOutput, WriteContextArgs, RANGE_0, | ||
RANGE_1, | ||
}; | ||
|
||
pub const BATCH: OperatorConstraints = OperatorConstraints { | ||
name: "batch", | ||
categories: &[OperatorCategory::Fold], | ||
hard_range_inn: RANGE_1, | ||
soft_range_inn: RANGE_1, | ||
hard_range_out: &(0..=1), | ||
soft_range_out: &(0..=1), | ||
num_args: 0, | ||
persistence_args: RANGE_0, | ||
type_args: RANGE_0, | ||
is_external_input: false, | ||
has_singleton_output: true, | ||
flo_type: Some(FloType::Windowing), | ||
ports_inn: None, | ||
ports_out: None, | ||
input_delaytype_fn: |_| None, | ||
write_fn: |wc @ &WriteContextArgs { | ||
root, | ||
context, | ||
hydroflow, | ||
op_span, | ||
ident, | ||
is_pull, | ||
inputs, | ||
outputs, | ||
singleton_output_ident, | ||
.. | ||
}, | ||
_diagnostics| { | ||
let write_prologue = quote_spanned! {op_span=> | ||
#[allow(clippy::redundant_closure_call)] | ||
let #singleton_output_ident = #hydroflow.add_state( | ||
::std::cell::RefCell::new(::std::vec::Vec::new()) | ||
); | ||
|
||
// TODO(mingwei): Is this needed? | ||
// Reset the value to the initializer fn if it is a new tick. | ||
#hydroflow.set_state_tick_hook(#singleton_output_ident, move |rcell| { rcell.take(); }); | ||
}; | ||
|
||
let vec_ident = wc.make_ident("vec"); | ||
|
||
let write_iterator = if is_pull { | ||
// Pull. | ||
let input = &inputs[0]; | ||
quote_spanned! {op_span=> | ||
let mut #vec_ident = #context.state_ref(#singleton_output_ident).borrow_mut(); | ||
*#vec_ident = #input.collect::<::std::vec::Vec<_>>(); | ||
let #ident = ::std::iter::once(::std::clone::Clone::clone(&*#vec_ident)); | ||
} | ||
} else if let Some(output) = outputs.first() { | ||
// Push with output. | ||
quote_spanned! {op_span=> | ||
let mut #vec_ident = #context.state_ref(#singleton_output_ident).borrow_mut(); | ||
let #ident = #root::pusherator::inspect::Inspect::new(|item| { | ||
::std::vec::Vec::push(#vec_ident, ::std::clone::Clone::clone(item)); | ||
}, #output); | ||
} | ||
} else { | ||
// Push with no output. | ||
quote_spanned! {op_span=> | ||
let mut #vec_ident = #context.state_ref(#singleton_output_ident).borrow_mut(); | ||
let #ident = #root::pusherator::for_each::ForEach::new(|item| { | ||
::std::vec::Vec::push(#vec_ident, item); | ||
}); | ||
} | ||
}; | ||
|
||
Ok(OperatorWriteOutput { | ||
write_prologue, | ||
write_iterator, | ||
..Default::default() | ||
}) | ||
}, | ||
}; |
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