Don't include the document node path in the stable node id by default (#1388)

* Don't include the document node path in the stable node id by default

Make the inclusion of the document path for the stable node id optional
and only enable it for the MonitorNode for now

* Fix tests
This commit is contained in:
Dennis Kobert 2023-08-13 12:25:42 +02:00 committed by GitHub
parent dc4b16aead
commit 752df128e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 8 deletions

View File

@ -207,6 +207,7 @@ fn static_nodes() -> Vec<DocumentNodeType> {
DocumentNode { DocumentNode {
inputs: vec![NodeInput::node(0, 0)], inputs: vec![NodeInput::node(0, 0)],
implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode<_>"), implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode<_>"),
skip_deduplication: true,
..Default::default() ..Default::default()
}, },
), ),
@ -1986,6 +1987,7 @@ pub static IMAGINATE_NODE: Lazy<DocumentNodeType> = Lazy::new(|| DocumentNodeTyp
name: "Frame Monitor".into(), name: "Frame Monitor".into(),
inputs: vec![NodeInput::Network(concrete!(ImageFrame<Color>))], inputs: vec![NodeInput::Network(concrete!(ImageFrame<Color>))],
implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode<_>"), implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode<_>"),
skip_deduplication: true,
..Default::default() ..Default::default()
}, },
), ),

View File

@ -77,7 +77,9 @@ pub struct TypeDescriptor {
#[specta(skip)] #[specta(skip)]
pub id: Option<TypeId>, pub id: Option<TypeId>,
pub name: Cow<'static, str>, pub name: Cow<'static, str>,
#[serde(default)]
pub size: usize, pub size: usize,
#[serde(default)]
pub align: usize, pub align: usize,
} }

View File

@ -40,6 +40,8 @@ pub struct DocumentNode {
pub inputs: Vec<NodeInput>, pub inputs: Vec<NodeInput>,
pub implementation: DocumentNodeImplementation, pub implementation: DocumentNodeImplementation,
pub metadata: DocumentNodeMetadata, pub metadata: DocumentNodeMetadata,
#[serde(default)]
pub skip_deduplication: bool,
pub path: Option<Vec<NodeId>>, pub path: Option<Vec<NodeId>>,
} }
@ -97,6 +99,7 @@ impl DocumentNode {
input, input,
construction_args: args, construction_args: args,
document_node_path: self.path.unwrap_or(Vec::new()), document_node_path: self.path.unwrap_or(Vec::new()),
skip_deduplication: self.skip_deduplication,
} }
} else { } else {
unreachable!("tried to resolve not flattened node on resolved node {:?}", self); unreachable!("tried to resolve not flattened node on resolved node {:?}", self);
@ -1063,6 +1066,7 @@ mod test {
input: ProtoNodeInput::Network(concrete!(u32)), input: ProtoNodeInput::Network(concrete!(u32)),
construction_args: ConstructionArgs::Nodes(vec![(0, false)]), construction_args: ConstructionArgs::Nodes(vec![(0, false)]),
document_node_path: vec![], document_node_path: vec![],
skip_deduplication: false,
}; };
assert_eq!(proto_node, reference); assert_eq!(proto_node, reference);
} }
@ -1080,6 +1084,7 @@ mod test {
input: ProtoNodeInput::Network(concrete!(u32)), input: ProtoNodeInput::Network(concrete!(u32)),
construction_args: ConstructionArgs::Nodes(vec![(14, false)]), construction_args: ConstructionArgs::Nodes(vec![(14, false)]),
document_node_path: vec![1, 0], document_node_path: vec![1, 0],
skip_deduplication: false,
}, },
), ),
( (
@ -1089,6 +1094,7 @@ mod test {
input: ProtoNodeInput::Node(10, false), input: ProtoNodeInput::Node(10, false),
construction_args: ConstructionArgs::Nodes(vec![]), construction_args: ConstructionArgs::Nodes(vec![]),
document_node_path: vec![1, 1], document_node_path: vec![1, 1],
skip_deduplication: false,
}, },
), ),
(14, ProtoNode::value(ConstructionArgs::Value(TaggedValue::U32(2)), vec![1, 4])), (14, ProtoNode::value(ConstructionArgs::Value(TaggedValue::U32(2)), vec![1, 4])),

View File

@ -36,6 +36,7 @@ pub trait ImaginateTerminationHandle: Debug + Send + Sync + 'static {
#[derive(Default, Debug, specta::Type)] #[derive(Default, Debug, specta::Type)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
struct InternalImaginateControl { struct InternalImaginateControl {
#[serde(skip)]
status: Mutex<ImaginateStatus>, status: Mutex<ImaginateStatus>,
trigger_regenerate: AtomicBool, trigger_regenerate: AtomicBool,
#[serde(skip)] #[serde(skip)]

View File

@ -190,12 +190,13 @@ impl ConstructionArgs {
} }
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Clone, Hash, Eq)] #[derive(Debug, Clone, PartialEq, Hash, Eq)]
pub struct ProtoNode { pub struct ProtoNode {
pub construction_args: ConstructionArgs, pub construction_args: ConstructionArgs,
pub input: ProtoNodeInput, pub input: ProtoNodeInput,
pub identifier: NodeIdentifier, pub identifier: NodeIdentifier,
pub document_node_path: Vec<NodeId>, pub document_node_path: Vec<NodeId>,
pub skip_deduplication: bool,
} }
/// A ProtoNodeInput represents the input of a node in a ProtoNetwork. /// A ProtoNodeInput represents the input of a node in a ProtoNetwork.
@ -231,7 +232,9 @@ impl ProtoNode {
self.identifier.name.hash(&mut hasher); self.identifier.name.hash(&mut hasher);
self.construction_args.hash(&mut hasher); self.construction_args.hash(&mut hasher);
self.document_node_path.hash(&mut hasher); if self.skip_deduplication {
self.document_node_path.hash(&mut hasher);
}
std::mem::discriminant(&self.input).hash(&mut hasher); std::mem::discriminant(&self.input).hash(&mut hasher);
match self.input { match self.input {
ProtoNodeInput::None => (), ProtoNodeInput::None => (),
@ -252,6 +255,7 @@ impl ProtoNode {
construction_args: value, construction_args: value,
input: ProtoNodeInput::None, input: ProtoNodeInput::None,
document_node_path: path, document_node_path: path,
skip_deduplication: false,
} }
} }
@ -359,6 +363,7 @@ impl ProtoNetwork {
construction_args: ConstructionArgs::Nodes(vec![(input_node_id, false), (node_id, true)]), construction_args: ConstructionArgs::Nodes(vec![(input_node_id, false), (node_id, true)]),
input, input,
document_node_path: path, document_node_path: path,
skip_deduplication: false,
}, },
)); ));
@ -735,12 +740,12 @@ mod test {
assert_eq!( assert_eq!(
ids, ids,
vec![ vec![
16203111412429166836, 2785293541695324513,
8181436982058796771, 12994980551665119079,
10130798762907147404, 17926586814106640907,
1082623390433068677, 2523412932923113119,
4567264975997576294, 12965978620570332342,
8215587082195034469 16191561097939296982
] ]
); );
} }
@ -757,6 +762,7 @@ mod test {
input: ProtoNodeInput::Node(11, false), input: ProtoNodeInput::Node(11, false),
construction_args: ConstructionArgs::Nodes(vec![]), construction_args: ConstructionArgs::Nodes(vec![]),
document_node_path: vec![], document_node_path: vec![],
skip_deduplication: false,
}, },
), ),
( (
@ -766,6 +772,7 @@ mod test {
input: ProtoNodeInput::Node(11, false), input: ProtoNodeInput::Node(11, false),
construction_args: ConstructionArgs::Nodes(vec![]), construction_args: ConstructionArgs::Nodes(vec![]),
document_node_path: vec![], document_node_path: vec![],
skip_deduplication: false,
}, },
), ),
( (
@ -775,6 +782,7 @@ mod test {
input: ProtoNodeInput::Network(concrete!(u32)), input: ProtoNodeInput::Network(concrete!(u32)),
construction_args: ConstructionArgs::Nodes(vec![(14, false)]), construction_args: ConstructionArgs::Nodes(vec![(14, false)]),
document_node_path: vec![], document_node_path: vec![],
skip_deduplication: false,
}, },
), ),
( (
@ -784,6 +792,7 @@ mod test {
input: ProtoNodeInput::Node(10, false), input: ProtoNodeInput::Node(10, false),
construction_args: ConstructionArgs::Nodes(vec![]), construction_args: ConstructionArgs::Nodes(vec![]),
document_node_path: vec![], document_node_path: vec![],
skip_deduplication: false,
}, },
), ),
( (
@ -793,6 +802,7 @@ mod test {
input: ProtoNodeInput::None, input: ProtoNodeInput::None,
construction_args: ConstructionArgs::Value(value::TaggedValue::U32(2)), construction_args: ConstructionArgs::Value(value::TaggedValue::U32(2)),
document_node_path: vec![], document_node_path: vec![],
skip_deduplication: false,
}, },
), ),
] ]