Derive extent forwarding for level-preserving passthroughs

This commit is contained in:
Dennis Kobert
2026-08-22 15:34:22 +00:00
parent 13cd718c90
commit 0b2aa3798a
9 changed files with 67 additions and 35 deletions

View File

@@ -1,9 +1,10 @@
use core_types::context::{ContextModification, Ctx, DeriveCtx};
use core_types::gpoll::Interrupt;
use core_types::extent::{ExtentIn, LevelIn, ValueIn};
use core_types::gpoll::{Extent, GPoll, Interrupt};
/// Filters out what should be unused components of the context based on the specified requirements.
/// This node is inserted by the compiler to "zero out" unused context components.
#[node_macro::node(category(""))]
#[node_macro::node(category(""), extent(context_modification_extent))]
fn context_modification<T>(
ctx: impl Ctx + DeriveCtx,
/// The data to pass through, evaluated with the stripped down context.
@@ -14,3 +15,7 @@ fn context_modification<T>(
let scope = ctx.scope().nullified(modification.features, Some(modification.sources()));
value.eval(&ctx.nullified(modification.features, &scope))
}
fn context_modification_extent(value: ExtentIn<'_>, _modification: ValueIn<'_, ContextModification>, level: LevelIn) -> GPoll<Extent> {
value.at(level)
}

View File

@@ -31,6 +31,6 @@ fn unwrap_option<T: Default>(_: impl Ctx, #[implementations(Option<f64>, Option<
/// 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 {
fn clone<T: Clone>(_: impl Ctx, #[implementations(Raster<CPU>, f64)] value: &T) -> T {
value.clone()
}

View File

@@ -99,7 +99,7 @@ fn frame_memo_extent(content: ExtentIn<'_>, level: LevelIn) -> GPoll<Extent> {
type MonitorValue = Arc<Mutex<Option<IORecord<CtxSnapshot, RecordCapture>>>>;
/// 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"))]
#[node_macro::node(category(""), path(graphene_core::memo), serialize(serialize_monitor), properties("monitor_properties"), extent(monitor_extent))]
fn monitor<'e>(
ctx: impl Ctx + DeriveCtx + ExtractAll + ExtractArena<'e> + InjectIndex + Copy,
#[data] io: MonitorValue,
@@ -126,6 +126,10 @@ fn monitor<'e>(
result
}
fn monitor_extent(content: ExtentIn<'_>, level: LevelIn) -> GPoll<Extent> {
content.at(level)
}
fn serialize_monitor(io: &MonitorValue) -> Option<Arc<dyn std::any::Any + Send + Sync>> {
let io = io.lock().unwrap();
io.as_ref().map(|io| Arc::new(io.clone()) as Arc<dyn std::any::Any + Send + Sync>)

View File

@@ -4,11 +4,15 @@ use core_types::{Ctx, ops::Convert, ops::ConvertAsync, transform::Footprint};
use std::marker::PhantomData;
/// Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes.
#[node_macro::node(category("General"), skip_impl)]
#[node_macro::node(category("General"), skip_impl, extent(passthrough_extent))]
fn passthrough<T: Send>(_: impl Ctx, content: T) -> T {
content
}
fn passthrough_extent(content: core_types::extent::ExtentIn<'_>, level: core_types::extent::LevelIn) -> core_types::gpoll::GPoll<core_types::gpoll::Extent> {
content.at(level)
}
#[node_macro::node(category(""), skip_impl)]
fn into<T: Send + Into<O>, O: Send>(_: impl Ctx, value: T, #[data] _out_ty: PhantomData<O>) -> O {
value.into()

View File

@@ -259,22 +259,6 @@ mod test {
};
}
#[test]
fn repeat_pushes_the_iteration_index_in_order() {
test_ctx!(ctx, cell);
let x_translations = |values: [f64; 3]| values.map(|x| DVec2::new(x, 0.)).to_vec();
let lift = RecordLift::<List<Vector>, _>::new(IndexProbe);
let layout = Node::<ContextImpl>::layout(&lift).clone();
let forward = super::repeat(&ctx, ElementLazyInput::new(&lift, &cell, 0, &layout), 3, false).unwrap();
assert_eq!(row_translations(&forward, ATTR_TRANSFORM), x_translations([0., 1., 2.]));
let reversed = super::repeat(&ctx, ElementLazyInput::new(&lift, &cell, 0, &layout), 3, true).unwrap();
assert_eq!(row_translations(&reversed, ATTR_TRANSFORM), x_translations([2., 1., 0.]));
}
#[test]
fn repeat_array_spaces_copies_along_the_direction() {
test_ctx!(ctx, cell);