Skip to content

Commit

Permalink
Merge f0c285a into sapling-pr-archive-shadaj
Browse files Browse the repository at this point in the history
  • Loading branch information
shadaj authored Dec 29, 2023
2 parents c17dafd + f0c285a commit b6c69eb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hydroflow_plus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cli_integration = [ "hydroflow/cli_integration" ]

[dependencies]
quote = "1.0.0"
syn = { version = "2.0.0", features = [ "parsing", "extra-traits" ] }
syn = { version = "2.0.0", features = [ "parsing", "extra-traits", "visit-mut" ] }
proc-macro2 = "1.0.57"
proc-macro-crate = "1.1.0"
hydroflow = { path = "../hydroflow", version = "^0.5.0", default-features = false }
Expand Down
26 changes: 23 additions & 3 deletions hydroflow_plus/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::de::DeserializeOwned;
use serde::Serialize;
use stageleft::{IntoQuotedMut, Quoted};
use syn::parse_quote;
use syn::visit_mut::VisitMut;

use crate::builder::Builders;
use crate::node::{
Expand Down Expand Up @@ -334,6 +335,22 @@ fn get_this_crate() -> TokenStream {
}
}

/// Rewrites use of alloc::string::* to use std::string::*
struct RewriteAlloc {}
impl VisitMut for RewriteAlloc {
fn visit_path_mut(&mut self, i: &mut syn::Path) {
if i.segments.iter().take(2).collect::<Vec<_>>()
== vec![
&syn::PathSegment::from(syn::Ident::new("alloc", Span::call_site())),
&syn::PathSegment::from(syn::Ident::new("string", Span::call_site())),
]
{
*i.segments.first_mut().unwrap() =
syn::PathSegment::from(syn::Ident::new("std", Span::call_site()));
}
}
}

fn node_send_direct<'a, T, W, N: HfNode<'a>>(me: &Stream<'a, T, W, N>, sink: Pipeline) {
let self_ident = &me.ident;

Expand All @@ -357,7 +374,8 @@ fn node_send_bincode<'a, T: Serialize, W, N: HfNode<'a>>(me: &Stream<'a, T, W, N
let root = get_this_crate();

// This may fail when instantiated in an environment with different deps
let t_type: syn::Type = syn::parse_str(std::any::type_name::<T>()).unwrap();
let mut t_type: syn::Type = syn::parse_str(std::any::type_name::<T>()).unwrap();
RewriteAlloc {}.visit_type_mut(&mut t_type);

builders
.entry(me.node.id())
Expand All @@ -378,7 +396,8 @@ fn cluster_demux_bincode<'a, T, W, N: HfNode<'a>>(me: &Stream<'a, (u32, T), W, N
let root = get_this_crate();

// This may fail when instantiated in an environment with different deps
let t_type: syn::Type = syn::parse_str(std::any::type_name::<T>()).unwrap();
let mut t_type: syn::Type = syn::parse_str(std::any::type_name::<T>()).unwrap();
RewriteAlloc {}.visit_type_mut(&mut t_type);

builders
.entry(me.node.id())
Expand Down Expand Up @@ -438,7 +457,8 @@ fn node_recv_bincode<'a, T1, T2: DeserializeOwned, W, N: HfNode<'a>, N2: HfNode<
let root = get_this_crate();

// This may fail when instantiated in an environment with different deps
let t_type: syn::Type = syn::parse_str(std::any::type_name::<T2>()).unwrap();
let mut t_type: syn::Type = syn::parse_str(std::any::type_name::<T2>()).unwrap();
RewriteAlloc {}.visit_type_mut(&mut t_type);

builders.entry(other.id()).or_default().add_statement({
if tagged {
Expand Down
3 changes: 0 additions & 3 deletions hydroflow_plus_test/src/bin/map_reduce.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// TODO(shadaj): rewrite type names that involve String
extern crate alloc;

// cannot use hydroflow::main because connect_local_blocking causes a deadlock
#[tokio::main]
async fn main() {
Expand Down

0 comments on commit b6c69eb

Please sign in to comment.