diff --git a/editor/src/node_graph_executor/runtime.rs b/editor/src/node_graph_executor/runtime.rs index 0c0ca0a0eb..8436d57e74 100644 --- a/editor/src/node_graph_executor/runtime.rs +++ b/editor/src/node_graph_executor/runtime.rs @@ -377,7 +377,7 @@ impl NodeRuntime { assert_eq!(scoped_network.exports.len(), 1, "Graph with multiple outputs not yet handled"); let c = Compiler {}; - let proto_network = match c.compile_single(scoped_network, self.executor.typing_context_mut()) { + let proto_network = match c.compile_single(scoped_network, Some(self.executor.typing_context_mut())) { Ok(network) => network, Err(e) => return Err((ResolvedDocumentNodeTypesDelta::default(), e)), }; diff --git a/node-graph/graph-craft/benches/compile_demo_art_criterion.rs b/node-graph/graph-craft/benches/compile_demo_art_criterion.rs index c559e738b8..2632de8c7e 100644 --- a/node-graph/graph-craft/benches/compile_demo_art_criterion.rs +++ b/node-graph/graph-craft/benches/compile_demo_art_criterion.rs @@ -1,12 +1,15 @@ -use criterion::{Criterion, black_box, criterion_group, criterion_main}; +use criterion::{Criterion, criterion_group, criterion_main}; use graph_craft::util::DEMO_ART; +use std::hint::black_box; fn compile_to_proto(c: &mut Criterion) { use graph_craft::util::{compile, load_from_name}; let mut c = c.benchmark_group("Compile Network cold"); for name in DEMO_ART { let network = load_from_name(name); - c.bench_function(name, |b| b.iter_batched(|| network.clone(), |network| compile(black_box(network)), criterion::BatchSize::SmallInput)); + c.bench_function(name, |b| { + b.iter_batched(|| network.clone(), |network| compile(black_box(network), None), criterion::BatchSize::SmallInput) + }); } } diff --git a/node-graph/graph-craft/benches/compile_demo_art_iai.rs b/node-graph/graph-craft/benches/compile_demo_art_iai.rs index 789a6640ff..01c71dd86d 100644 --- a/node-graph/graph-craft/benches/compile_demo_art_iai.rs +++ b/node-graph/graph-craft/benches/compile_demo_art_iai.rs @@ -5,7 +5,7 @@ use iai_callgrind::{library_benchmark, library_benchmark_group, main}; #[library_benchmark] #[benches::with_setup(args = ["isometric-fountain", "painted-dreams", "procedural-string-lights", "parametric-dunescape", "red-dress", "valley-of-spires"], setup = load_from_name)] pub fn compile_to_proto(_input: NodeNetwork) { - std::hint::black_box(compile(_input)); + std::hint::black_box(compile(_input, None)); } library_benchmark_group!(name = compile_group; benchmarks = compile_to_proto); diff --git a/node-graph/graph-craft/src/graphene_compiler.rs b/node-graph/graph-craft/src/graphene_compiler.rs index 24f94a7c20..9534b2d126 100644 --- a/node-graph/graph-craft/src/graphene_compiler.rs +++ b/node-graph/graph-craft/src/graphene_compiler.rs @@ -5,7 +5,7 @@ use std::error::Error; pub struct Compiler {} impl Compiler { - pub fn compile(&self, mut network: NodeNetwork, ty: &mut TypingContext) -> impl Iterator> { + pub fn compile<'a>(&'a self, mut network: NodeNetwork, mut ty: Option<&mut TypingContext>) -> impl Iterator> { let node_ids = network.nodes.keys().copied().collect::>(); network.populate_dependants(); for id in node_ids { @@ -17,12 +17,12 @@ impl Compiler { let proto_networks = network.into_proto_networks(); proto_networks.map(move |mut proto_network| { - proto_network.insert_context_nullification_nodes(ty)?; + proto_network.insert_context_nullification_nodes(ty.as_deref_mut())?; proto_network.generate_stable_node_ids(); Ok(proto_network) }) } - pub fn compile_single(&self, network: NodeNetwork, ty: &mut TypingContext) -> Result { + pub fn compile_single(&self, network: NodeNetwork, ty: Option<&mut TypingContext>) -> Result { assert_eq!(network.exports.len(), 1, "Graph with multiple outputs not yet handled"); let Some(proto_network) = self.compile(network, ty).next() else { return Err("Failed to convert graph into proto graph".to_string()); diff --git a/node-graph/graph-craft/src/proto.rs b/node-graph/graph-craft/src/proto.rs index 11e2c2c12b..3b4aa69ec0 100644 --- a/node-graph/graph-craft/src/proto.rs +++ b/node-graph/graph-craft/src/proto.rs @@ -213,14 +213,14 @@ enum NodeState { struct NodeList<'a> { vec: Vec<(NodeId, ProtoNode)>, - ty: &'a mut TypingContext, + ty: Option<&'a mut TypingContext>, id_mapping: Vec, } impl<'a> NodeList<'a> { - fn push_node(&mut self, node: ProtoNode, old_node_idx: Option) -> Result<(NodeId, Type), GraphErrors> { + fn push_node(&mut self, node: ProtoNode, old_node_idx: Option) -> Result<(NodeId, Option), GraphErrors> { let node_id = node.stable_node_id().unwrap(); - let out_ty = self.ty.infer(node_id, &node)?.return_value; + let out_ty = if let Some(ty) = &mut self.ty { Some(ty.infer(node_id, &node)?.return_value) } else { None }; // log::debug!("{old_node_idx:?}, {node_id:?}, {node:?}, {:?}", self.id_mapping); if let Some(old_node_idx) = old_node_idx { assert_eq!(old_node_idx, self.id_mapping.len()); @@ -316,7 +316,7 @@ impl ProtoNetwork { /// Inserts context nullification nodes to optimize caching. /// This analysis is performed after topological sorting to ensure proper dependency tracking. - pub fn insert_context_nullification_nodes(&mut self, ty: &mut TypingContext) -> Result<(), String> { + pub fn insert_context_nullification_nodes(&mut self, ty: Option<&mut TypingContext>) -> Result<(), String> { // Perform topological sort once self.reorder_ids()?; @@ -394,7 +394,7 @@ impl ProtoNetwork { Ok(nullification_node_id) } - fn find_context_dependencies(&mut self, id: NodeId, new_order: &mut NodeList, results: &mut Vec<(ContextFeatures, NodeId, Type, bool)>) -> Result<(), GraphErrors> { + fn find_context_dependencies(&mut self, id: NodeId, new_order: &mut NodeList, results: &mut Vec<(ContextFeatures, NodeId, Option, bool)>) -> Result<(), GraphErrors> { let mut branch_dependencies = Vec::new(); let mut combined_deps = ContextFeatures::default(); let node_index = id.0 as usize; diff --git a/node-graph/graph-craft/src/util.rs b/node-graph/graph-craft/src/util.rs index 514a8971ad..6d546d913f 100644 --- a/node-graph/graph-craft/src/util.rs +++ b/node-graph/graph-craft/src/util.rs @@ -8,7 +8,7 @@ pub fn load_network(document_string: &str) -> NodeNetwork { serde_json::from_str::(&document).expect("Failed to parse document") } -pub fn compile(network: NodeNetwork, ty: &mut TypingContext) -> ProtoNetwork { +pub fn compile(network: NodeNetwork, ty: Option<&mut TypingContext>) -> ProtoNetwork { let compiler = Compiler {}; compiler.compile_single(network, ty).unwrap() } diff --git a/node-graph/graphene-cli/src/main.rs b/node-graph/graphene-cli/src/main.rs index 98330bf7b5..61e02253f9 100644 --- a/node-graph/graphene-cli/src/main.rs +++ b/node-graph/graphene-cli/src/main.rs @@ -232,7 +232,7 @@ fn compile_graph(document_string: String, editor_api: Arc) -> Res let compiler = Compiler {}; let mut ty = TypingContext::new(&interpreted_executor::node_registry::NODE_REGISTRY); - compiler.compile_single(wrapped_network, &mut ty).map_err(|x| x.into()) + compiler.compile_single(wrapped_network, Some(&mut ty)).map_err(|x| x.into()) } fn create_executor(proto_network: ProtoNetwork) -> Result> { diff --git a/node-graph/libraries/rendering/Cargo.toml b/node-graph/libraries/rendering/Cargo.toml index e33ce052fd..02e33c7f56 100644 --- a/node-graph/libraries/rendering/Cargo.toml +++ b/node-graph/libraries/rendering/Cargo.toml @@ -22,6 +22,5 @@ kurbo = { workspace = true } vector-types = { workspace = true } graphic-types = { workspace = true } - # Workspace dependencies vello = { workspace = true }