From a6392c6d0000d58ad72d52d29d81277f60f56966 Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Wed, 10 Nov 2021 13:34:31 +1030 Subject: [PATCH] Use xtra-productivity from comit-network --- Cargo.lock | 19 +--- Cargo.toml | 3 +- daemon/Cargo.toml | 2 +- xtra_productivity/Cargo.toml | 17 --- xtra_productivity/src/lib.rs | 107 ------------------ .../tests/pass/actor_with_generics.rs | 27 ----- .../tests/pass/can_handle_message.rs | 62 ---------- xtra_productivity/tests/ui.rs | 6 - 8 files changed, 4 insertions(+), 239 deletions(-) delete mode 100644 xtra_productivity/Cargo.toml delete mode 100644 xtra_productivity/src/lib.rs delete mode 100644 xtra_productivity/tests/pass/actor_with_generics.rs delete mode 100644 xtra_productivity/tests/pass/can_handle_message.rs delete mode 100644 xtra_productivity/tests/ui.rs diff --git a/Cargo.lock b/Cargo.lock index 546bebb..9ae8a55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3391,20 +3391,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "trybuild" -version = "1.0.52" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "150e726dc059e6fbd4fce3288f5bb3cf70128cf63b0dde23b938a3cad810fb23" -dependencies = [ - "glob", - "lazy_static", - "serde", - "serde_json", - "termcolor", - "toml", -] - [[package]] name = "tungstenite" version = "0.14.0" @@ -3846,13 +3832,10 @@ dependencies = [ [[package]] name = "xtra_productivity" version = "0.1.0" +source = "git+https://github.com/comit-network/xtra-productivity?rev=eda11a682dbbf16a9004cfe5e30baa1c60062a67#eda11a682dbbf16a9004cfe5e30baa1c60062a67" dependencies = [ - "async-trait", "quote", "syn", - "tokio", - "trybuild", - "xtra", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6e37a98..f192ebe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["daemon", "xtra_productivity"] +members = ["daemon"] resolver = "2" [patch.crates-io] @@ -7,3 +7,4 @@ rocket = { git = "https://github.com/SergioBenitez/Rocket" } # Need to patch roc xtra = { git = "https://github.com/Restioson/xtra" } # Latest master has crucial patches. secp256k1-zkp = { git = "https://github.com/ElementsProject/rust-secp256k1-zkp" } # Latest master has crucial patches. maia = { git = "https://github.com/comit-network/maia", rev = "70fc548da0fe4f34478fb34ec437fa9a434c7ee3" } +xtra_productivity = { git = "https://github.com/comit-network/xtra-productivity", rev = "eda11a682dbbf16a9004cfe5e30baa1c60062a67" } diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index 90fe40e..1e3fa8d 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -46,7 +46,7 @@ tracing-subscriber = { version = "0.2", default-features = false, features = ["f uuid = { version = "0.8", features = ["serde", "v4"] } x25519-dalek = { version = "1.1" } xtra = { version = "0.6", features = ["with-tokio-1"] } -xtra_productivity = { path = "../xtra_productivity" } +xtra_productivity = { version = "0.1.0" } [features] # Feature flag to enable tests that take longer to compile. diff --git a/xtra_productivity/Cargo.toml b/xtra_productivity/Cargo.toml deleted file mode 100644 index 1839147..0000000 --- a/xtra_productivity/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "xtra_productivity" -version = "0.1.0" -edition = "2018" - -[lib] -proc-macro = true - -[dependencies] -quote = "1" -syn = { version = "1", features = ["full"] } - -[dev-dependencies] -async-trait = "0.1.51" -tokio = { version = "1", features = ["rt-multi-thread", "macros"] } -trybuild = "1" -xtra = { version = "0.6", features = ["with-tokio-1"] } diff --git a/xtra_productivity/src/lib.rs b/xtra_productivity/src/lib.rs deleted file mode 100644 index 99e1d26..0000000 --- a/xtra_productivity/src/lib.rs +++ /dev/null @@ -1,107 +0,0 @@ -use proc_macro::TokenStream; -use quote::quote; -use syn::{FnArg, GenericParam, ImplItem, ItemImpl, MetaNameValue, ReturnType}; - -#[proc_macro_attribute] -pub fn xtra_productivity(attribute: TokenStream, item: TokenStream) -> TokenStream { - let block = syn::parse::(item).unwrap(); - let want_message_impl = if attribute.is_empty() { - true - } else { - let attribute = syn::parse::(attribute).unwrap(); - if !attribute.path.is_ident("message_impl") { - panic!( - "Unexpected attribute {:?}", - attribute.path.get_ident().unwrap() - ) - } - - matches!( - attribute.lit, - syn::Lit::Bool(syn::LitBool { value: true, .. }) - ) - }; - - let actor = block.self_ty; - - let generic_params = &block.generics.params; - - let generic_types = block - .generics - .params - .iter() - .filter_map(|param| match param { - GenericParam::Type(ty) => Some(ty.ident.clone()), - _ => None, - }) - .collect::>(); - - let additional_bounds = block - .generics - .where_clause - .map(|bounds| { - let predicates = bounds.predicates; - - quote! { - #predicates - } - }) - .unwrap_or_default(); - - let code = block - .items - .into_iter() - .filter_map(|block_item| match block_item { - ImplItem::Method(method) => Some(method), - _ => None, - }) - .map(|method| { - let message_arg = method.sig.inputs[1].clone(); - - let message_type = match message_arg { - // receiver represents self - FnArg::Receiver(_) => unreachable!("cannot have receiver on second position"), - FnArg::Typed(ref typed) => typed.ty.clone() - }; - - let method_return = method.sig.output; - let method_block = method.block; - - let context_arg = method.sig.inputs.iter().nth(2).map(|fn_arg| quote! { #fn_arg }).unwrap_or_else(|| quote! { - _ctx: &mut xtra::Context - }); - - let result_type = match method_return { - ReturnType::Default => quote! { () }, - ReturnType::Type(_, ref t) => quote! { #t } - }; - - let message_impl = if want_message_impl { - quote! { - impl xtra::Message for #message_type { - type Result = #result_type; - } - } - } else { - quote! {} - }; - - quote! { - #message_impl - - #[async_trait::async_trait] - impl<#generic_params> xtra::Handler<#message_type> for #actor - where - #additional_bounds - #(#generic_types: Send + 'static),* - { - async fn handle(&mut self, #message_arg, #context_arg) #method_return #method_block - } - } - }).collect::>(); - - (quote! { - #(#code)* - }) - .into() -} diff --git a/xtra_productivity/tests/pass/actor_with_generics.rs b/xtra_productivity/tests/pass/actor_with_generics.rs deleted file mode 100644 index 2aeb5c4..0000000 --- a/xtra_productivity/tests/pass/actor_with_generics.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::marker::PhantomData; -use xtra_productivity::xtra_productivity; - -struct ActorWithParam { - ty: PhantomData, -} - -struct DummyMessage; - -trait Foo {} - -impl xtra::Actor for ActorWithParam {} - -// Dummy actor, xtra::Handler and xtra::Message impls generated by xtra_productivity -#[xtra_productivity] -impl ActorWithParam -where - C: Foo, -{ - pub fn handle_dummy_message(&mut self, _message: DummyMessage) { - assert_impls_foo::(); - } -} - -fn assert_impls_foo() {} - -fn main() {} diff --git a/xtra_productivity/tests/pass/can_handle_message.rs b/xtra_productivity/tests/pass/can_handle_message.rs deleted file mode 100644 index 91e751d..0000000 --- a/xtra_productivity/tests/pass/can_handle_message.rs +++ /dev/null @@ -1,62 +0,0 @@ -use xtra::spawn::TokioGlobalSpawnExt; -use xtra::Actor; -use xtra_productivity::xtra_productivity; - -struct DummyActor; - -impl xtra::Actor for DummyActor {} - -#[derive(Clone)] -struct DummyMessage; - -struct DummyMessageWithContext; - -// Dummy actor, xtra::Handler and xtra::Message impls generated by xtra_productivity -#[xtra_productivity] -impl DummyActor { - pub fn handle_dummy_message(&mut self, message: DummyMessage) -> i32 { - let _ = message.clone(); - 0 - } - - pub fn handle_dummy_message_with_context( - &mut self, - _message: DummyMessageWithContext, - context: &mut xtra::Context, - ) { - let _ = context.address(); - } -} - -fn is_i32(_: i32) {} - -struct DummyMessageWithoutMessageImpl; - -#[xtra_productivity(message_impl = false)] -impl DummyActor { - pub fn handle_dummy_message_without_message_impl( - &mut self, - _message: DummyMessageWithoutMessageImpl, - ) { - } -} - -impl xtra::Message for DummyMessageWithoutMessageImpl { - type Result = (); -} - -#[tokio::main] -async fn main() { - // Create dummy actor - let dummy_actor = DummyActor.create(None).spawn_global(); - - // Send message to dummy actor - let i32 = dummy_actor.send(DummyMessage).await.unwrap(); - is_i32(i32); - dummy_actor.send(DummyMessageWithContext).await.unwrap(); - - dummy_actor - .send(DummyMessageWithoutMessageImpl) - .await - .unwrap(); -} diff --git a/xtra_productivity/tests/ui.rs b/xtra_productivity/tests/ui.rs deleted file mode 100644 index c13cfdf..0000000 --- a/xtra_productivity/tests/ui.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[test] -fn ui() { - let t = trybuild::TestCases::new(); - t.compile_fail("tests/ui/*.rs"); - t.pass("tests/pass/*.rs"); -}