do not apply lazily

This commit is contained in:
Alexander Wang 2025-02-28 11:17:18 -07:00
parent 4520ec2c43
commit d17a6e395c
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
3 changed files with 372 additions and 9 deletions

View file

@ -5471,6 +5471,22 @@ a.width: 339
assert.Equal(t, 5, len(g.Objects))
},
},
{
name: "suspension-restore-edge",
run: func(t *testing.T) {
g, _ := assertCompile(t, `
a -> b
c
**: suspend
(** -> **)[*]: suspend
d
# Also restores the objects connected
(** -> b)[*]: restore
`, ``)
assert.Equal(t, 3, len(g.Objects))
},
},
}
for _, tc := range tca {

View file

@ -868,10 +868,12 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) {
}
if len(refctx.Key.Edges) == 0 && (refctx.Key.Primary.Suspension != nil || refctx.Key.Value.Suspension != nil) {
if refctx.Key.Primary.Suspension != nil {
f.suspended = refctx.Key.Primary.Suspension.Value
} else {
f.suspended = refctx.Key.Value.Suspension.Value
if !c.lazyGlobBeingApplied {
if refctx.Key.Primary.Suspension != nil {
f.suspended = refctx.Key.Primary.Suspension.Value
} else {
f.suspended = refctx.Key.Value.Suspension.Value
}
}
return
}
@ -1176,12 +1178,13 @@ func (c *compiler) _compileEdges(refctx *RefContext) {
}
if refctx.Key.Primary.Suspension != nil || refctx.Key.Value.Suspension != nil {
if refctx.Key.Primary.Suspension != nil {
e.suspended = refctx.Key.Primary.Suspension.Value
} else {
e.suspended = refctx.Key.Value.Suspension.Value
if !c.lazyGlobBeingApplied {
if refctx.Key.Primary.Suspension != nil {
e.suspended = refctx.Key.Primary.Suspension.Value
} else {
e.suspended = refctx.Key.Value.Suspension.Value
}
}
continue
}
e.References = append(e.References, &EdgeReference{
@ -1322,6 +1325,9 @@ func (m *Map) removeSuspendedFields() {
}
for i := len(m.Fields) - 1; i >= 0; i-- {
if m.Fields[i].Name == nil {
continue
}
_, isReserved := d2ast.ReservedKeywords[m.Fields[i].Name.ScalarString()]
if isReserved {
continue

View file

@ -0,0 +1,341 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,0:0:0-9:0:108",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,1:0:1-1:6:7",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,1:0:1-1:6:7",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,1:0:1-1:1:2",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,1:5:6-1:6:7",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,1:5:6-1:6:7",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,2:0:8-2:1:9",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,2:0:8-2:1:9",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,2:0:8-2:1:9",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"primary": {},
"value": {}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,3:0:10-3:11:21",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,3:0:10-3:2:12",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,3:0:10-3:2:12",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"primary": {},
"value": {
"suspension": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,3:4:14-3:11:21",
"value": true
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,4:0:22-4:22:44",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,4:1:23-4:9:31",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,4:1:23-4:3:25",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,4:1:23-4:3:25",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,4:7:29-4:9:31",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,4:7:29-4:9:31",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"dst_arrow": ">"
}
],
"edge_index": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,4:10:32-4:13:35",
"int": null,
"glob": true
},
"primary": {},
"value": {
"suspension": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,4:15:37-4:22:44",
"value": true
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,5:0:45-5:1:46",
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,5:0:45-5:1:46",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,5:0:45-5:1:46",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"primary": {},
"value": {}
}
},
{
"comment": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,7:0:48-7:37:85",
"value": "Also restores the objects connected"
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,8:0:86-8:21:107",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,8:1:87-8:8:94",
"src": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,8:1:87-8:3:89",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,8:1:87-8:3:89",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,8:7:93-8:8:94",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,8:7:93-8:8:94",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"edge_index": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,8:9:95-8:12:98",
"int": null,
"glob": true
},
"primary": {},
"value": {
"suspension": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,8:14:100-8:21:107",
"value": false
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"attributes": {
"label": {
"value": ""
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "d",
"id_val": "d",
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,5:0:45-5:1:46",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile2/globs/suspension-restore-edge.d2,5:0:45-5:1:46",
"value": [
{
"string": "d",
"raw_string": "d"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "d"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
}
]
},
"err": null
}