diff --git a/hydroflow_plus/Cargo.toml b/hydroflow_plus/Cargo.toml index 2a9aa18c135e..262f2758be59 100644 --- a/hydroflow_plus/Cargo.toml +++ b/hydroflow_plus/Cargo.toml @@ -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 } diff --git a/hydroflow_plus/src/stream.rs b/hydroflow_plus/src/stream.rs index 918e621fbdc9..a638eda32e5c 100644 --- a/hydroflow_plus/src/stream.rs +++ b/hydroflow_plus/src/stream.rs @@ -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::{ @@ -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![ + &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; @@ -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::()).unwrap(); + let mut t_type: syn::Type = syn::parse_str(std::any::type_name::()).unwrap(); + RewriteAlloc {}.visit_type_mut(&mut t_type); builders .entry(me.node.id()) @@ -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::()).unwrap(); + let mut t_type: syn::Type = syn::parse_str(std::any::type_name::()).unwrap(); + RewriteAlloc {}.visit_type_mut(&mut t_type); builders .entry(me.node.id()) @@ -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::()).unwrap(); + let mut t_type: syn::Type = syn::parse_str(std::any::type_name::()).unwrap(); + RewriteAlloc {}.visit_type_mut(&mut t_type); builders.entry(other.id()).or_default().add_statement({ if tagged { diff --git a/hydroflow_plus_test/src/bin/map_reduce.rs b/hydroflow_plus_test/src/bin/map_reduce.rs index 0a78e3eba638..6818a1146b10 100644 --- a/hydroflow_plus_test/src/bin/map_reduce.rs +++ b/hydroflow_plus_test/src/bin/map_reduce.rs @@ -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() {