@@ -36,6 +36,7 @@ export class Handle implements Comparable<Handle> {
36
36
private _originalFate : Fate | null = null ;
37
37
private _originalId : string | null = null ;
38
38
private _connections : HandleConnection [ ] = [ ] ;
39
+ private _associatedHandles : Handle [ ] = [ ] ;
39
40
private _mappedType : Type | undefined = undefined ;
40
41
private _storageKey : StorageKey | undefined = undefined ;
41
42
capabilities : Capabilities ;
@@ -102,6 +103,7 @@ export class Handle implements Comparable<Handle> {
102
103
// attached HandleConnection objects.
103
104
handle . _connections = [ ] ;
104
105
handle . _pattern = this . _pattern ;
106
+ handle . _associatedHandles = this . _associatedHandles . map ( h => cloneMap . get ( h ) as Handle ) ;
105
107
}
106
108
return handle ;
107
109
}
@@ -123,7 +125,7 @@ export class Handle implements Comparable<Handle> {
123
125
_mergedFate ( fates : Fate [ ] ) {
124
126
assert ( fates . length > 0 , `Cannot merge empty fates list` ) ;
125
127
// Merging handles only used in coalesce-recipe strategy, which is only done for use/create/? fates.
126
- assert ( ! fates . includes ( 'map' ) && ! fates . includes ( 'copy' ) , `Merging map/copy not supported yet` ) ;
128
+ assert ( ! fates . some ( f => f === 'map' || f === 'copy' || f === 'join' ) , `Merging map/copy/join not supported yet` ) ;
127
129
128
130
// If all fates were `use` keep their fate, otherwise set to `create`.
129
131
return fates . every ( fate => fate === 'use' ) ? 'use' : 'create' ;
@@ -206,6 +208,7 @@ export class Handle implements Comparable<Handle> {
206
208
get localName ( ) { return this . _localName ; }
207
209
set localName ( name : string ) { this . _localName = name ; }
208
210
get connections ( ) { return this . _connections ; } // HandleConnection*
211
+ get associatedHandles ( ) { return this . _associatedHandles ; }
209
212
get storageKey ( ) { return this . _storageKey ; }
210
213
set storageKey ( key : StorageKey ) { this . _storageKey = key ; }
211
214
get pattern ( ) { return this . _pattern ; }
@@ -216,6 +219,7 @@ export class Handle implements Comparable<Handle> {
216
219
set immediateValue ( value : ParticleSpec ) { this . _immediateValue = value ; }
217
220
get ttl ( ) { return this . _ttl ; }
218
221
set ttl ( ttl : Ttl ) { this . _ttl = ttl ; }
222
+ get isSynthetic ( ) { return this . fate === 'join' ; } // Join handles are the first type of synthetic handles, other may come.
219
223
220
224
static effectiveType ( handleType : Type , connections : { type ?: Type , direction ?: Direction , relaxed ?: boolean } [ ] ) {
221
225
const variableMap = new Map < TypeVariableInfo | Schema , TypeVariableInfo | Schema > ( ) ;
@@ -332,13 +336,17 @@ export class Handle implements Comparable<Handle> {
332
336
// E.g. hostedParticle = ShowProduct
333
337
return undefined ;
334
338
}
339
+ const getName = ( h :Handle ) => ( ( nameMap && nameMap . get ( h ) ) || h . localName ) ;
335
340
// TODO: type? maybe output in a comment
336
341
const result : string [ ] = [ ] ;
337
- const name = ( nameMap && nameMap . get ( this ) ) || this . localName ;
342
+ const name = getName ( this ) ;
338
343
if ( name ) {
339
344
result . push ( `${ name } :` ) ;
340
345
}
341
346
result . push ( this . fate ) ;
347
+ if ( this . associatedHandles . length ) {
348
+ result . push ( `(${ this . associatedHandles . map ( h => getName ( h ) ) . join ( ', ' ) } )` ) ;
349
+ }
342
350
if ( this . capabilities && ! this . capabilities . isEmpty ( ) ) {
343
351
result . push ( this . capabilities . toString ( ) ) ;
344
352
}
@@ -376,4 +384,9 @@ export class Handle implements Comparable<Handle> {
376
384
findConnectionByDirection ( dir : Direction ) : HandleConnection | undefined {
377
385
return this . _connections . find ( conn => conn . direction === dir ) ;
378
386
}
387
+
388
+ associateHandle ( handle : Handle ) {
389
+ assert ( this . fate === 'join' ) ;
390
+ this . _associatedHandles . push ( handle ) ;
391
+ }
379
392
}
0 commit comments