mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 07:38:12 +08:00
Flip poll kernels and derived-context lazy nodes onto record wires and land record roots at the host rim
This commit is contained in:
@@ -357,6 +357,30 @@ macro_rules! tagged_value {
|
|||||||
if ty == edge_type::<RenderOutput>() {
|
if ty == edge_type::<RenderOutput>() {
|
||||||
return Ok(handle.downcast::<RenderOutput>().map_err(|e| format!("{e:?}"))?.eval(ctx).map(TaggedValue::RenderOutput));
|
return Ok(handle.downcast::<RenderOutput>().map_err(|e| format!("{e:?}"))?.eval(ctx).map(TaggedValue::RenderOutput));
|
||||||
}
|
}
|
||||||
|
// =======================
|
||||||
|
// RECORD WIRES, WHICH LAND AS THEIR ELEMENT
|
||||||
|
// =======================
|
||||||
|
if ty == core_types::registry::record_edge_type::<()>() {
|
||||||
|
return Ok(handle.downcast_record::<()>().map_err(|e| format!("{e:?}"))?.eval(ctx).map(|_| TaggedValue::None));
|
||||||
|
}
|
||||||
|
$(
|
||||||
|
if ty == core_types::registry::record_edge_type::<$ty>() {
|
||||||
|
let layout = handle.layout().ok_or_else(|| "a record edge must carry its layout".to_string())?.clone();
|
||||||
|
return Ok(handle
|
||||||
|
.downcast_record::<$ty>()
|
||||||
|
.map_err(|e| format!("{e:?}"))?
|
||||||
|
.eval(ctx)
|
||||||
|
.map(|value| TaggedValue::$identifier(unsafe { core_types::record::read_element::<$ty>(layout.rec(&value)) })));
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
if ty == core_types::registry::record_edge_type::<RenderOutput>() {
|
||||||
|
let layout = handle.layout().ok_or_else(|| "a record edge must carry its layout".to_string())?.clone();
|
||||||
|
return Ok(handle
|
||||||
|
.downcast_record::<RenderOutput>()
|
||||||
|
.map_err(|e| format!("{e:?}"))?
|
||||||
|
.eval(ctx)
|
||||||
|
.map(|value| TaggedValue::RenderOutput(unsafe { core_types::record::read_element::<RenderOutput>(layout.rec(&value)) })));
|
||||||
|
}
|
||||||
Err(format!("Cannot convert edge of type {ty} to TaggedValue"))
|
Err(format!("Cannot convert edge of type {ty} to TaggedValue"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -289,6 +289,65 @@ pub trait RecordEdge<'e, C>: Node<C, Output = RecordValue<'e>> {}
|
|||||||
|
|
||||||
impl<'e, C, N: Node<C, Output = RecordValue<'e>>> RecordEdge<'e, C> for N {}
|
impl<'e, C, N: Node<C, Output = RecordValue<'e>>> RecordEdge<'e, C> for N {}
|
||||||
|
|
||||||
|
/// Builds an element-only record from a kernel's poll: inline layouts land
|
||||||
|
/// in the value, larger ones spill to the record stack, arena exhaustion of
|
||||||
|
/// a parked element reports as an error poll.
|
||||||
|
pub fn lift_poll<'e, T: Send + Sync + 'static>(poll: GPoll<T>, layout: &Layout, arena: &'e crate::arena::Arena) -> GPoll<RecordValue<'e>> {
|
||||||
|
let build = |element: T| {
|
||||||
|
if layout.is_inline() {
|
||||||
|
let mut value = RecordValue::zeroed();
|
||||||
|
unsafe { write_element(value.as_mut_ptr(), element, arena)? };
|
||||||
|
Some(value)
|
||||||
|
} else {
|
||||||
|
let dst = stack::push(layout.frame_bytes());
|
||||||
|
let written = unsafe { write_element(dst, element, arena) };
|
||||||
|
stack::pop(dst);
|
||||||
|
written.map(|()| RecordValue::spilled(unsafe { Rec::new(dst.cast_const()) }))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let exhausted = || {
|
||||||
|
GPoll::Error(Box::new(crate::gpoll::GraphError {
|
||||||
|
kind: crate::gpoll::ErrorKind::ArenaExhausted,
|
||||||
|
trace: Vec::new(),
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
match poll {
|
||||||
|
GPoll::Final(element) => build(element).map_or_else(exhausted, GPoll::Final),
|
||||||
|
GPoll::Partial(element) => build(element).map_or_else(exhausted, GPoll::Partial),
|
||||||
|
GPoll::Fallback(boxed) => {
|
||||||
|
let (element, error) = *boxed;
|
||||||
|
build(element).map_or_else(exhausted, |value| GPoll::Fallback(Box::new((value, error))))
|
||||||
|
}
|
||||||
|
GPoll::Pending => GPoll::Pending,
|
||||||
|
GPoll::Error(error) => GPoll::Error(error),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The raw lazy edge handed to a poll kernel whose wire rides records while
|
||||||
|
/// the kernel consumes the plain element.
|
||||||
|
pub struct ElementEdge<'a, El, N> {
|
||||||
|
node: &'a N,
|
||||||
|
layout: &'a Layout,
|
||||||
|
_marker: std::marker::PhantomData<fn() -> El>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, El: Clone, N> ElementEdge<'a, El, N> {
|
||||||
|
pub fn new(node: &'a N, layout: &'a Layout) -> Self {
|
||||||
|
Self {
|
||||||
|
node,
|
||||||
|
layout,
|
||||||
|
_marker: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn eval<'d, C>(&self, ctx: &C) -> GPoll<El>
|
||||||
|
where
|
||||||
|
N: Node<C, Output = RecordValue<'d>>,
|
||||||
|
{
|
||||||
|
self.node.eval(ctx).map(|value| unsafe { read_element::<El>(self.layout.rec(&value)) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The lazy input handed to a kernel whose edge rides a record wire while
|
/// The lazy input handed to a kernel whose edge rides a record wire while
|
||||||
/// the kernel consumes the plain element.
|
/// the kernel consumes the plain element.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
@@ -696,34 +755,7 @@ where
|
|||||||
type Output = RecordValue<'e>;
|
type Output = RecordValue<'e>;
|
||||||
|
|
||||||
fn eval(&self, input: &C) -> GPoll<RecordValue<'e>> {
|
fn eval(&self, input: &C) -> GPoll<RecordValue<'e>> {
|
||||||
let build = |element: El| {
|
lift_poll(self.edge.eval(input), &self.layout, input.arena())
|
||||||
if self.layout.is_inline() {
|
|
||||||
let mut value = RecordValue::zeroed();
|
|
||||||
unsafe { write_element(value.as_mut_ptr(), element, input.arena())? };
|
|
||||||
Some(value)
|
|
||||||
} else {
|
|
||||||
let dst = stack::push(self.layout.frame_bytes());
|
|
||||||
let written = unsafe { write_element(dst, element, input.arena()) };
|
|
||||||
stack::pop(dst);
|
|
||||||
written.map(|()| RecordValue::spilled(unsafe { Rec::new(dst.cast_const()) }))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let exhausted = || {
|
|
||||||
GPoll::Error(Box::new(crate::gpoll::GraphError {
|
|
||||||
kind: crate::gpoll::ErrorKind::ArenaExhausted,
|
|
||||||
trace: Vec::new(),
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
match self.edge.eval(input) {
|
|
||||||
GPoll::Final(element) => build(element).map_or_else(exhausted, GPoll::Final),
|
|
||||||
GPoll::Partial(element) => build(element).map_or_else(exhausted, GPoll::Partial),
|
|
||||||
GPoll::Fallback(boxed) => {
|
|
||||||
let (element, error) = *boxed;
|
|
||||||
build(element).map_or_else(exhausted, |value| GPoll::Fallback(Box::new((value, error))))
|
|
||||||
}
|
|
||||||
GPoll::Pending => GPoll::Pending,
|
|
||||||
GPoll::Error(error) => GPoll::Error(error),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout(&self) -> Option<&Layout> {
|
fn layout(&self) -> Option<&Layout> {
|
||||||
|
|||||||
@@ -816,7 +816,16 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
|||||||
GenericParam::Type(type_param) => !derive_routing || Some(&type_param.ident) != routing.as_ref().map(|routing| &routing.generic),
|
GenericParam::Type(type_param) => !derive_routing || Some(&type_param.ident) != routing.as_ref().map(|routing| &routing.generic),
|
||||||
_ => true,
|
_ => true,
|
||||||
})
|
})
|
||||||
.map(&generic_tokens)
|
.map(|param| match param {
|
||||||
|
// Flipped kernels clone lazy elements out of their records, so
|
||||||
|
// every element generic carries the bound wire values satisfy.
|
||||||
|
GenericParam::Type(type_param) if flip && Some(&type_param.ident) != ctx_param.map(|ctx_param| &ctx_param.ident) => {
|
||||||
|
let mut bounded = type_param.clone();
|
||||||
|
bounded.bounds.push(syn::parse_quote!(::core::clone::Clone));
|
||||||
|
quote!(#bounded)
|
||||||
|
}
|
||||||
|
param => generic_tokens(param),
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let mut impl_generics: Vec<TokenStream2> = parsed
|
let mut impl_generics: Vec<TokenStream2> = parsed
|
||||||
.fn_generics
|
.fn_generics
|
||||||
@@ -874,6 +883,24 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if flip {
|
||||||
|
let mut kernel_lazy = false;
|
||||||
|
for (index, field) in regular_fields.iter().enumerate() {
|
||||||
|
if matches!(&field.ty, ParsedFieldType::Node(_)) {
|
||||||
|
kernel_lazy = true;
|
||||||
|
let source_generic = format_ident!("__Source{index}");
|
||||||
|
let derived_extra = derives
|
||||||
|
.then(|| quote!(+ for<'__derived> #core_types::record::RecordEdge<'__derived, #core_types::context::Derived<'__derived, #ctx_ident>>))
|
||||||
|
.into_iter();
|
||||||
|
generics.push(quote! {
|
||||||
|
#source_generic: #core_types::node::Node<#ctx_ident, Output = #core_types::record::RecordValue<'__record>> #(#derived_extra)*
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if kernel_lazy {
|
||||||
|
generics.insert(0, quote!('__record));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let data_field_generic_idents: Vec<Ident> = parsed
|
let data_field_generic_idents: Vec<Ident> = parsed
|
||||||
.fn_generics
|
.fn_generics
|
||||||
@@ -947,8 +974,13 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
|||||||
let source_generic = format_ident!("__Source{index}");
|
let source_generic = format_ident!("__Source{index}");
|
||||||
quote!(#pat: #core_types::record::RecordLazyInput<'_, '__record, #source_generic>)
|
quote!(#pat: #core_types::record::RecordLazyInput<'_, '__record, #source_generic>)
|
||||||
}
|
}
|
||||||
|
ParsedFieldType::Node(NodeParsedField { output_type, .. }) if flip && raw_lazy => {
|
||||||
|
let source_generic = format_ident!("__Source{index}");
|
||||||
|
quote!(#pat: &#core_types::record::ElementEdge<'_, #output_type, #source_generic>)
|
||||||
|
}
|
||||||
ParsedFieldType::Node(NodeParsedField { output_type, .. }) if flip => {
|
ParsedFieldType::Node(NodeParsedField { output_type, .. }) if flip => {
|
||||||
quote!(#pat: #core_types::record::ElementLazyInput<'_, #output_type, impl for<'__el> #core_types::record::RecordEdge<'__el, #ctx_ident>>)
|
let source_generic = format_ident!("__Source{index}");
|
||||||
|
quote!(#pat: #core_types::record::ElementLazyInput<'_, #output_type, #source_generic>)
|
||||||
}
|
}
|
||||||
ParsedFieldType::Node(NodeParsedField { output_type, .. }) if raw_lazy => {
|
ParsedFieldType::Node(NodeParsedField { output_type, .. }) if raw_lazy => {
|
||||||
let bound = lazy_bound(output_type);
|
let bound = lazy_bound(output_type);
|
||||||
@@ -965,7 +997,13 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
|||||||
let record_value_ty: Type = syn::parse_quote!(#core_types::record::RecordValue<'__record>);
|
let record_value_ty: Type = syn::parse_quote!(#core_types::record::RecordValue<'__record>);
|
||||||
let node_bounds = regular_fields.iter().enumerate().zip(&node_generics).map(|((index, field), node_generic)| match &field.ty {
|
let node_bounds = regular_fields.iter().enumerate().zip(&node_generics).map(|((index, field), node_generic)| match &field.ty {
|
||||||
ParsedFieldType::Regular(_) if flip => quote!(#node_generic: #core_types::node::Node<#ctx_ident, Output = #record_value_ty>),
|
ParsedFieldType::Regular(_) if flip => quote!(#node_generic: #core_types::node::Node<#ctx_ident, Output = #record_value_ty>),
|
||||||
ParsedFieldType::Node(_) if flip => quote!(#node_generic: for<'__el> #core_types::record::RecordEdge<'__el, #ctx_ident>),
|
ParsedFieldType::Node(_) if flip => match derives {
|
||||||
|
true => quote! {
|
||||||
|
#node_generic: #core_types::node::Node<#ctx_ident, Output = #record_value_ty>,
|
||||||
|
#node_generic: for<'__derived> #core_types::record::RecordEdge<'__derived, #core_types::context::Derived<'__derived, #ctx_ident>>
|
||||||
|
},
|
||||||
|
false => quote!(#node_generic: #core_types::node::Node<#ctx_ident, Output = #record_value_ty>),
|
||||||
|
},
|
||||||
ParsedFieldType::Regular(RegularParsedField { ty, lend: Some(_), .. }) => {
|
ParsedFieldType::Regular(RegularParsedField { ty, lend: Some(_), .. }) => {
|
||||||
let lifetime = lend_lifetime.as_ref().expect("lend fields imply the lend lifetime");
|
let lifetime = lend_lifetime.as_ref().expect("lend fields imply the lend lifetime");
|
||||||
quote!(#node_generic: #core_types::node::Node<#ctx_ident, Output = &#lifetime #ty>)
|
quote!(#node_generic: #core_types::node::Node<#ctx_ident, Output = &#lifetime #ty>)
|
||||||
@@ -1071,10 +1109,16 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
|||||||
ParsedFieldType::Node(NodeParsedField { output_type, .. }) if derive_routing && routing_source(output_type) => quote! {
|
ParsedFieldType::Node(NodeParsedField { output_type, .. }) if derive_routing && routing_source(output_type) => quote! {
|
||||||
let #name = #core_types::record::RecordLazyInput::new(&self.#name, &__cell, #index);
|
let #name = #core_types::record::RecordLazyInput::new(&self.#name, &__cell, #index);
|
||||||
},
|
},
|
||||||
ParsedFieldType::Node(_) if flip => {
|
ParsedFieldType::Node(NodeParsedField { output_type, .. }) if flip && raw_lazy => {
|
||||||
let slot = format_ident!("__in_{index}");
|
let slot = format_ident!("__in_{index}");
|
||||||
quote! {
|
quote! {
|
||||||
let #name = #core_types::record::ElementLazyInput::new(&self.#name, &__cell, #index, &self.#slot);
|
let #name = #core_types::record::ElementEdge::<#output_type, _>::new(&self.#name, &self.#slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ParsedFieldType::Node(NodeParsedField { output_type, .. }) if flip => {
|
||||||
|
let slot = format_ident!("__in_{index}");
|
||||||
|
quote! {
|
||||||
|
let #name = #core_types::record::ElementLazyInput::<#output_type, _>::new(&self.#name, &__cell, #index, &self.#slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ParsedFieldType::Node(_) if raw_lazy => quote!(),
|
ParsedFieldType::Node(_) if raw_lazy => quote!(),
|
||||||
@@ -1102,6 +1146,7 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
|||||||
let call_args = regular_fields.iter().filter(|field| !injected_name(&field.pat_ident.ident)).map(|field| {
|
let call_args = regular_fields.iter().filter(|field| !injected_name(&field.pat_ident.ident)).map(|field| {
|
||||||
let name = &field.pat_ident.ident;
|
let name = &field.pat_ident.ident;
|
||||||
match &field.ty {
|
match &field.ty {
|
||||||
|
ParsedFieldType::Node(_) if flip && raw_lazy => quote!(&#name),
|
||||||
ParsedFieldType::Node(_) if raw_lazy => quote!(&self.#name),
|
ParsedFieldType::Node(_) if raw_lazy => quote!(&self.#name),
|
||||||
_ => quote!(#name),
|
_ => quote!(#name),
|
||||||
}
|
}
|
||||||
@@ -1359,6 +1404,11 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
let flip_tail = flip.then(|| {
|
let flip_tail = flip.then(|| {
|
||||||
|
if matches!(kernel_kind(&parsed.output_type), KernelKind::Poll(_)) {
|
||||||
|
return quote! {
|
||||||
|
__cell.merge(#core_types::record::lift_poll(#kernel_call, &self.__layout, #core_types::context::ExtractArena::arena(__input)))
|
||||||
|
};
|
||||||
|
}
|
||||||
let kernel_value = match kernel_kind(&parsed.output_type) {
|
let kernel_value = match kernel_kind(&parsed.output_type) {
|
||||||
KernelKind::Interrupt(_) => quote! {
|
KernelKind::Interrupt(_) => quote! {
|
||||||
match #kernel_call {
|
match #kernel_call {
|
||||||
@@ -1838,9 +1888,6 @@ pub(crate) fn record_flip(parsed: &ParsedNodeFn) -> bool {
|
|||||||
if parsed.attributes.batch.is_some() || parsed.attributes.shader_node.is_some() || parsed.attributes.plain {
|
if parsed.attributes.batch.is_some() || parsed.attributes.shader_node.is_some() || parsed.attributes.plain {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if matches!(kernel_kind(&parsed.output_type), KernelKind::Poll(_)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if type_disqualifies(&slot_value_type(&parsed.output_type)) {
|
if type_disqualifies(&slot_value_type(&parsed.output_type)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1851,11 +1898,12 @@ pub(crate) fn record_flip(parsed: &ParsedNodeFn) -> bool {
|
|||||||
// Registry rows assign a generic from a field it names bare, so a
|
// Registry rows assign a generic from a field it names bare, so a
|
||||||
// generic without such a position keeps the plain lowering.
|
// generic without such a position keeps the plain lowering.
|
||||||
GenericParam::Type(type_param) => {
|
GenericParam::Type(type_param) => {
|
||||||
let bare = parsed.fields.iter().any(|field| match &field.ty {
|
let bare = parsed.fields.iter().any(|field| {
|
||||||
ParsedFieldType::Regular(RegularParsedField { ty, .. }) => {
|
let ty = match &field.ty {
|
||||||
matches!(ty, Type::Path(path) if path.qself.is_none() && path.path.get_ident() == Some(&type_param.ident))
|
ParsedFieldType::Regular(RegularParsedField { ty, .. }) => ty,
|
||||||
}
|
ParsedFieldType::Node(NodeParsedField { output_type, .. }) => output_type,
|
||||||
_ => false,
|
};
|
||||||
|
matches!(ty, Type::Path(path) if path.qself.is_none() && path.path.get_ident() == Some(&type_param.ident))
|
||||||
});
|
});
|
||||||
if !bare {
|
if !bare {
|
||||||
return false;
|
return false;
|
||||||
@@ -1864,16 +1912,7 @@ pub(crate) fn record_flip(parsed: &ParsedNodeFn) -> bool {
|
|||||||
GenericParam::Lifetime(_) | GenericParam::Const(_) => return false,
|
GenericParam::Lifetime(_) | GenericParam::Const(_) => return false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let has_lazy = parsed.fields.iter().any(|field| matches!(&field.ty, ParsedFieldType::Node(_)));
|
true
|
||||||
let derives = context_param(parsed).is_some_and(|ctx_param| {
|
|
||||||
ctx_param.bounds.iter().any(|bound| match bound {
|
|
||||||
TypeParamBound::Trait(trait_bound) => trait_bound.path.segments.last().is_some_and(|segment| segment.ident == "DeriveCtx"),
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
});
|
|
||||||
// A derived-context kernel evaluates lazy edges at contexts the element
|
|
||||||
// wrapper cannot prove, so those keep the plain lowering for now.
|
|
||||||
!(has_lazy && derives)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn routing_io(parsed: &ParsedNodeFn) -> Option<RoutingIo> {
|
pub(crate) fn routing_io(parsed: &ParsedNodeFn) -> Option<RoutingIo> {
|
||||||
@@ -2191,11 +2230,12 @@ fn flip_entries_tokens(parsed: &ParsedNodeFn, struct_name: &Ident, regular_field
|
|||||||
.map(|generic| {
|
.map(|generic| {
|
||||||
regular_fields
|
regular_fields
|
||||||
.iter()
|
.iter()
|
||||||
.position(|field| match &field.ty {
|
.position(|field| {
|
||||||
ParsedFieldType::Regular(RegularParsedField { ty, .. }) => {
|
let ty = match &field.ty {
|
||||||
matches!(ty, Type::Path(path) if path.qself.is_none() && path.path.get_ident() == Some(generic))
|
ParsedFieldType::Regular(RegularParsedField { ty, .. }) => ty,
|
||||||
}
|
ParsedFieldType::Node(NodeParsedField { output_type, .. }) => output_type,
|
||||||
_ => false,
|
};
|
||||||
|
matches!(ty, Type::Path(path) if path.qself.is_none() && path.path.get_ident() == Some(generic))
|
||||||
})
|
})
|
||||||
.map(|index| (generic.clone(), index))
|
.map(|index| (generic.clone(), index))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use std::sync::Mutex;
|
|||||||
/// Helps speed up repeated renders in a computationally-heavy part of the node graph.
|
/// Helps speed up repeated renders in a computationally-heavy part of the node graph.
|
||||||
///
|
///
|
||||||
/// Stores the last evaluated data that flowed through this node and immediately returns that data on subsequent renders if the context has not changed.
|
/// Stores the last evaluated data that flowed through this node and immediately returns that data on subsequent renders if the context has not changed.
|
||||||
#[node_macro::node(category("General"), path(graphene_core::memo), skip_impl, extent(memoize_extent))]
|
#[node_macro::node(category("General"), path(graphene_core::memo), skip_impl, plain, extent(memoize_extent))]
|
||||||
fn memoize<I: CacheHash, T: Clone>(input: I, #[data] cache: Arc<Mutex<Option<(u64, T, Finality)>>>, content: impl Node<I, Output = T>) -> GPoll<T> {
|
fn memoize<I: CacheHash, T: Clone>(input: I, #[data] cache: Arc<Mutex<Option<(u64, T, Finality)>>>, content: impl Node<I, Output = T>) -> GPoll<T> {
|
||||||
let key = cache_key(&input);
|
let key = cache_key(&input);
|
||||||
if let Some((hash, value, finality)) = cache.lock().unwrap().as_ref()
|
if let Some((hash, value, finality)) = cache.lock().unwrap().as_ref()
|
||||||
@@ -111,7 +111,7 @@ fn lend<'e, T: Send + Sync>(ctx: impl Ctx + ExtractArena<'e>, value: T) -> GPoll
|
|||||||
type MonitorValue<T> = Arc<Mutex<Option<Arc<IORecord<CtxSnapshot, T>>>>>;
|
type MonitorValue<T> = Arc<Mutex<Option<Arc<IORecord<CtxSnapshot, T>>>>>;
|
||||||
|
|
||||||
/// The Monitor node is used by the editor to access the data flowing through it.
|
/// The Monitor node is used by the editor to access the data flowing through it.
|
||||||
#[node_macro::node(category(""), path(graphene_core::memo), serialize(serialize_monitor), properties("monitor_properties"), skip_impl)]
|
#[node_macro::node(category(""), path(graphene_core::memo), serialize(serialize_monitor), properties("monitor_properties"), skip_impl, plain)]
|
||||||
fn monitor<T: Clone + 'static + Send + Sync>(
|
fn monitor<T: Clone + 'static + Send + Sync>(
|
||||||
ctx: impl Ctx + DeriveCtx + ExtractAll,
|
ctx: impl Ctx + DeriveCtx + ExtractAll,
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
|
|||||||
Reference in New Issue
Block a user