Skip to content

Commit cbb54f0

Browse files
committed
fix suspend
1 parent 3bbb338 commit cbb54f0

File tree

7 files changed

+1162
-3
lines changed

7 files changed

+1162
-3
lines changed

d2compiler/compile_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -5617,6 +5617,44 @@ d -> d: "suspend"
56175617
assert.Equal(t, 1, len(g.Edges))
56185618
},
56195619
},
5620+
{
5621+
name: "unsuspend-edge-label",
5622+
run: func(t *testing.T) {
5623+
g, _ := assertCompile(t, `
5624+
a -> b: hello
5625+
c
5626+
**: suspend
5627+
(** -> **)[*]: suspend
5628+
5629+
(* -> *)[*]: unsuspend
5630+
`, ``)
5631+
assert.Equal(t, 2, len(g.Objects))
5632+
assert.Equal(t, 1, len(g.Edges))
5633+
assert.Equal(t, "hello", g.Edges[0].Label.Value)
5634+
},
5635+
},
5636+
{
5637+
name: "unsuspend-shape-label",
5638+
run: func(t *testing.T) {
5639+
g, _ := assertCompile(t, `
5640+
a: hello
5641+
*: suspend
5642+
*: unsuspend
5643+
`, ``)
5644+
assert.Equal(t, 1, len(g.Objects))
5645+
assert.Equal(t, "hello", g.Objects[0].Label.Value)
5646+
},
5647+
},
5648+
{
5649+
name: "suspend-shape",
5650+
run: func(t *testing.T) {
5651+
g, _ := assertCompile(t, `
5652+
a: hello
5653+
*: suspend
5654+
`, ``)
5655+
assert.Equal(t, 0, len(g.Objects))
5656+
},
5657+
},
56205658
{
56215659
name: "edge-glob-ampersand-filter/1",
56225660
run: func(t *testing.T) {

d2ir/compile.go

-2
Original file line numberDiff line numberDiff line change
@@ -1285,12 +1285,10 @@ func (c *compiler) _compileEdges(refctx *RefContext) {
12851285

12861286
// If we're unsuspending an edge, we should also unsuspend its src and dst objects
12871287
if !suspensionValue {
1288-
// Find the source and destination objects
12891288
srcPath, dstPath := e.ID.SrcPath, e.ID.DstPath
12901289
srcObj := refctx.ScopeMap.GetField(srcPath...)
12911290
dstObj := refctx.ScopeMap.GetField(dstPath...)
12921291

1293-
// Unsuspend the objects
12941292
if srcObj != nil {
12951293
srcObj.suspended = false
12961294
}

d2ir/d2ir.go

+35-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,41 @@ func (rc *RefContext) EdgeIndex() int {
650650
func (rc *RefContext) Equal(rc2 *RefContext) bool {
651651
// We intentionally ignore edges here because the same glob can produce multiple RefContexts that should be treated the same with only the edge as the difference.
652652
// Same with ScopeMap.
653-
return rc.Key.Equals(rc2.Key) && rc.Scope == rc2.Scope && rc.ScopeAST == rc2.ScopeAST
653+
if !(rc.Key.Equals(rc2.Key) && rc.Scope == rc2.Scope && rc.ScopeAST == rc2.ScopeAST) {
654+
return false
655+
}
656+
657+
// Check if suspension values match for suspension operations
658+
// We don't want these two to equal
659+
// 1. *: suspend
660+
// 2. *: unsuspend
661+
hasSuspension1 := (rc.Key.Primary.Suspension != nil || rc.Key.Value.Suspension != nil)
662+
hasSuspension2 := (rc2.Key.Primary.Suspension != nil || rc2.Key.Value.Suspension != nil)
663+
664+
if hasSuspension1 || hasSuspension2 {
665+
var val1, val2 bool
666+
if rc.Key.Primary.Suspension != nil {
667+
val1 = rc.Key.Primary.Suspension.Value
668+
} else if rc.Key.Value.Suspension != nil {
669+
val1 = rc.Key.Value.Suspension.Value
670+
}
671+
672+
if rc2.Key.Primary.Suspension != nil {
673+
val2 = rc2.Key.Primary.Suspension.Value
674+
} else if rc2.Key.Value.Suspension != nil {
675+
val2 = rc2.Key.Value.Suspension.Value
676+
}
677+
678+
if hasSuspension1 && hasSuspension2 && val1 != val2 {
679+
return false
680+
}
681+
682+
if hasSuspension1 != hasSuspension2 {
683+
return false
684+
}
685+
}
686+
687+
return true
654688
}
655689

656690
func (m *Map) FieldCountRecursive() int {

testdata/d2compiler/TestCompile2/globs/suspend-shape.exp.json

+101
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)