diff --git a/document/graph-storage/src/attributes/attr.rs b/document/graph-storage/src/attributes/attr.rs index 5e78c1a47f8..4fd1055cebd 100644 --- a/document/graph-storage/src/attributes/attr.rs +++ b/document/graph-storage/src/attributes/attr.rs @@ -1,7 +1,6 @@ pub mod node { pub const CALL_ARGUMENT: &str = "call_argument"; pub const VISIBLE: &str = "visible"; - pub const SKIP_DEDUPLICATION: &str = "skip_deduplication"; pub const REFLECTION_METADATA: &str = "reflection_metadata"; pub mod input { diff --git a/document/graph-storage/src/from_runtime.rs b/document/graph-storage/src/from_runtime.rs index 81ff9e7a0af..35bcd4a4fe0 100644 --- a/document/graph-storage/src/from_runtime.rs +++ b/document/graph-storage/src/from_runtime.rs @@ -382,9 +382,6 @@ fn convert_node( attributes .set_if_not_default(node::VISIBLE, &doc_node.visible, &true, timestamp) .map_err(map_serialization_error(node::VISIBLE))?; - attributes - .set_if_not_default(node::SKIP_DEDUPLICATION, &doc_node.skip_deduplication, &false, timestamp) - .map_err(map_serialization_error(node::SKIP_DEDUPLICATION))?; write_ui_attributes(&mut attributes, ctx.metadata, network, runtime_node_id, timestamp)?; diff --git a/document/graph-storage/src/tests/round_trip.rs b/document/graph-storage/src/tests/round_trip.rs index 4b29a1ca7f0..8efddb3ed3a 100644 --- a/document/graph-storage/src/tests/round_trip.rs +++ b/document/graph-storage/src/tests/round_trip.rs @@ -260,8 +260,7 @@ fn test_metadata_preservation() { inputs: vec![NodeInput::import(concrete!(f64), 0), NodeInput::import(Type::Generic(Cow::Borrowed("T")), 1)], implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("test::NodeWithMetadata")), call_argument: concrete!(String), - visible: false, // Non-default value - skip_deduplication: true, // Non-default value + visible: false, // Non-default value ..Default::default() }, ), @@ -296,9 +295,6 @@ fn test_metadata_preservation() { // Verify visible is preserved assert_eq!(orig_node_0.visible, conv_node_0.visible, "visible should be preserved"); - // Verify skip_deduplication is preserved - assert_eq!(orig_node_0.skip_deduplication, conv_node_0.skip_deduplication, "skip_deduplication should be preserved"); - // Verify import_type is preserved for Import inputs match (&orig_node_0.inputs[0], &conv_node_0.inputs[0]) { (NodeInput::Import { import_type: orig_type, .. }, NodeInput::Import { import_type: conv_type, .. }) => { @@ -354,11 +350,6 @@ fn test_demo_artwork_round_trip() { artwork_name, node_id ); assert_eq!(orig_node.visible, conv_node.visible, "{}: visible should be preserved for node {:?}", artwork_name, node_id); - assert_eq!( - orig_node.skip_deduplication, conv_node.skip_deduplication, - "{}: skip_deduplication should be preserved for node {:?}", - artwork_name, node_id - ); // Check input count assert_eq!( diff --git a/document/graph-storage/src/to_runtime.rs b/document/graph-storage/src/to_runtime.rs index 115c81b0a1d..7d1124a5dd0 100644 --- a/document/graph-storage/src/to_runtime.rs +++ b/document/graph-storage/src/to_runtime.rs @@ -457,7 +457,6 @@ fn convert_node(context: &ConversionContext, node: &crate::Node) -> Result @2); +// The removed Monitor node passes its one input on, as a Passthrough does +rename!("graphene_core::memo::MonitorNode"@1 => "graphene_core::ops::PassthroughNode"@2); diff --git a/editor/src/messages/portfolio/document/document_diff.rs b/editor/src/messages/portfolio/document/document_diff.rs index 9eb8f1b7bb5..eec11095813 100644 --- a/editor/src/messages/portfolio/document/document_diff.rs +++ b/editor/src/messages/portfolio/document/document_diff.rs @@ -262,9 +262,6 @@ fn diff_document_node(out: &mut String, expected: &graph_craft::document::Docume if expected.visible != actual.visible { let _ = writeln!(out, " visible: expected={} actual={}", expected.visible, actual.visible); } - if expected.skip_deduplication != actual.skip_deduplication { - let _ = writeln!(out, " skip_deduplication: expected={} actual={}", expected.skip_deduplication, actual.skip_deduplication); - } if expected.compile_metadata != actual.compile_metadata { let _ = writeln!(out, " compile_metadata: expected={:?} actual={:?}", expected.compile_metadata, actual.compile_metadata); } diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 02c5b824498..bdcdaeac493 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -4894,7 +4894,7 @@ mod document_message_handler_tests { } // Merging nodes whose output isn't wired downstream produces an encapsulating subnetwork with no exports. - // Inspecting it via the Data panel (which splices in a monitor node) must not leave a dangling reference that crashes compilation. + // Inspecting it via the Data panel must not leave a dangling reference that crashes compilation. #[tokio::test] async fn merge_selected_nodes_while_inspecting_does_not_crash() { let mut editor = EditorTestUtils::create(); @@ -4909,7 +4909,7 @@ mod document_message_handler_tests { let merged = editor.active_document().network_interface.selected_nodes_in_nested_network(&[]).unwrap().0.clone(); assert_eq!(merged.len(), 1, "merge should leave one encapsulating node selected"); - // Simulate the Data panel inspecting the merged node, which compiles the graph with a monitor node spliced in + // Simulate the Data panel inspecting the merged node let portfolio = &mut editor.editor.dispatcher.message_handlers.portfolio_message_handler; let document_id = portfolio.active_document_id.unwrap(); let document = portfolio.documents.get_mut(&document_id).unwrap(); diff --git a/editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs b/editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs index d3daee0c602..3582d70b9c5 100644 --- a/editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs +++ b/editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs @@ -802,10 +802,6 @@ fn static_node_inspector() -> NodeInspector { map.insert("grid_inspector".to_string(), Box::new(node_inspector::grid_inspector)); map.insert("spiral_inspector".to_string(), Box::new(node_inspector::spiral_inspector)); map.insert("sample_polyline_inspector".to_string(), Box::new(node_inspector::sample_polyline_inspector)); - map.insert( - "monitor_inspector".to_string(), - Box::new(|_node_id, _context| node_inspector::string_inspector("Used internally by the editor to read the data passing through it.")), - ); map } diff --git a/editor/src/messages/portfolio/document/node_graph/document_node_definitions/document_node_derive.rs b/editor/src/messages/portfolio/document/node_graph/document_node_definitions/document_node_derive.rs index 78793f346a3..8687c4da03d 100644 --- a/editor/src/messages/portfolio/document/node_graph/document_node_definitions/document_node_derive.rs +++ b/editor/src/messages/portfolio/document/node_graph/document_node_definitions/document_node_derive.rs @@ -23,7 +23,7 @@ pub(super) fn post_process_nodes(custom: Vec) -> HashMap // Add the rest of the protonodes from the macro. // Typed nodes are registered in `core_types::NODE_REGISTRY` via the macro's auto-generated `register_node` codegen. - // `skip_impl` nodes (e.g. Cache, Monitor) bypass that registration but are wired up manually in + // `skip_impl` nodes (e.g. Cache) bypass that registration but are wired up manually in // `interpreted_executor::node_registry::NODE_REGISTRY` via `async_node!`. We consult that extended registry as a // fallback when deriving `call_argument` so it reflects the impls actually registered, which will usually be `Context`. let extended_node_registry = &*interpreted_executor::node_registry::NODE_REGISTRY; diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/queries.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/queries.rs index 5b537d04921..9f5fd8f6e62 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/queries.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/queries.rs @@ -1222,7 +1222,6 @@ impl NodeNetworkInterface { node.inputs = old_node.inputs; node.call_argument = old_node.manual_composition.unwrap_or_default(); node.visible = old_node.visible; - node.skip_deduplication = old_node.skip_deduplication; node.original_location = old_node.original_location; node_metadata.persistent_metadata.display_name = old_node.alias; node_metadata.persistent_metadata.locked = old_node.locked; diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/reconcile.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/reconcile.rs index 5f2009eb6b5..958f9fbfa04 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/reconcile.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/reconcile.rs @@ -221,7 +221,7 @@ impl NodeNetworkInterface { return; }; - let deltas = if current.implementation == target.implementation && current.skip_deduplication == target.skip_deduplication { + let deltas = if current.implementation == target.implementation { field_deltas(location, local_id, (current, current_metadata), (&target, &target_metadata)) } else { vec![ diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/resolved_types.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/resolved_types.rs index 5c29530c200..806f1a08b13 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/resolved_types.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/resolved_types.rs @@ -61,7 +61,7 @@ static INPUT_CONVERSIONS: Lazy> = Lazy::new(|| { NODE_REGISTRY .iter() @@ -420,7 +420,7 @@ impl NodeNetworkInterface { } /// A check of which wire types an input accepts, built once so testing many types searches the node's matching implementations only once. - /// Unlike [`Self::input_accepts_type`], a node passing its input's type through unchanged (like Monitor) also needs the inputs it feeds to accept the type. + /// Unlike [`Self::input_accepts_type`], a node passing its input's type through unchanged (like Memoize) also needs the inputs it feeds to accept the type. fn type_acceptor(&self, input_connector: &InputConnector, network_path: &[NodeId]) -> Box bool> { let accepts_here: Box bool> = match input_connector { InputConnector::Export(export_index) => match network_path.split_last() { diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface/template.rs b/editor/src/messages/portfolio/document/utility_types/network_interface/template.rs index 4fc43914e88..c5ed3bde941 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface/template.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface/template.rs @@ -21,8 +21,6 @@ pub struct NodeTemplate { pub implementation: NodeTemplateImplementation, /// Represents the eye icon for hiding/showing the node in the graph UI. pub visible: bool, - /// Prevents identical proto nodes from being deduplicated during compilation, e.g. for monitor nodes. - pub skip_deduplication: bool, /// A name chosen by the user for this instance of the node. Empty indicates no given name, in which case the implementation name is displayed in italics. pub display_name: String, /// Metadata to override the Inspector widgets for each input. Kept the same length as `inputs`. @@ -57,7 +55,6 @@ impl Default for NodeTemplate { call_argument: concrete!(Context), implementation: NodeTemplateImplementation::default(), visible: true, - skip_deduplication: false, display_name: String::new(), input_metadata: Vec::new(), output_names: Vec::new(), @@ -110,7 +107,6 @@ impl NodeTemplate { call_argument, implementation, visible, - skip_deduplication, compile_metadata: _, original_location: _, } = document_node; @@ -161,7 +157,6 @@ impl NodeTemplate { call_argument, implementation, visible, - skip_deduplication, display_name, input_metadata, output_names, @@ -179,7 +174,6 @@ impl NodeTemplate { call_argument, implementation, visible, - skip_deduplication, display_name, mut input_metadata, mut output_names, @@ -211,7 +205,6 @@ impl NodeTemplate { call_argument, implementation, visible, - skip_deduplication, compile_metadata: None, original_location: Default::default(), }; diff --git a/editor/src/messages/portfolio/document_migration.rs b/editor/src/messages/portfolio/document_migration.rs index 45c7c83a63a..c7e566911be 100644 --- a/editor/src/messages/portfolio/document_migration.rs +++ b/editor/src/messages/portfolio/document_migration.rs @@ -117,10 +117,6 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[ "raster_nodes::std_nodes::SampleImageNode", ], }, - NodeReplacement { - node: graphene_std::memo::monitor::IDENTIFIER, - aliases: &["graphene_core::memo::MonitorNode"], - }, NodeReplacement { node: graphene_std::memo::memoize::IDENTIFIER, aliases: &["graphene_core::memo::MemoNode", "graphene_core::memo::ImpureMemoNode"], @@ -1163,6 +1159,14 @@ pub fn document_migration_replace_resources_referenced_by_hash(document_serializ (out, hash_to_id) } +/// The removed Monitor node, which old documents still hold. +const MONITOR_IDENTIFIER: ProtoNodeIdentifier = ProtoNodeIdentifier::new("graphene_core::memo::MonitorNode"); + +/// Whether the implementation is the removed Monitor node, with or without the type arguments it was once stored with. +fn is_monitor(implementation: &DocumentNodeImplementation) -> bool { + matches!(implementation, DocumentNodeImplementation::ProtoNode(identifier) if identifier.as_str().split('<').next() == Some(MONITOR_IDENTIFIER.as_str())) +} + /// Whether the node is a subgraph that feeds its first input through a Monitor into a Transform proto node and forwards the other four inputs unchanged, making it equivalent to a bare Transform node. fn is_monitored_transform_subgraph(node: &DocumentNode, document_network: &graph_craft::document::NodeNetwork) -> bool { let Some(network) = document_network.implementation_network(&node.implementation) else { @@ -1178,7 +1182,7 @@ fn is_monitored_transform_subgraph(node: &DocumentNode, document_network: &graph _ => false, }) }; - let Some((monitor_id, monitor)) = find_proto_node(&graphene_std::memo::monitor::IDENTIFIER) else { + let Some((monitor_id, monitor)) = find_proto_node(&MONITOR_IDENTIFIER) else { return false; }; let Some((transform_id, transform)) = find_proto_node(&graphene_std::transform_nodes::transform::IDENTIFIER) else { @@ -1404,8 +1408,7 @@ pub fn document_migration_upgrades(document: &mut DocumentMessageHandler, reset_ let reference = document.network_interface.reference(node_id, &path)?; let is_merge_or_artboard = [DefinitionIdentifier::Network("Merge".into()), DefinitionIdentifier::Network("Artboard".into())].contains(&reference); - let monitor = DocumentNodeImplementation::ProtoNode(graphene_std::memo::monitor::IDENTIFIER); - let has_monitor = network.nodes.values().any(|inner_node| inner_node.implementation == monitor); + let has_monitor = network.nodes.values().any(|inner_node| is_monitor(&inner_node.implementation)); (is_merge_or_artboard && has_monitor).then_some((*node_id, path, reference)) }) @@ -1415,6 +1418,23 @@ pub fn document_migration_upgrades(document: &mut DocumentMessageHandler, reset_ document.network_interface.replace_implementation(node_id, network_path, &mut definition.default_node_template()); } + // Any Monitor still left becomes a Passthrough of its content, once the passes above have used it to recognize old networks + let monitors: Vec<(NodeId, Vec)> = document + .network_interface + .document_network() + .recursive_nodes() + .filter(|(_, node, _)| is_monitor(&node.implementation)) + .map(|(node_id, _, path)| (*node_id, path)) + .collect(); + for (node_id, network_path) in &monitors { + let mut passthrough = NodeTemplate { + implementation: NodeTemplateImplementation::ProtoNode(graphene_std::ops::passthrough::IDENTIFIER), + ..Default::default() + }; + document.network_interface.replace_implementation(node_id, network_path, &mut passthrough); + document.network_interface.set_call_argument(node_id, network_path, passthrough.call_argument); + } + // The old "Math" node evaluated an expression over "A" and "B". A lexable static expression not reading a wired `B` becomes "Math Function" // with `A` as `x` and a constant `B` inlined. Anything else becomes "Extend" feeding "Math Formula", which reads the pair as `a` and `b`. let math_nodes: Vec<(NodeId, Vec, Vec)> = document @@ -4941,7 +4961,7 @@ mod tests { let content = std::mem::replace(&mut extend.inputs[1], NodeInput::node(monitor_id, 0)); let monitor_template = NodeTemplate { inputs: vec![content], - implementation: NodeTemplateImplementation::ProtoNode(graphene_std::memo::monitor::IDENTIFIER), + implementation: NodeTemplateImplementation::ProtoNode(MONITOR_IDENTIFIER), ..Default::default() }; network_template.nodes.insert(monitor_id, monitor_template); @@ -4956,14 +4976,34 @@ mod tests { else { panic!("{name} should stay a network node") }; - let monitor = DocumentNodeImplementation::ProtoNode(graphene_std::memo::monitor::IDENTIFIER); - assert!( - network.nodes.values().all(|inner_node| inner_node.implementation != monitor), - "{name} should no longer have a Monitor node" - ); + // A Monitor left in place would become a Passthrough, so only the rebuilt network has the definition's node count + let NodeTemplateImplementation::Network(shipped) = resolve_network_node_type(name).expect("The definition should exist").default_node_template().implementation else { + panic!("{name} should be a network node") + }; + assert_eq!(network.nodes.len(), shipped.nodes.len(), "{name} should be rebuilt from its definition, without the Monitor node"); } } + // The removed Monitor node keeps passing on its content wherever it's left + #[test] + fn a_monitor_node_becomes_a_passthrough() { + let node_id = NodeId(1); + let mut document = DocumentMessageHandler::default(); + let content = NodeInput::value(TaggedValue::Number(42.), false); + let monitor_template = NodeTemplate { + inputs: vec![content.clone()], + implementation: NodeTemplateImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::memo::MonitorNode<_, _, _>")), + ..Default::default() + }; + document.network_interface.insert_node(node_id, monitor_template, &[]); + + migrate(&mut document); + + let node = &document.network_interface.document_network().nodes[&node_id]; + assert_eq!(node.implementation, DocumentNodeImplementation::ProtoNode(graphene_std::ops::passthrough::IDENTIFIER)); + assert_eq!(node.inputs, [content]); + } + // Regex Find's Match Index is now an integer, so an old instance rounds its stored F64 index and rebuilds the subgraph // that fed the decimal index to its two item-at-index nodes #[test] diff --git a/editor/src/messages/tool/common_functionality/shapes/ellipse_shape.rs b/editor/src/messages/tool/common_functionality/shapes/ellipse_shape.rs index 6db48fc6714..8b031b2ac92 100644 --- a/editor/src/messages/tool/common_functionality/shapes/ellipse_shape.rs +++ b/editor/src/messages/tool/common_functionality/shapes/ellipse_shape.rs @@ -76,8 +76,8 @@ mod test_ellipse { let node_graph_layer = NodeGraphLayer::new(layer, &document.network_interface); let ellipse_node = node_graph_layer.upstream_node_id_from_protonode(ellipse::IDENTIFIER)?; Some(ResolvedEllipse { - radius_x: instrumented.grab_ranked_input::(&vec![ellipse_node], &editor.runtime).unwrap(), - radius_y: instrumented.grab_ranked_input::(&vec![ellipse_node], &editor.runtime).unwrap(), + radius_x: instrumented.grab_ranked_input::(&[ellipse_node], &editor.runtime).unwrap(), + radius_y: instrumented.grab_ranked_input::(&[ellipse_node], &editor.runtime).unwrap(), transform: document.metadata().transform_to_document(layer), }) }) diff --git a/editor/src/messages/tool/tool_messages/fill_tool.rs b/editor/src/messages/tool/tool_messages/fill_tool.rs index e399351ba0c..522dbd2db20 100644 --- a/editor/src/messages/tool/tool_messages/fill_tool.rs +++ b/editor/src/messages/tool/tool_messages/fill_tool.rs @@ -280,18 +280,25 @@ fn whole_expanse_rect(layer: LayerNodeIdentifier, document: &DocumentMessageHand #[cfg(test)] mod test_fill { pub use crate::test_utils::test_prelude::*; + use graphene_std::Graphic; use graphene_std::color::SRGBA8; use graphene_std::list::Item; use graphene_std::vector::fill; - // The Fill tool writes solid colors, whose stored values the input monitor records as `Item` wires + // The Fill tool writes solid colors, which reach the paint input embedded as `Graphic` items async fn get_fills(editor: &mut EditorTestUtils) -> Vec> { let instrumented = match editor.eval_graph_until_finished().await { Ok(instrumented) => instrumented, Err(e) => panic!("Failed to evaluate graph: {e}"), }; - instrumented.grab_all_input::>(&editor.runtime).collect() + instrumented + .grab_all_input::>(&editor.runtime) + .filter_map(|paint| match paint.into_element() { + Graphic::Color(color) => Some(color), + _ => None, + }) + .collect() } #[tokio::test] diff --git a/editor/src/node_graph_executor.rs b/editor/src/node_graph_executor.rs index 44dd518293a..983adaeab1f 100644 --- a/editor/src/node_graph_executor.rs +++ b/editor/src/node_graph_executor.rs @@ -243,14 +243,14 @@ impl NodeGraphExecutor { .expect("Failed to send the thumbnails in view"); } - /// Updates the network to monitor all inputs. Useful for the testing. + /// Updates the network, giving back the paths of its proto nodes so tests can read what their inputs received. #[cfg(test)] pub(crate) fn update_node_graph_instrumented(&mut self, document: &mut DocumentMessageHandler) -> Result { // We should always invalidate the cache. self.node_graph_hash = crate::application::generate_uuid(); let mut network = document.network_interface.document_network().clone(); network.inline_definitions().map_err(|error| error.to_string())?; - let instrumented = Instrumented::new(&mut network); + let instrumented = Instrumented::new(&network); let resources = document.resources.registry.clone(); @@ -1218,120 +1218,73 @@ pub use test::Instrumented; #[cfg(test)] mod test { - use std::sync::Arc; - use super::*; use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface; use crate::test_utils::test_prelude::{self, NodeGraphLayer}; use graph_craft::ProtoNodeIdentifier; - use graph_craft::document::{DocumentNode, NodeNetwork}; - use graphene_std::Context; + use graph_craft::document::NodeNetwork; use graphene_std::NodeParameter; use graphene_std::list::Item; - use graphene_std::memo::IORecord; use test_prelude::LayerNodeIdentifier; - /// Stores all of the monitor nodes that have been attached to a graph + /// The path of each proto node in an evaluated graph, by which tests read the values its inputs received. #[derive(Default)] pub struct Instrumented { - protonodes_by_name: HashMap>>>, - protonodes_by_path: HashMap, Vec>>, + protonodes_by_name: HashMap>>, } impl Instrumented { - /// Adds montior nodes to the network - fn add(&mut self, network: &mut NodeNetwork, path: &mut Vec) { - // Required to do seperately to satiate the borrow checker. - let mut monitor_nodes = Vec::new(); - for (id, node) in network.nodes.iter_mut() { - // Recursively instrument - if let DocumentNodeImplementation::Network(nested) = &mut node.implementation { - path.push(*id); - self.add(nested, path); - path.pop(); - } - let mut monitor_node_ids = Vec::with_capacity(node.inputs.len()); - for input in &mut node.inputs { - let node_id = NodeId::new(); - path.push(node_id); - monitor_node_ids.push(path.clone()); - path.pop(); - - // A None value has nothing to record and a reflection must stay on the node it describes, so such a slot stays a dead path that introspects as absent - let is_none = matches!(input, NodeInput::Value { tagged_value, .. } if matches!(&**tagged_value, graph_craft::document::value::TaggedValue::None)); - if is_none || matches!(input, NodeInput::Reflection(_)) { - continue; - } - - let old_input = std::mem::replace(input, NodeInput::node(node_id, 0)); - monitor_nodes.push((old_input, node_id)); - } - if let DocumentNodeImplementation::ProtoNode(identifier) = &mut node.implementation { - path.push(*id); - self.protonodes_by_name.entry(identifier.clone()).or_default().push(monitor_node_ids.clone()); - self.protonodes_by_path.insert(path.clone(), monitor_node_ids); - path.pop(); + /// Records the path of each proto node in the network and the networks nested in it. + fn add(&mut self, network: &NodeNetwork, path: &mut Vec) { + for (id, node) in &network.nodes { + path.push(*id); + match &node.implementation { + DocumentNodeImplementation::Network(nested) => self.add(nested, path), + DocumentNodeImplementation::ProtoNode(identifier) => self.protonodes_by_name.entry(identifier.clone()).or_default().push(path.clone()), + _ => {} } - } - for (input, monitor_id) in monitor_nodes { - let monitor_node = DocumentNode { - inputs: vec![input], - implementation: DocumentNodeImplementation::ProtoNode(graphene_std::memo::monitor::IDENTIFIER), - call_argument: graph_craft::generic!(T), - skip_deduplication: true, - ..Default::default() - }; - network.nodes.insert(monitor_id, monitor_node); + path.pop(); } } - /// Instrument a graph and return a new [Instrumented] state. - pub fn new(network: &mut NodeNetwork) -> Self { + pub fn new(network: &NodeNetwork) -> Self { let mut instrumented = Self::default(); instrumented.add(network, &mut Vec::new()); instrumented } - /// Pulls a concrete output type out of a monitor record, tolerating the three context shapes the executor records against. - fn downcast_record(dynamic: Arc) -> Option { - if let Some(x) = dynamic.downcast_ref::>() { - Some(x.output.clone()) - } else if let Some(x) = dynamic.downcast_ref::>() { - Some(x.output.clone()) - } else { - dynamic.downcast_ref::>().map(|x| x.output.clone()) - } + /// Reads the value an input of the proto node at this path received, if it has the `Output` type. + /// Only the value types the Data panel can show come through. + fn grab_input(path: &[NodeId], input_index: usize, runtime: &NodeRuntime) -> Option { + let observation = Observation { + node_path: path.to_vec(), + connector: ObservedConnector::Input(input_index), + overrides: ContextOverrides::default(), + }; + runtime.observe(observation)?.downcast_ref::().cloned() } - /// Grab all of the values of the input every time it occurs in the graph, downcast to the recorded `Output` type. - /// A record whose type does not match `Output` is skipped, so a wrong `Output` yields an empty iterator rather than an error. - pub fn grab_all_input<'a, Input: NodeParameter + 'a, Output: Send + Sync + Clone + 'static>(&'a self, runtime: &'a NodeRuntime) -> impl Iterator + 'a { + /// Grab all of the values of the input every time it occurs in the graph, downcast to the received `Output` type. + /// A value whose type does not match `Output` is skipped, so a wrong `Output` yields an empty iterator rather than an error. + pub fn grab_all_input<'a, Input: NodeParameter + 'a, Output: Clone + 'static>(&'a self, runtime: &'a NodeRuntime) -> impl Iterator + 'a { self.protonodes_by_name .get(&Input::NODE_IDENTIFIER) - .map_or([].as_slice(), |x| x.as_slice()) + .map_or([].as_slice(), |paths| paths.as_slice()) .iter() - .filter_map(|inputs| inputs.get(Input::INDEX)) - .filter_map(|input_monitor_node| runtime.executor.introspect(input_monitor_node).ok()) - .filter_map(Instrumented::downcast_record::) + .filter_map(|path| Self::grab_input::(path, Input::INDEX, runtime)) } - pub fn grab_protonode_input(&self, path: &Vec, runtime: &NodeRuntime) -> Option { - let input_monitor_node = self.protonodes_by_path.get(path)?.get(Input::INDEX)?; - - let dynamic = runtime.executor.introspect(input_monitor_node).ok()?; - - Self::downcast_record::(dynamic) + pub fn grab_protonode_input(&self, path: &[NodeId], runtime: &NodeRuntime) -> Option { + Self::grab_input::(path, Input::INDEX, runtime) } - /// Grabs a ranked input's recorded value as its bare element `Element`. - /// A stored value materializes as an `Item` wire, so the monitor records the whole cell and this unwraps its element. - pub fn grab_ranked_input(&self, path: &Vec, runtime: &NodeRuntime) -> Option { - let input_monitor_node = self.protonodes_by_path.get(path)?.get(Input::INDEX)?; - let dynamic = runtime.executor.introspect(input_monitor_node).ok()?; - Self::downcast_record::>(dynamic).map(|item| item.into_element()) + /// Grabs a ranked input's received value as its bare element `Element`. + /// A stored value materializes as an `Item` wire, so the input receives the whole cell and this unwraps its element. + pub fn grab_ranked_input(&self, path: &[NodeId], runtime: &NodeRuntime) -> Option { + Self::grab_input::>(path, Input::INDEX, runtime).map(Item::into_element) } - pub fn grab_input_from_layer( + pub fn grab_input_from_layer( &self, layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface, @@ -1339,7 +1292,7 @@ mod test { ) -> Option { let node_graph_layer = NodeGraphLayer::new(layer, network_interface); let node = node_graph_layer.upstream_node_id_from_protonode(Input::NODE_IDENTIFIER)?; - self.grab_protonode_input::(&vec![node], runtime) + self.grab_protonode_input::(&[node], runtime) } } } diff --git a/editor/src/node_graph_executor/recompile_tests.rs b/editor/src/node_graph_executor/recompile_tests.rs index 8c5801ee60f..c395f3b7bf0 100644 --- a/editor/src/node_graph_executor/recompile_tests.rs +++ b/editor/src/node_graph_executor/recompile_tests.rs @@ -19,7 +19,7 @@ async fn compile_and_run(editor: &mut EditorTestUtils) { } /// The proto node IDs compiled for the document node paths that pass `keep`. The executor keeps the nodes an update drops -/// for one more update, so a first update clears those of the test harness's instrumented graph. +/// for one more update, so a first update clears those of the graph before it. async fn compiled_ids(editor: &mut EditorTestUtils, keep: impl Fn(&[NodeId]) -> bool) -> HashSet { compile_and_run(editor).await; compile_and_run(editor).await; diff --git a/editor/src/node_graph_executor/runtime.rs b/editor/src/node_graph_executor/runtime.rs index ad302392091..5f5845ad1b5 100644 --- a/editor/src/node_graph_executor/runtime.rs +++ b/editor/src/node_graph_executor/runtime.rs @@ -390,6 +390,14 @@ impl NodeRuntime { self.sender.send(NodeGraphUpdate::ExecutionResponse(Box::new(response))).expect("Failed to send response"); } + /// Reads one observation from the last evaluation, apart from the observations the runtime keeps. + #[cfg(test)] + pub(crate) fn observe(&self, observation: Observation) -> Option { + let mut observer = Observer::default(); + observer.set((), Some(observation)); + observer.evaluate(&self.executor, self.old_graph.as_ref()).remove(&())?.data + } + async fn read_back(&self, texture: Texture) -> Raster { let application_io = self.editor_api.application_io.as_ref().unwrap(); let executor = application_io.gpu_executor().expect("GPU executor should be available when we receive a texture"); diff --git a/node-graph/README.md b/node-graph/README.md index b63e711937b..01a82ab0c03 100644 --- a/node-graph/README.md +++ b/node-graph/README.md @@ -14,7 +14,6 @@ pub struct DocumentNode { pub call_argument: Type, pub implementation: DocumentNodeImplementation, pub visible: bool, - pub skip_deduplication: bool, pub compile_metadata: Option, pub original_location: OriginalLocation, } @@ -139,7 +138,7 @@ When the document graph is executed, the following steps occur: - The constructor functions are run with the `ConstructionArgs` enum. Constructors generally evaluate the result of these inputs, e.g. if you have a `Pi` node that is used as the second input to an `Add` node, the `Add` node's constructor will evaluate the `Pi` node. This is visible if you place a log statement in the `Pi` node's implementation. - The resolved functions are stored in a `BorrowTree`, which allows previous proto-nodes to be referenced as inputs by later nodes. The `BorrowTree` ensures nodes can't be removed while being referenced by other nodes. -The registry rows for a node declared with the `node` macro are generated by it, one per `#[implementations(...)]` pairing. The rows written by hand in `node_registry.rs` are for the adapters that convert between wire types and for executor-internal nodes such as the memoize and monitor nodes. +The registry rows for a node declared with the `node` macro are generated by it, one per `#[implementations(...)]` pairing. The rows written by hand in `node_registry.rs` are for the adapters that convert between wire types and for executor-internal nodes such as the memoize nodes. ## Debugging diff --git a/node-graph/graph-craft/src/compiler/flatten.rs b/node-graph/graph-craft/src/compiler/flatten.rs index 488f5a832df..054d3b8854f 100644 --- a/node-graph/graph-craft/src/compiler/flatten.rs +++ b/node-graph/graph-craft/src/compiler/flatten.rs @@ -29,7 +29,7 @@ impl DocumentNode { } impl NodeNetwork { - /// Populate the [`DocumentNode::path`], which stores the location of the document node to allow for matching the resulting proto nodes to the document node for the purposes of typing and finding monitor nodes. + /// Populate the [`DocumentNode::path`], which stores the location of the document node to allow for matching the resulting proto nodes to the document node for the purposes of typing and observing node values. /// /// Table entries are not visited, since each instance gets its paths when [`Self::flatten`] copies the entry. pub fn generate_node_paths(&mut self, prefix: &[NodeId]) { diff --git a/node-graph/graph-craft/src/compiler/lowering.rs b/node-graph/graph-craft/src/compiler/lowering.rs index b14f196f5c7..9da36994284 100644 --- a/node-graph/graph-craft/src/compiler/lowering.rs +++ b/node-graph/graph-craft/src/compiler/lowering.rs @@ -28,7 +28,6 @@ impl DocumentNode { call_argument: self.call_argument, construction_args, original_location: self.original_location, - skip_deduplication: self.skip_deduplication, compile_metadata: self.compile_metadata.unwrap_or_default(), upstream_context_features: Default::default(), } diff --git a/node-graph/graph-craft/src/document.rs b/node-graph/graph-craft/src/document.rs index 3a05fdc3b7b..4d2908edc5d 100644 --- a/node-graph/graph-craft/src/document.rs +++ b/node-graph/graph-craft/src/document.rs @@ -44,11 +44,6 @@ pub struct DocumentNode { /// Represents the eye icon for hiding/showing the node in the graph UI. When hidden, a node gets replaced with a passthrough node during the graph flattening step. #[serde(default = "return_true")] pub visible: bool, - /// When two different proto nodes hash to the same value (e.g. two value nodes each containing `2_u32` or two multiply nodes that have the same node IDs as input), the duplicates are removed. - /// See [`ProtoNetwork::generate_stable_node_ids`] for details. - /// However sometimes this is not desirable, for example in the case of a [`graphene_core::memo::MonitorNode`] that needs to be accessed outside of the graph. - #[serde(default)] - pub skip_deduplication: bool, #[serde(skip)] pub compile_metadata: Option, /// The path to this node and its inputs and outputs as of when [`NodeNetwork::generate_node_paths`] was called. @@ -82,7 +77,6 @@ impl Default for DocumentNode { call_argument: concrete!(Context), implementation: Default::default(), visible: true, - skip_deduplication: Default::default(), original_location: OriginalLocation::default(), compile_metadata: Default::default(), } @@ -817,7 +811,6 @@ impl core_types::graphene_hash::CacheHash for DocumentNode { self.call_argument.cache_hash(state); self.implementation.cache_hash(state); self.visible.cache_hash(state); - self.skip_deduplication.cache_hash(state); self.compile_metadata.cache_hash(state); } } diff --git a/node-graph/graph-craft/src/document/migration.rs b/node-graph/graph-craft/src/document/migration.rs index 5470dee0d6b..206d4e7e2b3 100644 --- a/node-graph/graph-craft/src/document/migration.rs +++ b/node-graph/graph-craft/src/document/migration.rs @@ -88,11 +88,6 @@ pub struct OldDocumentNode { pub locked: bool, /// Metadata about the node including its position in the graph UI. Ensure the click target in the encapsulating network is updated when the node moves by using network.update_click_target(node_id). pub metadata: OldDocumentNodeMetadata, - /// When two different proto nodes hash to the same value (e.g. two value nodes each containing `2_u32` or two multiply nodes that have the same node IDs as input), the duplicates are removed. - /// See [`ProtoNetwork::generate_stable_node_ids`] for details. - /// However sometimes this is not desirable, for example in the case of a [`graphene_core::memo::MonitorNode`] that needs to be accessed outside of the graph. - #[serde(default)] - pub skip_deduplication: bool, /// The path to this node and its inputs and outputs as of when [`NodeNetwork::generate_node_paths`] was called. #[serde(skip)] pub original_location: OriginalLocation, diff --git a/node-graph/graph-craft/src/proto.rs b/node-graph/graph-craft/src/proto.rs index 1b0c1fef54d..462ee099ce3 100644 --- a/node-graph/graph-craft/src/proto.rs +++ b/node-graph/graph-craft/src/proto.rs @@ -124,7 +124,6 @@ pub struct ProtoNode { pub call_argument: Type, pub identifier: ProtoNodeIdentifier, pub original_location: OriginalLocation, - pub skip_deduplication: bool, pub(crate) compile_metadata: NodeCompileMetadata, /// The context features read by this node and everything upstream of it. pub upstream_context_features: ContextFeatures, @@ -137,7 +136,6 @@ impl Default for ProtoNode { construction_args: ConstructionArgs::Value(value::TaggedValue::Integer(0).into()), call_argument: concrete!(()), original_location: OriginalLocation::default(), - skip_deduplication: false, compile_metadata: Default::default(), upstream_context_features: ContextFeatures::empty(), } @@ -146,16 +144,12 @@ impl Default for ProtoNode { impl ProtoNode { /// A stable node ID is a hash of a node that should stay constant. This is used in order to remove duplicates from the graph. - /// In the case of `skip_deduplication`, the `document_node_path` is also hashed in order to avoid duplicate monitor nodes from being removed (which would make it impossible to load thumbnails). pub fn stable_node_id(&self) -> Option { use std::hash::Hasher; let mut hasher = rustc_hash::FxHasher::default(); self.identifier.as_str().hash(&mut hasher); self.construction_args.cache_hash(&mut hasher); - if self.skip_deduplication { - self.original_location.path.hash(&mut hasher); - } std::mem::discriminant(&self.call_argument).hash(&mut hasher); self.call_argument.hash(&mut hasher); @@ -173,7 +167,6 @@ impl ProtoNode { path: Some(path), ..Default::default() }, - skip_deduplication: false, compile_metadata: Default::default(), upstream_context_features: ContextFeatures::empty(), } @@ -355,7 +348,6 @@ impl ProtoNetwork { }, compile_metadata: forwarding, upstream_context_features: features, - ..Default::default() }, )); @@ -387,7 +379,6 @@ impl ProtoNetwork { }, compile_metadata: forwarding, upstream_context_features: features, - ..Default::default() }, )); nullification_node_id diff --git a/node-graph/interpreted-executor/src/dynamic_executor.rs b/node-graph/interpreted-executor/src/dynamic_executor.rs index b40e1f47d0e..68185553e9f 100644 --- a/node-graph/interpreted-executor/src/dynamic_executor.rs +++ b/node-graph/interpreted-executor/src/dynamic_executor.rs @@ -113,11 +113,6 @@ impl DynamicExecutor { Ok(ResolvedDocumentNodeTypesDelta { add, remove }) } - /// Calls the `Node::serialize` for that specific node, returning for example the cached value for a monitor node. The node path must match the document node path. - pub fn introspect(&self, node_path: &[NodeId]) -> Result, IntrospectError> { - self.tree.introspect(node_path) - } - pub fn input_type(&self) -> Option { self.typing_context.type_of(self.output).map(|node_io| node_io.call_argument.clone()) } @@ -311,13 +306,6 @@ impl BorrowTree { self.nodes.insert(id, (node, path, inputs)); } - /// Calls the `Node::serialize` for that specific node, returning for example the cached value for a monitor node. The node path must match the document node path. - pub fn introspect(&self, node_path: &[NodeId]) -> Result, IntrospectError> { - let (id, _) = self.source_map.get(node_path).ok_or_else(|| IntrospectError::PathNotFound(node_path.to_vec()))?; - let (node, _path, _) = self.nodes.get(id).ok_or(IntrospectError::ProtoNodeNotFound(*id))?; - node.node().serialize().ok_or(IntrospectError::NoData) - } - pub fn get(&self, id: NodeId) -> Option { self.nodes.get(&id).map(|(node, _, _)| node.clone() as SharedNodeContainer) } diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index 31f305f4143..51f19ebf1f0 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -34,50 +34,6 @@ use std::sync::Arc; // TODO: turn into hashmap fn node_registry() -> HashMap> { let mut node_types: Vec<(ProtoNodeIdentifier, NodeConstructor, NodeIOTypes)> = vec![ - // ============= - // MONITOR NODES - // ============= - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List>]), - #[cfg(feature = "gpu")] - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List>]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item>]), - #[cfg(feature = "gpu")] - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item>]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Item]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => ListDyn]), - async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => List]), // Context nullification #[cfg(feature = "gpu")] async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => Item>, Context => Item]), @@ -298,8 +254,8 @@ fn node_registry() -> HashMap { $register!( @@ -354,7 +310,7 @@ fn node_registry() -> HashMap HashMap)); - // The memoize + monitor + context-nullification triple for each value type in the shared list above: the compiler wraps - // a ranked connector's broadcast sibling in a Memoize + context-nullification pair, and test instrumentation monitors any wire. + // The memoize + context-nullification pair the compiler wraps a ranked connector's broadcast sibling in, for each value type in the shared list above. // Node identifiers are passed explicitly since `stringify!` would mangle the path's whitespace through this nested macro. macro_rules! cache_chain_nodes { (each: $value:ty) => {{ let entries: Vec<(ProtoNodeIdentifier, NodeConstructor, NodeIOTypes)> = vec![ async_node!(identifier: graphene_core::memo::memoize::IDENTIFIER, graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => $value]), - async_node!(identifier: graphene_core::memo::monitor::IDENTIFIER, graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => $value]), async_node!(identifier: graphene_core::context_modification::context_modification::IDENTIFIER, graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => $value, Context => Item]), ]; entries diff --git a/node-graph/libraries/core-types/src/lib.rs b/node-graph/libraries/core-types/src/lib.rs index e8531118d6c..c1c59659248 100644 --- a/node-graph/libraries/core-types/src/lib.rs +++ b/node-graph/libraries/core-types/src/lib.rs @@ -55,11 +55,6 @@ pub trait Node { fn node_name(&self) -> &'static str { std::any::type_name::() } - /// Serialize the node which is used for the `introspect` function which can retrieve values from monitor nodes. - fn serialize(&self) -> Option> { - log::warn!("Node::serialize not implemented for {}", std::any::type_name::()); - None - } } mod types; @@ -107,9 +102,6 @@ impl + ?Sized> Node for &N { fn node_name(&self) -> &'static str { (**self).node_name() } - fn serialize(&self) -> Option> { - (**self).serialize() - } } impl + ?Sized> Node for Box { type Output = N::Output; @@ -120,9 +112,6 @@ impl + ?Sized> Node for Box { fn node_name(&self) -> &'static str { (**self).node_name() } - fn serialize(&self) -> Option> { - (**self).serialize() - } } impl + ?Sized> Node for std::sync::Arc { type Output = N::Output; @@ -133,9 +122,6 @@ impl + ?Sized> Node for std::sync::Arc { fn node_name(&self) -> &'static str { (**self).node_name() } - fn serialize(&self) -> Option> { - (**self).serialize() - } } /// A compile-time symbol naming one parameter of one proto node. diff --git a/node-graph/libraries/core-types/src/memo.rs b/node-graph/libraries/core-types/src/memo.rs index 80766fc860b..64cff1a1242 100644 --- a/node-graph/libraries/core-types/src/memo.rs +++ b/node-graph/libraries/core-types/src/memo.rs @@ -4,13 +4,6 @@ use std::hash::{Hash, Hasher}; use std::ops::Deref; use std::sync::Arc; -/// Stores both what a node was called with and what it returned. -#[derive(Clone, Debug)] -pub struct IORecord { - pub input: I, - pub output: O, -} - #[derive(Clone, Debug)] pub struct MemoHash { hash: u64, diff --git a/node-graph/libraries/core-types/src/ops.rs b/node-graph/libraries/core-types/src/ops.rs index 95f9b2173ee..525a03b514d 100644 --- a/node-graph/libraries/core-types/src/ops.rs +++ b/node-graph/libraries/core-types/src/ops.rs @@ -17,10 +17,6 @@ where fn eval(&self, input: &I) -> Poll { self.0.eval(input) } - - fn serialize(&self) -> Option> { - self.0.serialize() - } } impl, I> TypeNode>::Output> { pub fn new(node: N) -> Self { diff --git a/node-graph/libraries/core-types/src/registry.rs b/node-graph/libraries/core-types/src/registry.rs index 53747cb9751..6413e878627 100644 --- a/node-graph/libraries/core-types/src/registry.rs +++ b/node-graph/libraries/core-types/src/registry.rs @@ -351,10 +351,6 @@ where .unwrap_or_else(|_| panic!("DowncastBothNode wrong output type: expected {} in: \n{}", std::any::type_name::(), self.node.node().node_name())) }) } - - fn serialize(&self) -> Option> { - self.node.node().serialize() - } } impl DowncastBothNode { pub const fn new(node: SharedNodeContainer) -> Self { @@ -386,10 +382,6 @@ where .unwrap_or_else(|| panic!("DynAnyNode Input: expected {} in:\n{}", std::any::type_name::(), std::any::type_name::())); self.node.eval(input).map(|output| Box::new(output) as Any) } - - fn serialize(&self) -> Option> { - self.node.serialize() - } } impl DynAnyNode { pub const fn new(node: N) -> Self { diff --git a/node-graph/libraries/rendering/src/renderer.rs b/node-graph/libraries/rendering/src/renderer.rs index 02311185f09..42ee13ef55c 100644 --- a/node-graph/libraries/rendering/src/renderer.rs +++ b/node-graph/libraries/rendering/src/renderer.rs @@ -683,7 +683,7 @@ fn create_peniko_gradient_brush(gradient_item: ItemRef<'_, Gradient>, multiplied Some((brush, gradient_to_device)) } -// TODO: Click targets can be removed from the render output, since the vector data is available in the vector modify data from Monitor nodes. +// TODO: Click targets can be removed from the render output, since the vector data is available in the vector modify data the editor observes on 'Path' nodes. // This will require that the transform for child layers into that layer space be calculated, or it could be returned from the RenderOutput instead of click targets. #[derive(Debug, Default, Clone, PartialEq, DynAny)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/node-graph/node-macro/src/codegen.rs b/node-graph/node-macro/src/codegen.rs index 1449657c13d..1b2f840da85 100644 --- a/node-graph/node-macro/src/codegen.rs +++ b/node-graph/node-macro/src/codegen.rs @@ -524,18 +524,6 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn quote!(#[derive(Debug, Clone)]) }; - // Generate serialize method if serialize attribute is specified - let serialize_impl = if let Some(serialize_fn) = &parsed.attributes.serialize { - let data_field_refs = data_field_names.iter().map(|name| quote!(&self.#name)); - quote! { - fn serialize(&self) -> Option> { - #serialize_fn(#(#data_field_refs),*) - } - } - } else { - quote!() - }; - let eval_prelude = quote! { use #core_types::misc::Clampable; @@ -647,8 +635,6 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn let __state = self.slots.resolve(__key, &__runtime, __source, __placeholder, move || async move { #landed_call }); __cell.merge(__state) } - - #serialize_impl } } else { quote! { @@ -662,8 +648,6 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn }; #fold } - - #serialize_impl } }; @@ -757,8 +741,6 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn }; __cell.run(__kernel) } - - #serialize_impl } }); @@ -832,8 +814,6 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn }; __cell.run(__kernel) } - - #serialize_impl } }); diff --git a/node-graph/node-macro/src/destructure.rs b/node-graph/node-macro/src/destructure.rs index 25845c4acab..d47770c6c3d 100644 --- a/node-graph/node-macro/src/destructure.rs +++ b/node-graph/node-macro/src/destructure.rs @@ -236,7 +236,7 @@ pub fn derive_destructure_impl(item: TokenStream2) -> syn::Result } }; - // Memoize lets the node's outputs share one evaluation, and Monitor lets the editor inspect the struct + // Memoize lets the node's outputs share one evaluation let registration_module = format_ident!("_{struct_snake_name}_registration"); let wasm_registration = format_ident!("__node_registry_{}_{}", NODE_ID.fetch_add(1, Ordering::SeqCst), struct_ident); let registration = quote! { @@ -246,15 +246,15 @@ pub fn derive_destructure_impl(item: TokenStream2) -> syn::Result use #gcore::ctor::ctor; #[cfg_attr(not(target_family = "wasm"), ctor(unsafe, crate_path = core_types::ctor))] - fn register_memoize_and_monitor() { - #graphene_core::memo::register_memoize_and_monitor::<#struct_ident>(); - #graphene_core::memo::register_memoize_and_monitor::<#mapped_ident>(); + fn register_memoize() { + #graphene_core::memo::register_memoize::<#struct_ident>(); + #graphene_core::memo::register_memoize::<#mapped_ident>(); } #[cfg(target_family = "wasm")] #[unsafe(no_mangle)] extern "C" fn #wasm_registration() { - register_memoize_and_monitor(); + register_memoize(); } } }; diff --git a/node-graph/node-macro/src/parsing.rs b/node-graph/node-macro/src/parsing.rs index 1e671ac92d7..06241e9efde 100644 --- a/node-graph/node-macro/src/parsing.rs +++ b/node-graph/node-macro/src/parsing.rs @@ -65,8 +65,6 @@ pub(crate) struct NodeFnAttributes { pub(crate) inspector_string: Option, /// whether to `#[cfg]` gate the node implementation, defaults to None pub(crate) cfg: Option, - /// Custom serialization function path (e.g., "my_module::custom_serialize") - pub(crate) serialize: Option, pub(crate) flags: NodeFlags, /// Fn producing an placeholder value used while node evaluation is pending pub(crate) placeholder: Option, @@ -441,7 +439,6 @@ impl Parse for NodeFnAttributes { let mut path = None; let mut inspector_string = None; let mut cfg = None; - let mut serialize = None; let mut flags = NodeFlags::default(); let mut placeholder = None; let mut version = None; @@ -544,20 +541,6 @@ impl Parse for NodeFnAttributes { let meta = meta.require_list()?; cfg = Some(meta.tokens.clone()); } - // Function name for custom serialization of this node's data. This is only used by the Monitor node. - // - // Example usage: - // #[node_macro::node(..., serialize(my_module::custom_serialize), ...)] - "serialize" => { - let meta = meta.require_list()?; - if serialize.is_some() { - return Err(Error::new_spanned(meta, "Multiple 'serialize' attributes are not allowed")); - } - let parsed_path: Path = meta - .parse_args() - .map_err(|_| Error::new_spanned(meta, "Expected a valid path for 'serialize', e.g., serialize(my_module::custom_serialize)"))?; - serialize = Some(parsed_path); - } // Instructs the preprocessor to insert a Memoize node after this node in the generated subnetwork, // caching its output across evaluations with identical inputs. // @@ -621,7 +604,7 @@ impl Parse for NodeFnAttributes { indoc!( r#" Unsupported attribute in `node`. - Supported attributes are 'category', 'name', 'icon', 'path', 'skip_impl', 'inspector', 'cfg', 'serialize', 'memoize', 'footprint_invariant', 'forwards_input', 'inject_scope', 'placeholder', 'no_partial', and 'version'. + Supported attributes are 'category', 'name', 'icon', 'path', 'skip_impl', 'inspector', 'cfg', 'memoize', 'footprint_invariant', 'forwards_input', 'inject_scope', 'placeholder', 'no_partial', and 'version'. Example usage: #[node_macro::node(..., name("Test Node"), ...)] "# @@ -651,7 +634,6 @@ impl Parse for NodeFnAttributes { path, inspector_string, cfg, - serialize, flags, placeholder, version, diff --git a/node-graph/nodes/gcore/src/memo.rs b/node-graph/nodes/gcore/src/memo.rs index d9a33519246..d8496070f13 100644 --- a/node-graph/nodes/gcore/src/memo.rs +++ b/node-graph/nodes/gcore/src/memo.rs @@ -1,7 +1,6 @@ use core_types::graphene_hash::CacheHash; -use core_types::memo::*; use core_types::registry::{DowncastBothNode, DynAnyNode, NODE_REGISTRY, NodeConstructor, PanicNode, TypeErasedBox}; -use core_types::{Context, Interrupt, NodeIO, NodeIOTypes, Poll, WasmNotSend, concrete, fn_type}; +use core_types::{Context, NodeIO, NodeIOTypes, Poll, WasmNotSend, concrete, fn_type}; use dyn_any::StaticType; use std::hash::DefaultHasher; use std::hash::Hasher; @@ -36,39 +35,13 @@ fn memoize(input: I, conten state } -type MonitorValue = Arc>>>>; - -/// 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), inspector("monitor_inspector"), skip_impl, forwards_input)] -fn monitor( - input: I, - content: impl Node, - #[allow(clippy::type_complexity)] - #[data] - io: MonitorValue, -) -> Result { - let output = content.eval(input.clone())?; - *io.lock().unwrap() = Some(Arc::new(IORecord { input, output: output.clone() })); - Ok(output) -} - -fn serialize_monitor(io: &MonitorValue) -> Option> { - let io = io.lock().unwrap(); - io.as_ref().map(|output| output.clone() as Arc) -} - -/// Registers the Memoize and Monitor implementations for `T`, as `#[derive(node_macro::Destructure)]` does for each multi-output node struct. -pub fn register_memoize_and_monitor + 'static>() { +/// Registers the Memoize implementation for `T`, as `#[derive(node_macro::Destructure)]` does for each multi-output node struct. +pub fn register_memoize + 'static>() { let memoize_constructor: NodeConstructor = |mut arguments| { let node = MemoizeNode::new(DowncastBothNode::::new(arguments.pop().expect("Not enough arguments provided to construct node"))); let any: DynAnyNode = DynAnyNode::new(node); Box::new(any) as TypeErasedBox }; - let monitor_constructor: NodeConstructor = |mut arguments| { - let node = MonitorNode::new(DowncastBothNode::::new(arguments.pop().expect("Not enough arguments provided to construct node"))); - let any: DynAnyNode = DynAnyNode::new(node); - Box::new(any) as TypeErasedBox - }; let memoize_types: NodeIOTypes = { let node = MemoizeNode::new(PanicNode::::new()); @@ -76,16 +49,9 @@ pub fn register_memoize_and_monitor::Static); node_io }; - let monitor_types: NodeIOTypes = { - let node = MonitorNode::new(PanicNode::::new()); - let mut node_io = NodeIO::::to_node_io(&node, vec![fn_type!(Context, T)]); - node_io.call_argument = concrete!(::Static); - node_io - }; let mut registry = NODE_REGISTRY.lock().unwrap(); registry.entry(memoize::IDENTIFIER).or_default().push((memoize_constructor, memoize_types)); - registry.entry(monitor::IDENTIFIER).or_default().push((monitor_constructor, monitor_types)); } #[cfg(test)] diff --git a/node-graph/nodes/graphic/src/graphic.rs b/node-graph/nodes/graphic/src/graphic.rs index a95f0ea7414..8e43ead5346 100644 --- a/node-graph/nodes/graphic/src/graphic.rs +++ b/node-graph/nodes/graphic/src/graphic.rs @@ -1058,12 +1058,12 @@ fn flatten_graphic(_: impl Ctx, content: List, fully_flatten: Item) -> List { let mut output: List = content.clone().into_flattened_list(); - // TODO: Replace this snapshot hack with per-layer metadata driven by each layer's Monitor node. + // TODO: Replace this snapshot hack with per-layer metadata driven by observing each layer's content. // TODO: Flattening here erases the upstream `List` hierarchy that editor metadata collection walks // TODO: to populate `upstream_footprints` / `local_transforms` / `click_targets` per child layer. As a workaround // TODO: we stash the pre-flattened list on the output so `List::collect_metadata` can recurse into it, // TODO: which conflates render output with editor metadata and forces the pre-compensation dance below. - // TODO: The cleaner fix is to drive each layer's metadata from its own Monitor's captured `(Context, List)`, + // TODO: The cleaner fix is to drive each layer's metadata from an observation of its `List` content and context, // TODO: at which point this attribute (and the equivalents in Boolean Operation, Solidify Stroke, Combine Paths, // TODO: Morph, Rasterize) become unnecessary. if !output.is_empty() && !is_lone_anonymous_leaf(&content) { diff --git a/node-graph/preprocessor/src/lib.rs b/node-graph/preprocessor/src/lib.rs index 83a982f6d82..27f7f39e950 100644 --- a/node-graph/preprocessor/src/lib.rs +++ b/node-graph/preprocessor/src/lib.rs @@ -315,7 +315,6 @@ impl Preprocessor { call_argument: input_type.clone(), implementation: DocumentNodeImplementation::ProtoNode(id.clone()), visible: true, - skip_deduplication: false, ..Default::default() }; @@ -371,7 +370,6 @@ impl Preprocessor { generated: true, }), visible: true, - skip_deduplication: false, ..Default::default() }; @@ -862,7 +860,7 @@ mod tests { assert_eq!(info.constant_inputs.count_ones(), 1, "{identifier:?} should only require its name to be constant"); } - for identifier in [graphene_core::memo::memoize::IDENTIFIER, graphene_core::memo::monitor::IDENTIFIER, ops::passthrough::IDENTIFIER] { + for identifier in [graphene_core::memo::memoize::IDENTIFIER, ops::passthrough::IDENTIFIER] { assert!(compile_metadata(&identifier).forwards_input, "{identifier:?} should forward its input"); } } diff --git a/website/content/volunteer/guide/graphene/_index.md b/website/content/volunteer/guide/graphene/_index.md index 8d8ca4ea637..2ef5143a098 100644 --- a/website/content/volunteer/guide/graphene/_index.md +++ b/website/content/volunteer/guide/graphene/_index.md @@ -103,4 +103,3 @@ Since Graphene is fundamentally a programming language, throughout this document -