Skip to content

Commit

Permalink
internal/core/adt: base error mode on requested state
Browse files Browse the repository at this point in the history
See comments in internal/core/adt/context.go.

This fixes broken tests in scalars/embed.txtar

Issue #2113

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I32c1a34bc91e3df7d7daf7da209e89204eaba19d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546861
Reviewed-by: Paul Jolly <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mpvl committed Nov 30, 2022
1 parent 88857e0 commit 214e112
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 87 deletions.
12 changes: 6 additions & 6 deletions cue/testdata/basicrewrite/012_selecting.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ h: _|_ // invalid operation: [3].b (type list does not support selection)
].b
}
-- out/eval/stats --
Leaks: 9
Leaks: 17
Freed: 10
Reused: 8
Allocs: 11
Retain: 9
Allocs: 19
Retain: 17

Unifications: 19
Conjuncts: 19
Disjuncts: 17
Unifications: 27
Conjuncts: 35
Disjuncts: 25
-- out/eval --
Errors:
e: invalid struct selector 4 (type int):
Expand Down
14 changes: 7 additions & 7 deletions cue/testdata/builtins/incomplete.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ multipleErrors: {
}
}
-- out/eval/stats --
Leaks: 10
Freed: 119
Reused: 114
Allocs: 15
Retain: 37
Leaks: 7
Freed: 122
Reused: 117
Allocs: 12
Retain: 32

Unifications: 109
Conjuncts: 265
Disjuncts: 152
Conjuncts: 267
Disjuncts: 150
-- out/eval --
Errors:
badListType.decimal: cannot use 2 (type int) as list in argument 1 to list.Max:
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/comprehensions/issue837.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Allocs: 19
Retain: 11

Unifications: 114
Conjuncts: 291
Conjuncts: 307
Disjuncts: 173
-- out/eval --
Errors:
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/comprehensions/pushdown.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ Allocs: 23
Retain: 68

Unifications: 389
Conjuncts: 632
Conjuncts: 636
Disjuncts: 433
-- out/eval --
Errors:
Expand Down
2 changes: 1 addition & 1 deletion cue/testdata/definitions/comprehensions.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Allocs: 5
Retain: 2

Unifications: 6
Conjuncts: 6
Conjuncts: 9
Disjuncts: 8
-- out/eval --
Errors:
Expand Down
12 changes: 6 additions & 6 deletions cue/testdata/eval/incomplete.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ issue1837: {
}
}
-- out/eval/stats --
Leaks: 4
Freed: 28
Reused: 23
Allocs: 9
Retain: 44
Leaks: 0
Freed: 32
Reused: 26
Allocs: 6
Retain: 40

Unifications: 32
Conjuncts: 101
Conjuncts: 122
Disjuncts: 35
-- out/eval --
(struct){
Expand Down
14 changes: 7 additions & 7 deletions cue/testdata/eval/let.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ keepDescending: t2: {
}

-- out/eval/stats --
Leaks: 7
Freed: 47
Reused: 38
Allocs: 16
Retain: 23
Leaks: 6
Freed: 48
Reused: 39
Allocs: 15
Retain: 21

Unifications: 52
Conjuncts: 66
Disjuncts: 60
Conjuncts: 74
Disjuncts: 59
-- out/eval --
(struct){
let A#1 = (int){ 9 }
Expand Down
6 changes: 3 additions & 3 deletions cue/testdata/export/issue854.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Leaks: 4
Freed: 2
Reused: 0
Allocs: 6
Retain: 7
Retain: 18

Unifications: 6
Conjuncts: 8
Disjuncts: 8
Conjuncts: 21
Disjuncts: 11
-- out/eval --
(struct){
theb: (_|_){
Expand Down
12 changes: 6 additions & 6 deletions cue/testdata/references/index.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ varNegativeIndex: {
a: [1, 2, 3][n]
}
-- out/eval/stats --
Leaks: 12
Leaks: 15
Freed: 36
Reused: 33
Allocs: 15
Retain: 12
Allocs: 18
Retain: 15

Unifications: 40
Conjuncts: 50
Disjuncts: 45
Unifications: 43
Conjuncts: 56
Disjuncts: 48
-- out/eval --
Errors:
outOfBoundsDisjunction: invalid list index 1 (out of bounds):
Expand Down
12 changes: 6 additions & 6 deletions cue/testdata/resolve/016_index.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ e7: def["b"]
e7: 〈0;def〉["b"]
}
-- out/eval/stats --
Leaks: 10
Leaks: 16
Freed: 32
Reused: 26
Allocs: 16
Retain: 12
Allocs: 22
Retain: 18

Unifications: 34
Conjuncts: 44
Disjuncts: 42
Unifications: 40
Conjuncts: 61
Disjuncts: 48
-- out/eval --
Errors:
c: invalid list index "3" (type string):
Expand Down
63 changes: 22 additions & 41 deletions cue/testdata/scalars/embed.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ merged: t1: p3: {
#fn: { #in2: c1: string, #in2.c1 }
#fn: { #in2: _, _ }
}
// TODO(broken): these tests should resolve as above.
merged: t2: p1: {
#fn: { #in2: {}, _ }
#fn: { #in2: c1: string, #in2.c1 }
Expand All @@ -135,27 +134,19 @@ merged: t2: p3: {
}

-- out/eval/stats --
Leaks: 3
Freed: 120
Reused: 113
Allocs: 10
Retain: 45
Leaks: 1
Freed: 123
Reused: 115
Allocs: 9
Retain: 47

Unifications: 119
Conjuncts: 297
Disjuncts: 150
Unifications: 120
Conjuncts: 307
Disjuncts: 156
-- out/eval --
Errors:
listEmbed.b6: invalid list index 5 (out of bounds):
./in.cue:28:9
merged.t2.p1.#fn: undefined field: c1:
./issue2113.cue:20:32
merged.t2.p1.x: undefined field: c1:
./issue2113.cue:20:32
merged.t2.p2.#fn: undefined field: c1:
./issue2113.cue:24:32
merged.t2.p3.#fn: undefined field: c1:
./issue2113.cue:30:32

Result:
(_|_){
Expand Down Expand Up @@ -261,8 +252,7 @@ Result:
0: (string){ "foo" }
}
}
merged: (_|_){
// [eval]
merged: (struct){
t1: (struct){
p1: (struct){
#fn: (string){
Expand Down Expand Up @@ -307,30 +297,24 @@ Result:
}
}
}
t2: (_|_){
// [eval]
p1: (_|_){
// [eval]
#fn: (_|_){
// [eval] merged.t2.p1.#fn: undefined field: c1:
// ./issue2113.cue:20:32
t2: (struct){
p1: (struct){
#fn: (string){
string
#in2: (#struct){
c1: (string){ string }
}
}
x: (_|_){
// [eval] merged.t2.p1.x: undefined field: c1:
// ./issue2113.cue:20:32
x: (string){
"V 1"
#in2: (#struct){
c1: (string){ "V 1" }
}
}
}
p2: (_|_){
// [eval]
#fn: (_|_){
// [eval] merged.t2.p2.#fn: undefined field: c1:
// ./issue2113.cue:24:32
p2: (struct){
#fn: (string){
string
#in2: (#struct){
c1: (string){ string }
}
Expand All @@ -342,20 +326,17 @@ Result:
}
}
}
p3: (_|_){
// [eval]
p3: (struct){
x: (string){
"V 1"
#in2: (#struct){
c1: (string){ "V 1" }
}
}
#fn: (_|_){
// [eval] merged.t2.p3.#fn: undefined field: c1:
// ./issue2113.cue:30:32
#fn: (string){
string
#in2: (#struct){
c1: (_|_){// string
}
c1: (string){ string }
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions internal/core/adt/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,11 @@ func (c *OpContext) lookup(x *Vertex, pos token.Pos, l Feature, state VertexStat
}
}
code := IncompleteError
if !x.Accept(c, l) {
// As long as we have incomplete information, we cannot mark the
// inability to look up a field as "final", as it may resolve down the
// line.
permanent := x.status > Conjuncts
if (state > Partial || permanent) && !x.Accept(c, l) {
code = 0
} else if hasCycle {
code = CycleError
Expand All @@ -886,7 +890,7 @@ func (c *OpContext) lookup(x *Vertex, pos token.Pos, l Feature, state VertexStat
}
c.AddBottom(&Bottom{
Code: code,
Permanent: x.status >= Conjuncts,
Permanent: permanent,
Err: err,
})
}
Expand Down

0 comments on commit 214e112

Please sign in to comment.