Simplify compilation

This commit is contained in:
Adam
2025-07-16 01:42:39 -07:00
parent f5c6b65fcc
commit 8b665d158c
24 changed files with 863 additions and 1012 deletions
+61 -29
View File
@@ -51,26 +51,52 @@ pub trait ExtractAll: ExtractFootprint + ExtractDownstreamTransform + ExtractInd
impl<T: ?Sized + ExtractFootprint + ExtractDownstreamTransform + ExtractIndex + ExtractRealTime + ExtractAnimationTime + ExtractVarArgs> ExtractAll for T {}
#[derive(Debug, Clone, PartialEq)]
#[repr(u8)]
pub enum ContextDependency {
ExtractFootprint,
ExtractFootprint = 0b10000000,
// Can be used by cull nodes to check if the final output would be outside the footprint viewport
ExtractDownstreamTransform,
ExtractRealTime,
ExtractAnimationTime,
ExtractIndex,
ExtractVarArgs,
ExtractDownstreamTransform = 0b01000000,
ExtractRealTime = 0b00100000,
ExtractAnimationTime = 0b00010000,
ExtractIndex = 0b00001000,
ExtractVarArgs = 0b00000100,
}
pub fn all_context_dependencies() -> Vec<ContextDependency> {
vec![
ContextDependency::ExtractFootprint,
// Can be used by cull nodes to check if the final output would be outside the footprint viewport
ContextDependency::ExtractDownstreamTransform,
ContextDependency::ExtractRealTime,
ContextDependency::ExtractAnimationTime,
ContextDependency::ExtractIndex,
ContextDependency::ExtractVarArgs,
]
#[derive(Debug, Clone, PartialEq)]
pub struct ContextDependencies(pub u8);
impl ContextDependencies {
pub fn all_context_dependencies() -> Self {
ContextDependencies(0b11111100)
}
pub fn none() -> Self {
ContextDependencies(0b00000000)
}
pub fn is_empty(&self) -> bool {
self.0 & Self::all_context_dependencies().0 == 0
}
pub fn from(dependencies: Vec<ContextDependency>) -> Self {
let mut new = Self::none();
for dependency in dependencies {
new.0 |= dependency as u8
}
new
}
pub fn inverse(self) -> Self {
Self(!self.0)
}
pub fn add_dependencies(&mut self, other: &Self) {
self.0 |= other.0
}
pub fn difference(&mut self, other: &Self) {
self.0 = (!self.0) & other.0
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -348,19 +374,25 @@ impl OwnedContextImpl {
}
}
pub fn nullify(&mut self, nullify: &Vec<ContextDependency>) {
for context_dependency in nullify {
match context_dependency {
ContextDependency::ExtractFootprint => self.footprint = None,
ContextDependency::ExtractDownstreamTransform => self.downstream_transform = None,
ContextDependency::ExtractRealTime => self.real_time = None,
ContextDependency::ExtractAnimationTime => self.animation_time = None,
ContextDependency::ExtractIndex => self.index = None,
ContextDependency::ExtractVarArgs => {
self.varargs = None;
self.parent = None
}
}
pub fn nullify(&mut self, nullify: &ContextDependencies) {
if nullify.0 & (ContextDependency::ExtractFootprint as u8) != 0 {
self.footprint = None;
}
if nullify.0 & (ContextDependency::ExtractDownstreamTransform as u8) != 0 {
self.downstream_transform = None;
}
if nullify.0 & (ContextDependency::ExtractRealTime as u8) != 0 {
self.real_time = None;
}
if nullify.0 & (ContextDependency::ExtractAnimationTime as u8) != 0 {
self.animation_time = None;
}
if nullify.0 & (ContextDependency::ExtractIndex as u8) != 0 {
self.index = None;
}
if nullify.0 & (ContextDependency::ExtractVarArgs as u8) != 0 {
self.varargs = None;
self.parent = None
}
}
}
+2 -8
View File
@@ -60,17 +60,11 @@ pub trait Node<'i, Input> {
std::any::type_name::<Self>()
}
/// Get the call argument or output data for the monitor node on the next evaluation after set_introspect_input
/// Also returns a boolean of whether the node was evaluated
fn introspect(&self, _introspect_mode: IntrospectMode) -> Option<std::sync::Arc<dyn std::any::Any + Send + Sync>> {
// If check if evaluated is true, then it returns None if the node has not been evaluated since the last introspection
fn introspect(&self, _check_if_evaluated: bool) -> Option<std::sync::Arc<dyn std::any::Any + Send + Sync>> {
log::warn!("Node::introspect not implemented for {}", std::any::type_name::<Self>());
None
}
// The introspect mode is set before the graph evaluation, and tells the monitor node what data to store
fn set_introspect(&self, _introspect_mode: IntrospectMode) {
log::warn!("Node::set_introspect not implemented for {}", std::any::type_name::<Self>());
}
}
mod types;
+13 -46
View File
@@ -12,7 +12,6 @@ use std::sync::Mutex;
pub struct MonitorMemoNode<T, CachedNode> {
// Introspection cache, uses the hash of the nullified context with default var args
// cache: Arc<Mutex<std::collections::HashMap<u64, Arc<T>>>>,
// Return value cache,
cache: Arc<Mutex<Option<(u64, Arc<T>)>>>,
node: CachedNode,
changed_since_last_eval: Arc<Mutex<bool>>,
@@ -25,31 +24,7 @@ where
// TODO: This should return a reference to the cached cached_value
// but that requires a lot of lifetime magic <- This was suggested by copilot but is pretty accurate xD
type Output = DynFuture<'i, T>;
// fn eval(&'i self, input: I) -> Self::Output {
// let mut hasher = DefaultHasher::new();
// input.hash(&mut hasher);
// let hash = hasher.finish();
// if let Some(data) = self.cache.lock().unwrap().get(&hash) {
// let cloned_data = (**data).clone();
// Box::pin(async move { cloned_data })
// } else {
// let fut = self.node.eval(input);
// let cache = self.cache.clone();
// Box::pin(async move {
// let value = fut.await;
// cache.lock().unwrap().insert(hash, Arc::new(value.clone()));
// value
// })
// }
// }
// fn introspect(&self, _introspect_mode: IntrospectMode) -> Option<std::sync::Arc<dyn std::any::Any + Send + Sync>> {
// let mut hasher = DefaultHasher::new();
// OwnedContextImpl::default().into_context().hash(&mut hasher);
// let hash = hasher.finish();
// self.cache.lock().unwrap().get(&hash).map(|data| (*data).clone() as Arc<dyn std::any::Any + Send + Sync>)
// }
fn eval(&'i self, input: I) -> Self::Output {
let mut hasher = DefaultHasher::new();
input.hash(&mut hasher);
@@ -69,13 +44,20 @@ where
})
}
}
fn introspect(&self, _introspect_mode: IntrospectMode) -> Option<std::sync::Arc<dyn std::any::Any + Send + Sync>> {
if *self.changed_since_last_eval.lock().unwrap() {
*self.changed_since_last_eval.lock().unwrap() = false;
Some(self.cache.lock().unwrap().as_ref().expect("Cached data should always be evaluated before introspection").1.clone() as Arc<dyn std::any::Any + Send + Sync>)
} else {
None
// TODO: Consider returning a reference to the entire cache so the frontend reference is automatically updated as the context changes
fn introspect(&self, check_if_evaluated: bool) -> Option<std::sync::Arc<dyn std::any::Any + Send + Sync>> {
let mut changed = self.changed_since_last_eval.lock().unwrap();
if check_if_evaluated {
if !*changed {
return None;
}
}
*changed = false;
let cache_guard = self.cache.lock().unwrap();
let cached = cache_guard.as_ref().expect("Cached data should always be evaluated before introspection");
Some(cached.1.clone() as Arc<dyn std::any::Any + Send + Sync>)
}
}
@@ -230,21 +212,6 @@ where
output
})
}
// After introspecting, the input/output get set to None because the Arc is moved to the editor where it can be directly accessed.
fn introspect(&self, introspect_mode: IntrospectMode) -> Option<Arc<dyn std::any::Any + Send + Sync>> {
match introspect_mode {
IntrospectMode::Input => self.input.lock().unwrap().take().map(|input| input as Arc<dyn std::any::Any + Send + Sync>),
IntrospectMode::Data => self.output.lock().unwrap().take().map(|output| output as Arc<dyn std::any::Any + Send + Sync>),
}
}
fn set_introspect(&self, introspect_mode: IntrospectMode) {
match introspect_mode {
IntrospectMode::Input => *self.introspect_input.lock().unwrap() = true,
IntrospectMode::Data => *self.introspect_output.lock().unwrap() = true,
}
}
}
impl<I, O, N> MonitorNode<I, O, N> {
+4 -8
View File
@@ -1,4 +1,4 @@
use crate::{Node, NodeIO, NodeIOTypes, ProtoNodeIdentifier, Type, WasmNotSend};
use crate::{ContextDependencies, Node, NodeIO, NodeIOTypes, ProtoNodeIdentifier, Type, WasmNotSend};
use dyn_any::{DynAny, StaticType};
use std::borrow::Cow;
use std::collections::HashMap;
@@ -109,7 +109,7 @@ pub static NODE_REGISTRY: NodeRegistry = LazyLock::new(|| Mutex::new(HashMap::ne
pub static NODE_METADATA: LazyLock<Mutex<HashMap<ProtoNodeIdentifier, NodeMetadata>>> = LazyLock::new(|| Mutex::new(HashMap::new()));
pub static NODE_CONTEXT_DEPENDENCY: LazyLock<Mutex<HashMap<String, Vec<crate::ContextDependency>>>> = LazyLock::new(|| Mutex::new(HashMap::new()));
pub static NODE_CONTEXT_DEPENDENCY: LazyLock<Mutex<HashMap<String, ContextDependencies>>> = LazyLock::new(|| Mutex::new(HashMap::new()));
#[cfg(not(target_arch = "wasm32"))]
pub type DynFuture<'n, T> = Pin<Box<dyn Future<Output = T> + 'n + Send>>;
@@ -290,12 +290,8 @@ where
}
}
fn introspect(&self, introspect_mode: crate::IntrospectMode) -> Option<std::sync::Arc<dyn std::any::Any + Send + Sync>> {
self.node.introspect(introspect_mode)
}
fn set_introspect(&self, introspect_mode: crate::IntrospectMode) {
self.node.set_introspect(introspect_mode);
fn introspect(&self, check_if_evaluated: bool) -> Option<std::sync::Arc<dyn std::any::Any + Send + Sync>> {
self.node.introspect(check_if_evaluated)
}
fn reset(&self) {