Skip to content

Commit c69222e

Browse files
committed
Fix type checking errors
* Keep connection information during node resolution * Fix TypeDescriptor PartialEq implementation
1 parent 7cb8102 commit c69222e

File tree

4 files changed

+39
-29
lines changed

4 files changed

+39
-29
lines changed

node-graph/gcore/src/types.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct NodeIdentifier {
4040
pub name: Cow<'static, str>,
4141
}
4242

43-
#[derive(Clone, Debug, PartialEq, Eq, Hash, specta::Type)]
43+
#[derive(Clone, Debug, Eq, specta::Type)]
4444
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4545
pub struct TypeDescriptor {
4646
#[cfg_attr(feature = "serde", serde(skip))]
@@ -49,6 +49,18 @@ pub struct TypeDescriptor {
4949
pub name: Cow<'static, str>,
5050
}
5151

52+
impl core::hash::Hash for TypeDescriptor {
53+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
54+
self.id.hash(state);
55+
}
56+
}
57+
58+
impl PartialEq for TypeDescriptor {
59+
fn eq(&self, other: &Self) -> bool {
60+
self.id == other.id
61+
}
62+
}
63+
5264
#[derive(Clone, PartialEq, Eq, Hash, specta::Type)]
5365
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5466
pub enum Type {
@@ -60,7 +72,7 @@ impl core::fmt::Debug for Type {
6072
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
6173
match self {
6274
Self::Generic(arg0) => f.write_fmt(format_args!("Generic({})", arg0)),
63-
Self::Concrete(arg0) => f.write_fmt(format_args!("Concrete({})", arg0.name)),
75+
Self::Concrete(arg0) => f.write_fmt(format_args!("Concrete(({}, {:?}))", arg0.name, arg0.id)),
6476
}
6577
}
6678
}

node-graph/graph-craft/src/proto.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,20 @@ impl ProtoNetwork {
191191
}
192192

193193
pub fn resolve_inputs(&mut self) {
194-
while !self.resolve_inputs_impl() {}
194+
let mut resolved = HashSet::new();
195+
while !self.resolve_inputs_impl(&mut resolved) {}
195196
}
196-
fn resolve_inputs_impl(&mut self) -> bool {
197+
fn resolve_inputs_impl(&mut self, resolved: &mut HashSet<NodeId>) -> bool {
197198
self.reorder_ids();
198199

199200
let mut lookup = self.nodes.iter().map(|(id, _)| (*id, *id)).collect::<HashMap<_, _>>();
200201
let compose_node_id = self.nodes.len() as NodeId;
201202
let inputs = self.nodes.iter().map(|(_, node)| node.input.clone()).collect::<Vec<_>>();
202203

203-
if let Some((input_node, id, input)) = self.nodes.iter_mut().find_map(|(id, node)| {
204+
let resolved_lookup = resolved.clone();
205+
if let Some((input_node, id, input)) = self.nodes.iter_mut().filter(|(id, _)| !resolved_lookup.contains(id)).find_map(|(id, node)| {
204206
if let ProtoNodeInput::Node(input_node) = node.input {
205-
node.input = ProtoNodeInput::None;
207+
resolved.insert(*id);
206208
let pre_node_input = inputs.get(input_node as usize).expect("input node should exist");
207209
Some((input_node, *id, pre_node_input.clone()))
208210
} else {
@@ -371,17 +373,16 @@ impl TypingContext {
371373
if parameters.iter().any(|p| matches!(p, Type::Generic(_))) {
372374
return Err(format!("Generic types are not supported in parameters: {:?} occured in {:?}", parameters, node.identifier));
373375
}
374-
let covariant = |output, input| match (output, input) {
376+
let covariant = |output, input| match (&output, &input) {
375377
(Type::Concrete(t1), Type::Concrete(t2)) => t1 == t2,
376378
(Type::Concrete(_), Type::Generic(_)) => true,
377379
// TODO: verify if this actually corerct
378-
(Type::Generic(t1), Type::Generic(t2)) => true,
379-
(Type::Generic(_), Type::Concrete(_)) => true,
380+
(Type::Generic(_), _) => false,
380381
};
381382

382383
let valid_output_types = impls
383384
.keys()
384-
.filter(|node_io| covariant(node_io.input.clone(), input.clone()) && node_io.parameters.iter().zip(parameters.iter()).all(|(p1, p2)| covariant(p1.clone(), p2.clone())))
385+
.filter(|node_io| covariant(input.clone(), node_io.input.clone()) && parameters.iter().zip(node_io.parameters.iter()).all(|(p1, p2)| covariant(p1.clone(), p2.clone())))
385386
.collect::<Vec<_>>();
386387

387388
let substitution_results = valid_output_types
@@ -403,10 +404,13 @@ impl TypingContext {
403404
let valid_impls = substitution_results.iter().filter_map(|result| result.as_ref().ok()).collect::<Vec<_>>();
404405

405406
match valid_impls.as_slice() {
406-
[] => Err(format!(
407-
"No valid implementations found for {identifier} with input {input:?} and parameters {parameters:?}.\nTypes that are implemented: {:?}",
408-
substitution_results,
409-
)),
407+
[] => {
408+
dbg!(&self.infered);
409+
Err(format!(
410+
"No implementations found for {identifier} with input {input:?} and parameters {parameters:?}.\nTypes that are implemented: {:?}",
411+
impls,
412+
))
413+
}
410414
[(org_nio, output)] => {
411415
let node_io = NodeIOTypes::new(input, (*output).clone(), parameters);
412416

@@ -512,11 +516,11 @@ mod test {
512516
ids,
513517
vec![
514518
15907139529964845467,
515-
14791354678635908268,
516-
17522454908046327116,
517-
12722973206210391299,
518-
4508311079153412646,
519-
13250284155406988548
519+
17186311536944112733,
520+
1674503539363691855,
521+
10408773954839245246,
522+
1677533587730447846,
523+
6826908746727711035
520524
]
521525
);
522526
}

node-graph/interpreted-executor/src/executor.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,7 @@ impl BorrowTree {
141141
}
142142

143143
pub fn push_node(&mut self, id: NodeId, proto_node: ProtoNode, typing_context: &TypingContext) -> Result<(), String> {
144-
let ProtoNode { input, construction_args, identifier } = proto_node;
145-
146-
assert!(
147-
!matches!(&input, &ProtoNodeInput::Node(_)),
148-
"Only nodes without inputs are supported. Any inputs should already be resolved by placing ComposeNodes {:?}, {:?}, {:?}",
149-
identifier,
150-
construction_args,
151-
input,
152-
);
144+
let ProtoNode { construction_args, identifier, .. } = proto_node;
153145

154146
match construction_args {
155147
ConstructionArgs::Value(value) => {

node-graph/interpreted-executor/src/node_registry.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use graphene_std::memo::CacheNode;
2020

2121
use crate::executor::NodeContainer;
2222

23+
use dyn_any::StaticType;
24+
2325
macro_rules! register_node {
2426
($path:ty, input: $input:ty, params: [$($type:ty),*]) => {
2527
(
@@ -37,7 +39,7 @@ macro_rules! register_node {
3739
let node = <$path>::new($(graphene_std::any::input_node::<$type>(_node)),*);
3840
let params = vec![$(concrete!($type)),*];
3941
let mut node_io = <$path as NodeIO<'_, $input>>::to_node_io(&node, params);
40-
node_io.input = concrete!($input);
42+
node_io.input = concrete!(<$input as StaticType>::Static);
4143
node_io
4244
}
4345
)

0 commit comments

Comments
 (0)