From bb364c92ad31c1da326f234749f8b7efd011a7cf Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sat, 23 Aug 2025 18:21:54 +0200 Subject: [PATCH] Fix automatic Into node insertion (#3087) Fix automatic into node insertion --- node-graph/gcore/src/ops.rs | 49 +++---------------- node-graph/gcore/src/registry.rs | 3 +- .../interpreted-executor/src/node_registry.rs | 33 ++++++++----- node-graph/preprocessor/src/lib.rs | 3 +- 4 files changed, 33 insertions(+), 55 deletions(-) diff --git a/node-graph/gcore/src/ops.rs b/node-graph/gcore/src/ops.rs index 0ef40a86..c80a1adb 100644 --- a/node-graph/gcore/src/ops.rs +++ b/node-graph/gcore/src/ops.rs @@ -1,3 +1,5 @@ +use graphene_core_shaders::Ctx; + use crate::Node; use std::marker::PhantomData; @@ -41,28 +43,9 @@ impl<'i, N: for<'a> Node<'a, I> + Clone, I: 'i> Clone for TypeNode Node<'a, I> + Copy, I: 'i> Copy for TypeNode>::Output> {} -// Into -pub struct IntoNode(PhantomData); -impl IntoNode { - pub const fn new() -> Self { - Self(PhantomData) - } -} -impl Default for IntoNode { - fn default() -> Self { - Self::new() - } -} -impl<'input, I: 'input, O: 'input> Node<'input, I> for IntoNode -where - I: Into + Sync + Send, -{ - type Output = dyn_any::DynFuture<'input, O>; - - #[inline] - fn eval(&'input self, input: I) -> Self::Output { - Box::pin(async move { input.into() }) - } +#[node_macro::node(skip_impl)] +fn into<'i, T: 'i + Send + Into, O: 'i + Send>(_: impl Ctx, value: T, _out_ty: PhantomData) -> O { + value.into() } /// The [`Convert`] trait allows for conversion between Rust primitive numeric types. @@ -122,25 +105,9 @@ impl_convert!(u128); impl_convert!(isize); impl_convert!(usize); -// Convert -pub struct ConvertNode(PhantomData); -impl<_O> ConvertNode<_O> { - pub const fn new() -> Self { - Self(core::marker::PhantomData) - } -} -impl<_O> Default for ConvertNode<_O> { - fn default() -> Self { - Self::new() - } -} -impl<'input, I: 'input + Convert<_O> + Sync + Send, _O: 'input> Node<'input, I> for ConvertNode<_O> { - type Output = ::dyn_any::DynFuture<'input, _O>; - - #[inline] - fn eval(&'input self, input: I) -> Self::Output { - Box::pin(async move { input.convert() }) - } +#[node_macro::node(skip_impl)] +fn convert<'i, T: 'i + Send + Convert, O: 'i + Send>(_: impl Ctx, value: T, _out_ty: PhantomData) -> O { + value.convert() } #[cfg(test)] diff --git a/node-graph/gcore/src/registry.rs b/node-graph/gcore/src/registry.rs index 3553c030..32fcf019 100644 --- a/node-graph/gcore/src/registry.rs +++ b/node-graph/gcore/src/registry.rs @@ -153,13 +153,14 @@ where { type Output = DynFuture<'input, O>; #[inline] + #[track_caller] fn eval(&'input self, input: I) -> Self::Output { { let node_name = self.node.node_name(); let input = Box::new(input); let future = self.node.eval(input); Box::pin(async move { - let out = dyn_any::downcast(future.await).unwrap_or_else(|e| panic!("DowncastBothNode Input {e} in: \n{node_name}")); + let out = dyn_any::downcast(future.await).unwrap_or_else(|e| panic!("DowncastBothNode wrong output type: {e} in: \n{node_name}")); *out }) } diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index 673b481e..1f87d269 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -294,17 +294,23 @@ mod node_registry_macros { (from: $from:ty, to: $to:ty) => { ( ProtoNodeIdentifier::new(concat!["graphene_core::ops::IntoNode<", stringify!($to), ">"]), - |_| { + |mut args| { Box::pin(async move { - let node = graphene_core::ops::IntoNode::<$to>::new(); - let any: DynAnyNode<$from, _, _> = graphene_std::any::DynAnyNode::new(node); + let node = graphene_core::ops::IntoNode::new( + graphene_std::any::downcast_node::(args.pop().unwrap()), + graphene_std::any::FutureWrapperNode::new(graphene_std::value::ClonedNode::new(std::marker::PhantomData::<$to>)), + ); + let any: DynAnyNode = graphene_std::any::DynAnyNode::new(node); Box::new(any) as TypeErasedBox }) }, { - let node = graphene_core::ops::IntoNode::<$to>::new(); - let mut node_io = NodeIO::<'_, $from>::to_async_node_io(&node, vec![]); - node_io.call_argument = future!(<$from as StaticType>::Static); + let node = graphene_core::ops::IntoNode::new( + graphene_std::any::PanicNode:: + Send>>>::new(), + graphene_std::any::FutureWrapperNode::new(graphene_std::value::ClonedNode::new(std::marker::PhantomData::<$to>)), + ); + let params = vec![fn_type_fut!(Context, $from)]; + let node_io = NodeIO::<'_, Context>::to_async_node_io(&node, params); node_io }, ) @@ -333,17 +339,20 @@ mod node_registry_macros { (from: $from:ty, to: $to:ty) => { ( ProtoNodeIdentifier::new(concat!["graphene_core::ops::ConvertNode<", stringify!($to), ">"]), - |_| { + |mut args| { Box::pin(async move { - let node = graphene_core::ops::ConvertNode::<$to>::new(); - let any: DynAnyNode<$from, _, _> = graphene_std::any::DynAnyNode::new(node); + let node = graphene_core::ops::ConvertNode::new(graphene_std::any::downcast_node::(args.pop().unwrap()), +graphene_std::any::FutureWrapperNode::new(graphene_std::value::ClonedNode::new(std::marker::PhantomData::<$to>)) ); + let any: DynAnyNode = graphene_std::any::DynAnyNode::new(node); Box::new(any) as TypeErasedBox }) }, { - let node = graphene_core::ops::ConvertNode::<$to>::new(); - let mut node_io = NodeIO::<'_, $from>::to_async_node_io(&node, vec![]); - node_io.call_argument = future!(<$from as StaticType>::Static); + let node = graphene_core::ops::ConvertNode::new(graphene_std::any::PanicNode:: + Send>>>::new(), + +graphene_std::any::FutureWrapperNode::new(graphene_std::value::ClonedNode::new(std::marker::PhantomData::<$to>)) ); + let params = vec![fn_type_fut!(Context, $from)]; + let node_io = NodeIO::<'_, Context>::to_async_node_io(&node, params); node_io }, ) diff --git a/node-graph/preprocessor/src/lib.rs b/node-graph/preprocessor/src/lib.rs index 47ad8b6b..0bdca59f 100644 --- a/node-graph/preprocessor/src/lib.rs +++ b/node-graph/preprocessor/src/lib.rs @@ -61,7 +61,7 @@ pub fn generate_node_substitutions() -> HashMap { + 1 => { let input = inputs.iter().next().unwrap(); let input_ty = input.nested_type(); @@ -87,6 +87,7 @@ pub fn generate_node_substitutions() -> HashMap