@@ -407,56 +407,64 @@ func (po *poset) newconst(n *Value) {
407
407
po .upushconst (i , 0 )
408
408
}
409
409
410
- // aliasnode records that n2 is an alias of n1
410
+ // aliasnewnode records that a single node n2 (not in the poset yet) is an alias
411
+ // of the master node n1.
412
+ func (po * poset ) aliasnewnode (n1 , n2 * Value ) {
413
+ i1 , i2 := po .values [n1 .ID ], po .values [n2 .ID ]
414
+ if i1 == 0 || i2 != 0 {
415
+ panic ("aliasnewnode invalid arguments" )
416
+ }
417
+
418
+ po .values [n2 .ID ] = i1
419
+ po .upushalias (n2 .ID , 0 )
420
+ }
421
+
422
+ // aliasnode records that n2 (already in the poset) is an alias of n1
411
423
func (po * poset ) aliasnode (n1 , n2 * Value ) {
412
424
i1 := po .values [n1 .ID ]
413
425
if i1 == 0 {
414
426
panic ("aliasnode for non-existing node" )
415
427
}
416
428
417
429
i2 := po .values [n2 .ID ]
418
- if i2 != 0 {
419
- // Rename all references to i2 into i1
420
- // (do not touch i1 itself, otherwise we can create useless self-loops)
421
- for idx , n := range po .nodes {
422
- if uint32 (idx ) != i1 {
423
- l , r := n .l , n .r
424
- if l .Target () == i2 {
425
- po .setchl (uint32 (idx ), newedge (i1 , l .Strict ()))
426
- po .upush (undoSetChl , uint32 (idx ), l )
427
- }
428
- if r .Target () == i2 {
429
- po .setchr (uint32 (idx ), newedge (i1 , r .Strict ()))
430
- po .upush (undoSetChr , uint32 (idx ), r )
431
- }
430
+ if i2 == 0 {
431
+ panic ("aliasnode for non-existing node" )
432
+ }
433
+ // Rename all references to i2 into i1
434
+ // (do not touch i1 itself, otherwise we can create useless self-loops)
435
+ for idx , n := range po .nodes {
436
+ if uint32 (idx ) != i1 {
437
+ l , r := n .l , n .r
438
+ if l .Target () == i2 {
439
+ po .setchl (uint32 (idx ), newedge (i1 , l .Strict ()))
440
+ po .upush (undoSetChl , uint32 (idx ), l )
432
441
}
433
- }
434
-
435
- // Reassign all existing IDs that point to i2 to i1.
436
- // This includes n2.ID.
437
- for k , v := range po .values {
438
- if v == i2 {
439
- po .values [k ] = i1
440
- po .upushalias (k , i2 )
442
+ if r .Target () == i2 {
443
+ po .setchr (uint32 (idx ), newedge (i1 , r .Strict ()))
444
+ po .upush (undoSetChr , uint32 (idx ), r )
441
445
}
442
446
}
447
+ }
443
448
444
- if n2 .isGenericIntConst () {
445
- val := n2 .AuxInt
446
- if po .flags & posetFlagUnsigned != 0 {
447
- val = int64 (n2 .AuxUnsigned ())
448
- }
449
- if po .constants [val ] != i2 {
450
- panic ("aliasing constant which is not registered" )
451
- }
452
- po .constants [val ] = i1
453
- po .upushconst (i1 , i2 )
449
+ // Reassign all existing IDs that point to i2 to i1.
450
+ // This includes n2.ID.
451
+ for k , v := range po .values {
452
+ if v == i2 {
453
+ po .values [k ] = i1
454
+ po .upushalias (k , i2 )
454
455
}
456
+ }
455
457
456
- } else {
457
- // n2.ID wasn't seen before, so record it as alias to i1
458
- po .values [n2 .ID ] = i1
459
- po .upushalias (n2 .ID , 0 )
458
+ if n2 .isGenericIntConst () {
459
+ val := n2 .AuxInt
460
+ if po .flags & posetFlagUnsigned != 0 {
461
+ val = int64 (n2 .AuxUnsigned ())
462
+ }
463
+ if po .constants [val ] != i2 {
464
+ panic ("aliasing constant which is not registered" )
465
+ }
466
+ po .constants [val ] = i1
467
+ po .upushconst (i1 , i2 )
460
468
}
461
469
}
462
470
@@ -1093,11 +1101,11 @@ func (po *poset) SetEqual(n1, n2 *Value) bool {
1093
1101
i1 = po .newnode (n1 )
1094
1102
po .roots = append (po .roots , i1 )
1095
1103
po .upush (undoNewRoot , i1 , 0 )
1096
- po .aliasnode (n1 , n2 )
1104
+ po .aliasnewnode (n1 , n2 )
1097
1105
case f1 && ! f2 :
1098
- po .aliasnode (n1 , n2 )
1106
+ po .aliasnewnode (n1 , n2 )
1099
1107
case ! f1 && f2 :
1100
- po .aliasnode (n2 , n1 )
1108
+ po .aliasnewnode (n2 , n1 )
1101
1109
case f1 && f2 :
1102
1110
if i1 == i2 {
1103
1111
// Already aliased, ignore
0 commit comments