@@ -41,7 +41,6 @@ impl core::fmt::Display for ProtoNetwork {
4141 ProtoNodeInput :: None => f. write_str ( "None" ) ?,
4242 ProtoNodeInput :: ManualComposition ( ty) => f. write_fmt ( format_args ! ( "Manual Composition (type = {ty:?})" ) ) ?,
4343 ProtoNodeInput :: Node ( _) => f. write_str ( "Node" ) ?,
44- ProtoNodeInput :: NodeLambda ( _) => f. write_str ( "Lambda Node" ) ?,
4544 }
4645 f. write_str ( "\n " ) ?;
4746
@@ -52,7 +51,7 @@ impl core::fmt::Display for ProtoNetwork {
5251 }
5352 ConstructionArgs :: Nodes ( nodes) => {
5453 for id in nodes {
55- write_node ( f, network, id . 0 , indent + 1 ) ?;
54+ write_node ( f, network, * id , indent + 1 ) ?;
5655 }
5756 }
5857 ConstructionArgs :: Inline ( inline) => {
@@ -78,7 +77,7 @@ pub enum ConstructionArgs {
7877 /// A list of nodes used as inputs to the constructor function in `node_registry.rs`.
7978 /// The bool indicates whether to treat the node as lambda node.
8079 // TODO: use a struct for clearer naming.
81- Nodes ( Vec < ( NodeId , bool ) > ) ,
80+ Nodes ( Vec < NodeId > ) ,
8281 /// Used for GPU computation to work around the limitations of rust-gpu.
8382 Inline ( InlineRust ) ,
8483}
@@ -121,7 +120,7 @@ impl Hash for ConstructionArgs {
121120impl ConstructionArgs {
122121 pub fn new_function_args ( & self ) -> Vec < String > {
123122 match self {
124- ConstructionArgs :: Nodes ( nodes) => nodes. iter ( ) . map ( |( n , _ ) | format ! ( "n{:0x}" , n. 0 ) ) . collect ( ) ,
123+ ConstructionArgs :: Nodes ( nodes) => nodes. iter ( ) . map ( |n | format ! ( "n{:0x}" , n. 0 ) ) . collect ( ) ,
125124 ConstructionArgs :: Value ( value) => vec ! [ value. to_primitive_string( ) ] ,
126125 ConstructionArgs :: Inline ( inline) => vec ! [ inline. expr. clone( ) ] ,
127126 }
@@ -172,15 +171,7 @@ pub enum ProtoNodeInput {
172171 /// Grayscale example:
173172 ///
174173 /// We're interested in receiving an input of the desaturated image data which has been fed through a grayscale filter.
175- /// (If we were interested in the grayscale filter itself, we would use the `NodeLambda` variant.)
176174 Node ( NodeId ) ,
177- /// Unlike the `Node` variant, with `NodeLambda` we treat the connected node singularly as a lambda node while ignoring all nodes which feed into it from upstream.
178- ///
179- /// Grayscale example:
180- ///
181- /// We're interested in receiving an input of a particular image filter, such as a grayscale filter in the form of a grayscale node lambda.
182- /// (If we were interested in some image data that had been fed through a grayscale filter, we would use the `Node` variant.)
183- NodeLambda ( NodeId ) ,
184175}
185176
186177impl ProtoNode {
@@ -202,8 +193,7 @@ impl ProtoNode {
202193 ProtoNodeInput :: ManualComposition ( ref ty) => {
203194 ty. hash ( & mut hasher) ;
204195 }
205- ProtoNodeInput :: Node ( id) => ( id, false ) . hash ( & mut hasher) ,
206- ProtoNodeInput :: NodeLambda ( id) => ( id, true ) . hash ( & mut hasher) ,
196+ ProtoNodeInput :: Node ( id) => id. hash ( & mut hasher) ,
207197 } ;
208198
209199 Some ( NodeId ( hasher. finish ( ) ) )
@@ -230,23 +220,17 @@ impl ProtoNode {
230220
231221 /// Converts all references to other node IDs into new IDs by running the specified function on them.
232222 /// This can be used when changing the IDs of the nodes, for example in the case of generating stable IDs.
233- pub fn map_ids ( & mut self , f : impl Fn ( NodeId ) -> NodeId , skip_lambdas : bool ) {
234- match self . input {
235- ProtoNodeInput :: Node ( id) => self . input = ProtoNodeInput :: Node ( f ( id) ) ,
236- ProtoNodeInput :: NodeLambda ( id) => {
237- if !skip_lambdas {
238- self . input = ProtoNodeInput :: NodeLambda ( f ( id) )
239- }
240- }
241- _ => ( ) ,
223+ pub fn map_ids ( & mut self , f : impl Fn ( NodeId ) -> NodeId ) {
224+ if let ProtoNodeInput :: Node ( id) = self . input {
225+ self . input = ProtoNodeInput :: Node ( f ( id) )
242226 }
243227
244228 if let ConstructionArgs :: Nodes ( ids) = & mut self . construction_args {
245- ids. iter_mut ( ) . filter ( | ( _ , lambda ) | ! ( skip_lambdas && * lambda ) ) . for_each ( |( id , _ ) | * id = f ( * id) ) ;
229+ ids. iter_mut ( ) . for_each ( |id | * id = f ( * id) ) ;
246230 }
247231 }
248232
249- pub fn unwrap_construction_nodes ( & self ) -> Vec < ( NodeId , bool ) > {
233+ pub fn unwrap_construction_nodes ( & self ) -> Vec < NodeId > {
250234 match & self . construction_args {
251235 ConstructionArgs :: Nodes ( nodes) => nodes. clone ( ) ,
252236 _ => panic ! ( "tried to unwrap nodes from non node construction args \n node: {self:#?}" ) ,
@@ -285,16 +269,13 @@ impl ProtoNetwork {
285269 pub fn collect_outwards_edges ( & self ) -> HashMap < NodeId , Vec < NodeId > > {
286270 let mut edges: HashMap < NodeId , Vec < NodeId > > = HashMap :: new ( ) ;
287271 for ( id, node) in & self . nodes {
288- match & node. input {
289- ProtoNodeInput :: Node ( ref_id) | ProtoNodeInput :: NodeLambda ( ref_id) => {
290- self . check_ref ( ref_id, id) ;
291- edges. entry ( * ref_id) . or_default ( ) . push ( * id)
292- }
293- _ => ( ) ,
272+ if let ProtoNodeInput :: Node ( ref_id) = & node. input {
273+ self . check_ref ( ref_id, id) ;
274+ edges. entry ( * ref_id) . or_default ( ) . push ( * id)
294275 }
295276
296277 if let ConstructionArgs :: Nodes ( ref_nodes) = & node. construction_args {
297- for ( ref_id, _ ) in ref_nodes {
278+ for ref_id in ref_nodes {
298279 self . check_ref ( ref_id, id) ;
299280 edges. entry ( * ref_id) . or_default ( ) . push ( * id)
300281 }
@@ -313,7 +294,7 @@ impl ProtoNetwork {
313294 let Some ( sni) = self . nodes [ index] . 1 . stable_node_id ( ) else {
314295 panic ! ( "failed to generate stable node id for node {:#?}" , self . nodes[ index] . 1 ) ;
315296 } ;
316- self . replace_node_id ( & outwards_edges, NodeId ( index as u64 ) , sni, false ) ;
297+ self . replace_node_id ( & outwards_edges, NodeId ( index as u64 ) , sni) ;
317298 self . nodes [ index] . 0 = sni;
318299 }
319300 }
@@ -323,16 +304,13 @@ impl ProtoNetwork {
323304 pub fn collect_inwards_edges ( & self ) -> HashMap < NodeId , Vec < NodeId > > {
324305 let mut edges: HashMap < NodeId , Vec < NodeId > > = HashMap :: new ( ) ;
325306 for ( id, node) in & self . nodes {
326- match & node. input {
327- ProtoNodeInput :: Node ( ref_id) | ProtoNodeInput :: NodeLambda ( ref_id) => {
328- self . check_ref ( ref_id, id) ;
329- edges. entry ( * id) . or_default ( ) . push ( * ref_id)
330- }
331- _ => ( ) ,
307+ if let ProtoNodeInput :: Node ( ref_id) = & node. input {
308+ self . check_ref ( ref_id, id) ;
309+ edges. entry ( * id) . or_default ( ) . push ( * ref_id)
332310 }
333311
334312 if let ConstructionArgs :: Nodes ( ref_nodes) = & node. construction_args {
335- for ( ref_id, _ ) in ref_nodes {
313+ for ref_id in ref_nodes {
336314 self . check_ref ( ref_id, id) ;
337315 edges. entry ( * id) . or_default ( ) . push ( * ref_id)
338316 }
@@ -348,16 +326,13 @@ impl ProtoNetwork {
348326 let mut inwards_edges = vec ! [ Vec :: new( ) ; self . nodes. len( ) ] ;
349327 for ( node_id, node) in & self . nodes {
350328 let node_index = id_map[ node_id] ;
351- match & node. input {
352- ProtoNodeInput :: Node ( ref_id) | ProtoNodeInput :: NodeLambda ( ref_id) => {
353- self . check_ref ( ref_id, & NodeId ( node_index as u64 ) ) ;
354- inwards_edges[ node_index] . push ( id_map[ ref_id] ) ;
355- }
356- _ => { }
329+ if let ProtoNodeInput :: Node ( ref_id) = & node. input {
330+ self . check_ref ( ref_id, & NodeId ( node_index as u64 ) ) ;
331+ inwards_edges[ node_index] . push ( id_map[ ref_id] ) ;
357332 }
358333
359334 if let ConstructionArgs :: Nodes ( ref_nodes) = & node. construction_args {
360- for ( ref_id, _ ) in ref_nodes {
335+ for ref_id in ref_nodes {
361336 self . check_ref ( ref_id, & NodeId ( node_index as u64 ) ) ;
362337 inwards_edges[ node_index] . push ( id_map[ ref_id] ) ;
363338 }
@@ -400,27 +375,27 @@ impl ProtoNetwork {
400375 compose_node_id,
401376 ProtoNode {
402377 identifier : ProtoNodeIdentifier :: new ( "graphene_core::structural::ComposeNode" ) ,
403- construction_args : ConstructionArgs :: Nodes ( vec ! [ ( input_node_id, false ) , ( node_id, true ) ] ) ,
378+ construction_args : ConstructionArgs :: Nodes ( vec ! [ input_node_id, node_id] ) ,
404379 input,
405380 original_location : OriginalLocation { path, ..Default :: default ( ) } ,
406381 skip_deduplication : false ,
407382 } ,
408383 ) ) ;
409384
410- self . replace_node_id ( & outwards_edges, node_id, compose_node_id, true ) ;
385+ self . replace_node_id ( & outwards_edges, node_id, compose_node_id) ;
411386 }
412387 }
413388 self . reorder_ids ( ) ?;
414389 Ok ( ( ) )
415390 }
416391
417392 /// Update all of the references to a node ID in the graph with a new ID named `compose_node_id`.
418- fn replace_node_id ( & mut self , outwards_edges : & HashMap < NodeId , Vec < NodeId > > , node_id : NodeId , compose_node_id : NodeId , skip_lambdas : bool ) {
393+ fn replace_node_id ( & mut self , outwards_edges : & HashMap < NodeId , Vec < NodeId > > , node_id : NodeId , compose_node_id : NodeId ) {
419394 // Update references in other nodes to use the new compose node
420395 if let Some ( referring_nodes) = outwards_edges. get ( & node_id) {
421396 for & referring_node_id in referring_nodes {
422397 let ( _, referring_node) = & mut self . nodes [ referring_node_id. 0 as usize ] ;
423- referring_node. map_ids ( |id| if id == node_id { compose_node_id } else { id } , skip_lambdas )
398+ referring_node. map_ids ( |id| if id == node_id { compose_node_id } else { id } )
424399 }
425400 }
426401
@@ -508,7 +483,7 @@ impl ProtoNetwork {
508483 for ( index, & id) in order. iter ( ) . enumerate ( ) {
509484 let mut node = std:: mem:: take ( & mut self . nodes [ id. 0 as usize ] . 1 ) ;
510485 // Update node references to reflect the new order
511- node. map_ids ( |id| NodeId ( * new_positions. get ( & id) . expect ( "node not found in lookup table" ) as u64 ) , false ) ;
486+ node. map_ids ( |id| NodeId ( * new_positions. get ( & id) . expect ( "node not found in lookup table" ) as u64 ) ) ;
512487 new_nodes. push ( ( NodeId ( index as u64 ) , node) ) ;
513488 }
514489
@@ -670,7 +645,7 @@ impl TypingContext {
670645 // If the node has nodes as inputs we can infer the types from the node outputs
671646 ConstructionArgs :: Nodes ( ref nodes) => nodes
672647 . iter ( )
673- . map ( |( id , _ ) | {
648+ . map ( |id | {
674649 self . inferred
675650 . get ( id)
676651 . ok_or_else ( || vec ! [ GraphError :: new( node, GraphErrorType :: NodeNotFound ( * id) ) ] )
@@ -685,7 +660,7 @@ impl TypingContext {
685660 let primary_input_or_call_argument = match node. input {
686661 ProtoNodeInput :: None => concrete ! ( ( ) ) ,
687662 ProtoNodeInput :: ManualComposition ( ref ty) => ty. clone ( ) ,
688- ProtoNodeInput :: Node ( id) | ProtoNodeInput :: NodeLambda ( id ) => {
663+ ProtoNodeInput :: Node ( id) => {
689664 let input = self . inferred . get ( & id) . ok_or_else ( || vec ! [ GraphError :: new( node, GraphErrorType :: InputNodeNotFound ( id) ) ] ) ?;
690665 input. return_value . clone ( )
691666 }
@@ -936,7 +911,7 @@ mod test {
936911 println ! ( "{construction_network:#?}" ) ;
937912 assert_eq ! ( construction_network. nodes[ 0 ] . 1 . identifier. name. as_ref( ) , "value" ) ;
938913 assert_eq ! ( construction_network. nodes. len( ) , 6 ) ;
939- assert_eq ! ( construction_network. nodes[ 5 ] . 1 . construction_args, ConstructionArgs :: Nodes ( vec![ ( NodeId ( 3 ) , false ) , ( NodeId ( 4 ) , true ) ] ) ) ;
914+ assert_eq ! ( construction_network. nodes[ 5 ] . 1 . construction_args, ConstructionArgs :: Nodes ( vec![ ( NodeId ( 3 ) ) , ( NodeId ( 4 ) ) ] ) ) ;
940915 }
941916
942917 #[ test]
@@ -950,11 +925,11 @@ mod test {
950925 ids,
951926 vec![
952927 NodeId ( 16997244687192517417 ) ,
953- NodeId ( 12226224850522777131 ) ,
954- NodeId ( 9162113827627229771 ) ,
955- NodeId ( 12793582657066318419 ) ,
956- NodeId ( 16945623684036608820 ) ,
957- NodeId ( 2640415155091892458 )
928+ NodeId ( 7064939117677356327 ) ,
929+ NodeId ( 10605314923684175783 ) ,
930+ NodeId ( 6550828352538976747 ) ,
931+ NodeId ( 277515424782779520 ) ,
932+ NodeId ( 8855802688584342558 )
958933 ]
959934 ) ;
960935 }
@@ -987,7 +962,7 @@ mod test {
987962 ProtoNode {
988963 identifier : "cons" . into ( ) ,
989964 input : ProtoNodeInput :: ManualComposition ( concrete ! ( u32 ) ) ,
990- construction_args : ConstructionArgs :: Nodes ( vec ! [ ( NodeId ( 14 ) , false ) ] ) ,
965+ construction_args : ConstructionArgs :: Nodes ( vec ! [ NodeId ( 14 ) ] ) ,
991966 ..Default :: default ( )
992967 } ,
993968 ) ,
0 commit comments