Skip to content

Commit

Permalink
internal/core/adt: limit error propagation to cross package
Browse files Browse the repository at this point in the history
This check mostly necessary to catch cross-package
errors. Within packages it may result in unintuitive error
messages. This is because the error status of a node may
change during evaluation.
Note that package nodes are self-contained and that because
of a lack of cycles, a package node is always fully evaluated
before a referring node.

In order to determine whether an error crosses package
boundaries, we mark the originating node in the error. An
error orginates from a different package if they root node
is different.

There are probably less error-prone mechanisms to determine
the package, but the impact of getting it wrong is quite small,
so this is sufficient for now.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I82c5e199a1bc0746abb60b825c31e03587061f39
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200793
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Matthew Sackman <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mpvl committed Sep 6, 2024
1 parent abb6364 commit fbcadd9
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 128 deletions.
13 changes: 3 additions & 10 deletions cue/testdata/comprehensions/iferror.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ Result:
incomplete: (_|_){
// [incomplete] incomplete: undefined field: d:
// ./in.cue:16:7
// incomplete: undefined field: d:
// ./in.cue:23:21
list: (#list){
0: (int){ 1 }
1: (int){ 2 }
Expand Down Expand Up @@ -268,16 +270,7 @@ diff old new

Result:
(_|_){
@@ -31,8 +31,6 @@
incomplete: (_|_){
// [incomplete] incomplete: undefined field: d:
// ./in.cue:16:7
- // incomplete: undefined field: d:
- // ./in.cue:23:21
list: (#list){
0: (int){ 1 }
1: (int){ 2 }
@@ -66,17 +64,23 @@
@@ -66,17 +66,23 @@
issue1972: (_|_){
// [eval]
err1: (_|_){
Expand Down
26 changes: 8 additions & 18 deletions cue/testdata/cycle/023_reentrance.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@ Result:
// ./in.cue:7:5
// ./in.cue:3:35
// ./in.cue:5:5
// non-concrete value int in operand to <:
// ./in.cue:10:5
// ./in.cue:3:35
// ./in.cue:5:5
}
}
fib: (_|_){
// [incomplete] fib: non-concrete value int in operand to >=:
// ./in.cue:7:5
// ./in.cue:5:5
// fib: non-concrete value int in operand to <:
// ./in.cue:10:5
// ./in.cue:5:5
n: (int){ int }
}
fib1: (int){ 1 }
Expand Down Expand Up @@ -150,24 +157,7 @@ diff old new

Result:
(_|_){
@@ -16,10 +12,6 @@
// ./in.cue:7:5
// ./in.cue:3:35
// ./in.cue:5:5
- // non-concrete value int in operand to <:
- // ./in.cue:10:5
- // ./in.cue:3:35
- // ./in.cue:5:5
}
}
fib: (_|_){
@@ -26,33 +18,23 @@
// [incomplete] fib: non-concrete value int in operand to >=:
// ./in.cue:7:5
// ./in.cue:5:5
- // fib: non-concrete value int in operand to <:
- // ./in.cue:10:5
- // ./in.cue:5:5
@@ -32,27 +28,20 @@
n: (int){ int }
}
fib1: (int){ 1 }
Expand Down
28 changes: 14 additions & 14 deletions cue/testdata/cycle/chain.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ issue2052: full: {
d: #Depth & {#in: tree}
}
-- out/evalalpha/stats --
Leaks: 19999
Freed: 1462
Reused: 1461
Allocs: 20000
Leaks: 20362
Freed: 1534
Reused: 1533
Allocs: 20363
Retain: 0

Unifications: 7506
Conjuncts: 107540
Disjuncts: 13655
Unifications: 7655
Conjuncts: 109511
Disjuncts: 13941
-- out/evalalpha --
Errors:
issue2052.t1.#Depth: adding field #basic not allowed as field set was already referenced:
Expand Down Expand Up @@ -725,18 +725,18 @@ diff old new
-Reused: 1816
-Allocs: 70
-Retain: 169
+Leaks: 19999
+Freed: 1462
+Reused: 1461
+Allocs: 20000
+Leaks: 20362
+Freed: 1534
+Reused: 1533
+Allocs: 20363
+Retain: 0

-Unifications: 801
-Conjuncts: 3177
-Disjuncts: 1979
+Unifications: 7506
+Conjuncts: 107540
+Disjuncts: 13655
+Unifications: 7655
+Conjuncts: 109511
+Disjuncts: 13941
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
Expand Down
48 changes: 6 additions & 42 deletions cue/testdata/cycle/compbottomnofinal.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,6 @@ Disjuncts: 215
#Y: (_|_){
// [incomplete] small.p1.#Y: undefined field: port:
// ./in.cue:28:50
// small.p1.#X.port: cyclic reference to field port:
// ./in.cue:31:4
}
#X: (_|_){
// [incomplete] small.p1.#X.port: cyclic reference to field port:
Expand All @@ -409,8 +407,6 @@ Disjuncts: 215
#Y: (_|_){
// [incomplete] medium.p1.#Y: undefined field: port:
// ./in.cue:58:50
// medium.p1.#X.port: cyclic reference to field port:
// ./in.cue:70:4
}
Y: (struct){
}
Expand All @@ -423,8 +419,6 @@ Disjuncts: 215
#Y: (_|_){
// [incomplete] medium.p2.#Y: undefined field: port:
// ./in.cue:80:50
// medium.p2.#X.port: cyclic reference to field port:
// ./in.cue:86:4
}
#X: (_|_){
// [incomplete] medium.p2.#X.port: cyclic reference to field port:
Expand All @@ -439,8 +433,6 @@ Disjuncts: 215
#Y: (_|_){
// [incomplete] medium.p3.#Y: undefined field: port:
// ./in.cue:108:50
// medium.p3.#X.port: cyclic reference to field port:
// ./in.cue:114:4
}
#X: (_|_){
// [incomplete] medium.p3.#X.port: cyclic reference to field port:
Expand All @@ -455,9 +447,7 @@ Disjuncts: 215
// ./in.cue:134:4
}
#Y: (_|_){
// [incomplete] medium.p4.#X.port: cyclic reference to field port:
// ./in.cue:134:4
// medium.p4.#Y: undefined field: port:
// [incomplete] medium.p4.#Y: undefined field: port:
// ./in.cue:142:50
}
}
Expand Down Expand Up @@ -496,8 +486,6 @@ Disjuncts: 215
X: (_|_){
// [incomplete] large.p1.X: undefined field: port:
// ./in.cue:199:33
// large.p1.#X.port: cyclic reference to field port:
// ./in.cue:211:4
}
#X: (_|_){
// [incomplete] large.p1.#X.port: cyclic reference to field port:
Expand All @@ -514,8 +502,6 @@ Disjuncts: 215
X: (_|_){
// [incomplete] large.p2.X: undefined field: port:
// ./in.cue:235:33
// large.p2.#X.port: cyclic reference to field port:
// ./in.cue:252:4
}
Y: (struct){
userinfo: (string){ "user" }
Expand All @@ -536,8 +522,6 @@ Disjuncts: 215
X: (_|_){
// [incomplete] large.p3.X: undefined field: port:
// ./in.cue:276:33
// large.p3.#X.port: cyclic reference to field port:
// ./in.cue:288:4
}
#X: (_|_){
// [incomplete] large.p3.#X.port: cyclic reference to field port:
Expand All @@ -558,8 +542,6 @@ Disjuncts: 215
X: (_|_){
// [incomplete] large.p4.X: undefined field: port:
// ./in.cue:317:33
// large.p4.#X.port: cyclic reference to field port:
// ./in.cue:329:4
}
#X: (_|_){
// [incomplete] large.p4.#X.port: cyclic reference to field port:
Expand All @@ -582,7 +564,7 @@ Disjuncts: 215
diff old new
--- old
+++ new
@@ -1,35 +1,36 @@
@@ -1,35 +1,34 @@
(struct){
minimal: (struct){
a: (_|_){
Expand Down Expand Up @@ -622,8 +604,6 @@ diff old new
+ #Y: (_|_){
+ // [incomplete] small.p1.#Y: undefined field: port:
+ // ./in.cue:28:50
+ // small.p1.#X.port: cyclic reference to field port:
+ // ./in.cue:31:4
+ }
+ #X: (_|_){
+ // [incomplete] small.p1.#X.port: cyclic reference to field port:
Expand All @@ -641,7 +621,7 @@ diff old new
}
}
}
@@ -36,65 +37,69 @@
@@ -36,65 +35,61 @@
medium: (struct){
#userHostPort: (string){ "^(:(?P<port>\\d+))?$" }
p1: (struct){
Expand Down Expand Up @@ -675,8 +655,6 @@ diff old new
+ #Y: (_|_){
+ // [incomplete] medium.p1.#Y: undefined field: port:
+ // ./in.cue:58:50
+ // medium.p1.#X.port: cyclic reference to field port:
+ // ./in.cue:70:4
+ }
+ Y: (struct){
+ }
Expand All @@ -689,8 +667,6 @@ diff old new
+ #Y: (_|_){
+ // [incomplete] medium.p2.#Y: undefined field: port:
+ // ./in.cue:80:50
+ // medium.p2.#X.port: cyclic reference to field port:
+ // ./in.cue:86:4
+ }
+ #X: (_|_){
+ // [incomplete] medium.p2.#X.port: cyclic reference to field port:
Expand Down Expand Up @@ -724,8 +700,6 @@ diff old new
- // [cycle] medium.p4.#X: cycle with field Y.port:
- // ./in.cue:134:7
+ // ./in.cue:108:50
+ // medium.p3.#X.port: cyclic reference to field port:
+ // ./in.cue:114:4
+ }
+ #X: (_|_){
+ // [incomplete] medium.p3.#X.port: cyclic reference to field port:
Expand All @@ -740,9 +714,7 @@ diff old new
+ // ./in.cue:134:4
+ }
+ #Y: (_|_){
+ // [incomplete] medium.p4.#X.port: cyclic reference to field port:
+ // ./in.cue:134:4
+ // medium.p4.#Y: undefined field: port:
+ // [incomplete] medium.p4.#Y: undefined field: port:
+ // ./in.cue:142:50
}
}
Expand All @@ -763,7 +735,7 @@ diff old new
}
Y: (struct){
}
@@ -101,14 +106,14 @@
@@ -101,14 +96,14 @@
}
p6: (struct){
#X: (_|_){
Expand All @@ -786,7 +758,7 @@ diff old new
}
}
}
@@ -115,81 +120,91 @@
@@ -115,81 +110,83 @@
large: (struct){
#userHostPort: (string){ "^((?P<userinfo>[[:alnum:]]*)@)?(?P<host>[[:alnum:].]+)(:(?P<port>\\d+))?$" }
p1: (struct){
Expand Down Expand Up @@ -872,8 +844,6 @@ diff old new
+ X: (_|_){
+ // [incomplete] large.p1.X: undefined field: port:
+ // ./in.cue:199:33
+ // large.p1.#X.port: cyclic reference to field port:
+ // ./in.cue:211:4
+ }
+ #X: (_|_){
+ // [incomplete] large.p1.#X.port: cyclic reference to field port:
Expand All @@ -890,8 +860,6 @@ diff old new
+ X: (_|_){
+ // [incomplete] large.p2.X: undefined field: port:
+ // ./in.cue:235:33
+ // large.p2.#X.port: cyclic reference to field port:
+ // ./in.cue:252:4
+ }
+ Y: (struct){
+ userinfo: (string){ "user" }
Expand All @@ -912,8 +880,6 @@ diff old new
+ X: (_|_){
+ // [incomplete] large.p3.X: undefined field: port:
+ // ./in.cue:276:33
+ // large.p3.#X.port: cyclic reference to field port:
+ // ./in.cue:288:4
+ }
+ #X: (_|_){
+ // [incomplete] large.p3.#X.port: cyclic reference to field port:
Expand All @@ -934,8 +900,6 @@ diff old new
+ X: (_|_){
+ // [incomplete] large.p4.X: undefined field: port:
+ // ./in.cue:317:33
+ // large.p4.#X.port: cyclic reference to field port:
+ // ./in.cue:329:4
+ }
+ #X: (_|_){
+ // [incomplete] large.p4.#X.port: cyclic reference to field port:
Expand Down
29 changes: 10 additions & 19 deletions cue/testdata/eval/issue2550.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,29 @@ Result:
let _bar#1 = (_){ _ }
}
-- out/evalalpha --
Errors:
undefined field: missing:
./in.cue:4:8

Result:
(_|_){
// [incomplete] undefined field: missing:
// [eval] undefined field: missing:
// ./in.cue:4:8
foo: (_|_){
// [incomplete] undefined field: missing:
// ./in.cue:4:8
}
bar: (#struct){
}
let _bar#1 = (_|_){
// [incomplete] undefined field: missing:
// ./in.cue:4:8
}
let _bar#1 = (_){ _ }
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,13 +1,14 @@
-Errors:
-undefined field: missing:
- ./in.cue:4:8
-
-Result:
@@ -6,7 +6,10 @@
(_|_){
- // [eval] undefined field: missing:
+ // [incomplete] undefined field: missing:
// [eval] undefined field: missing:
// ./in.cue:4:8
- foo: (string){ string }
+ foo: (_|_){
Expand All @@ -76,11 +72,6 @@ diff old new
+ }
bar: (#struct){
}
- let _bar#1 = (_){ _ }
+ let _bar#1 = (_|_){
+ // [incomplete] undefined field: missing:
+ // ./in.cue:4:8
+ }
}
let _bar#1 = (_){ _ }
-- diff/todo/p2 --
Let seems to have misplaced error, even though it does not affect outcome.
2 changes: 2 additions & 0 deletions internal/core/adt/binop.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ func BinOp(c *OpContext, op Op, left, right Value) Value {
return &Bottom{
Code: IncompleteError,
Err: c.Newf(msg, left, op),
Node: c.vertex,
}
}
if right.Concreteness() > Concrete {
return &Bottom{
Code: IncompleteError,
Err: c.Newf(msg, right, op),
Node: c.vertex,
}
}

Expand Down
Loading

0 comments on commit fbcadd9

Please sign in to comment.