Skip to content

Commit af05acf

Browse files
committed
Fix generic type resolution
1 parent 2cb37a9 commit af05acf

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use super::node_properties;
22
use super::utility_types::FrontendNodeType;
33
use crate::messages::layout::utility_types::widget_prelude::*;
44
use crate::messages::portfolio::document::utility_types::network_interface::{
5-
DocumentNodeMetadata, DocumentNodePersistentMetadata, NodeNetworkInterface, NodeNetworkMetadata, NodeNetworkPersistentMetadata, NodeTemplate, NodeTypePersistentMetadata, NumberInputSettings,
6-
PropertiesRow, Vec2InputSettings, WidgetOverride,
5+
DocumentNodeMetadata, DocumentNodePersistentMetadata, NodeNetworkInterface, NodeNetworkMetadata, NodeNetworkPersistentMetadata, NodePersistentMetadata, NodePosition, NodeTemplate,
6+
NodeTypePersistentMetadata, NumberInputSettings, PropertiesRow, Vec2InputSettings, WidgetOverride,
77
};
88
use crate::messages::portfolio::utility_types::PersistentData;
99
use crate::messages::prelude::Message;
@@ -2734,7 +2734,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
27342734
match inputs.len() {
27352735
1 => {
27362736
let input = inputs.iter().next().unwrap();
2737-
let fn_input = input.fn_input().expect("Node inputs should have a function type");
27382737
let input_ty = input.nested_type();
27392738
let into_node_identifier = ProtoNodeIdentifier {
27402739
name: format!("graphene_core::ops::IntoNode<{}>", input_ty.clone()).into(),
@@ -2782,6 +2781,13 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
27822781
.collect();
27832782
nodes.insert(NodeId(input_count as u64), document_node);
27842783
node_names.insert(NodeId(input_count as u64), display_name.to_string());
2784+
let node_type_metadata = |id: NodeId| {
2785+
NodeTypePersistentMetadata::Node(NodePersistentMetadata::new(NodePosition::Absolute(if id.0 == input_count as u64 {
2786+
IVec2::default()
2787+
} else {
2788+
IVec2 { x: -10, y: id.0 as i32 }
2789+
})))
2790+
};
27852791

27862792
let node = DocumentNodeDefinition {
27872793
identifier: display_name,
@@ -2822,10 +2828,15 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
28222828
node_metadata: node_names
28232829
.into_iter()
28242830
.map(|(id, display_name)| {
2831+
let node_type_metadata = node_type_metadata(id);
28252832
(
28262833
id,
28272834
DocumentNodeMetadata {
2828-
persistent_metadata: DocumentNodePersistentMetadata { display_name, ..Default::default() },
2835+
persistent_metadata: DocumentNodePersistentMetadata {
2836+
display_name,
2837+
node_type_metadata,
2838+
..Default::default()
2839+
},
28292840
..Default::default()
28302841
},
28312842
)

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6438,6 +6438,12 @@ pub struct NodePersistentMetadata {
64386438
position: NodePosition,
64396439
}
64406440

6441+
impl NodePersistentMetadata {
6442+
pub fn new(position: NodePosition) -> Self {
6443+
Self { position }
6444+
}
6445+
}
6446+
64416447
/// A layer can either be position as Absolute or in a Stack
64426448
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
64436449
pub enum LayerPosition {

node-graph/gcore/src/types.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use core::any::TypeId;
22

33
#[cfg(not(feature = "std"))]
44
pub use alloc::borrow::Cow;
5-
use spirv_std::image::sample_with::NoneTy;
65
#[cfg(feature = "std")]
76
pub use std::borrow::Cow;
87

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,12 @@ fn collect_generics(types: &NodeIOTypes) -> Vec<Cow<'static, str>> {
838838

839839
/// Checks if a generic type can be substituted with a concrete type and returns the concrete type
840840
fn check_generic(types: &NodeIOTypes, input: &Type, parameters: &[Type], generic: &str) -> Result<Type, String> {
841-
let inputs = [(&types.call_argument, input)]
841+
let inputs = [(Some(&types.call_argument), Some(input))]
842842
.into_iter()
843-
.chain(types.inputs.iter().map(|x| x.nested_type()).zip(parameters.iter().map(|x| x.nested_type())));
844-
let concrete_inputs = inputs.filter(|(ni, _)| matches!(ni, Type::Generic(input) if generic == input));
845-
let mut outputs = concrete_inputs.map(|(_, out)| out);
843+
.chain(types.inputs.iter().map(|x| x.fn_input()).zip(parameters.iter().map(|x| x.fn_input())))
844+
.chain(types.inputs.iter().map(|x| x.fn_output()).zip(parameters.iter().map(|x| x.fn_output())));
845+
let concrete_inputs = inputs.filter(|(ni, _)| matches!(ni, Some(Type::Generic(input)) if generic == input));
846+
let mut outputs = concrete_inputs.flat_map(|(_, out)| out);
846847
let out_ty = outputs
847848
.next()
848849
.ok_or_else(|| format!("Generic output type {generic} is not dependent on input {input:?} or parameters {parameters:?}",))?;

0 commit comments

Comments
 (0)