Clean up imports and warnings in Rust code

This commit is contained in:
Keavon Chambers 2023-01-13 12:45:14 -08:00
parent b030a1860b
commit bf1a3e3daf
15 changed files with 204 additions and 191 deletions

View file

@ -1,8 +1,10 @@
use crate::messages::input_mapper::utility_types::misc::ActionKeys;
use crate::messages::layout::utility_types::layout_widget::WidgetCallback;
use crate::messages::{input_mapper::utility_types::misc::ActionKeys, portfolio::document::node_graph::FrontendGraphDataType};
use crate::messages::portfolio::document::node_graph::FrontendGraphDataType;
use graphite_proc_macros::WidgetBuilder;
use derivative::*;
use graphite_proc_macros::WidgetBuilder;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Derivative, Serialize, Deserialize, WidgetBuilder)]

View file

@ -1,7 +1,9 @@
use crate::messages::input_mapper::utility_types::misc::ActionKeys;
use crate::messages::layout::utility_types::layout_widget::WidgetCallback;
use document_legacy::{color::Color, layers::layer_info::LayerDataTypeDiscriminant, LayerId};
use document_legacy::color::Color;
use document_legacy::layers::layer_info::LayerDataTypeDiscriminant;
use document_legacy::LayerId;
use graphite_proc_macros::WidgetBuilder;
use derivative::*;

View file

@ -62,23 +62,23 @@ fn start_widgets(document_node: &DocumentNode, node_id: NodeId, index: usize, na
widgets
}
fn text_widget(document_node: &DocumentNode, node_id: NodeId, index: usize, name: &str, blank_assist: bool) -> Vec<WidgetHolder> {
let mut widgets = start_widgets(document_node, node_id, index, name, FrontendGraphDataType::Text, blank_assist);
// fn text_widget(document_node: &DocumentNode, node_id: NodeId, index: usize, name: &str, blank_assist: bool) -> Vec<WidgetHolder> {
// let mut widgets = start_widgets(document_node, node_id, index, name, FrontendGraphDataType::Text, blank_assist);
if let NodeInput::Value {
tagged_value: TaggedValue::String(x),
exposed: false,
} = &document_node.inputs[index]
{
widgets.extend_from_slice(&[
WidgetHolder::unrelated_separator(),
TextInput::new(x.clone())
.on_update(update_value(|x: &TextInput| TaggedValue::String(x.value.clone()), node_id, index))
.widget_holder(),
])
}
widgets
}
// if let NodeInput::Value {
// tagged_value: TaggedValue::String(x),
// exposed: false,
// } = &document_node.inputs[index]
// {
// widgets.extend_from_slice(&[
// WidgetHolder::unrelated_separator(),
// TextInput::new(x.clone())
// .on_update(update_value(|x: &TextInput| TaggedValue::String(x.value.clone()), node_id, index))
// .widget_holder(),
// ])
// }
// widgets
// }
fn text_area_widget(document_node: &DocumentNode, node_id: NodeId, index: usize, name: &str, blank_assist: bool) -> Vec<WidgetHolder> {
let mut widgets = start_widgets(document_node, node_id, index, name, FrontendGraphDataType::Text, blank_assist);

View file

@ -139,6 +139,7 @@ impl Fsm for NodeGraphToolFsmState {
responses.push_back(DocumentMessage::DeselectAllLayers.into());
use graph_craft::{document::*, generic, proto::*};
let network = NodeNetwork {
inputs: vec![0],
output: 1,

View file

@ -1,18 +1,19 @@
#![cfg_attr(all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows")]
use std::sync::Arc;
use graphite_editor::application::Editor;
use graphite_editor::messages::frontend::utility_types::FrontendImageData;
use graphite_editor::messages::prelude::*;
use axum::body::StreamBody;
use axum::extract::Path;
use axum::http;
use axum::response::IntoResponse;
use axum::{routing::get, Router};
use axum::routing::get;
use axum::Router;
use fern::colors::{Color, ColoredLevelConfig};
use graphite_editor::application::Editor;
use graphite_editor::messages::frontend::utility_types::FrontendImageData;
use graphite_editor::messages::prelude::*;
use http::{Response, StatusCode};
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::Mutex;
use tauri::Manager;

View file

@ -1,5 +1,6 @@
use super::*;
use crate::{consts::MIN_SEPERATION_VALUE, ComputeType};
use crate::consts::MIN_SEPERATION_VALUE;
use crate::ComputeType;
use glam::DVec2;

View file

@ -544,8 +544,8 @@ mod test {
#[test]
fn window_node() {
let radius = ValueNode::new(1u32);
static data: &[Color] = &[Color::from_rgbf32_unchecked(1., 0., 0.); 25];
let image = ValueNode::<_>::new(ImageSlice { width: 5, height: 5, data });
static DATA: &[Color] = &[Color::from_rgbf32_unchecked(1., 0., 0.); 25];
let image = ValueNode::<_>::new(ImageSlice { width: 5, height: 5, data: DATA });
let window = WindowNode::new(radius, image);
//let window: TypeNode<_, u32, ImageWindowIterator<'static>> = TypeNode::new(window);
let vec = window.eval(0);
@ -560,8 +560,8 @@ mod test {
fn blur_node() {
let radius = ValueNode::new(1u32);
let sigma = ValueNode::new(3f64);
static data: &[Color] = &[Color::from_rgbf32_unchecked(1., 0., 0.); 20];
let image = ValueNode::<_>::new(ImageSlice { width: 10, height: 2, data });
static DATA: &[Color] = &[Color::from_rgbf32_unchecked(1., 0., 0.); 20];
let image = ValueNode::<_>::new(ImageSlice { width: 10, height: 2, data: DATA });
let window = WindowNode::new(radius, image);
let window: TypeNode<_, u32, ImageWindowIterator<'static>> = TypeNode::new(window);
let pos_to_dist = MapSndNode::new(DistanceNode);
@ -579,6 +579,6 @@ mod test {
assert_eq!(vec.len(), 10);
let vec = ComposeNode::new(blur, collect);
let vec: TypeNode<_, (), Vec<Color>> = TypeNode::new(vec);
let image = vec.eval(());
let _image = vec.eval(());
}
}

View file

@ -2,7 +2,8 @@ use std::error::Error;
use dyn_any::DynAny;
use crate::{document::NodeNetwork, proto::ProtoNetwork};
use crate::document::NodeNetwork;
use crate::proto::ProtoNetwork;
pub struct Compiler {}

View file

@ -198,7 +198,8 @@ where
}
}*/
use graphene_core::{ops::dynamic::Dynamic, AsRefNode};
use graphene_core::ops::dynamic::Dynamic;
use graphene_core::AsRefNode;
pub struct BoxedComposition<'a, Second> {
pub first: Box<dyn Node<(), Output = Dynamic<'a>>>,
pub second: Second,

View file

@ -1,9 +1,12 @@
use graph_craft::document::*;
use graph_craft::proto::*;
use graphene_core::raster::Image;
use graphene_core::value::ValueNode;
use graphene_core::Node;
use bytemuck::Pod;
use core::marker::PhantomData;
use dyn_any::StaticTypeSized;
use graph_craft::document::*;
use graph_craft::proto::*;
use graphene_core::{raster::Image, value::ValueNode, Node};
pub struct MapGpuNode<NN: Node<()>, I: IntoIterator<Item = S>, S: StaticTypeSized + Sync + Send + Pod, O: StaticTypeSized + Sync + Send + Pod>(pub NN, PhantomData<(S, I, O)>);

View file

@ -1,9 +1,11 @@
use core::marker::PhantomData;
use dyn_any::{DynAny, StaticType};
use graphene_core::ops::FlatMapResultNode;
use graphene_core::generic::FnNode;
use graphene_core::ops::{FlatMapResultNode, MapResultNode};
use graphene_core::raster::{Color, Image};
use graphene_core::structural::{ComposeNode, ConsNode};
use graphene_core::{generic::FnNode, ops::MapResultNode, structural::Then, value::ValueNode, Node};
use graphene_core::structural::{ComposeNode, ConsNode, Then};
use graphene_core::value::ValueNode;
use graphene_core::Node;
use image::Pixel;
use std::path::Path;

View file

@ -1,11 +1,12 @@
use std::error::Error;
use crate::node_registry::push_node;
use borrow_stack::{BorrowStack, FixedSizeStack};
use graph_craft::executor::Executor;
use graph_craft::proto::ProtoNetwork;
use graphene_core::Node;
use graphene_std::any::{Any, TypeErasedNode};
use crate::node_registry::push_node;
use graph_craft::{executor::Executor, proto::ProtoNetwork};
use std::error::Error;
pub struct DynamicExecutor {
stack: FixedSizeStack<TypeErasedNode<'static>>,

View file

@ -3,7 +3,7 @@ use glam::DVec2;
use graphene_core::generic::FnNode;
use graphene_core::ops::{AddNode, CloneNode, IdNode, TypeNode};
use graphene_core::raster::color::Color;
use graphene_core::raster::{Image, MapFnIterator};
use graphene_core::raster::Image;
use graphene_core::structural::{ComposeNode, ConsNode, Then};
use graphene_core::value::ValueNode;
use graphene_core::vector::subpath::Subpath;
@ -483,7 +483,7 @@ static NODE_REGISTRY: &[(NodeIdentifier, NodeConstructor)] = &[
(NodeIdentifier::new("graphene_std::memo::CacheNode", &[concrete!("Image")]), |proto_node, stack| {
let node_id = proto_node.input.unwrap_node() as usize;
use graphene_core::raster::*;
if let ConstructionArgs::Nodes(image_args) = proto_node.construction_args {
if let ConstructionArgs::Nodes(_image_args) = proto_node.construction_args {
stack.push_fn(move |nodes| {
let image = nodes.get(node_id).unwrap();
let node: DynAnyNode<_, Image, Image, &Image> = DynAnyNode::new(CacheNode::new());

View file

@ -1,21 +1,20 @@
use std::path::Path;
use super::context::Context;
use graph_craft::executor::{Any, Executor};
use graphene_core::gpu::PushConstants;
use bytemuck::Pod;
use dyn_any::StaticTypeSized;
use graph_craft::executor::{Any, Executor};
use vulkano::{
buffer::{self, BufferUsage, CpuAccessibleBuffer},
command_buffer::{allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage},
descriptor_set::{allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet},
device::Device,
memory::allocator::StandardMemoryAllocator,
pipeline::{ComputePipeline, Pipeline, PipelineBindPoint},
sync::GpuFuture,
};
use graph_craft::proto::*;
use graphene_core::gpu::PushConstants;
use vulkano::buffer::{self, BufferUsage, CpuAccessibleBuffer};
use vulkano::command_buffer::allocator::StandardCommandBufferAllocator;
use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage};
use vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator;
use vulkano::descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet};
use vulkano::device::Device;
use vulkano::memory::allocator::StandardMemoryAllocator;
use vulkano::pipeline::{ComputePipeline, Pipeline, PipelineBindPoint};
use vulkano::sync::GpuFuture;
#[derive(Debug)]
pub struct GpuExecutor<I: StaticTypeSized, O> {
@ -111,73 +110,72 @@ fn create_buffer<T: Pod + Send + Sync>(data: Vec<T>, alloc: &StandardMemoryAlloc
buffer::CpuAccessibleBuffer::from_iter(alloc, buffer_usage, false, data.into_iter())
}
#[cfg(test)]
mod test {
use super::*;
use graph_craft::concrete;
use graph_craft::generic;
// TODO: Fix this test
// #[cfg(test)]
// mod test {
// use graph_craft::proto::{ConstructionArgs, NodeIdentifier, ProtoNetwork, ProtoNode, ProtoNodeInput, Type};
// use graph_craft::{concrete, generic};
fn inc_network() -> ProtoNetwork {
let mut construction_network = ProtoNetwork {
inputs: vec![10],
output: 1,
nodes: [
(
1,
ProtoNode {
identifier: NodeIdentifier::new("graphene_core::ops::IdNode", &[generic!("u32")]),
input: ProtoNodeInput::Node(11),
construction_args: ConstructionArgs::Nodes(vec![]),
},
),
(
10,
ProtoNode {
identifier: NodeIdentifier::new("graphene_core::structural::ConsNode", &[generic!("&ValueNode<u32>"), generic!("()")]),
input: ProtoNodeInput::Network,
construction_args: ConstructionArgs::Nodes(vec![14]),
},
),
(
11,
ProtoNode {
identifier: NodeIdentifier::new("graphene_core::ops::AddNode", &[generic!("u32"), generic!("u32")]),
input: ProtoNodeInput::Node(10),
construction_args: ConstructionArgs::Nodes(vec![]),
},
),
(
14,
ProtoNode {
identifier: NodeIdentifier::new("graphene_core::value::ValueNode", &[concrete!("u32")]),
input: ProtoNodeInput::None,
construction_args: ConstructionArgs::Value(Box::new(3_u32)),
},
),
]
.into_iter()
.collect(),
};
construction_network.resolve_inputs();
construction_network.reorder_ids();
construction_network
}
// fn inc_network() -> ProtoNetwork {
// let mut construction_network = ProtoNetwork {
// inputs: vec![10],
// output: 1,
// nodes: [
// (
// 1,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::ops::IdNode", &[generic!("u32")]),
// input: ProtoNodeInput::Node(11),
// construction_args: ConstructionArgs::Nodes(vec![]),
// },
// ),
// (
// 10,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::structural::ConsNode", &[generic!("&ValueNode<u32>"), generic!("()")]),
// input: ProtoNodeInput::Network,
// construction_args: ConstructionArgs::Nodes(vec![14]),
// },
// ),
// (
// 11,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::ops::AddNode", &[generic!("u32"), generic!("u32")]),
// input: ProtoNodeInput::Node(10),
// construction_args: ConstructionArgs::Nodes(vec![]),
// },
// ),
// (
// 14,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::value::ValueNode", &[concrete!("u32")]),
// input: ProtoNodeInput::None,
// construction_args: ConstructionArgs::Value(Box::new(3_u32)),
// },
// ),
// ]
// .into_iter()
// .collect(),
// };
// construction_network.resolve_inputs();
// construction_network.reorder_ids();
// construction_network
// }
// TODO: Fix this test
/*#[test]
fn add_on_gpu() {
use crate::executor::Executor;
let m = compiler::Metadata::new("project".to_owned(), vec!["test@example.com".to_owned()]);
let network = inc_network();
let temp_dir = tempfile::tempdir().expect("failed to create tempdir");
// #[test]
// fn add_on_gpu() {
// use crate::executor::Executor;
// let m = compiler::Metadata::new("project".to_owned(), vec!["test@example.com".to_owned()]);
// let network = inc_network();
// let temp_dir = tempfile::tempdir().expect("failed to create tempdir");
let executor: GpuExecutor<u32, u32> = GpuExecutor::new(Context::new(), network, m, temp_dir.path()).unwrap();
// let executor: GpuExecutor<u32, u32> = GpuExecutor::new(Context::new(), network, m, temp_dir.path()).unwrap();
let data: Vec<_> = (0..1024).map(|x| x as u32).collect();
let result = executor.execute(Box::new(data)).unwrap();
let result = dyn_any::downcast::<Vec<u32>>(result).unwrap();
for (i, r) in result.iter().enumerate() {
assert_eq!(*r, i as u32 + 3);
}
}*/
}
// let data: Vec<_> = (0..1024).map(|x| x as u32).collect();
// let result = executor.execute(Box::new(data)).unwrap();
// let result = dyn_any::downcast::<Vec<u32>>(result).unwrap();
// for (i, r) in result.iter().enumerate() {
// assert_eq!(*r, i as u32 + 3);
// }
// }
// }

View file

@ -170,74 +170,74 @@ async fn execute_shader<I: Pod + Send + Sync, O: Pod + Send + Sync>(device: Arc<
}
}
#[cfg(test)]
mod test {
use super::*;
use graph_craft::concrete;
use graph_craft::generic;
use graph_craft::proto::*;
// TODO: Fix this test
// #[cfg(test)]
// mod test {
// use super::*;
// use graph_craft::concrete;
// use graph_craft::generic;
// use graph_craft::proto::*;
fn inc_network() -> ProtoNetwork {
let mut construction_network = ProtoNetwork {
inputs: vec![10],
output: 1,
nodes: [
(
1,
ProtoNode {
identifier: NodeIdentifier::new("graphene_core::ops::IdNode", &[generic!("u32")]),
input: ProtoNodeInput::Node(11),
construction_args: ConstructionArgs::Nodes(vec![]),
},
),
(
10,
ProtoNode {
identifier: NodeIdentifier::new("graphene_core::structural::ConsNode", &[generic!("&ValueNode<u32>"), generic!("()")]),
input: ProtoNodeInput::Network,
construction_args: ConstructionArgs::Nodes(vec![14]),
},
),
(
11,
ProtoNode {
identifier: NodeIdentifier::new("graphene_core::ops::AddNode", &[generic!("u32"), generic!("u32")]),
input: ProtoNodeInput::Node(10),
construction_args: ConstructionArgs::Nodes(vec![]),
},
),
(
14,
ProtoNode {
identifier: NodeIdentifier::new("graphene_core::value::ValueNode", &[concrete!("u32")]),
input: ProtoNodeInput::None,
construction_args: ConstructionArgs::Value(Box::new(3_u32)),
},
),
]
.into_iter()
.collect(),
};
construction_network.resolve_inputs();
construction_network.reorder_ids();
construction_network
}
// #[test]
// fn add_on_gpu() {
// use crate::executor::Executor;
// let m = compiler::Metadata::new("project".to_owned(), vec!["test@example.com".to_owned()]);
// let network = inc_network();
// let temp_dir = tempfile::tempdir().expect("failed to create tempdir");
// TODO: Fix this test
/*#[test]
fn add_on_gpu() {
use crate::executor::Executor;
let m = compiler::Metadata::new("project".to_owned(), vec!["test@example.com".to_owned()]);
let network = inc_network();
let temp_dir = tempfile::tempdir().expect("failed to create tempdir");
// let executor: GpuExecutor<u32, u32> = GpuExecutor::new(Context::new(), network, m, temp_dir.path()).unwrap();
let executor: GpuExecutor<u32, u32> = GpuExecutor::new(Context::new(), network, m, temp_dir.path()).unwrap();
// let data: Vec<_> = (0..1024).map(|x| x as u32).collect();
// let result = executor.execute(Box::new(data)).unwrap();
// let result = dyn_any::downcast::<Vec<u32>>(result).unwrap();
// for (i, r) in result.iter().enumerate() {
// assert_eq!(*r, i as u32 + 3);
// }
// }
let data: Vec<_> = (0..1024).map(|x| x as u32).collect();
let result = executor.execute(Box::new(data)).unwrap();
let result = dyn_any::downcast::<Vec<u32>>(result).unwrap();
for (i, r) in result.iter().enumerate() {
assert_eq!(*r, i as u32 + 3);
}
}*/
}
// fn inc_network() -> ProtoNetwork {
// let mut construction_network = ProtoNetwork {
// inputs: vec![10],
// output: 1,
// nodes: [
// (
// 1,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::ops::IdNode", &[generic!("u32")]),
// input: ProtoNodeInput::Node(11),
// construction_args: ConstructionArgs::Nodes(vec![]),
// },
// ),
// (
// 10,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::structural::ConsNode", &[generic!("&ValueNode<u32>"), generic!("()")]),
// input: ProtoNodeInput::Network,
// construction_args: ConstructionArgs::Nodes(vec![14]),
// },
// ),
// (
// 11,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::ops::AddNode", &[generic!("u32"), generic!("u32")]),
// input: ProtoNodeInput::Node(10),
// construction_args: ConstructionArgs::Nodes(vec![]),
// },
// ),
// (
// 14,
// ProtoNode {
// identifier: NodeIdentifier::new("graphene_core::value::ValueNode", &[concrete!("u32")]),
// input: ProtoNodeInput::None,
// construction_args: ConstructionArgs::Value(Box::new(3_u32)),
// },
// ),
// ]
// .into_iter()
// .collect(),
// };
// construction_network.resolve_inputs();
// construction_network.reorder_ids();
// construction_network
// }
// }