mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-20 21:56:09 +08:00
Retire the lend machinery and flip the clone node onto record wires
This commit is contained in:
@@ -29,9 +29,8 @@ fn unwrap_option<T: Default>(_: impl Ctx, #[implementations(Option<f64>, Option<
|
||||
input.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Clones the value borrowed from a lending edge. Doubles as the checker-inserted clone-out
|
||||
/// adapter, so it keeps the plain lowering while the record transition runs.
|
||||
#[node_macro::node(category("Debug"), plain)]
|
||||
/// Clones the element out of its record wire.
|
||||
#[node_macro::node(category("Debug"))]
|
||||
fn clone<T: Clone>(_: impl Ctx, #[implementations(List<Raster<CPU>>)] value: &T) -> T {
|
||||
value.clone()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use core_types::arena::{Arena, ArenaCell};
|
||||
use core_types::arena::ArenaCell;
|
||||
use core_types::context::{Ctx, CtxSnapshot, DeriveCtx, ExtractAll, ExtractArena};
|
||||
use core_types::frame_table::{FrameTable, Lookup};
|
||||
use core_types::gpoll::{Extent, Finality, GPoll};
|
||||
@@ -102,34 +102,6 @@ where
|
||||
node.content.extent(ctx)
|
||||
}
|
||||
|
||||
pub fn park<T: Send + Sync>(arena: &Arena, result: GPoll<T>) -> GPoll<&T> {
|
||||
match result {
|
||||
GPoll::Final(value) => match arena.alloc(value) {
|
||||
Some((parked, _)) => GPoll::Final(parked),
|
||||
None => GPoll::arena_exhausted(),
|
||||
},
|
||||
GPoll::Partial(value) => match arena.alloc(value) {
|
||||
Some((parked, _)) => GPoll::Partial(parked),
|
||||
None => GPoll::arena_exhausted(),
|
||||
},
|
||||
GPoll::Fallback(boxed) => {
|
||||
let (value, error) = *boxed;
|
||||
match arena.alloc(value) {
|
||||
Some((parked, _)) => GPoll::Fallback(Box::new((parked, error))),
|
||||
None => GPoll::arena_exhausted(),
|
||||
}
|
||||
}
|
||||
GPoll::Pending => GPoll::Pending,
|
||||
GPoll::Error(error) => GPoll::Error(error),
|
||||
}
|
||||
}
|
||||
|
||||
/// Adapts an owned edge to a lending one by parking each result in the eval arena.
|
||||
#[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 = Arc<Mutex<Option<IORecord<CtxSnapshot, RecordCapture>>>>;
|
||||
|
||||
/// The Monitor node is used by the editor to access the data flowing through it.
|
||||
@@ -156,6 +128,7 @@ fn serialize_monitor(io: &MonitorValue) -> Option<Arc<dyn std::any::Any + Send +
|
||||
mod tests {
|
||||
use super::*;
|
||||
use core_types::SourceId;
|
||||
use core_types::arena::Arena;
|
||||
use core_types::context::{ContextImpl, EvalScope};
|
||||
use core_types::registry::{EdgeHandle, ErasedLendNode, ErasedNode, ErasedRecordNode};
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
@@ -81,7 +81,6 @@ fn forward_record<T>(_: impl Ctx, element: T) -> T {
|
||||
element
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -180,11 +179,7 @@ mod tests {
|
||||
let stacked = multiply_opacity_layout(&modified);
|
||||
reserve_for(&[&source_layout, &modified, &stacked]);
|
||||
|
||||
let chain = MultiplyOpacityNode::new(
|
||||
MultiplyOpacityNode::new(bare_source(&source_layout, 2.), ValueNode(0.5), &source_layout),
|
||||
ValueNode(0.5),
|
||||
&modified,
|
||||
);
|
||||
let chain = MultiplyOpacityNode::new(MultiplyOpacityNode::new(bare_source(&source_layout, 2.), ValueNode(0.5), &source_layout), ValueNode(0.5), &modified);
|
||||
assert_eq!(chain.layout(), Some(&stacked));
|
||||
let GPoll::Final(value) = chain.eval(&ctx) else {
|
||||
panic!("expected a final record");
|
||||
@@ -372,18 +367,6 @@ mod tests {
|
||||
assert!(error.kind == "negative factor");
|
||||
}
|
||||
|
||||
static FACTOR: f64 = 3.;
|
||||
|
||||
struct StaticLendNode(&'static f64);
|
||||
|
||||
impl<'e> Node<ContextImpl<'e>> for StaticLendNode {
|
||||
type Output = &'e f64;
|
||||
|
||||
fn eval(&self, _input: &ContextImpl<'e>) -> GPoll<&'e f64> {
|
||||
GPoll::Final(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lend_value_params_wire_into_record_kernels() {
|
||||
let arena = Arena::new(1024).unwrap();
|
||||
@@ -396,11 +379,7 @@ mod tests {
|
||||
let scaled = scale_layout(&modified);
|
||||
reserve_for(&[&source_layout, &modified, &scaled]);
|
||||
|
||||
let chain = ScaleNode::new(
|
||||
MultiplyOpacityNode::new(bare_source(&source_layout, 2.), ValueNode(0.5), &source_layout),
|
||||
StaticLendNode(&FACTOR),
|
||||
&modified,
|
||||
);
|
||||
let chain = ScaleNode::new(MultiplyOpacityNode::new(bare_source(&source_layout, 2.), ValueNode(0.5), &source_layout), ValueNode(3.), &modified);
|
||||
let GPoll::Final(value) = chain.eval(&ctx) else {
|
||||
panic!("expected a final record");
|
||||
};
|
||||
@@ -585,11 +564,7 @@ mod tests {
|
||||
reserve_for(&[&layout]);
|
||||
|
||||
let probed = |features: ContextFeatures| {
|
||||
let node = crate::context_modification::ContextModificationNode::new(
|
||||
RealTimeProbe { layout: layout.clone() },
|
||||
ValueNode(ContextModification::from_sources(features, &[])),
|
||||
&layout,
|
||||
);
|
||||
let node = crate::context_modification::ContextModificationNode::new(RealTimeProbe { layout: layout.clone() }, ValueNode(ContextModification::from_sources(features, &[])), &layout);
|
||||
assert_eq!(Node::<ContextImpl>::layout(&node), Some(&layout));
|
||||
let GPoll::Final(value) = node.eval(&ctx) else {
|
||||
panic!("expected a final record");
|
||||
|
||||
Reference in New Issue
Block a user