From 214e11278cbe09e8ae1cbeff83bb7e61cfe1894c Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Wed, 30 Nov 2022 11:19:15 +0100 Subject: [PATCH] internal/core/adt: base error mode on requested state See comments in internal/core/adt/context.go. This fixes broken tests in scalars/embed.txtar Issue #2113 Signed-off-by: Marcel van Lohuizen Change-Id: I32c1a34bc91e3df7d7daf7da209e89204eaba19d Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/546861 Reviewed-by: Paul Jolly Unity-Result: CUEcueckoo TryBot-Result: CUEcueckoo --- cue/testdata/basicrewrite/012_selecting.txtar | 12 ++-- cue/testdata/builtins/incomplete.txtar | 14 ++--- cue/testdata/comprehensions/issue837.txtar | 2 +- cue/testdata/comprehensions/pushdown.txtar | 2 +- cue/testdata/definitions/comprehensions.txtar | 2 +- cue/testdata/eval/incomplete.txtar | 12 ++-- cue/testdata/eval/let.txtar | 14 ++--- cue/testdata/export/issue854.txtar | 6 +- cue/testdata/references/index.txtar | 12 ++-- cue/testdata/resolve/016_index.txtar | 12 ++-- cue/testdata/scalars/embed.txtar | 63 +++++++------------ internal/core/adt/context.go | 8 ++- 12 files changed, 72 insertions(+), 87 deletions(-) diff --git a/cue/testdata/basicrewrite/012_selecting.txtar b/cue/testdata/basicrewrite/012_selecting.txtar index d47f249e8f4..5fa660318bc 100644 --- a/cue/testdata/basicrewrite/012_selecting.txtar +++ b/cue/testdata/basicrewrite/012_selecting.txtar @@ -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): diff --git a/cue/testdata/builtins/incomplete.txtar b/cue/testdata/builtins/incomplete.txtar index 39b750d8247..a1486e168d7 100644 --- a/cue/testdata/builtins/incomplete.txtar +++ b/cue/testdata/builtins/incomplete.txtar @@ -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: diff --git a/cue/testdata/comprehensions/issue837.txtar b/cue/testdata/comprehensions/issue837.txtar index e36900e11a4..fb2c0d980d7 100644 --- a/cue/testdata/comprehensions/issue837.txtar +++ b/cue/testdata/comprehensions/issue837.txtar @@ -71,7 +71,7 @@ Allocs: 19 Retain: 11 Unifications: 114 -Conjuncts: 291 +Conjuncts: 307 Disjuncts: 173 -- out/eval -- Errors: diff --git a/cue/testdata/comprehensions/pushdown.txtar b/cue/testdata/comprehensions/pushdown.txtar index e638bbb7fc9..01869651ff1 100644 --- a/cue/testdata/comprehensions/pushdown.txtar +++ b/cue/testdata/comprehensions/pushdown.txtar @@ -709,7 +709,7 @@ Allocs: 23 Retain: 68 Unifications: 389 -Conjuncts: 632 +Conjuncts: 636 Disjuncts: 433 -- out/eval -- Errors: diff --git a/cue/testdata/definitions/comprehensions.txtar b/cue/testdata/definitions/comprehensions.txtar index 607f4ef01f8..59586572f85 100644 --- a/cue/testdata/definitions/comprehensions.txtar +++ b/cue/testdata/definitions/comprehensions.txtar @@ -17,7 +17,7 @@ Allocs: 5 Retain: 2 Unifications: 6 -Conjuncts: 6 +Conjuncts: 9 Disjuncts: 8 -- out/eval -- Errors: diff --git a/cue/testdata/eval/incomplete.txtar b/cue/testdata/eval/incomplete.txtar index a9b6087e8ba..f205462e193 100644 --- a/cue/testdata/eval/incomplete.txtar +++ b/cue/testdata/eval/incomplete.txtar @@ -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){ diff --git a/cue/testdata/eval/let.txtar b/cue/testdata/eval/let.txtar index 733d41b5c3f..33d6bf08864 100644 --- a/cue/testdata/eval/let.txtar +++ b/cue/testdata/eval/let.txtar @@ -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 } diff --git a/cue/testdata/export/issue854.txtar b/cue/testdata/export/issue854.txtar index d4a18ac95fa..b06ab8f7354 100644 --- a/cue/testdata/export/issue854.txtar +++ b/cue/testdata/export/issue854.txtar @@ -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: (_|_){ diff --git a/cue/testdata/references/index.txtar b/cue/testdata/references/index.txtar index cf958da77b0..81fb2a48b29 100644 --- a/cue/testdata/references/index.txtar +++ b/cue/testdata/references/index.txtar @@ -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): diff --git a/cue/testdata/resolve/016_index.txtar b/cue/testdata/resolve/016_index.txtar index 717c24a5125..4d8018ebbf6 100644 --- a/cue/testdata/resolve/016_index.txtar +++ b/cue/testdata/resolve/016_index.txtar @@ -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): diff --git a/cue/testdata/scalars/embed.txtar b/cue/testdata/scalars/embed.txtar index 0332d2db94d..7086288b804 100644 --- a/cue/testdata/scalars/embed.txtar +++ b/cue/testdata/scalars/embed.txtar @@ -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 } @@ -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: (_|_){ @@ -261,8 +252,7 @@ Result: 0: (string){ "foo" } } } - merged: (_|_){ - // [eval] + merged: (struct){ t1: (struct){ p1: (struct){ #fn: (string){ @@ -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 } } @@ -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 } } } } diff --git a/internal/core/adt/context.go b/internal/core/adt/context.go index ef6592c5495..dc6c364b24c 100644 --- a/internal/core/adt/context.go +++ b/internal/core/adt/context.go @@ -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 @@ -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, }) }