Skip to content

Commit db9cc73

Browse files
committed
core/toposort: Correct CloseInfo Decl
Toposort depends on StructInfos in Vertices to include the Decl which contains the StructInfo. It uses this to establish a parent-child relationship which enables it to walk topologically over the StructLits which contributed to a Vertex. In evalv3, when creating a StructInfo, the closeContext may contain the Decl we want. In evalv2, when creating a StructInfo, the closeInfo may contain the Decl we want, but this code was previously faulty: if the closeInfo had a nil Decl, then we would search parent closeInfos. This is faulty because it could feed into toposort the notion that a Decl is its own parent, which leads to infinite loop and stack explosion. Removing the search through any parent closeInfo solves this problem. The effect of this actually reduces the difference for toposort between evalv2 and evalv3, so it is beneficial in this regard too. Fixes #3710. Signed-off-by: Matthew Sackman <[email protected]> Change-Id: I8a8e7c0e83386c20428bd2d8723d5b24f5181677 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207989 Reviewed-by: Marcel van Lohuizen <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 870bfc2 commit db9cc73

File tree

8 files changed

+79
-101
lines changed

8 files changed

+79
-101
lines changed

.github/workflows/evict_caches.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
run: touch -t 202211302355 $(find * -type d)
2222
- name: Restore git file modification times
2323
uses: chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe
24-
- id: DispatchTrailer
25-
name: Try to extract Dispatch-Trailer
24+
- name: Try to extract Dispatch-Trailer
25+
id: DispatchTrailer
2626
run: |-
2727
x="$(git log -1 --pretty='%(trailers:key=Dispatch-Trailer,valueonly)')"
2828
if [[ "$x" == "" ]]
@@ -38,11 +38,11 @@ jobs:
3838
echo "value<<EOD" >> $GITHUB_OUTPUT
3939
echo "$x" >> $GITHUB_OUTPUT
4040
echo "EOD" >> $GITHUB_OUTPUT
41-
- if: |-
41+
- name: Check we don't have Dispatch-Trailer on a protected branch
42+
if: |-
4243
((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
4344
Dispatch-Trailer: {"type":"')))) && (contains(github.event.head_commit.message, '
4445
Dispatch-Trailer: {"type":"'))
45-
name: Check we don't have Dispatch-Trailer on a protected branch
4646
run: |-
4747
echo "github.event.head_commit.message contains Dispatch-Trailer but we are on a protected branch"
4848
false

.github/workflows/trybot.yaml

+14-14
Original file line numberDiff line numberDiff line change
@@ -127,40 +127,40 @@ jobs:
127127
run: go test -short ./...
128128
- name: Test with -tags=cuewasm
129129
run: go test -tags cuewasm ./cmd/cue/cmd ./cue/interpreter/wasm
130-
- name: gcloud auth for end-to-end tests
131-
id: auth
130+
- id: auth
132131
uses: google-github-actions/auth@v2
133132
with:
134133
credentials_json: ${{ secrets.E2E_GCLOUD_KEY }}
135134
if: |-
136135
github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
137136
Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-24.04')
138-
- name: gcloud setup for end-to-end tests
137+
name: gcloud auth for end-to-end tests
138+
- if: |-
139+
github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
140+
Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-24.04')
141+
name: gcloud setup for end-to-end tests
139142
uses: google-github-actions/setup-gcloud@v2
140-
if: |-
143+
- if: |-
141144
github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
142145
Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-24.04')
143-
- name: End-to-end test
144-
env:
145-
CUE_TEST_TOKEN: ${{ secrets.E2E_PORCUEPINE_CUE_TOKEN }}
146+
name: End-to-end test
146147
run: |-
147148
cd internal/_e2e
148149
go test -race
149-
if: |-
150-
github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
151-
Dispatch-Trailer: {"type":"')))) || (github.ref == 'refs/heads/ci/test')) && (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-24.04')
152-
- name: Go checks
150+
env:
151+
CUE_TEST_TOKEN: ${{ secrets.E2E_PORCUEPINE_CUE_TOKEN }}
152+
- if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-24.04')
153+
name: Go checks
153154
run: |-
154155
go vet ./...
155156
go mod tidy
156157
(cd internal/_e2e && go test -run=-)
157-
if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-24.04')
158-
- name: staticcheck
158+
- if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-24.04')
159+
name: staticcheck
159160
uses: dominikh/staticcheck-action@v1
160161
with:
161162
version: 2024.1.1
162163
install-go: false
163-
if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-24.04')
164164
- if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-24.04')
165165
name: Check all git tags are available
166166
run: |-

cmd/cue/cmd/testdata/script/cmd_issue2060.txtar

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ StrokesName: ZenStrokes1
136136
PlatformName: Linux
137137
CommandBindingsCount: 1
138138
CommandBindings:
139-
- CmdName: CursorMoveToLineForward
139+
- BindingsMax: 0
140+
CmdName: CursorMoveToLineForward
140141
CmdHumanName: Cursor Down
141142
EditorCmdText: '"command": "move", "args": test'
142143
BindingsCount: 1
143-
BindingsMax: 0
144144
Bindings:
145145
- DefText: Down
146146
BindText: Down

internal/core/adt/closed.go

-15
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ func (c CloseInfo) SpawnEmbed(x Node) CloseInfo {
180180
mode: closeEmbed,
181181
root: EmbeddingSpan,
182182
span: c.span() | EmbeddingSpan,
183-
decl: c.closeInfo.Decl(),
184183
}
185184
return c
186185
}
@@ -194,7 +193,6 @@ func (c CloseInfo) SpawnGroup(x Expr) CloseInfo {
194193
parent: c.closeInfo,
195194
location: x,
196195
span: c.span(),
197-
decl: c.closeInfo.Decl(),
198196
}
199197
return c
200198
}
@@ -208,7 +206,6 @@ func (c CloseInfo) SpawnSpan(x Node, t SpanType) CloseInfo {
208206
location: x,
209207
root: t,
210208
span: c.span() | t,
211-
decl: c.closeInfo.Decl(),
212209
}
213210
return c
214211
}
@@ -231,7 +228,6 @@ func (c CloseInfo) SpawnRef(arc *Vertex, isDef bool, x Expr) CloseInfo {
231228
parent: c.closeInfo,
232229
location: x,
233230
span: span,
234-
decl: c.closeInfo.Decl(),
235231
}
236232
}
237233
if isDef {
@@ -306,17 +302,6 @@ type closeInfo struct {
306302
decl Decl
307303
}
308304

309-
// Returns the first non-nil Decl from c, or c's parents, if possible.
310-
func (c *closeInfo) Decl() Decl {
311-
for c != nil && c.decl == nil {
312-
c = c.parent
313-
}
314-
if c == nil {
315-
return nil
316-
}
317-
return c.decl
318-
}
319-
320305
// closeStats holds the administrative fields for a closeInfo value. Each
321306
// closeInfo is associated with a single closeStats value per unification
322307
// operator. This association is done through an OpContext. This allows the

internal/core/adt/composite.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,8 @@ func (v *Vertex) AddStruct(s *StructLit, env *Environment, ci CloseInfo) *Struct
14651465
}
14661466
if cc := ci.cc; cc != nil && cc.decl != nil {
14671467
info.Decl = cc.decl
1468-
} else if decl := ci.closeInfo.Decl(); decl != nil {
1469-
info.Decl = decl
1468+
} else if ci := ci.closeInfo; ci != nil && ci.decl != nil {
1469+
info.Decl = ci.decl
14701470
}
14711471
for _, t := range v.Structs {
14721472
if *t == info { // TODO: check for different identity.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- input.cue --
2+
package p
3+
4+
#Exporter: {
5+
_objects: {...}
6+
_imports: [...]
7+
8+
objects: [
9+
for _, objs in _objects {
10+
objs
11+
}
12+
for import in _imports for obj in import._export.objects {
13+
obj
14+
}
15+
]
16+
}
17+
18+
out: #Exporter & {
19+
_imports: [_app1]
20+
}
21+
_app1: {
22+
_export: #Exporter & {
23+
_imports: [_app2]
24+
}
25+
}
26+
_app2: {
27+
_export: #Exporter & {
28+
_objects: leaf: leafField: "leaf value"
29+
}
30+
}
31+
-- out/TestTopologicalSort/lexicographical=false --
32+
{
33+
#Exporter: {
34+
objects: []
35+
}
36+
out: {
37+
objects: [{
38+
leafField: "leaf value"
39+
}]
40+
}
41+
}
42+
-- out/TestTopologicalSort/lexicographical=true --
43+
{
44+
#Exporter: {
45+
objects: []
46+
}
47+
out: {
48+
objects: [{
49+
leafField: "leaf value"
50+
}]
51+
}
52+
}

internal/core/toposort/testdata/t.txtar

+4-46
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ k2: {
366366
diff old new
367367
--- old
368368
+++ new
369-
@@ -56,35 +56,35 @@
369+
@@ -56,19 +56,19 @@
370370
w: 4
371371
}
372372
d3: {
@@ -396,48 +396,6 @@ diff old new
396396
t: 10
397397
}
398398
d5: {
399-
- za: 11
400-
- x: 3
401-
- w: 4
402-
- z: 1
403-
- y: 2
404-
+ x: 3
405-
+ w: 4
406-
+ z: 1
407-
+ y: 2
408-
+ za: 11
409-
t: 10
410-
}
411-
d6: {
412-
- za: 11
413-
- x: 3
414-
- w: 4
415-
- z: 1
416-
- y: 2
417-
+ x: 3
418-
+ w: 4
419-
+ z: 1
420-
+ y: 2
421-
+ za: 11
422-
t: 10
423-
}
424-
e1: {
425-
@@ -232,11 +232,11 @@
426-
z: 3
427-
}
428-
k2: {
429-
+ d: 0
430-
+ c: 1
431-
+ b: 2
432-
+ z: 3
433-
e: 3
434-
- d: 0
435-
- c: 1
436-
- b: 2
437-
- z: 3
438-
a: 0
439-
}
440-
}
441399
-- diff/explanation/todo/p1 --
442400
Not sure what is wrong.
443401
-- out/TestTopologicalSort/lexicographical=false --
@@ -515,19 +473,19 @@ Not sure what is wrong.
515473
t: 10
516474
}
517475
d5: {
518-
za: 11
519476
x: 3
520477
w: 4
521478
z: 1
522479
y: 2
480+
za: 11
523481
t: 10
524482
}
525483
d6: {
526-
za: 11
527484
x: 3
528485
w: 4
529486
z: 1
530487
y: 2
488+
za: 11
531489
t: 10
532490
}
533491
e1: {
@@ -675,11 +633,11 @@ Not sure what is wrong.
675633
z: 3
676634
}
677635
k2: {
678-
e: 3
679636
d: 0
680637
c: 1
681638
b: 2
682639
z: 3
640+
e: 3
683641
a: 0
684642
}
685643
}

tools/flow/testdata/issue2490.txtar

+1-18
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,11 @@ graph TD
2323
graph TD
2424
t0("root.foo [Terminated]")
2525

26-
-- out/run-v3/t1/value --
27-
{
28-
$id: "tool/cli.Print"
29-
text: "{}"
30-
stdout: "foo"
31-
}
32-
-- diff/-out/run-v3/t1/value<==>+out/run/t1/value --
33-
diff old new
34-
--- old
35-
+++ new
36-
@@ -1,5 +1,5 @@
37-
{
38-
$id: "tool/cli.Print"
39-
- stdout: "foo"
40-
text: "{}"
41-
+ stdout: "foo"
42-
}
4326
-- out/run/t1/value --
4427
{
4528
$id: "tool/cli.Print"
46-
stdout: "foo"
4729
text: "{}"
30+
stdout: "foo"
4831
}
4932
-- out/run/t1/stats --
5033
Leaks: 0

0 commit comments

Comments
 (0)