mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Derive extent forwarding for level-preserving passthroughs
This commit is contained in:
@@ -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 = ®ular_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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user