From c814abc34712a8c29e4a3bb2aab6499c45d8f1f2 Mon Sep 17 00:00:00 2001 From: nat-rix Date: Mon, 24 Apr 2023 21:44:06 +0200 Subject: [PATCH] Fix too many locals in wasm binary (#1159) Split function into smaller non-inlinable ones this fixes the issue that rust creates too many wasm locals in non-optimized builds. That lead to a compile error in such builds. Co-authored-by: Keavon Chambers --- .../interpreted-executor/src/node_registry.rs | 95 +++++++++++-------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/node-graph/interpreted-executor/src/node_registry.rs b/node-graph/interpreted-executor/src/node_registry.rs index 360b0d7d..5f1b48ab 100644 --- a/node-graph/interpreted-executor/src/node_registry.rs +++ b/node-graph/interpreted-executor/src/node_registry.rs @@ -68,48 +68,59 @@ macro_rules! register_node { }; } macro_rules! raster_node { - ($path:ty, params: [$($type:ty),*]) => { - vec![ - ( - NodeIdentifier::new(stringify!($path)), - |args| { - let node = construct_node!(args, $path, [$($type),*]); - let any: DynAnyNode = graphene_std::any::DynAnyNode::new(graphene_core::value::ValueNode::new(node)); - Box::pin(any) - }, - { - let params = vec![$(value_fn!($type)),*]; - NodeIOTypes::new(concrete!(Color), concrete!(Color), params) - }, - ), - ( - NodeIdentifier::new(stringify!($path)), - |args| { - let node = construct_node!(args, $path, [$($type),*]); - let map_node = graphene_std::raster::MapImageNode::new(graphene_core::value::ValueNode::new(node)); - let any: DynAnyNode, _, _> = graphene_std::any::DynAnyNode::new(graphene_core::value::ValueNode::new(map_node)); - Box::pin(any) - }, - { - let params = vec![$(value_fn!($type)),*]; - NodeIOTypes::new(concrete!(Image), concrete!(Image), params) - }, - ), - ( - NodeIdentifier::new(stringify!($path)), - |args| { - let node = construct_node!(args, $path, [$($type),*]); - let map_node = graphene_std::raster::MapImageNode::new(graphene_core::value::ValueNode::new(node)); - let any: DynAnyNode, _, _> = graphene_std::any::DynAnyNode::new(graphene_core::value::ValueNode::new(map_node)); - Box::pin(any) - }, - { - let params = vec![$(value_fn!($type)),*]; - NodeIOTypes::new(concrete!(ImageFrame), concrete!(ImageFrame), params) - }, - ) - ] - } + ($path:ty, params: [$($type:ty),*]) => {{ + // this function could also be inlined but serves as a workaround for + // [wasm-pack#981](https://github.com/rustwasm/wasm-pack/issues/981). + // The non-inlining function leads to fewer locals in the resulting + // wasm binary. This issue currently only applies to debug builds, so + // we guard inlining to only happen on production builds for + // optimization purposes. + #[cfg_attr(debug_assertions, inline(never))] + #[cfg_attr(not(debug_assertions), inline)] + fn generate_triples() -> Vec<(NodeIdentifier, NodeConstructor, NodeIOTypes)> { + vec![ + ( + NodeIdentifier::new(stringify!($path)), + |args| { + let node = construct_node!(args, $path, [$($type),*]); + let any: DynAnyNode = graphene_std::any::DynAnyNode::new(graphene_core::value::ValueNode::new(node)); + Box::pin(any) + }, + { + let params = vec![$(value_fn!($type)),*]; + NodeIOTypes::new(concrete!(Color), concrete!(Color), params) + }, + ), + ( + NodeIdentifier::new(stringify!($path)), + |args| { + let node = construct_node!(args, $path, [$($type),*]); + let map_node = graphene_std::raster::MapImageNode::new(graphene_core::value::ValueNode::new(node)); + let any: DynAnyNode, _, _> = graphene_std::any::DynAnyNode::new(graphene_core::value::ValueNode::new(map_node)); + Box::pin(any) + }, + { + let params = vec![$(value_fn!($type)),*]; + NodeIOTypes::new(concrete!(Image), concrete!(Image), params) + }, + ), + ( + NodeIdentifier::new(stringify!($path)), + |args| { + let node = construct_node!(args, $path, [$($type),*]); + let map_node = graphene_std::raster::MapImageNode::new(graphene_core::value::ValueNode::new(node)); + let any: DynAnyNode, _, _> = graphene_std::any::DynAnyNode::new(graphene_core::value::ValueNode::new(map_node)); + Box::pin(any) + }, + { + let params = vec![$(value_fn!($type)),*]; + NodeIOTypes::new(concrete!(ImageFrame), concrete!(ImageFrame), params) + }, + ) + ] + } + generate_triples() + }}; } //TODO: turn into hashmap