Skip to content

Commit 469f0a6

Browse files
authored
Remove lambda node inputs since they are no longer used (#3084)
* Remove lambda node inputs as they are now unused * Fix warnings * Fix tests * Fix clippy warning
1 parent 7377871 commit 469f0a6

5 files changed

Lines changed: 60 additions & 99 deletions

File tree

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,9 @@ impl NodeNetworkInterface {
458458
/// If the node is not in the hashmap then a default input is found based on the compiled network, using the node_id passed as a parameter
459459
pub fn map_ids(&mut self, mut node_template: NodeTemplate, node_id: &NodeId, new_ids: &HashMap<NodeId, NodeId>, network_path: &[NodeId]) -> NodeTemplate {
460460
for (input_index, input) in node_template.document_node.inputs.iter_mut().enumerate() {
461-
if let &mut NodeInput::Node { node_id: id, output_index, lambda } = input {
461+
if let &mut NodeInput::Node { node_id: id, output_index } = input {
462462
if let Some(&new_id) = new_ids.get(&id) {
463-
*input = NodeInput::Node {
464-
node_id: new_id,
465-
output_index,
466-
lambda,
467-
};
463+
*input = NodeInput::Node { node_id: new_id, output_index };
468464
} else {
469465
// Disconnect node input if it is not connected to another node in new_ids
470466
let tagged_value = TaggedValue::from_type_or_none(&self.input_type(&InputConnector::node(*node_id, input_index), network_path).0);

node-graph/graph-craft/src/document.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,15 @@ impl OriginalLocation {
211211
}
212212
impl DocumentNode {
213213
/// Locate the input that is a [`NodeInput::Network`] at index `offset` and replace it with a [`NodeInput::Node`].
214-
pub fn populate_first_network_input(&mut self, node_id: NodeId, output_index: usize, offset: usize, lambda: bool, source: impl Iterator<Item = Source>, skip: usize) {
214+
pub fn populate_first_network_input(&mut self, node_id: NodeId, output_index: usize, offset: usize, source: impl Iterator<Item = Source>, skip: usize) {
215215
let (index, _) = self
216216
.inputs
217217
.iter()
218218
.enumerate()
219219
.nth(offset)
220220
.unwrap_or_else(|| panic!("no network input found for {self:#?} and offset: {offset}"));
221221

222-
self.inputs[index] = NodeInput::Node { node_id, output_index, lambda };
222+
self.inputs[index] = NodeInput::Node { node_id, output_index };
223223
let input_source = &mut self.original_location.inputs_source;
224224
for source in source {
225225
input_source.insert(source, (index + self.original_location.skip_inputs).saturating_sub(skip));
@@ -241,9 +241,9 @@ impl DocumentNode {
241241
assert_eq!(self.inputs.len(), 0, "A value node cannot have any inputs. Current inputs: {:?}", self.inputs);
242242
(ProtoNodeInput::ManualComposition(concrete!(graphene_core::Context<'static>)), ConstructionArgs::Value(tagged_value))
243243
}
244-
NodeInput::Node { node_id, output_index, lambda } => {
244+
NodeInput::Node { node_id, output_index } => {
245245
assert_eq!(output_index, 0, "Outputs should be flattened before converting to proto node");
246-
let node = if lambda { ProtoNodeInput::NodeLambda(node_id) } else { ProtoNodeInput::Node(node_id) };
246+
let node = ProtoNodeInput::Node(node_id);
247247
(node, ConstructionArgs::Nodes(vec![]))
248248
}
249249
NodeInput::Network { import_type, .. } => (ProtoNodeInput::ManualComposition(import_type), ConstructionArgs::Nodes(vec![])),
@@ -266,7 +266,7 @@ impl DocumentNode {
266266
}
267267
if let ConstructionArgs::Nodes(nodes) = &mut args {
268268
nodes.extend(self.inputs.iter().map(|input| match input {
269-
NodeInput::Node { node_id, lambda, .. } => (*node_id, *lambda),
269+
NodeInput::Node { node_id, .. } => *node_id,
270270
_ => unreachable!(),
271271
}));
272272
}
@@ -284,7 +284,7 @@ impl DocumentNode {
284284
#[derive(Debug, Clone, PartialEq, Hash, DynAny, serde::Serialize, serde::Deserialize)]
285285
pub enum NodeInput {
286286
/// A reference to another node in the same network from which this node can receive its input.
287-
Node { node_id: NodeId, output_index: usize, lambda: bool },
287+
Node { node_id: NodeId, output_index: usize },
288288

289289
/// A hardcoded value that can't change after the graph is compiled. Gets converted into a value node during graph compilation.
290290
Value { tagged_value: MemoHash<TaggedValue>, exposed: bool },
@@ -323,11 +323,7 @@ pub enum DocumentNodeMetadata {
323323

324324
impl NodeInput {
325325
pub const fn node(node_id: NodeId, output_index: usize) -> Self {
326-
Self::Node { node_id, output_index, lambda: false }
327-
}
328-
329-
pub const fn lambda(node_id: NodeId, output_index: usize) -> Self {
330-
Self::Node { node_id, output_index, lambda: true }
326+
Self::Node { node_id, output_index }
331327
}
332328

333329
pub fn value(tagged_value: TaggedValue, exposed: bool) -> Self {
@@ -344,12 +340,8 @@ impl NodeInput {
344340
}
345341

346342
fn map_ids(&mut self, f: impl Fn(NodeId) -> NodeId) {
347-
if let &mut NodeInput::Node { node_id, output_index, lambda } = self {
348-
*self = NodeInput::Node {
349-
node_id: f(node_id),
350-
output_index,
351-
lambda,
352-
}
343+
if let &mut NodeInput::Node { node_id, output_index } = self {
344+
*self = NodeInput::Node { node_id: f(node_id), output_index }
353345
}
354346
}
355347

@@ -952,9 +944,9 @@ impl NodeNetwork {
952944
let parent_input = node.inputs.get(*import_index).unwrap_or_else(|| panic!("Import index {import_index} should always exist"));
953945
match *parent_input {
954946
// If the input to self is a node, connect the corresponding output of the inner network to it
955-
NodeInput::Node { node_id, output_index, lambda } => {
947+
NodeInput::Node { node_id, output_index } => {
956948
let skip = node.original_location.skip_inputs;
957-
nested_node.populate_first_network_input(node_id, output_index, nested_input_index, lambda, node.original_location.inputs(*import_index), skip);
949+
nested_node.populate_first_network_input(node_id, output_index, nested_input_index, node.original_location.inputs(*import_index), skip);
958950
let input_node = self.nodes.get_mut(&node_id).unwrap_or_else(|| panic!("unable find input node {node_id:?}"));
959951
input_node.original_location.dependants[output_index].push(nested_node_id);
960952
}
@@ -1052,7 +1044,6 @@ impl NodeNetwork {
10521044
*export = NodeInput::Node {
10531045
node_id: merged_node_id,
10541046
output_index: 0,
1055-
lambda: false,
10561047
};
10571048
}
10581049
}
@@ -1319,7 +1310,7 @@ mod test {
13191310
nodes: [
13201311
id_node.clone(),
13211312
DocumentNode {
1322-
inputs: vec![NodeInput::lambda(NodeId(0), 0)],
1313+
inputs: vec![NodeInput::node(NodeId(0), 0)],
13231314
implementation: DocumentNodeImplementation::Extract,
13241315
..Default::default()
13251316
},
@@ -1374,7 +1365,7 @@ mod test {
13741365
let reference = ProtoNode {
13751366
identifier: "graphene_core::structural::ConsNode".into(),
13761367
input: ProtoNodeInput::ManualComposition(concrete!(u32)),
1377-
construction_args: ConstructionArgs::Nodes(vec![(NodeId(0), false)]),
1368+
construction_args: ConstructionArgs::Nodes(vec![NodeId(0)]),
13781369
..Default::default()
13791370
};
13801371
assert_eq!(proto_node, reference);
@@ -1391,7 +1382,7 @@ mod test {
13911382
ProtoNode {
13921383
identifier: "graphene_core::structural::ConsNode".into(),
13931384
input: ProtoNodeInput::ManualComposition(concrete!(u32)),
1394-
construction_args: ConstructionArgs::Nodes(vec![(NodeId(14), false)]),
1385+
construction_args: ConstructionArgs::Nodes(vec![NodeId(14)]),
13951386
original_location: OriginalLocation {
13961387
path: Some(vec![NodeId(1), NodeId(0)]),
13971388
inputs_source: [(Source { node: vec![NodeId(1)], index: 1 }, 1)].into(),

node-graph/graph-craft/src/proto.rs

Lines changed: 36 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
121120
impl 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

186177
impl 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

Comments
 (0)