Support bare reference parameters and lending outputs in the node macro and make the clone node the clone-out adapter

This commit is contained in:
Dennis Kobert
2026-08-03 18:29:16 +00:00
parent 9b45af854a
commit 62b7ccf40c
10 changed files with 254 additions and 172 deletions

View File

@@ -29,8 +29,8 @@ fn unwrap_option<T: Default>(_: impl Ctx, #[implementations(Option<f64>, Option<
input.unwrap_or_default()
}
/// Meant for debugging purposes, not general use. Clones the input value.
/// Clones the value borrowed from a lending edge. Doubles as the checker-inserted clone-out adapter.
#[node_macro::node(category("Debug"))]
fn clone<'i, T: Clone + 'i>(_: impl Ctx, #[implementations(&List<Raster<CPU>>)] value: &'i T) -> T {
fn clone<T: Clone>(_: impl Ctx, #[implementations(List<Raster<CPU>>)] value: &T) -> T {
value.clone()
}

View File

@@ -103,75 +103,9 @@ pub fn park<T: Send + Sync>(arena: &Arena, result: GPoll<T>) -> GPoll<&T> {
}
/// Adapts an owned edge to a lending one by parking each result in the eval arena.
pub struct LendNode<T, NodeContent> {
content: NodeContent,
_value: std::marker::PhantomData<fn() -> T>,
}
impl<T, NodeContent> LendNode<T, NodeContent> {
pub fn new(content: NodeContent) -> Self {
Self {
content,
_value: std::marker::PhantomData,
}
}
}
impl<'e, Input, T, NodeContent> Node<Input> for LendNode<T, NodeContent>
where
Input: Ctx + ExtractArena<ArenaRef = &'e Arena>,
T: Send + Sync + 'e,
NodeContent: Node<Input, Output = T>,
{
type Output = &'e T;
fn eval(&self, input: &Input) -> GPoll<&'e T> {
park(input.arena(), self.content.eval(input))
}
fn extent(&self, input: &Input) -> GPoll<Extent> {
self.content.extent(input)
}
fn serialize(&self) -> Option<Arc<dyn std::any::Any + Send + Sync>> {
self.content.serialize()
}
}
/// Adapts a lending edge to an owned one by cloning the borrowed value out.
pub struct CloneOutNode<T, NodeContent> {
content: NodeContent,
_value: std::marker::PhantomData<fn() -> T>,
}
impl<T, NodeContent> CloneOutNode<T, NodeContent> {
pub fn new(content: NodeContent) -> Self {
Self {
content,
_value: std::marker::PhantomData,
}
}
}
impl<'e, Input, T, NodeContent> Node<Input> for CloneOutNode<T, NodeContent>
where
Input: Ctx + ExtractArena<ArenaRef = &'e Arena>,
T: Clone + 'e,
NodeContent: Node<Input, Output = &'e T>,
{
type Output = T;
fn eval(&self, input: &Input) -> GPoll<T> {
self.content.eval(input).map(Clone::clone)
}
fn extent(&self, input: &Input) -> GPoll<Extent> {
self.content.extent(input)
}
fn serialize(&self) -> Option<Arc<dyn std::any::Any + Send + Sync>> {
self.content.serialize()
}
#[node_macro::node(category(""), path(graphene_core::memo), skip_impl)]
fn lend<'e, T: Send + Sync>(ctx: impl Ctx + ExtractArena<'e>, value: T) -> GPoll<&'e T> {
park(ctx.arena(), GPoll::Final(value))
}
type MonitorValue<T> = Arc<Mutex<Option<Arc<IORecord<CtxSnapshot, T>>>>>;

View File

@@ -6,7 +6,7 @@ use raster_types::{CPU, Raster};
#[node_macro::node(category("Color"))]
fn image_color_palette(
_: impl Ctx,
image: List<Raster<CPU>>,
image: &List<Raster<CPU>>,
#[default(4)]
#[hard(1..)]
count: u32,