@@ -191,18 +191,20 @@ impl ProtoNetwork {
191
191
}
192
192
193
193
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) { }
195
196
}
196
- fn resolve_inputs_impl ( & mut self ) -> bool {
197
+ fn resolve_inputs_impl ( & mut self , resolved : & mut HashSet < NodeId > ) -> bool {
197
198
self . reorder_ids ( ) ;
198
199
199
200
let mut lookup = self . nodes . iter ( ) . map ( |( id, _) | ( * id, * id) ) . collect :: < HashMap < _ , _ > > ( ) ;
200
201
let compose_node_id = self . nodes . len ( ) as NodeId ;
201
202
let inputs = self . nodes . iter ( ) . map ( |( _, node) | node. input . clone ( ) ) . collect :: < Vec < _ > > ( ) ;
202
203
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) | {
204
206
if let ProtoNodeInput :: Node ( input_node) = node. input {
205
- node . input = ProtoNodeInput :: None ;
207
+ resolved . insert ( * id ) ;
206
208
let pre_node_input = inputs. get ( input_node as usize ) . expect ( "input node should exist" ) ;
207
209
Some ( ( input_node, * id, pre_node_input. clone ( ) ) )
208
210
} else {
@@ -371,17 +373,16 @@ impl TypingContext {
371
373
if parameters. iter ( ) . any ( |p| matches ! ( p, Type :: Generic ( _) ) ) {
372
374
return Err ( format ! ( "Generic types are not supported in parameters: {:?} occured in {:?}" , parameters, node. identifier) ) ;
373
375
}
374
- let covariant = |output, input| match ( output, input) {
376
+ let covariant = |output, input| match ( & output, & input) {
375
377
( Type :: Concrete ( t1) , Type :: Concrete ( t2) ) => t1 == t2,
376
378
( Type :: Concrete ( _) , Type :: Generic ( _) ) => true ,
377
379
// TODO: verify if this actually corerct
378
- ( Type :: Generic ( t1) , Type :: Generic ( t2) ) => true ,
379
- ( Type :: Generic ( _) , Type :: Concrete ( _) ) => true ,
380
+ ( Type :: Generic ( _) , _) => false ,
380
381
} ;
381
382
382
383
let valid_output_types = impls
383
384
. 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 ( ) ) ) )
385
386
. collect :: < Vec < _ > > ( ) ;
386
387
387
388
let substitution_results = valid_output_types
@@ -403,10 +404,13 @@ impl TypingContext {
403
404
let valid_impls = substitution_results. iter ( ) . filter_map ( |result| result. as_ref ( ) . ok ( ) ) . collect :: < Vec < _ > > ( ) ;
404
405
405
406
match valid_impls. as_slice ( ) {
406
- [ ] => Err ( format ! (
407
- "No valid implementations found for {identifier} with input {input:?} and parameters {parameters:?}.\n Types 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:?}.\n Types that are implemented: {:?}" ,
411
+ impls,
412
+ ) )
413
+ }
410
414
[ ( org_nio, output) ] => {
411
415
let node_io = NodeIOTypes :: new ( input, ( * output) . clone ( ) , parameters) ;
412
416
@@ -512,11 +516,11 @@ mod test {
512
516
ids,
513
517
vec![
514
518
15907139529964845467 ,
515
- 14791354678635908268 ,
516
- 17522454908046327116 ,
517
- 12722973206210391299 ,
518
- 4508311079153412646 ,
519
- 13250284155406988548
519
+ 17186311536944112733 ,
520
+ 1674503539363691855 ,
521
+ 10408773954839245246 ,
522
+ 1677533587730447846 ,
523
+ 6826908746727711035
520
524
]
521
525
) ;
522
526
}
0 commit comments