mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
A few minor lints and docs (#1436)
* A few minor lints and docs * Added required packages to compile on Debian-style linux * Inlined some format args, and removed some `&` in args (they cause about 6% slowdown that compiler cannot inline) * a few spelling mistakes * fix fmt
This commit is contained in:
@@ -58,9 +58,9 @@ impl DocumentNode {
|
||||
}
|
||||
|
||||
fn resolve_proto_node(mut self) -> ProtoNode {
|
||||
assert!(!self.inputs.is_empty() || self.manual_composition.is_some(), "Resolving document node {:#?} with no inputs", self);
|
||||
assert!(!self.inputs.is_empty() || self.manual_composition.is_some(), "Resolving document node {self:#?} with no inputs");
|
||||
let DocumentNodeImplementation::Unresolved(fqn) = self.implementation else {
|
||||
unreachable!("tried to resolve not flattened node on resolved node {:?}", self);
|
||||
unreachable!("tried to resolve not flattened node on resolved node {self:?}");
|
||||
};
|
||||
let (input, mut args) = if let Some(ty) = self.manual_composition {
|
||||
(ProtoNodeInput::ShortCircut(ty), ConstructionArgs::Nodes(vec![]))
|
||||
@@ -68,7 +68,7 @@ impl DocumentNode {
|
||||
let first = self.inputs.remove(0);
|
||||
match first {
|
||||
NodeInput::Value { tagged_value, .. } => {
|
||||
assert_eq!(self.inputs.len(), 0, "{}, {:?}", &self.name, &self.inputs);
|
||||
assert_eq!(self.inputs.len(), 0, "{}, {:?}", self.name, self.inputs);
|
||||
(ProtoNodeInput::None, ConstructionArgs::Value(tagged_value))
|
||||
}
|
||||
NodeInput::Node { node_id, output_index, lambda } => {
|
||||
@@ -82,9 +82,9 @@ impl DocumentNode {
|
||||
assert!(!self.inputs.iter().any(|input| matches!(input, NodeInput::Network(_))), "recieved non resolved parameter");
|
||||
assert!(
|
||||
!self.inputs.iter().any(|input| matches!(input, NodeInput::Value { .. })),
|
||||
"recieved value as parameter. inupts: {:#?}, construction_args: {:#?}",
|
||||
&self.inputs,
|
||||
&args
|
||||
"received value as parameter. inputs: {:#?}, construction_args: {:#?}",
|
||||
self.inputs,
|
||||
args
|
||||
);
|
||||
|
||||
// If we have one parameter of the type inline, set it as the construction args
|
||||
@@ -689,7 +689,7 @@ impl NodeNetwork {
|
||||
pub fn flatten_with_fns(&mut self, node: NodeId, map_ids: impl Fn(NodeId, NodeId) -> NodeId + Copy, gen_id: impl Fn() -> NodeId + Copy) {
|
||||
self.resolve_extract_nodes();
|
||||
let Some((id, mut node)) = self.nodes.remove_entry(&node) else {
|
||||
warn!("The node which was supposed to be flattened does not exist in the network, id {} network {:#?}", node, self);
|
||||
warn!("The node which was supposed to be flattened does not exist in the network, id {node} network {self:#?}");
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -804,7 +804,7 @@ impl NodeNetwork {
|
||||
}
|
||||
|
||||
fn remove_id_node(&mut self, id: NodeId) -> Result<(), String> {
|
||||
let node = self.nodes.get(&id).ok_or_else(|| format!("Node with id {} does not exist", id))?.clone();
|
||||
let node = self.nodes.get(&id).ok_or_else(|| format!("Node with id {id} does not exist"))?.clone();
|
||||
if let DocumentNodeImplementation::Unresolved(ident) = &node.implementation {
|
||||
if ident.name == "graphene_core::ops::IdNode" {
|
||||
assert_eq!(node.inputs.len(), 1, "Id node has more than one input");
|
||||
@@ -855,7 +855,7 @@ impl NodeNetwork {
|
||||
.collect::<Vec<_>>();
|
||||
for id in id_nodes {
|
||||
if let Err(e) = self.remove_id_node(id) {
|
||||
log::warn!("{}", e)
|
||||
log::warn!("{e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1070,8 +1070,8 @@ mod test {
|
||||
network.generate_node_paths(&[]);
|
||||
network.flatten_with_fns(1, |self_id, inner_id| self_id * 10 + inner_id, gen_node_id);
|
||||
let flat_network = flat_network();
|
||||
println!("{:#?}", flat_network);
|
||||
println!("{:#?}", network);
|
||||
println!("{flat_network:#?}");
|
||||
println!("{network:#?}");
|
||||
|
||||
assert_eq!(flat_network, network);
|
||||
}
|
||||
@@ -1131,7 +1131,7 @@ mod test {
|
||||
let resolved_network = network.into_proto_networks().collect::<Vec<_>>();
|
||||
|
||||
println!("{:#?}", resolved_network[0]);
|
||||
println!("{:#?}", construction_network);
|
||||
println!("{construction_network:#?}");
|
||||
assert_eq!(resolved_network[0], construction_network);
|
||||
}
|
||||
|
||||
@@ -1248,7 +1248,7 @@ mod test {
|
||||
#[test]
|
||||
fn simple_duplicate() {
|
||||
let result = output_duplicate(vec![NodeOutput::new(1, 0)], NodeInput::node(1, 0));
|
||||
println!("{:#?}", result);
|
||||
println!("{result:#?}");
|
||||
assert_eq!(result.outputs.len(), 1, "The number of outputs should remain as 1");
|
||||
assert_eq!(result.outputs[0], NodeOutput::new(11, 0), "The outer network output should be from a duplicated inner network");
|
||||
let mut ids = result.nodes.keys().copied().collect::<Vec<_>>();
|
||||
|
||||
@@ -202,7 +202,7 @@ impl<'a> TaggedValue {
|
||||
pub fn to_primitive_string(&self) -> String {
|
||||
match self {
|
||||
TaggedValue::None => "()".to_string(),
|
||||
TaggedValue::String(x) => format!("\"{}\"", x),
|
||||
TaggedValue::String(x) => format!("\"{x}\""),
|
||||
TaggedValue::U32(x) => x.to_string() + "_u32",
|
||||
TaggedValue::F32(x) => x.to_string() + "_f32",
|
||||
TaggedValue::F64(x) => x.to_string() + "_f64",
|
||||
|
||||
@@ -104,8 +104,8 @@ impl core::fmt::Display for ProtoNetwork {
|
||||
f.write_str("Primary input: ")?;
|
||||
match &node.input {
|
||||
ProtoNodeInput::None => f.write_str("None")?,
|
||||
ProtoNodeInput::Network(ty) => f.write_fmt(format_args!("Network (type = {:?})", ty))?,
|
||||
ProtoNodeInput::ShortCircut(ty) => f.write_fmt(format_args!("Lambda (type = {:?})", ty))?,
|
||||
ProtoNodeInput::Network(ty) => f.write_fmt(format_args!("Network (type = {ty:?})"))?,
|
||||
ProtoNodeInput::ShortCircut(ty) => f.write_fmt(format_args!("Lambda (type = {ty:?})"))?,
|
||||
ProtoNodeInput::Node(_, _) => f.write_str("Node")?,
|
||||
}
|
||||
f.write_str("\n")?;
|
||||
@@ -220,7 +220,7 @@ impl ProtoNodeInput {
|
||||
pub fn unwrap_node(self) -> NodeId {
|
||||
match self {
|
||||
ProtoNodeInput::Node(id, _) => id,
|
||||
_ => panic!("tried to unwrap id from non node input \n node: {:#?}", self),
|
||||
_ => panic!("tried to unwrap id from non node input \n node: {self:#?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ impl ProtoNode {
|
||||
pub fn unwrap_construction_nodes(&self) -> Vec<(NodeId, bool)> {
|
||||
match &self.construction_args {
|
||||
ConstructionArgs::Nodes(nodes) => nodes.clone(),
|
||||
_ => panic!("tried to unwrap nodes from non node construction args \n node: {:#?}", self),
|
||||
_ => panic!("tried to unwrap nodes from non node construction args \n node: {self:#?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,10 +282,7 @@ impl ProtoNetwork {
|
||||
fn check_ref(&self, ref_id: &NodeId, id: &NodeId) {
|
||||
assert!(
|
||||
self.nodes.iter().any(|(check_id, _)| check_id == ref_id),
|
||||
"Node id:{} has a reference which uses node id:{} which doesn't exist in network {:#?}",
|
||||
id,
|
||||
ref_id,
|
||||
self
|
||||
"Node id:{id} has a reference which uses node id:{ref_id} which doesn't exist in network {self:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -403,7 +400,7 @@ impl ProtoNetwork {
|
||||
return Ok(());
|
||||
};
|
||||
if temp_marks.contains(&node_id) {
|
||||
return Err(format!("Cycle detected {:#?}, {:#?}", &inwards_edges, &network));
|
||||
return Err(format!("Cycle detected {inwards_edges:#?}, {network:#?}"));
|
||||
}
|
||||
|
||||
if let Some(dependencies) = inwards_edges.get(&node_id) {
|
||||
@@ -586,7 +583,7 @@ impl TypingContext {
|
||||
.ok_or(format!("No implementations found for {:?}. Other implementations found {:?}", node.identifier, self.lookup))?;
|
||||
|
||||
if matches!(input, Type::Generic(_)) {
|
||||
return Err(format!("Generic types are not supported as inputs yet {:?} occurred in {:?}", &input, node.identifier));
|
||||
return Err(format!("Generic types are not supported as inputs yet {:?} occurred in {:?}", input, node.identifier));
|
||||
}
|
||||
if parameters.iter().any(|p| {
|
||||
matches!(p,
|
||||
@@ -695,7 +692,7 @@ mod test {
|
||||
fn topological_sort() {
|
||||
let construction_network = test_network();
|
||||
let sorted = construction_network.topological_sort().expect("Error when calling 'topological_sort' on 'construction_network.");
|
||||
println!("{:#?}", sorted);
|
||||
println!("{sorted:#?}");
|
||||
assert_eq!(sorted, vec![14, 10, 11, 1]);
|
||||
}
|
||||
|
||||
@@ -715,7 +712,7 @@ mod test {
|
||||
println!("nodes: {:#?}", construction_network.nodes);
|
||||
assert_eq!(sorted, vec![0, 1, 2, 3]);
|
||||
let ids: Vec<_> = construction_network.nodes.iter().map(|(id, _)| *id).collect();
|
||||
println!("{:#?}", ids);
|
||||
println!("{ids:#?}");
|
||||
println!("nodes: {:#?}", construction_network.nodes);
|
||||
assert_eq!(construction_network.nodes[0].1.identifier.name.as_ref(), "value");
|
||||
assert_eq!(ids, vec![0, 1, 2, 3]);
|
||||
@@ -729,7 +726,7 @@ mod test {
|
||||
let sorted = construction_network.topological_sort().expect("Error when calling 'topological_sort' on 'construction_network.");
|
||||
assert_eq!(sorted, vec![0, 1, 2, 3]);
|
||||
let ids: Vec<_> = construction_network.nodes.iter().map(|(id, _)| *id).collect();
|
||||
println!("{:#?}", ids);
|
||||
println!("{ids:#?}");
|
||||
assert_eq!(construction_network.nodes[0].1.identifier.name.as_ref(), "value");
|
||||
assert_eq!(ids, vec![0, 1, 2, 3]);
|
||||
}
|
||||
@@ -738,7 +735,7 @@ mod test {
|
||||
fn input_resolution() {
|
||||
let mut construction_network = test_network();
|
||||
construction_network.resolve_inputs().expect("Error when calling 'resolve_inputs' on 'construction_network.");
|
||||
println!("{:#?}", construction_network);
|
||||
println!("{construction_network:#?}");
|
||||
assert_eq!(construction_network.nodes[0].1.identifier.name.as_ref(), "value");
|
||||
assert_eq!(construction_network.nodes.len(), 6);
|
||||
assert_eq!(construction_network.nodes[5].1.construction_args, ConstructionArgs::Nodes(vec![(3, false), (4, true)]));
|
||||
|
||||
Reference in New Issue
Block a user