Skip to content

Commit 04e3def

Browse files
committed
refactor(dfir_lang): remove stratum, add push codegen for lattice_fold, lattice_reduce, _lattice_fold_batch
PR: #2970
1 parent 23d59a1 commit 04e3def

11 files changed

Lines changed: 63 additions & 131 deletions

dfir_lang/src/graph/ops/_lattice_fold_batch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use quote::{quote_spanned, ToTokens};
22
use syn::parse_quote;
33

44
use super::{
5-
DelayType, OpInstGenerics, OperatorCategory, OperatorConstraints, OperatorInstance,
5+
OpInstGenerics, OperatorCategory, OperatorConstraints, OperatorInstance,
66
OperatorWriteOutput, PortListSpec, WriteContextArgs, RANGE_0, RANGE_1,
77
};
88

@@ -44,7 +44,7 @@ pub const _LATTICE_FOLD_BATCH: OperatorConstraints = OperatorConstraints {
4444
flo_type: None,
4545
ports_inn: Some(|| PortListSpec::Fixed(parse_quote! { input, signal })),
4646
ports_out: None,
47-
input_delaytype_fn: |_| Some(DelayType::MonotoneAccum),
47+
input_delaytype_fn: |_| None,
4848
write_fn: |wc @ &WriteContextArgs {
4949
ident,
5050
op_span,

dfir_lang/src/graph/ops/lattice_fold.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use syn::parse_quote_spanned;
22

33
use super::{
4-
DelayType, OperatorCategory, OperatorConstraints, WriteContextArgs,
4+
OperatorCategory, OperatorConstraints, WriteContextArgs,
55
RANGE_0, RANGE_1,
66
};
77

@@ -41,17 +41,14 @@ pub const LATTICE_FOLD: OperatorConstraints = OperatorConstraints {
4141
flo_type: None,
4242
ports_inn: None,
4343
ports_out: None,
44-
input_delaytype_fn: |_| Some(DelayType::MonotoneAccum),
44+
input_delaytype_fn: |_| None,
4545
write_fn: |wc @ &WriteContextArgs {
4646
root,
47-
is_pull,
4847
op_span,
4948
arguments,
5049
..
5150
},
5251
diagnostics| {
53-
assert!(is_pull);
54-
5552
let first_arg = &arguments[0];
5653

5754
let arguments = &parse_quote_spanned! {op_span=>

dfir_lang/src/graph/ops/lattice_reduce.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use quote::quote_spanned;
22
use syn::parse_quote_spanned;
33

44
use super::{
5-
DelayType, OperatorCategory, OperatorConstraints, OperatorWriteOutput, RANGE_0, RANGE_1,
5+
OperatorCategory, OperatorConstraints, OperatorWriteOutput, RANGE_0, RANGE_1,
66
WriteContextArgs,
77
};
88

@@ -42,7 +42,7 @@ pub const LATTICE_REDUCE: OperatorConstraints = OperatorConstraints {
4242
flo_type: None,
4343
ports_inn: None,
4444
ports_out: None,
45-
input_delaytype_fn: |_| Some(DelayType::MonotoneAccum),
45+
input_delaytype_fn: |_| None,
4646
write_fn: |wc @ &WriteContextArgs {
4747
root,
4848
inputs,
@@ -51,8 +51,6 @@ pub const LATTICE_REDUCE: OperatorConstraints = OperatorConstraints {
5151
..
5252
},
5353
diagnostics| {
54-
assert!(is_pull);
55-
5654
let arguments = &parse_quote_spanned! {op_span=>
5755
|acc, item| { #root::lattices::Merge::<_>::merge(acc, item); }
5856
};
@@ -68,24 +66,27 @@ pub const LATTICE_REDUCE: OperatorConstraints = OperatorConstraints {
6866
write_tick_end,
6967
} = (super::reduce::REDUCE.write_fn)(&wc, diagnostics)?;
7068

71-
assert_eq!(1, inputs.len());
72-
let input = &inputs[0];
73-
74-
let write_iterator = quote_spanned! {op_span=>
75-
let #input = {
76-
#[inline(always)]
77-
fn check_inputs<Lat, Prev>(
78-
input: Prev,
79-
) -> impl #root::dfir_pipes::pull::Pull<Item = Lat, Meta = Prev::Meta, CanPend = Prev::CanPend, CanEnd = Prev::CanEnd>
80-
where
81-
Lat: #root::lattices::Merge<Lat>,
82-
Prev: #root::dfir_pipes::pull::Pull<Item = Lat>,
83-
{
84-
input
85-
}
86-
check_inputs(#input)
87-
};
88-
#write_iterator
69+
let write_iterator = if is_pull {
70+
assert_eq!(1, inputs.len());
71+
let input = &inputs[0];
72+
quote_spanned! {op_span=>
73+
let #input = {
74+
#[inline(always)]
75+
fn check_inputs<Lat, Prev>(
76+
input: Prev,
77+
) -> impl #root::dfir_pipes::pull::Pull<Item = Lat, Meta = Prev::Meta, CanPend = Prev::CanPend, CanEnd = Prev::CanEnd>
78+
where
79+
Lat: #root::lattices::Merge<Lat>,
80+
Prev: #root::dfir_pipes::pull::Pull<Item = Lat>,
81+
{
82+
input
83+
}
84+
check_inputs(#input)
85+
};
86+
#write_iterator
87+
}
88+
} else {
89+
write_iterator
8990
};
9091
Ok(OperatorWriteOutput {
9192
write_prologue,

dfir_rs/tests/snapshots/surface_lattice_bimorphism_persist_insertion__cartesian_product_multi_tick@graphvis_dot.snap

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ digraph {
1818
n11v1 [label="(n11v1) for_each(|x| out_send.send(x).unwrap())", shape=house, fillcolor="#ffff88"]
1919
n12v1 [label="(n12v1) handoff", shape=parallelogram, fillcolor="#ddddff"]
2020
n13v1 [label="(n13v1) handoff", shape=parallelogram, fillcolor="#ddddff"]
21-
n14v1 [label="(n14v1) handoff", shape=parallelogram, fillcolor="#ddddff"]
2221
n2v1 -> n3v1
2322
n1v1 -> n2v1
2423
n5v1 -> n6v1
@@ -28,10 +27,9 @@ digraph {
2827
n3v1 -> n7v1 [label="state"]
2928
n6v1 -> n8v1 [label="state"]
3029
n10v1 -> n11v1
31-
n9v1 -> n14v1
30+
n9v1 -> n10v1
3231
n12v1 -> n9v1 [label="0"]
3332
n13v1 -> n9v1 [label="1"]
34-
n14v1 -> n10v1 [color=red]
3533
n7v1 -> n9v1 [color=red]
3634
n8v1 -> n9v1 [color=red]
3735
subgraph sg_1v1 {
@@ -69,16 +67,6 @@ digraph {
6967
cluster=true
7068
label="var my_join"
7169
n9v1
72-
}
73-
}
74-
subgraph sg_4v1 {
75-
cluster=true
76-
fillcolor="#dddddd"
77-
style=filled
78-
label = "sg_4v1"
79-
subgraph sg_4v1_var_my_join {
80-
cluster=true
81-
label="var my_join"
8270
n10v1
8371
n11v1
8472
}

dfir_rs/tests/snapshots/surface_lattice_bimorphism_persist_insertion__cartesian_product_multi_tick@graphvis_mermaid.snap

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ linkStyle default stroke:#aaa
2121
11v1[/"(11v1) <code>for_each(|x| out_send.send(x).unwrap())</code>"\]:::pushClass
2222
12v1["(12v1) <code>handoff</code>"]:::otherClass
2323
13v1["(13v1) <code>handoff</code>"]:::otherClass
24-
14v1["(14v1) <code>handoff</code>"]:::otherClass
2524
2v1-->3v1
2625
1v1-->2v1
2726
5v1-->6v1
@@ -31,12 +30,11 @@ linkStyle default stroke:#aaa
3130
3v1-->|state|7v1
3231
6v1-->|state|8v1
3332
10v1-->11v1
34-
9v1-->14v1
33+
9v1-->10v1
3534
12v1-->|0|9v1
3635
13v1-->|1|9v1
37-
14v1-->10v1; linkStyle 12 stroke:#060
38-
7v1--x9v1; linkStyle 13 stroke:red
39-
8v1--x9v1; linkStyle 14 stroke:red
36+
7v1--x9v1; linkStyle 12 stroke:red
37+
8v1--x9v1; linkStyle 13 stroke:red
4038
subgraph sg_1v1 ["sg_1v1"]
4139
subgraph sg_1v1_var_lhs_op ["var <tt>lhs_op</tt>"]
4240
1v1
@@ -54,10 +52,6 @@ end
5452
subgraph sg_3v1 ["sg_3v1"]
5553
subgraph sg_3v1_var_my_join ["var <tt>my_join</tt>"]
5654
9v1
57-
end
58-
end
59-
subgraph sg_4v1 ["sg_4v1"]
60-
subgraph sg_4v1_var_my_join ["var <tt>my_join</tt>"]
6155
10v1
6256
11v1
6357
end

dfir_rs/tests/snapshots/surface_lattice_bimorphism_persist_insertion__cartesian_product_multi_tick_identity@graphvis_dot.snap

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ digraph {
1919
n12v1 [label="(n12v1) for_each(|x| out_send.send(x).unwrap())", shape=house, fillcolor="#ffff88"]
2020
n13v1 [label="(n13v1) handoff", shape=parallelogram, fillcolor="#ddddff"]
2121
n14v1 [label="(n14v1) handoff", shape=parallelogram, fillcolor="#ddddff"]
22-
n15v1 [label="(n15v1) handoff", shape=parallelogram, fillcolor="#ddddff"]
2322
n2v1 -> n3v1
2423
n1v1 -> n2v1
2524
n5v1 -> n6v1
@@ -30,10 +29,9 @@ digraph {
3029
n3v1 -> n13v1 [label="items"]
3130
n7v1 -> n14v1
3231
n11v1 -> n12v1
33-
n10v1 -> n15v1
32+
n10v1 -> n11v1
3433
n13v1 -> n10v1 [label="0"]
3534
n14v1 -> n10v1 [label="1"]
36-
n15v1 -> n11v1 [color=red]
3735
n8v1 -> n10v1 [color=red]
3836
n9v1 -> n10v1 [color=red]
3937
subgraph sg_1v1 {
@@ -76,16 +74,6 @@ digraph {
7674
cluster=true
7775
label="var my_join"
7876
n10v1
79-
}
80-
}
81-
subgraph sg_4v1 {
82-
cluster=true
83-
fillcolor="#dddddd"
84-
style=filled
85-
label = "sg_4v1"
86-
subgraph sg_4v1_var_my_join {
87-
cluster=true
88-
label="var my_join"
8977
n11v1
9078
n12v1
9179
}

dfir_rs/tests/snapshots/surface_lattice_bimorphism_persist_insertion__cartesian_product_multi_tick_identity@graphvis_mermaid.snap

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ linkStyle default stroke:#aaa
2222
12v1[/"(12v1) <code>for_each(|x| out_send.send(x).unwrap())</code>"\]:::pushClass
2323
13v1["(13v1) <code>handoff</code>"]:::otherClass
2424
14v1["(14v1) <code>handoff</code>"]:::otherClass
25-
15v1["(15v1) <code>handoff</code>"]:::otherClass
2625
2v1-->3v1
2726
1v1-->2v1
2827
5v1-->6v1
@@ -33,12 +32,11 @@ linkStyle default stroke:#aaa
3332
3v1-->|items|13v1
3433
7v1-->14v1
3534
11v1-->12v1
36-
10v1-->15v1
35+
10v1-->11v1
3736
13v1-->|0|10v1
3837
14v1-->|1|10v1
39-
15v1-->11v1; linkStyle 13 stroke:#060
40-
8v1--x10v1; linkStyle 14 stroke:red
41-
9v1--x10v1; linkStyle 15 stroke:red
38+
8v1--x10v1; linkStyle 13 stroke:red
39+
9v1--x10v1; linkStyle 14 stroke:red
4240
subgraph sg_1v1 ["sg_1v1"]
4341
subgraph sg_1v1_var_lhs_op ["var <tt>lhs_op</tt>"]
4442
1v1
@@ -59,10 +57,6 @@ end
5957
subgraph sg_3v1 ["sg_3v1"]
6058
subgraph sg_3v1_var_my_join ["var <tt>my_join</tt>"]
6159
10v1
62-
end
63-
end
64-
subgraph sg_4v1 ["sg_4v1"]
65-
subgraph sg_4v1_var_my_join ["var <tt>my_join</tt>"]
6660
11v1
6761
12v1
6862
end

dfir_rs/tests/snapshots/surface_lattice_bimorphism_persist_insertion__cartesian_product_multi_tick_tee@graphvis_dot.snap

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ digraph {
2020
n13v1 [label="(n13v1) for_each(|x| out_send.send(x).unwrap())", shape=house, fillcolor="#ffff88"]
2121
n14v1 [label="(n14v1) handoff", shape=parallelogram, fillcolor="#ddddff"]
2222
n15v1 [label="(n15v1) handoff", shape=parallelogram, fillcolor="#ddddff"]
23-
n16v1 [label="(n16v1) handoff", shape=parallelogram, fillcolor="#ddddff"]
2423
n2v1 -> n3v1
2524
n1v1 -> n2v1
2625
n5v1 -> n6v1
@@ -32,10 +31,9 @@ digraph {
3231
n3v1 -> n14v1 [label="items"]
3332
n7v1 -> n15v1
3433
n12v1 -> n13v1
35-
n11v1 -> n16v1
34+
n11v1 -> n12v1
3635
n14v1 -> n11v1 [label="0"]
3736
n15v1 -> n11v1 [label="1"]
38-
n16v1 -> n12v1 [color=red]
3937
n9v1 -> n11v1 [color=red]
4038
n10v1 -> n11v1 [color=red]
4139
subgraph sg_1v1 {
@@ -79,16 +77,6 @@ digraph {
7977
cluster=true
8078
label="var my_join"
8179
n11v1
82-
}
83-
}
84-
subgraph sg_4v1 {
85-
cluster=true
86-
fillcolor="#dddddd"
87-
style=filled
88-
label = "sg_4v1"
89-
subgraph sg_4v1_var_my_join {
90-
cluster=true
91-
label="var my_join"
9280
n12v1
9381
n13v1
9482
}

dfir_rs/tests/snapshots/surface_lattice_bimorphism_persist_insertion__cartesian_product_multi_tick_tee@graphvis_mermaid.snap

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ linkStyle default stroke:#aaa
2323
13v1[/"(13v1) <code>for_each(|x| out_send.send(x).unwrap())</code>"\]:::pushClass
2424
14v1["(14v1) <code>handoff</code>"]:::otherClass
2525
15v1["(15v1) <code>handoff</code>"]:::otherClass
26-
16v1["(16v1) <code>handoff</code>"]:::otherClass
2726
2v1-->3v1
2827
1v1-->2v1
2928
5v1-->6v1
@@ -35,12 +34,11 @@ linkStyle default stroke:#aaa
3534
3v1-->|items|14v1
3635
7v1-->15v1
3736
12v1-->13v1
38-
11v1-->16v1
37+
11v1-->12v1
3938
14v1-->|0|11v1
4039
15v1-->|1|11v1
41-
16v1-->12v1; linkStyle 14 stroke:#060
42-
9v1--x11v1; linkStyle 15 stroke:red
43-
10v1--x11v1; linkStyle 16 stroke:red
40+
9v1--x11v1; linkStyle 14 stroke:red
41+
10v1--x11v1; linkStyle 15 stroke:red
4442
subgraph sg_1v1 ["sg_1v1"]
4543
subgraph sg_1v1_var_lhs_op ["var <tt>lhs_op</tt>"]
4644
1v1
@@ -62,10 +60,6 @@ end
6260
subgraph sg_3v1 ["sg_3v1"]
6361
subgraph sg_3v1_var_my_join ["var <tt>my_join</tt>"]
6462
11v1
65-
end
66-
end
67-
subgraph sg_4v1 ["sg_4v1"]
68-
subgraph sg_4v1_var_my_join ["var <tt>my_join</tt>"]
6963
12v1
7064
13v1
7165
end

0 commit comments

Comments
 (0)