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): add APIs for running optimization passes
- Loading branch information
Showing
13 changed files
with
168 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,59 @@ | ||
use crate::ir::*; | ||
|
||
fn predicate_pushdown_node(node: HfPlusNode) -> HfPlusNode { | ||
match node { | ||
HfPlusNode::Map { | ||
f, | ||
input: box HfPlusNode::Persist(behind_persist), | ||
} => HfPlusNode::Persist(Box::new(predicate_pushdown_node(HfPlusNode::Map { | ||
f, | ||
input: behind_persist, | ||
}))), | ||
o => o, | ||
} | ||
} | ||
|
||
fn predicate_pushdown_leaf(leaf: HfPlusLeaf) -> HfPlusLeaf { | ||
match leaf { | ||
HfPlusLeaf::ForEach { f, input } => { | ||
let input = predicate_pushdown_node(*input); | ||
HfPlusLeaf::ForEach { | ||
f, | ||
input: Box::new(input), | ||
} | ||
} | ||
o => o, | ||
} | ||
} | ||
|
||
pub fn predicate_pushdown(ir: Vec<HfPlusLeaf>) -> Vec<HfPlusLeaf> { | ||
ir.into_iter().map(predicate_pushdown_leaf).collect() | ||
} | ||
|
||
#[stageleft::runtime] | ||
#[cfg(test)] | ||
mod tests { | ||
use stageleft::*; | ||
|
||
use crate::{Location, MultiGraph}; | ||
|
||
#[test] | ||
fn predicate_pushdown_through_map() { | ||
let flow = crate::builder::FlowBuilder::<MultiGraph>::new(); | ||
let process = flow.process(&()); | ||
|
||
process | ||
.source_iter(q!(0..10)) | ||
.all_ticks() | ||
.map(q!(|v| v + 1)) | ||
.for_each(q!(|n| println!("{}", n))); | ||
|
||
let built = flow.build(); | ||
|
||
insta::assert_debug_snapshot!(&built.ir); | ||
|
||
let pushed_down = built.optimize_with(super::predicate_pushdown); | ||
|
||
insta::assert_debug_snapshot!(&pushed_down.ir); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../snapshots/hydroflow_plus__persist_pushdown__tests__predicate_pushdown_through_map-2.snap
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,21 @@ | ||
--- | ||
source: hydroflow_plus/src/persist_pushdown.rs | ||
expression: "&pushed_down.ir" | ||
--- | ||
[ | ||
ForEach { | ||
f: { use crate :: __staged :: persist_pushdown :: tests :: * ; | n | println ! ("{}" , n) }, | ||
input: Persist( | ||
Map { | ||
f: { use crate :: __staged :: persist_pushdown :: tests :: * ; | v | v + 1 }, | ||
input: Source { | ||
source: Iter( | ||
{ use crate :: __staged :: persist_pushdown :: tests :: * ; 0 .. 10 }, | ||
), | ||
produces_delta: false, | ||
location_id: 0, | ||
}, | ||
}, | ||
), | ||
}, | ||
] |
21 changes: 21 additions & 0 deletions
21
...rc/snapshots/hydroflow_plus__persist_pushdown__tests__predicate_pushdown_through_map.snap
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,21 @@ | ||
--- | ||
source: hydroflow_plus/src/persist_pushdown.rs | ||
expression: "&built.ir" | ||
--- | ||
[ | ||
ForEach { | ||
f: { use crate :: __staged :: persist_pushdown :: tests :: * ; | n | println ! ("{}" , n) }, | ||
input: Map { | ||
f: { use crate :: __staged :: persist_pushdown :: tests :: * ; | v | v + 1 }, | ||
input: Persist( | ||
Source { | ||
source: Iter( | ||
{ use crate :: __staged :: persist_pushdown :: tests :: * ; 0 .. 10 }, | ||
), | ||
produces_delta: false, | ||
location_id: 0, | ||
}, | ||
), | ||
}, | ||
}, | ||
] |
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
Oops, something went wrong.