Remove unsafe code and clean up the code base in general (#1263)

* Remove unsafe code

* Make node graph test syncronous

* Add miri step to ci

* Remove unsafe from node graph evaluation

* Replace operation pseudo_hash with hash based on discriminant

* Fix test

* Move memo module to core and make it safe

* Fix formatting

* Remove unused stuff from gstd

* Use safe casting for creating key variants

* Fix memo node types

* Fix ref node

* "fix" ub

* Use correct input types for ExtractImageFrame

* Fix types for async nodes

* Fix missing implementation

* Manually override output type for async nodes

* Fix types for EditorApi

* Fix output type for WasmSurfaceHandle

* Remove unused miri.yml

* Fix incorrect type for cache node
This commit is contained in:
Dennis Kobert
2023-06-02 11:05:32 +02:00
committed by Keavon Chambers
parent 259dcdc628
commit 4e1bfddcd8
43 changed files with 520 additions and 1252 deletions

View File

@@ -7,7 +7,6 @@ use crate::messages::prelude::*;
use document_legacy::layers::layer_info::LayerDataType;
use document_legacy::{LayerId, Operation};
use dyn_any::DynAny;
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{generate_uuid, DocumentNodeImplementation, NodeId, NodeNetwork};
use graph_craft::executor::Compiler;
@@ -18,7 +17,7 @@ use graphene_core::renderer::{SvgSegment, SvgSegmentList};
use graphene_core::text::FontCache;
use graphene_core::vector::style::ViewMode;
use graphene_core::wasm_application_io::{WasmApplicationIo, WasmSurfaceHandleFrame};
use graphene_core::wasm_application_io::WasmApplicationIo;
use graphene_core::{Color, EditorApi, SurfaceFrame, SurfaceId};
use interpreted_executor::executor::DynamicExecutor;
@@ -110,7 +109,7 @@ impl NodeRuntime {
updates: responses,
new_thumbnails: self.thumbnails.clone(),
};
self.sender.send(response);
self.sender.send(response).expect("Failed to send response");
}
}
}
@@ -118,7 +117,7 @@ impl NodeRuntime {
/// Wraps a network in a scope and returns the new network and the paths to the monitor nodes.
fn wrap_network(network: NodeNetwork) -> (NodeNetwork, Vec<Vec<NodeId>>) {
let mut scoped_network = wrap_network_in_scope(network);
let scoped_network = wrap_network_in_scope(network);
//scoped_network.generate_node_paths(&[]);
let monitor_nodes = scoped_network
@@ -126,7 +125,6 @@ impl NodeRuntime {
.filter(|(node, _, _)| node.implementation == DocumentNodeImplementation::proto("graphene_std::memo::MonitorNode<_>"))
.map(|(_, _, path)| path)
.collect();
//scoped_network.remove_dead_nodes();
(scoped_network, monitor_nodes)
}
@@ -149,40 +147,23 @@ impl NodeRuntime {
return Err(e);
}
use dyn_any::IntoDynAny;
use graph_craft::executor::Executor;
let result = match self.executor.input_type() {
Some(t) if t == concrete!(EditorApi) => self.executor.execute(editor_api.into_dyn()).await.map_err(|e| e.to_string()),
Some(t) if t == concrete!(()) => self.executor.execute(().into_dyn()).await.map_err(|e| e.to_string()),
Some(t) if t == concrete!(EditorApi) => (&self.executor).execute(editor_api).await.map_err(|e| e.to_string()),
Some(t) if t == concrete!(()) => (&self.executor).execute(()).await.map_err(|e| e.to_string()),
_ => Err("Invalid input type".to_string()),
};
}?;
match result {
Ok(result) => {
if DynAny::type_id(result.as_ref()) == core::any::TypeId::of::<WasmSurfaceHandleFrame>() {
let Ok(value) = dyn_any::downcast::<WasmSurfaceHandleFrame>(result) else { unreachable!()};
let new_id = value.surface_handle.surface_id;
let old_id = self.canvas_cache.insert(path.to_vec(), new_id);
if let Some(old_id) = old_id {
if old_id != new_id {
self.wasm_io.destroy_surface(old_id);
}
}
return Ok(TaggedValue::SurfaceFrame(SurfaceFrame {
surface_id: new_id,
transform: value.transform,
}));
}
let type_name = DynAny::type_name(result.as_ref());
match TaggedValue::try_from_any(result) {
Some(x) => Ok(x),
None => Err(format!("Invalid output type: {}", type_name)),
if let TaggedValue::SurfaceFrame(SurfaceFrame { surface_id, transform }) = result {
let old_id = self.canvas_cache.insert(path.to_vec(), surface_id);
if let Some(old_id) = old_id {
if old_id != surface_id {
self.wasm_io.destroy_surface(old_id);
}
}
Err(e) => Err(e),
}
Ok(result)
}
/// Recomputes the thumbnails for the layers in the graph, modifying the state and updating the UI.
@@ -289,13 +270,13 @@ impl NodeGraphExecutor {
image_frame,
generation_id,
};
self.sender.send(NodeRuntimeMessage::GenerationRequest(request));
self.sender.send(NodeRuntimeMessage::GenerationRequest(request)).expect("Failed to send generation request");
generation_id
}
pub fn update_font_cache(&self, font_cache: FontCache) {
self.sender.send(NodeRuntimeMessage::FontCacheUpdate(font_cache));
self.sender.send(NodeRuntimeMessage::FontCacheUpdate(font_cache)).expect("Failed to send font cache update");
}
pub fn introspect_node(&self, path: &[NodeId]) -> Option<Arc<dyn std::any::Any>> {