Skip to content

Commit

Permalink
refactor(hydroflow_plus): use match_box macro to compile on stable (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel authored Dec 6, 2024
1 parent 1921637 commit 9ea5f06
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 125 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ Howdy 64
Howdy 65
Howdy 81
Howdy 82

Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ G'day 64
G'day 65
G'day 81
G'day 82

Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ Ahoy, 64
Ahoy, 65
Ahoy, 81
Ahoy, 82

Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ end
Reached: 0
Reached: 1
Reached: 3

Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ Reached: 1
Reached: 3
Reached: 2
Reached: 4

Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,3 @@ Received vertex: 11
Received vertex: 12
unreached_vertices vertex: 11
unreached_vertices vertex: 12

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ expression: output
---
HELLO
WORLD

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ expression: output
---
HELLO
WORLD

Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ hello
world
HELLO
WORLD

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ source: hydroflow/tests/surface_examples.rs
expression: output
---
Current tick: [0], stratum: 0

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ expression: output
---
HELLO
WORLD

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ expression: output
---
HELLO
WORLD

28 changes: 14 additions & 14 deletions hydroflow_plus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ deploy_runtime = [ "hydroflow/deploy_integration" ]
deploy = [ "deploy_runtime", "dep:hydro_deploy", "dep:trybuild-internals-api", "dep:toml", "dep:prettyplease" ]

[dependencies]
quote = "1.0.35"
syn = { version = "2.0.46", features = [ "parsing", "extra-traits", "visit-mut" ] }
proc-macro2 = "1.0.74"
proc-macro-crate = "1.0.0"
bincode = "1.3.1"
hydro_deploy = { path = "../hydro_deploy/core", version = "^0.10.0", optional = true }
hydroflow = { path = "../hydroflow", version = "^0.10.0", default-features = false }
hydroflow_lang = { path = "../hydroflow_lang", version = "^0.10.0" }
serde = { version = "1.0.197", features = [ "derive" ] }
bincode = "1.3.1"
tokio = { version = "1.29.0", features = [ "full" ] }
stageleft = { path = "../stageleft", version = "^0.5.0" }

match_box = "0.0.2"
nameof = "1.0.0"
prettyplease = { version = "0.2.0", features = [ "verbatim" ], optional = true }
proc-macro-crate = "1.0.0"
proc-macro2 = "1.0.74"
quote = "1.0.35"
sealed = "0.6.0"
serde = { version = "1.0.197", features = [ "derive" ] }
sha2 = "0.10.0"
stageleft = { path = "../stageleft", version = "^0.5.0" }
stageleft_tool = { path = "../stageleft_tool", version = "^0.4.0" }
hydro_deploy = { path = "../hydro_deploy/core", version = "^0.10.0", optional = true }
prettyplease = { version = "0.2.0", features = [ "verbatim" ], optional = true }
syn = { version = "2.0.46", features = [ "parsing", "extra-traits", "visit-mut" ] }
tokio = { version = "1.29.0", features = [ "full" ] }
toml = { version = "0.8.0", optional = true }
trybuild-internals-api = { version = "1.0.99", optional = true }
sealed = "0.6.0"

[build-dependencies]
stageleft_tool = { path = "../stageleft_tool", version = "^0.4.0" }

[dev-dependencies]
insta = "1.39"
hydro_deploy = { path = "../hydro_deploy/core", version = "^0.10.0" }
async-ssh2-lite = { version = "0.5.0", features = ["vendored-openssl"] }
ctor = "0.2.8"
hydro_deploy = { path = "../hydro_deploy/core", version = "^0.10.0" }
insta = "1.39"
trybuild = "1"
2 changes: 0 additions & 2 deletions hydroflow_plus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(box_patterns)]

stageleft::stageleft_no_entry_crate!();

pub use hydroflow;
Expand Down
196 changes: 99 additions & 97 deletions hydroflow_plus/src/rewrites/persist_pullup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,114 +7,116 @@ fn persist_pullup_node(
node: &mut HfPlusNode,
persist_pulled_tees: &mut HashSet<*const RefCell<HfPlusNode>>,
) {
*node = match std::mem::replace(node, HfPlusNode::Placeholder) {
HfPlusNode::Unpersist(box HfPlusNode::Persist(box behind_persist)) => behind_persist,

HfPlusNode::Delta(box HfPlusNode::Persist(box behind_persist)) => behind_persist,

HfPlusNode::Tee { inner } => {
if persist_pulled_tees.contains(&(inner.0.as_ref() as *const RefCell<HfPlusNode>)) {
HfPlusNode::Persist(Box::new(HfPlusNode::Tee {
inner: TeeNode(inner.0.clone()),
}))
} else if matches!(*inner.0.borrow(), HfPlusNode::Persist(_)) {
persist_pulled_tees.insert(inner.0.as_ref() as *const RefCell<HfPlusNode>);
if let HfPlusNode::Persist(box behind_persist) =
inner.0.replace(HfPlusNode::Placeholder)
{
*inner.0.borrow_mut() = behind_persist;
*node = match_box::match_box! {
match std::mem::replace(node, HfPlusNode::Placeholder) {
HfPlusNode::Unpersist(mb!(* HfPlusNode::Persist(mb!(* behind_persist)))) => behind_persist,

HfPlusNode::Delta(mb!(* HfPlusNode::Persist(mb!(* behind_persist)))) => behind_persist,

HfPlusNode::Tee { inner } => {
if persist_pulled_tees.contains(&(inner.0.as_ref() as *const RefCell<HfPlusNode>)) {
HfPlusNode::Persist(Box::new(HfPlusNode::Tee {
inner: TeeNode(inner.0.clone()),
}))
} else if matches!(*inner.0.borrow(), HfPlusNode::Persist(_)) {
persist_pulled_tees.insert(inner.0.as_ref() as *const RefCell<HfPlusNode>);
if let HfPlusNode::Persist(behind_persist) =
inner.0.replace(HfPlusNode::Placeholder)
{
*inner.0.borrow_mut() = *behind_persist;
} else {
unreachable!()
}

HfPlusNode::Persist(Box::new(HfPlusNode::Tee {
inner: TeeNode(inner.0.clone()),
}))
} else {
unreachable!()
HfPlusNode::Tee { inner }
}
}

HfPlusNode::Persist(Box::new(HfPlusNode::Tee {
inner: TeeNode(inner.0.clone()),
}))
} else {
HfPlusNode::Tee { inner }
HfPlusNode::Map {
f,
input: mb!(* HfPlusNode::Persist(behind_persist)),
} => HfPlusNode::Persist(Box::new(HfPlusNode::Map {
f,
input: behind_persist,
})),

HfPlusNode::FilterMap {
f,
input: mb!(* HfPlusNode::Persist(behind_persist)),
} => HfPlusNode::Persist(Box::new(HfPlusNode::FilterMap {
f,
input: behind_persist,
})),

HfPlusNode::FlatMap {
f,
input: mb!(* HfPlusNode::Persist(behind_persist)),
} => HfPlusNode::Persist(Box::new(HfPlusNode::FlatMap {
f,
input: behind_persist,
})),

HfPlusNode::Filter {
f,
input: mb!(* HfPlusNode::Persist(behind_persist)),
} => HfPlusNode::Persist(Box::new(HfPlusNode::Filter {
f,
input: behind_persist,
})),

HfPlusNode::Network {
from_location,
from_key,
to_location,
to_key,
serialize_pipeline,
instantiate_fn,
deserialize_pipeline,
input: mb!(* HfPlusNode::Persist(behind_persist)),
..
} => HfPlusNode::Persist(Box::new(HfPlusNode::Network {
from_location,
from_key,
to_location,
to_key,
serialize_pipeline,
instantiate_fn,
deserialize_pipeline,
input: behind_persist,
})),

HfPlusNode::Chain(mb!(* HfPlusNode::Persist(left)), mb!(* HfPlusNode::Persist(right))) => {
HfPlusNode::Persist(Box::new(HfPlusNode::Chain(left, right)))
}
}

HfPlusNode::Map {
f,
input: box HfPlusNode::Persist(behind_persist),
} => HfPlusNode::Persist(Box::new(HfPlusNode::Map {
f,
input: behind_persist,
})),

HfPlusNode::FilterMap {
f,
input: box HfPlusNode::Persist(behind_persist),
} => HfPlusNode::Persist(Box::new(HfPlusNode::FilterMap {
f,
input: behind_persist,
})),

HfPlusNode::FlatMap {
f,
input: box HfPlusNode::Persist(behind_persist),
} => HfPlusNode::Persist(Box::new(HfPlusNode::FlatMap {
f,
input: behind_persist,
})),

HfPlusNode::Filter {
f,
input: box HfPlusNode::Persist(behind_persist),
} => HfPlusNode::Persist(Box::new(HfPlusNode::Filter {
f,
input: behind_persist,
})),

HfPlusNode::Network {
from_location,
from_key,
to_location,
to_key,
serialize_pipeline,
instantiate_fn,
deserialize_pipeline,
input: box HfPlusNode::Persist(behind_persist),
..
} => HfPlusNode::Persist(Box::new(HfPlusNode::Network {
from_location,
from_key,
to_location,
to_key,
serialize_pipeline,
instantiate_fn,
deserialize_pipeline,
input: behind_persist,
})),

HfPlusNode::Chain(box HfPlusNode::Persist(left), box HfPlusNode::Persist(right)) => {
HfPlusNode::Persist(Box::new(HfPlusNode::Chain(left, right)))
}
HfPlusNode::CrossProduct(mb!(* HfPlusNode::Persist(left)), mb!(* HfPlusNode::Persist(right))) => {
HfPlusNode::Persist(Box::new(HfPlusNode::Delta(Box::new(
HfPlusNode::CrossProduct(
Box::new(HfPlusNode::Persist(left)),
Box::new(HfPlusNode::Persist(right)),
),
))))
}

HfPlusNode::CrossProduct(box HfPlusNode::Persist(left), box HfPlusNode::Persist(right)) => {
HfPlusNode::Persist(Box::new(HfPlusNode::Delta(Box::new(
HfPlusNode::CrossProduct(
HfPlusNode::Join(mb!(* HfPlusNode::Persist(left)), mb!(* HfPlusNode::Persist(right))) => {
HfPlusNode::Persist(Box::new(HfPlusNode::Delta(Box::new(HfPlusNode::Join(
Box::new(HfPlusNode::Persist(left)),
Box::new(HfPlusNode::Persist(right)),
),
))))
}
)))))
}

HfPlusNode::Join(box HfPlusNode::Persist(left), box HfPlusNode::Persist(right)) => {
HfPlusNode::Persist(Box::new(HfPlusNode::Delta(Box::new(HfPlusNode::Join(
Box::new(HfPlusNode::Persist(left)),
Box::new(HfPlusNode::Persist(right)),
)))))
}
HfPlusNode::Unique(mb!(* HfPlusNode::Persist(inner))) => {
HfPlusNode::Persist(Box::new(HfPlusNode::Delta(Box::new(HfPlusNode::Unique(
Box::new(HfPlusNode::Persist(inner)),
)))))
}

HfPlusNode::Unique(box HfPlusNode::Persist(inner)) => {
HfPlusNode::Persist(Box::new(HfPlusNode::Delta(Box::new(HfPlusNode::Unique(
Box::new(HfPlusNode::Persist(inner)),
)))))
node => node,
}

node => node,
};
}

Expand Down

0 comments on commit 9ea5f06

Please sign in to comment.