Skip to content

Commit f2a4bee

Browse files
feat(hydroflow)!: remove import!, fix #1110 (#1600)
in prep for rust stable #1587 No good way to resolve the source file paths on stable No way to get good diagnostics on external files in general, at all rust-lang/rfcs#3200
1 parent 408b904 commit f2a4bee

File tree

14 files changed

+23
-379
lines changed

14 files changed

+23
-379
lines changed

benches/benches/fork_join.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ fn benchmark_hydroflow(c: &mut Criterion) {
8686
fn benchmark_hydroflow_surface(c: &mut Criterion) {
8787
c.bench_function("fork_join/hydroflow/surface", |b| {
8888
b.iter(|| {
89-
let mut hf = hydroflow_syntax! {
90-
source_iter(0..NUM_INTS) -> import!("fork_join_20.hf") -> for_each(|x| { black_box(x); });
91-
};
89+
let mut hf = include!("fork_join_20.hf");
9290
hf.run_available();
9391
})
9492
});

benches/build.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@ pub fn fork_join() -> std::io::Result<()> {
1919
let file = File::create(path)?;
2020
let mut write = BufWriter::new(file);
2121

22-
writeln!(write, "a0 = mod -> tee();")?;
23-
22+
writeln!(write, "hydroflow_syntax! {{")?;
23+
writeln!(write, "a0 = source_iter(0..NUM_INTS) -> tee();")?;
2424
for i in 0..NUM_OPS {
2525
if i > 0 {
2626
writeln!(write, "a{} = union() -> tee();", i)?;
2727
}
2828
writeln!(write, "a{} -> filter(|x| x % 2 == 0) -> a{};", i, i + 1)?;
2929
writeln!(write, "a{} -> filter(|x| x % 2 == 1) -> a{};", i, i + 1)?;
3030
}
31-
32-
writeln!(write, "a{} = union() -> mod;", NUM_OPS)?;
31+
writeln!(
32+
write,
33+
"a{} = union() -> for_each(|x| {{ black_box(x); }});",
34+
NUM_OPS
35+
)?;
36+
writeln!(write, "}}")?;
3337

3438
write.flush()?;
3539

hydroflow/Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ required-features = [ "nightly" ]
2929
name = "python_udf"
3030
required-features = [ "python" ]
3131

32-
[[example]]
33-
name = "modules_outer_join"
34-
required-features = [ "debugging" ]
35-
36-
[[example]]
37-
name = "modules_triple_cross_join"
38-
required-features = [ "debugging" ]
39-
4032
[dependencies]
4133
bincode = "1.3.1"
4234
byteorder = "1.3.2"

hydroflow/examples/modules_outer_join/full_outer_join.hf

Lines changed: 0 additions & 23 deletions
This file was deleted.

hydroflow/examples/modules_outer_join/left_outer_join.hf

Lines changed: 0 additions & 16 deletions
This file was deleted.

hydroflow/examples/modules_outer_join/main.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

hydroflow/examples/modules_outer_join/right_outer_join.hf

Lines changed: 0 additions & 6 deletions
This file was deleted.

hydroflow/examples/modules_triple_cross_join/main.rs

Lines changed: 0 additions & 51 deletions
This file was deleted.

hydroflow/examples/modules_triple_cross_join/triple_cross_join.hf

Lines changed: 0 additions & 15 deletions
This file was deleted.

hydroflow_lang/src/graph/flat_graph_builder.rs

Lines changed: 1 addition & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::borrow::Cow;
44
use std::collections::btree_map::Entry;
55
use std::collections::{BTreeMap, BTreeSet};
6-
use std::path::PathBuf;
76

87
use itertools::Itertools;
98
use proc_macro2::Span;
@@ -71,9 +70,6 @@ pub struct FlatGraphBuilder {
7170
/// Use statements.
7271
uses: Vec<ItemUse>,
7372

74-
/// In order to make import!() statements relative to the current file, we need to know where the file is that is building the flat graph.
75-
invocating_file_path: PathBuf,
76-
7773
/// If the flat graph is being loaded as a module, then two initial ModuleBoundary nodes are inserted into the graph. One
7874
/// for the input into the module and one for the output out of the module.
7975
module_boundary_nodes: Option<(GraphNodeId, GraphNodeId)>,
@@ -86,37 +82,8 @@ impl FlatGraphBuilder {
8682
}
8783

8884
/// Convert the Hydroflow code AST into a graph builder.
89-
pub fn from_hfcode(input: HfCode, macro_invocation_path: PathBuf) -> Self {
90-
let mut builder = Self {
91-
invocating_file_path: macro_invocation_path,
92-
..Default::default()
93-
};
94-
builder.process_statements(input.statements);
95-
builder
96-
}
97-
98-
/// Convert the Hydroflow code AST into a graph builder.
99-
pub fn from_hfmodule(input: HfCode, root_path: PathBuf) -> Self {
85+
pub fn from_hfcode(input: HfCode) -> Self {
10086
let mut builder = Self::default();
101-
builder.invocating_file_path = root_path; // imports inside of modules should be relative to the importing file.
102-
builder.module_boundary_nodes = Some((
103-
builder.flat_graph.insert_node(
104-
GraphNode::ModuleBoundary {
105-
input: true,
106-
import_expr: Span::call_site(),
107-
},
108-
Some(Ident::new("input", Span::call_site())),
109-
None,
110-
),
111-
builder.flat_graph.insert_node(
112-
GraphNode::ModuleBoundary {
113-
input: false,
114-
import_expr: Span::call_site(),
115-
},
116-
Some(Ident::new("output", Span::call_site())),
117-
None,
118-
),
119-
));
12087
builder.process_statements(input.statements);
12188
builder
12289
}
@@ -276,118 +243,7 @@ impl FlatGraphBuilder {
276243
out: Some((PortIndexValue::Elided(op_span), GraphDet::Determined(nid))),
277244
}
278245
}
279-
Pipeline::Import(import) => {
280-
// TODO: https://github.com/rust-lang/rfcs/pull/3200
281-
// this would be way better...
282-
let file_path = {
283-
let mut dir = self.invocating_file_path.clone();
284-
dir.pop();
285-
dir.join(import.filename.value())
286-
};
287-
288-
let file_contents = match std::fs::read_to_string(&file_path) {
289-
Ok(contents) => contents,
290-
Err(err) => {
291-
self.diagnostics.push(Diagnostic::spanned(
292-
import.filename.span(),
293-
Level::Error,
294-
format!("filename: {}, err: {err}", import.filename.value()),
295-
));
296-
297-
return Ends {
298-
inn: None,
299-
out: None,
300-
};
301-
}
302-
};
303-
304-
let statements = match syn::parse_str::<HfCode>(&file_contents) {
305-
Ok(code) => code,
306-
Err(err) => {
307-
self.diagnostics.push(Diagnostic::spanned(
308-
import.span(),
309-
Level::Error,
310-
format!("Error in module: {}", err),
311-
));
312-
313-
return Ends {
314-
inn: None,
315-
out: None,
316-
};
317-
}
318-
};
319-
320-
let flat_graph_builder = FlatGraphBuilder::from_hfmodule(statements, file_path);
321-
let (flat_graph, _uses, diagnostics) = flat_graph_builder.build();
322-
diagnostics.iter().for_each(Diagnostic::emit);
323-
324-
self.merge_in(flat_graph, import.span())
325-
}
326-
}
327-
}
328-
329-
/// Merge one flatgraph into the current flatgraph
330-
/// other must be a flatgraph and not be partitioned yet.
331-
fn merge_in(&mut self, other: HydroflowGraph, parent_span: Span) -> Ends {
332-
assert_eq!(other.subgraphs().count(), 0);
333-
334-
let mut ends = Ends {
335-
inn: None,
336-
out: None,
337-
};
338-
339-
let mut node_mapping = BTreeMap::new();
340-
341-
for (other_node_id, node) in other.nodes() {
342-
match node {
343-
GraphNode::Operator(_) => {
344-
let varname = other.node_varname(other_node_id);
345-
let new_id = self.flat_graph.insert_node(node.clone(), varname, None);
346-
node_mapping.insert(other_node_id, new_id);
347-
}
348-
GraphNode::ModuleBoundary { input, .. } => {
349-
let new_id = self.flat_graph.insert_node(
350-
GraphNode::ModuleBoundary {
351-
input: *input,
352-
import_expr: parent_span,
353-
},
354-
Some(Ident::new(&format!("module_{}", input), parent_span)),
355-
None,
356-
);
357-
node_mapping.insert(other_node_id, new_id);
358-
359-
// in the case of nested imports, this module boundary might not be the module boundary into or out of the top-most module
360-
// So we have to be careful to only target those two boundaries.
361-
// There should be no inputs to it, if it is an input boundary, if it is the top-most one.
362-
// and there should be no outputs from it, if it is an output boundary, if it is the top-most one.
363-
if *input && other.node_predecessor_nodes(other_node_id).count() == 0 {
364-
if other.node_predecessor_nodes(other_node_id).count() == 0 {
365-
ends.inn =
366-
Some((PortIndexValue::Elided(None), GraphDet::Determined(new_id)));
367-
}
368-
} else if !(*input) && other.node_successor_nodes(other_node_id).count() == 0 {
369-
ends.out =
370-
Some((PortIndexValue::Elided(None), GraphDet::Determined(new_id)));
371-
}
372-
}
373-
GraphNode::Handoff { .. } => {
374-
panic!("Handoff in graph that is being merged into self")
375-
}
376-
}
377-
}
378-
379-
for (other_edge_id, (other_src, other_dst)) in other.edges() {
380-
let (src_port, dst_port) = other.edge_ports(other_edge_id);
381-
382-
let _new_edge_id = self.flat_graph.insert_edge(
383-
*node_mapping.get(&other_src).unwrap(),
384-
src_port.clone(),
385-
*node_mapping.get(&other_dst).unwrap(),
386-
dst_port.clone(),
387-
);
388246
}
389-
390-
ends
391247
}
392248

393249
/// Connects operator links as a final building step. Processes all the links stored in

0 commit comments

Comments
 (0)