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

@@ -1441,6 +1441,14 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
#core_types::node::Node::extent_at(&self.#name, __input, __level + #folded_levels)
}
}
} else if let Some(subject_index) = ir::forwarded_subject(&node).filter(|_| node.output.shape.depth == 0) {
// A level-preserving passthrough forwards its subject's extents.
let name = &regular_fields[subject_index].pat_ident.ident;
quote! {
fn extent_at(&self, __input: &#ctx_ident, __level: u8) -> #core_types::gpoll::GPoll<#core_types::gpoll::Extent> {
#core_types::node::Node::extent_at(&self.#name, __input, __level)
}
}
} else if node.output.shape.depth > 0 {
// A leveled output without an extent fn reports a lower bound;
// consumers size it by draining to the past-end signal.

View File

@@ -253,6 +253,24 @@ pub(crate) fn layout_meta_tokens(node: &Node, element_spec: TokenStream2, core_t
}
}
/// The single carried subject a level-preserving node forwards its extents
/// to: exactly one un-materialized subject, no level shift, and no fold.
pub(crate) fn forwarded_subject(node: &Node) -> Option<usize> {
if level_delta(node) != 0 || folded_subject(node).is_some() {
return None;
}
let mut sources = node
.inputs
.iter()
.enumerate()
.filter(|(index, input)| input.subject && materialized_levels(node, *index) == 0)
.map(|(index, _)| index);
match (sources.next(), sources.next()) {
(Some(index), None) => Some(index),
_ => None,
}
}
/// The materialized subject a node folds, as `(input, levels)`.
pub(crate) fn folded_subject(node: &Node) -> Option<(u8, u8)> {
node.inputs