diff --git a/Cargo.lock b/Cargo.lock index cd6e5d9689..338d3eb865 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2008,6 +2008,7 @@ dependencies = [ "graphene-hash", "graphic-types", "gungraun", + "interpreted-executor", "js-sys", "log", "mmap-io", diff --git a/document/graph-storage/src/tests/round_trip.rs b/document/graph-storage/src/tests/round_trip.rs index 9d7eb45c8d..faec422142 100644 --- a/document/graph-storage/src/tests/round_trip.rs +++ b/document/graph-storage/src/tests/round_trip.rs @@ -14,7 +14,7 @@ use crate::{NetworkId, NodeMetadataSource, PeerId, Position, Registry}; /// Test networks with Import inputs will fail compilation (which is expected). fn verify_network_compiles(network: &NodeNetwork) -> Result<(), String> { let compiler = Compiler {}; - compiler.compile_single(network.clone(), None).map_err(|e| format!("Compilation failed: {:?}", e))?; + compiler.compile_single(network.clone(), &graph_craft::proto::Registry::new()).map_err(|e| format!("Compilation failed: {:?}", e))?; Ok(()) } diff --git a/editor/src/node_graph_executor/runtime.rs b/editor/src/node_graph_executor/runtime.rs index c4c81f5453..2808614ef0 100644 --- a/editor/src/node_graph_executor/runtime.rs +++ b/editor/src/node_graph_executor/runtime.rs @@ -438,7 +438,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, None) { + let proto_network = match c.compile_single(scoped_network, &interpreted_executor::node_registry::NODE_REGISTRY) { Ok(network) => network, Err(e) => return Err((ResolvedDocumentNodeTypesDelta::default(), e)), }; diff --git a/node-graph/graph-craft/Cargo.toml b/node-graph/graph-craft/Cargo.toml index 688a0ea712..c7d8f98988 100644 --- a/node-graph/graph-craft/Cargo.toml +++ b/node-graph/graph-craft/Cargo.toml @@ -74,6 +74,7 @@ mmap-io = { workspace = true } [dev-dependencies] # Workspace dependencies graph-craft = { workspace = true, features = ["loading"] } +interpreted-executor = { workspace = true } pretty_assertions = { workspace = true } criterion = { workspace = true } gungraun = { workspace = true } 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 a614f8dbcf..5e3572b845 100644 --- a/node-graph/graph-craft/benches/compile_demo_art_criterion.rs +++ b/node-graph/graph-craft/benches/compile_demo_art_criterion.rs @@ -6,10 +6,11 @@ use graph_craft::util::DEMO_ART; fn compile_to_proto(c: &mut Criterion) { use graph_craft::util::{compile, load_from_name}; let mut c = c.benchmark_group("Compile Network cold"); + let registry = &interpreted_executor::node_registry::NODE_REGISTRY; 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), registry), criterion::BatchSize::SmallInput)); } } diff --git a/node-graph/graph-craft/benches/compile_demo_art_gungraun.rs b/node-graph/graph-craft/benches/compile_demo_art_gungraun.rs index 176df58ba8..93b2af2be8 100644 --- a/node-graph/graph-craft/benches/compile_demo_art_gungraun.rs +++ b/node-graph/graph-craft/benches/compile_demo_art_gungraun.rs @@ -5,7 +5,7 @@ use gungraun::prelude::*; #[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, &interpreted_executor::node_registry::NODE_REGISTRY)); } 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 95879980bc..8a53835d5e 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<'r>(&self, mut network: NodeNetwork, registry: Option<&'r Registry>) -> impl Iterator> + 'r { + pub fn compile<'r>(&self, mut network: NodeNetwork, registry: &'r Registry) -> impl Iterator> + 'r { network.resolve_scope_inputs(); network.generate_node_paths(&[]); let node_ids = network.nodes.keys().copied().collect::>(); @@ -19,15 +19,13 @@ impl Compiler { proto_networks.map(move |mut proto_network| { proto_network.insert_context_nullification_nodes()?; - if let Some(registry) = registry { - let _ = proto_network.resolve_types(registry); - proto_network.compute_layouts(); - } + let _ = proto_network.resolve_types(registry); + proto_network.compute_layouts(); proto_network.generate_stable_node_ids(); Ok(proto_network) }) } - pub fn compile_single(&self, network: NodeNetwork, registry: Option<&Registry>) -> Result { + pub fn compile_single(&self, network: NodeNetwork, registry: &Registry) -> Result { assert_eq!(network.exports.len(), 1, "Graph with multiple outputs not yet handled"); let Some(proto_network) = self.compile(network, registry).next() else { return Err("Failed to convert graph into proto graph".to_string()); diff --git a/node-graph/graph-craft/src/util.rs b/node-graph/graph-craft/src/util.rs index de241be5f8..56a3aec967 100644 --- a/node-graph/graph-craft/src/util.rs +++ b/node-graph/graph-craft/src/util.rs @@ -1,6 +1,6 @@ use crate::document::NodeNetwork; use crate::graphene_compiler::Compiler; -use crate::proto::ProtoNetwork; +use crate::proto::{ProtoNetwork, Registry}; pub fn load_network(document_string: &str) -> NodeNetwork { let document: serde_json::Value = serde_json::from_str(document_string).expect("Failed to parse document"); @@ -8,9 +8,9 @@ pub fn load_network(document_string: &str) -> NodeNetwork { serde_json::from_str::(&document).expect("Failed to parse document") } -pub fn compile(network: NodeNetwork) -> ProtoNetwork { +pub fn compile(network: NodeNetwork, registry: &Registry) -> ProtoNetwork { let compiler = Compiler {}; - compiler.compile_single(network, None).unwrap() + compiler.compile_single(network, registry).unwrap() } pub fn load_from_name(name: &str) -> NodeNetwork { diff --git a/node-graph/graphene-cli/src/main.rs b/node-graph/graphene-cli/src/main.rs index cda152c981..fc5688c889 100644 --- a/node-graph/graphene-cli/src/main.rs +++ b/node-graph/graphene-cli/src/main.rs @@ -314,7 +314,7 @@ fn compile_graph(network: NodeNetwork, editor_api: Arc, gdd: } let compiler = Compiler {}; - compiler.compile_single(network, Some(&interpreted_executor::node_registry::NODE_REGISTRY)).map_err(|x| x.into()) + compiler.compile_single(network, &interpreted_executor::node_registry::NODE_REGISTRY).map_err(|x| x.into()) } fn create_executor(proto_network: ProtoNetwork, runtime: Arc) -> Result> { diff --git a/node-graph/interpreted-executor/benches/benchmark_util.rs b/node-graph/interpreted-executor/benches/benchmark_util.rs index 6b888bbafc..1ba5875479 100644 --- a/node-graph/interpreted-executor/benches/benchmark_util.rs +++ b/node-graph/interpreted-executor/benches/benchmark_util.rs @@ -12,7 +12,7 @@ pub fn setup_network(name: &str) -> (DynamicExecutor, ProtoNetwork) { let mut network = wrap_network_in_scope(network, editor_api); let preprocessor = preprocessor::Preprocessor::new(); preprocessor.preprocess(&mut network, &|_| None).unwrap(); - let proto_network = compile(network); + let proto_network = compile(network, &interpreted_executor::node_registry::NODE_REGISTRY); let executor = DynamicExecutor::new(proto_network.clone()).unwrap(); (executor, proto_network) } diff --git a/node-graph/interpreted-executor/benches/run_demo_art_criterion.rs b/node-graph/interpreted-executor/benches/run_demo_art_criterion.rs index 996e84f7fe..01b3acb052 100644 --- a/node-graph/interpreted-executor/benches/run_demo_art_criterion.rs +++ b/node-graph/interpreted-executor/benches/run_demo_art_criterion.rs @@ -8,7 +8,7 @@ use interpreted_executor::dynamic_executor::DynamicExecutor; fn update_executor(name: &str, c: &mut BenchmarkGroup) { let network = load_from_name(name); - let proto_network = compile(network); + let proto_network = compile(network, &interpreted_executor::node_registry::NODE_REGISTRY); c.bench_function(name, |b| { b.iter_batched( @@ -28,7 +28,7 @@ fn update_executor_demo(c: &mut Criterion) { fn run_once(name: &str, c: &mut BenchmarkGroup) { let network = load_from_name(name); - let proto_network = compile(network); + let proto_network = compile(network, &interpreted_executor::node_registry::NODE_REGISTRY); let executor = DynamicExecutor::new(proto_network).unwrap(); let footprint = Footprint::default(); diff --git a/node-graph/interpreted-executor/src/lib.rs b/node-graph/interpreted-executor/src/lib.rs index f2f6e626c7..f314eb6448 100644 --- a/node-graph/interpreted-executor/src/lib.rs +++ b/node-graph/interpreted-executor/src/lib.rs @@ -44,7 +44,7 @@ mod tests { use graph_craft::graphene_compiler::Compiler; let compiler = Compiler {}; - let protograph = compiler.compile_single(network, Some(&crate::node_registry::NODE_REGISTRY)).expect("Graph should be generated"); + let protograph = compiler.compile_single(network, &crate::node_registry::NODE_REGISTRY).expect("Graph should be generated"); let _exec = DynamicExecutor::new(protograph).map(|_e| panic!("The network should not type check ")).unwrap_err(); }