Skip to content

Completed node output destructuring implementation#3806

Open
JustJ01 wants to merge 6 commits intoGraphiteEditor:masterfrom
JustJ01:finish-deconstruct-outputs
Open

Completed node output destructuring implementation#3806
JustJ01 wants to merge 6 commits intoGraphiteEditor:masterfrom
JustJ01:finish-deconstruct-outputs

Conversation

@JustJ01
Copy link
Contributor

@JustJ01 JustJ01 commented Feb 22, 2026

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @JustJ01, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request finalizes the implementation of node output destructuring, a feature that significantly enhances the granularity and flexibility of node interactions. By allowing complex struct outputs to be broken down into their constituent fields, it simplifies data flow and improves the usability of nodes within the graph, making it easier to connect specific data points without intermediate processing steps.

Highlights

  • Node Output Destructuring: Implemented the ability to deconstruct node outputs, allowing individual fields of a struct returned by a node to be exposed as separate outputs in the node graph.
  • New Destruct Trait: Introduced a Destruct trait in graphene-core to define how a struct's fields can be extracted and registered as node outputs.
  • Procedural Macro Support: Developed a new #[derive(Destruct)] procedural macro to automatically implement the Destruct trait for structs and generate corresponding field extractor nodes.
  • Node Metadata Extension: Extended the NodeMetadata struct to include a list of output_fields, providing registry information for destructured outputs.
Changelog
  • node-graph/gcore/src/registry.rs
    • Added output_fields to NodeMetadata struct to store information about destructured outputs.
    • Introduced StructField struct to represent metadata for individual fields.
    • Defined the Destruct trait, which types can implement to specify their destructurable fields.
  • node-graph/node-macro/src/codegen.rs
    • Modified generate_node_code to conditionally include output_fields in NodeMetadata based on the new deconstruct_output attribute.
    • Updated the protonode_identifier function to store &'static str directly in OnceLock for improved efficiency.
  • node-graph/node-macro/src/destruct.rs
    • Added a new module containing the implementation for the derive_destruct procedural macro.
    • Implemented logic to generate Destruct trait implementations for structs.
    • Included functionality to create individual extractor nodes for each field of a destructured struct.
    • Provided parsing for the #[output(name = "...")] attribute to allow custom naming of destructured outputs.
  • node-graph/node-macro/src/lib.rs
    • Integrated the new destruct module.
    • Registered the #[proc_macro_derive(Destruct)] attribute macro.
  • node-graph/node-macro/src/parsing.rs
    • Added a deconstruct_output field to the NodeFnAttributes struct.
    • Updated the parsing logic to recognize and process the deconstruct_output attribute for node functions.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Keavon
Copy link
Member

Keavon commented Feb 22, 2026

Please rebase on the latest upstream master.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces functionality for node output destructuring, allowing for the extraction of individual fields from a node's output. This involves adding output_fields to NodeMetadata, implementing a Destruct trait, and generating extractor nodes via a new destruct.rs module. The changes appear well-structured and integrate smoothly with the existing macro system. The OnceLock usage for protonode_identifier has been updated to correctly handle &'static str by leaking the boxed string, which is a common pattern for static string storage in Rust. The new deconstruct_output attribute in NodeFnAttributes provides a clear way to enable this feature for specific nodes.

@JustJ01 JustJ01 force-pushed the finish-deconstruct-outputs branch from e27f090 to e215927 Compare February 22, 2026 22:10
@TrueDoctor
Copy link
Member

Also, please configure your ai / editor / git to automatically run cargo fmt on save or pre commit

@JustJ01
Copy link
Contributor Author

JustJ01 commented Feb 23, 2026

@TrueDoctor I have made the requested changes which u asked for


#[cfg(feature = "std")]
#[node_macro::node(name("Split Channels"), category("Raster: Channels"), deconstruct_output)]
fn split_channels(_: impl Ctx, input: Table<Raster<CPU>>) -> SplitChannelsOutput {
Copy link
Contributor

@Ayush2k02 Ayush2k02 Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each call to extract_channel iterates over the entire raster. This means the image is traversed 4 times. Maybe do a single-pass implementation ?

Maybe do something like this

fn split_channels(_: impl Ctx, input: Table<Raster<CPU>>) -> SplitChannelsOutput {
    let (red, green, blue, alpha) = input.into_four_channels(); // hypothetical single-pass function
    SplitChannelsOutput { red, green, blue, alpha }
}

I can commit this function and implimentation if you'd like

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case we should not touch the split channels node at all since it makes the code less efficient, this was done as per Keavons request.

Comment on lines +55 to +58
static FIELDS: std::sync::OnceLock<Vec<#core_types::registry::StructField>> = std::sync::OnceLock::new();
FIELDS.get_or_init(|| vec![
#(#output_fields,)*
]).as_slice()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use heap memory + syncronization here instead of constructing a slice in place?


fn generate_extractor_node(core_types: &TokenStream2, fn_name: &syn::Ident, struct_name: &syn::Ident, field_name: &syn::Ident, ty: &Type, output_name: &LitStr) -> TokenStream2 {
quote! {
#[node_macro::node(category(""), name(#output_name))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add the name() annotation here?

Comment on lines +73 to +114
fn parse_output_name(attrs: &[syn::Attribute]) -> syn::Result<Option<String>> {
let mut output_name = None;

for attr in attrs {
if !attr.path().is_ident("output") {
continue;
}

let mut this_output_name = None;
match &attr.meta {
Meta::Path(_) => {
return Err(Error::new_spanned(attr, "Expected output metadata like #[output(name = \"Result\")]"));
}
Meta::NameValue(_) => {
return Err(Error::new_spanned(attr, "Expected output metadata like #[output(name = \"Result\")]"));
}
Meta::List(_) => {
attr.parse_nested_meta(|meta| {
if meta.path.is_ident("name") {
if this_output_name.is_some() {
return Err(meta.error("Multiple output names provided for one field"));
}
let value = meta.value()?;
let lit: LitStr = value.parse()?;
this_output_name = Some(lit.value());
Ok(())
} else {
Err(meta.error("Unsupported output metadata. Supported syntax is #[output(name = \"...\")]"))
}
})?;
}
}

let this_output_name = this_output_name.ok_or_else(|| Error::new_spanned(attr, "Missing output name. Use #[output(name = \"...\")]"))?;
if output_name.is_some() {
return Err(Error::new_spanned(attr, "Multiple #[output(...)] attributes are not allowed on one field"));
}
output_name = Some(this_output_name);
}

Ok(output_name)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function only used for overriding the field name? I don't think this code is currently used anywhere right? If it is indeed not used, it should be removed to reduce the code complexity

Comment on lines +140 to +145
let use_memo = !available_output_fields.is_empty()
&& node_registry.get(&memo_node).is_some_and(|memo_implementations| {
memo_implementations
.iter()
.any(|(_, node_io)| node_io.call_argument == *input_type && node_io.return_value == first_node_io.return_value)
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use_memo will currently always be false since you did not the new structs to the memo node implementations

inputs: vec![NodeInput::node(source_node_id, 0)],
call_argument: input_type.clone(),
implementation: DocumentNodeImplementation::ProtoNode(memo_node.clone()),
visible: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need to set visible to false since the entire network is hidden anyway

DocumentNode {
inputs: vec![NodeInput::node(source_node_id, 0)],
call_argument: input_type.clone(),
implementation: DocumentNodeImplementation::ProtoNode(memo_node.clone()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we get a static string for the identifier? why do we need heap allocations here?

@TrueDoctor
Copy link
Member

@cubic-dev-ai

@cubic-dev-ai
Copy link

cubic-dev-ai bot commented Mar 8, 2026

@cubic-dev-ai

@TrueDoctor I have started the AI code review. It will take a few minutes to complete.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 10 files


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

@Keavon Keavon force-pushed the master branch 2 times, most recently from 5bb6104 to 52d2b38 Compare March 9, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants