mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
Replace node definition string-based lookups with DefinitionIdentifier instances (#3451)
* create definition identifier and integrate it * Bug fixes and code review * formatting * Fix migrations * Fix remove handles migration * formatting * Fix test * Fix tests 2 * fix deserialization * Code review * Small fixes * Consolidate 'Morph' node migrations * Add old SamplePointsNode name to migrations list * Fix tests * Unrelated small fix * Fix migration crashes * Fix tests * Final code review * fmt * Add metadata --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -800,7 +800,7 @@ impl NodeNetwork {
|
||||
let path = node.original_location.path.clone().unwrap_or_default();
|
||||
|
||||
// Replace value inputs with dedicated value nodes
|
||||
if node.implementation != DocumentNodeImplementation::ProtoNode("core_types::value::ClonedNode".into()) {
|
||||
if node.implementation != DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::value::ClonedNode")) {
|
||||
Self::replace_value_inputs_with_nodes(&mut node.inputs, &mut self.nodes, &path, gen_id, map_ids, id);
|
||||
}
|
||||
|
||||
@@ -842,7 +842,10 @@ impl NodeNetwork {
|
||||
for (nested_node_id, mut nested_node) in inner_network.nodes.into_iter() {
|
||||
for (nested_input_index, nested_input) in nested_node.clone().inputs.iter().enumerate() {
|
||||
if let NodeInput::Import { import_index, .. } = nested_input {
|
||||
let parent_input = node.inputs.get(*import_index).unwrap_or_else(|| panic!("Import index {import_index} should always exist"));
|
||||
let parent_input = node
|
||||
.inputs
|
||||
.get(*import_index)
|
||||
.unwrap_or_else(|| panic!("Import index {import_index} of network node implementation {:?} should always exist", nested_node.implementation));
|
||||
match *parent_input {
|
||||
// If the input to self is a node, connect the corresponding output of the inner network to it
|
||||
NodeInput::Node { node_id, output_index } => {
|
||||
@@ -936,7 +939,7 @@ impl NodeNetwork {
|
||||
merged_node_id,
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::Value { tagged_value, exposed }],
|
||||
implementation: DocumentNodeImplementation::ProtoNode("core_types::value::ClonedNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::value::ClonedNode")),
|
||||
original_location,
|
||||
..Default::default()
|
||||
},
|
||||
@@ -1035,7 +1038,7 @@ impl NodeNetwork {
|
||||
assert_eq!(output_index, 0);
|
||||
// TODO: check if we can read lambda checking?
|
||||
let mut input_node = self.nodes.remove(&node_id).unwrap();
|
||||
node.implementation = DocumentNodeImplementation::ProtoNode("core_types::value::ClonedNode".into());
|
||||
node.implementation = DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::value::ClonedNode"));
|
||||
if let Some(input) = input_node.inputs.get_mut(0) {
|
||||
*input = match &input {
|
||||
NodeInput::Node { .. } => NodeInput::import(generic!(T), 0),
|
||||
@@ -1152,7 +1155,7 @@ mod test {
|
||||
NodeId(0),
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::import(concrete!(u32), 0), NodeInput::import(concrete!(u32), 1)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode("core_types::structural::ConsNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::structural::ConsNode")),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
@@ -1160,7 +1163,7 @@ mod test {
|
||||
NodeId(1),
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::node(NodeId(0), 0)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode("core_types::ops::AddPairNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::ops::AddPairNode")),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
@@ -1182,7 +1185,7 @@ mod test {
|
||||
NodeId(1),
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::import(concrete!(u32), 0), NodeInput::import(concrete!(u32), 1)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode("core_types::structural::ConsNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::structural::ConsNode")),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
@@ -1190,7 +1193,7 @@ mod test {
|
||||
NodeId(2),
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::node(NodeId(1), 0)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode("core_types::ops::AddPairNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::ops::AddPairNode")),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
@@ -1263,13 +1266,13 @@ mod test {
|
||||
let document_node = DocumentNode {
|
||||
inputs: vec![NodeInput::node(NodeId(0), 0)],
|
||||
call_argument: concrete!(u32),
|
||||
implementation: DocumentNodeImplementation::ProtoNode("core_types::structural::ConsNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::structural::ConsNode")),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let proto_node = document_node.resolve_proto_node();
|
||||
let reference = ProtoNode {
|
||||
identifier: "core_types::structural::ConsNode".into(),
|
||||
identifier: ProtoNodeIdentifier::new("core_types::structural::ConsNode"),
|
||||
call_argument: concrete!(u32),
|
||||
construction_args: ConstructionArgs::Nodes(vec![NodeId(0)]),
|
||||
..Default::default()
|
||||
@@ -1286,7 +1289,7 @@ mod test {
|
||||
(
|
||||
NodeId(10),
|
||||
ProtoNode {
|
||||
identifier: "core_types::structural::ConsNode".into(),
|
||||
identifier: ProtoNodeIdentifier::new("core_types::structural::ConsNode"),
|
||||
call_argument: concrete!(u32),
|
||||
construction_args: ConstructionArgs::Nodes(vec![NodeId(14)]),
|
||||
original_location: OriginalLocation {
|
||||
@@ -1302,7 +1305,7 @@ mod test {
|
||||
(
|
||||
NodeId(11),
|
||||
ProtoNode {
|
||||
identifier: "core_types::ops::AddPairNode".into(),
|
||||
identifier: ProtoNodeIdentifier::new("core_types::ops::AddPairNode"),
|
||||
call_argument: concrete!(Context),
|
||||
construction_args: ConstructionArgs::Nodes(vec![NodeId(10)]),
|
||||
original_location: OriginalLocation {
|
||||
@@ -1317,7 +1320,7 @@ mod test {
|
||||
(
|
||||
NodeId(14),
|
||||
ProtoNode {
|
||||
identifier: "core_types::value::ClonedNode".into(),
|
||||
identifier: ProtoNodeIdentifier::new("core_types::value::ClonedNode"),
|
||||
call_argument: concrete!(core_types::Context),
|
||||
construction_args: ConstructionArgs::Value(TaggedValue::U32(2).into()),
|
||||
original_location: OriginalLocation {
|
||||
@@ -1351,7 +1354,7 @@ mod test {
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::node(NodeId(14), 0)],
|
||||
call_argument: concrete!(u32),
|
||||
implementation: DocumentNodeImplementation::ProtoNode("core_types::structural::ConsNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::structural::ConsNode")),
|
||||
original_location: OriginalLocation {
|
||||
path: Some(vec![NodeId(1), NodeId(0)]),
|
||||
inputs_source: [(Source { node: vec![NodeId(1)], index: 1 }, 1)].into(),
|
||||
@@ -1365,7 +1368,7 @@ mod test {
|
||||
NodeId(14),
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::value(TaggedValue::U32(2), false)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode("core_types::value::ClonedNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::value::ClonedNode")),
|
||||
original_location: OriginalLocation {
|
||||
path: Some(vec![NodeId(1), NodeId(4)]),
|
||||
inputs_source: HashMap::new(),
|
||||
@@ -1379,7 +1382,7 @@ mod test {
|
||||
NodeId(11),
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::node(NodeId(10), 0)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode("core_types::ops::AddPairNode".into()),
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("core_types::ops::AddPairNode")),
|
||||
original_location: OriginalLocation {
|
||||
path: Some(vec![NodeId(1), NodeId(1)]),
|
||||
inputs_source: HashMap::new(),
|
||||
|
||||
@@ -30,7 +30,7 @@ impl core::fmt::Display for ProtoNetwork {
|
||||
return f.write_str("{{Unknown Node}}");
|
||||
};
|
||||
f.write_str("Node: ")?;
|
||||
f.write_str(&node.identifier.name)?;
|
||||
f.write_str(node.identifier.as_str())?;
|
||||
|
||||
f.write_str("\n")?;
|
||||
f.write_str(&"\t".repeat(indent))?;
|
||||
@@ -156,7 +156,7 @@ impl ProtoNode {
|
||||
use std::hash::Hasher;
|
||||
let mut hasher = rustc_hash::FxHasher::default();
|
||||
|
||||
self.identifier.name.hash(&mut hasher);
|
||||
self.identifier.as_str().hash(&mut hasher);
|
||||
self.construction_args.hash(&mut hasher);
|
||||
if self.skip_deduplication {
|
||||
self.original_location.path.hash(&mut hasher);
|
||||
@@ -612,7 +612,7 @@ impl GraphError {
|
||||
pub fn new(node: &ProtoNode, text: impl Into<GraphErrorType>) -> Self {
|
||||
Self {
|
||||
node_path: node.original_location.path.clone().unwrap_or_default(),
|
||||
identifier: node.identifier.name.clone(),
|
||||
identifier: Cow::Owned(node.identifier.as_str().to_string()),
|
||||
error: text.into(),
|
||||
}
|
||||
}
|
||||
@@ -916,7 +916,7 @@ mod test {
|
||||
let ids: Vec<_> = construction_network.nodes.iter().map(|(id, _)| *id).collect();
|
||||
println!("{ids:#?}");
|
||||
println!("nodes: {:#?}", construction_network.nodes);
|
||||
assert_eq!(construction_network.nodes[0].1.identifier.name.as_ref(), "value");
|
||||
assert_eq!(construction_network.nodes[0].1.identifier.as_str(), "value");
|
||||
assert_eq!(ids, vec![NodeId(0), NodeId(1), NodeId(2), NodeId(3)]);
|
||||
}
|
||||
|
||||
@@ -929,7 +929,7 @@ mod test {
|
||||
assert_eq!(sorted, vec![NodeId(0), NodeId(1), NodeId(2), NodeId(3)]);
|
||||
let ids: Vec<_> = construction_network.nodes.iter().map(|(id, _)| *id).collect();
|
||||
println!("{ids:#?}");
|
||||
assert_eq!(construction_network.nodes[0].1.identifier.name.as_ref(), "value");
|
||||
assert_eq!(construction_network.nodes[0].1.identifier.as_str(), "value");
|
||||
assert_eq!(ids, vec![NodeId(0), NodeId(1), NodeId(2), NodeId(3)]);
|
||||
}
|
||||
|
||||
@@ -940,7 +940,7 @@ mod test {
|
||||
.insert_context_nullification_nodes()
|
||||
.expect("Error when calling 'insert_context_nullification_nodes' on 'construction_network.");
|
||||
construction_network.generate_stable_node_ids();
|
||||
assert_eq!(construction_network.nodes[0].1.identifier.name.as_ref(), "value");
|
||||
assert_eq!(construction_network.nodes[0].1.identifier.as_str(), "value");
|
||||
let ids: Vec<_> = construction_network.nodes.iter().map(|(id, _)| *id).collect();
|
||||
|
||||
// If this assert fails: These NodeIds seem to be changing when you modify TaggedValue, just update them.
|
||||
@@ -958,7 +958,7 @@ mod test {
|
||||
(
|
||||
NodeId(7),
|
||||
ProtoNode {
|
||||
identifier: "id".into(),
|
||||
identifier: ProtoNodeIdentifier::new("id"),
|
||||
call_argument: concrete!(()),
|
||||
construction_args: ConstructionArgs::Nodes(vec![NodeId(11)]),
|
||||
..Default::default()
|
||||
@@ -967,7 +967,7 @@ mod test {
|
||||
(
|
||||
NodeId(1),
|
||||
ProtoNode {
|
||||
identifier: "id".into(),
|
||||
identifier: ProtoNodeIdentifier::new("id"),
|
||||
call_argument: concrete!(()),
|
||||
construction_args: ConstructionArgs::Nodes(vec![NodeId(11)]),
|
||||
..Default::default()
|
||||
@@ -976,7 +976,7 @@ mod test {
|
||||
(
|
||||
NodeId(10),
|
||||
ProtoNode {
|
||||
identifier: "cons".into(),
|
||||
identifier: ProtoNodeIdentifier::new("cons"),
|
||||
call_argument: concrete!(u32),
|
||||
construction_args: ConstructionArgs::Nodes(vec![NodeId(14)]),
|
||||
..Default::default()
|
||||
@@ -985,7 +985,7 @@ mod test {
|
||||
(
|
||||
NodeId(11),
|
||||
ProtoNode {
|
||||
identifier: "add".into(),
|
||||
identifier: ProtoNodeIdentifier::new("add"),
|
||||
call_argument: concrete!(()),
|
||||
construction_args: ConstructionArgs::Nodes(vec![NodeId(10)]),
|
||||
..Default::default()
|
||||
@@ -994,7 +994,7 @@ mod test {
|
||||
(
|
||||
NodeId(14),
|
||||
ProtoNode {
|
||||
identifier: "value".into(),
|
||||
identifier: ProtoNodeIdentifier::new("value"),
|
||||
call_argument: concrete!(()),
|
||||
construction_args: ConstructionArgs::Value(value::TaggedValue::U32(2).into()),
|
||||
..Default::default()
|
||||
@@ -1014,7 +1014,7 @@ mod test {
|
||||
(
|
||||
NodeId(1),
|
||||
ProtoNode {
|
||||
identifier: "id".into(),
|
||||
identifier: ProtoNodeIdentifier::new("id"),
|
||||
call_argument: concrete!(()),
|
||||
construction_args: ConstructionArgs::Nodes(vec![NodeId(2)]),
|
||||
..Default::default()
|
||||
@@ -1023,7 +1023,7 @@ mod test {
|
||||
(
|
||||
NodeId(2),
|
||||
ProtoNode {
|
||||
identifier: "id".into(),
|
||||
identifier: ProtoNodeIdentifier::new("id"),
|
||||
call_argument: concrete!(()),
|
||||
construction_args: ConstructionArgs::Nodes(vec![NodeId(1)]),
|
||||
..Default::default()
|
||||
|
||||
Reference in New Issue
Block a user