Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/eval: rewrite of closedness algorithm
Browse files Browse the repository at this point in the history
Spec did not change, but simplified algorithm.
Fixes many bugs.

This also adds a new compaction algorithm. This will be
enabled in a follow-up CL.

Also:
- "not allowed" failure is now registered with child. This
allows multiple failures to be recorded naturally, and
also retains more of the correct structure. But more
importantly, it prevents descending into the substructure,
preventing spurious errors.
- Position information has changed slightly, mostly for
the better.

This introduces a regression on trim. See tools/trim/trim_test.go

Fixes #271
Fixes #320
Fixes #370
Fixes #471
Fixes #476
Fixes #483
Fixes #490
Fixes #491
Fixes #493
Fixes #494
Fixes #496
Fixes #497

Change-Id: Ia90ebbbafd8cfc768188d33f109a2e33a4cee922
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7002
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Sep 12, 2020
1 parent 3d863fc commit 62528c3
Show file tree
Hide file tree
Showing 45 changed files with 2,393 additions and 956 deletions.
20 changes: 20 additions & 0 deletions cmd/cue/cmd/testdata/script/cmd_closed.txt
@@ -0,0 +1,20 @@
cue cmd run

-- task.cue --
package ci

// Must have
// - indirection through definition
// - unification of two list elements
// - one of those elements must be _
// - Must use merge and unify tool file

workflows: #Workflow

#Workflow: ["a"] & [_]

-- task_tool.cue --
package ci

command: run: {
}
38 changes: 38 additions & 0 deletions cmd/cue/cmd/testdata/script/issue476.txt
@@ -0,0 +1,38 @@
cue cmd dostuffloop
cmp stdout expect-stdout

-- x_tool.cue --
package x

import (
"tool/cli"
"encoding/yaml"
)

command: dostuff: {
write: cli.Print & {
text: "yaml is " + yaml.Marshal(w)
}
}

command: dostuffloop: {
for w in l {
write: cli.Print & {
text: "yaml is " + yaml.Marshal(w)
}
}
}
-- y.cue --
package x

#Workflow: {
#: "working-directory": string
}

l: [w]
w: #Workflow & {
}

-- expect-stdout --
yaml is {}

1 change: 1 addition & 0 deletions cmd/cue/cmd/testdata/script/trim.txt
Expand Up @@ -44,6 +44,7 @@ foo: multipath: {
}

t: u: {
x: 5
}
}

Expand Down
57 changes: 57 additions & 0 deletions cue/testdata/builtins/closed.txtar
@@ -0,0 +1,57 @@
-- in.cue --
a: close({
a: b: int
})

b: a & { x: int } // err
c: a & { a: c: int } // okay (non-recursive close)

-- out/eval --
Errors:
b: field `x` not allowed:
./in.cue:1:10
./in.cue:5:10

Result:
(_|_){
// [eval]
a: (#struct){
a: (#struct){
b: (int){ int }
}
}
b: (_|_){
// [eval]
a: (#struct){
b: (int){ int }
}
x: (_|_){
// [eval] b: field `x` not allowed:
// ./in.cue:1:10
// ./in.cue:5:10
}
}
c: (#struct){
a: (#struct){
b: (int){ int }
c: (int){ int }
}
}
}
-- out/compile --
--- in.cue
{
a: close({
a: {
b: int
}
})
b: (〈0;a〉 & {
x: int
})
c: (〈0;a〉 & {
a: {
c: int
}
})
}
44 changes: 44 additions & 0 deletions cue/testdata/builtins/issue490.txtar
@@ -0,0 +1,44 @@
-- test.cue --
A: close({
a: 1
b: 2
})

B: A & {
c: 3
}
-- out/eval --
Errors:
B: field `c` not allowed:
./test.cue:1:10
./test.cue:7:2

Result:
(_|_){
// [eval]
A: (#struct){
a: (int){ 1 }
b: (int){ 2 }
}
B: (_|_){
// [eval]
a: (int){ 1 }
b: (int){ 2 }
c: (_|_){
// [eval] B: field `c` not allowed:
// ./test.cue:1:10
// ./test.cue:7:2
}
}
}
-- out/compile --
--- test.cue
{
A: close({
a: 1
b: 2
})
B: (〈0;A〉 & {
c: 3
})
}
30 changes: 17 additions & 13 deletions cue/testdata/definitions/026_combined_definitions.txtar
Expand Up @@ -119,13 +119,13 @@ d1: #D1 & {
-- out/eval --
Errors:
#D4.env: field `b` not allowed:
./in.cue:26:7
./in.cue:27:7
./in.cue:30:1
./in.cue:30:6
d1.env: field `c` not allowed:
./in.cue:2:1
./in.cue:3:7
./in.cue:4:7
./in.cue:9:5
./in.cue:9:17

Result:
Expand All @@ -144,14 +144,16 @@ Result:
d1: (_|_){
// [eval]
env: (_|_){
// [eval] d1.env: field `c` not allowed:
// ./in.cue:2:1
// ./in.cue:3:7
// ./in.cue:4:7
// ./in.cue:9:17
// [eval]
a: (string){ "A" }
b: (string){ "B" }
c: (string){ "C" }
c: (_|_){
// [eval] d1.env: field `c` not allowed:
// ./in.cue:3:7
// ./in.cue:4:7
// ./in.cue:9:5
// ./in.cue:9:17
}
}
#def: (#struct){
a: (string){ "A" }
Expand All @@ -171,12 +173,14 @@ Result:
#D4: (_|_){
// [eval]
env: (_|_){
// [eval] #D4.env: field `b` not allowed:
// ./in.cue:27:7
// ./in.cue:30:1
// ./in.cue:30:6
// [eval]
a: (int){ int }
b: (int){ int }
b: (_|_){
// [eval] #D4.env: field `b` not allowed:
// ./in.cue:26:7
// ./in.cue:27:7
// ./in.cue:30:6
}
}
}
#DC: (#struct){
Expand Down
18 changes: 11 additions & 7 deletions cue/testdata/definitions/032_definitions_with_embedding.txtar
Expand Up @@ -82,9 +82,10 @@
-- out/eval --
Errors:
#e1.a: field `d` not allowed:
./in.cue:1:1
./in.cue:2:5
./in.cue:6:2
./in.cue:7:5
./in.cue:12:6
./in.cue:12:15

Result:
Expand All @@ -105,14 +106,17 @@ Result:
#e1: (_|_){
// [eval]
a: (_|_){
// [eval] #e1.a: field `d` not allowed:
// ./in.cue:1:1
// ./in.cue:2:5
// ./in.cue:7:5
// ./in.cue:12:15
// [eval]
b: (int){ int }
c: (int){ int }
d: (int){ 4 }
d: (_|_){
// [eval] #e1.a: field `d` not allowed:
// ./in.cue:2:5
// ./in.cue:6:2
// ./in.cue:7:5
// ./in.cue:12:6
// ./in.cue:12:15
}
}
b: (int){ 3 }
}
Expand Down
20 changes: 11 additions & 9 deletions cue/testdata/definitions/033_Issue_#153.txtar
Expand Up @@ -63,24 +63,26 @@ Junk: {
-- out/eval --
Errors:
listOfCloseds.0: field `b` not allowed:
./in.cue:5:1
./in.cue:2:21
./in.cue:5:10
./in.cue:14:18
./in.cue:15:20
./in.cue:13:1
./in.cue:16:4

Result:
(_|_){
// [eval]
listOfCloseds: (_|_){
// [eval]
0: (_|_){
// [eval] listOfCloseds.0: field `b` not allowed:
// ./in.cue:5:1
// ./in.cue:5:10
// ./in.cue:14:18
// ./in.cue:15:20
// [eval]
a: (int){ |(*(int){ 0 }, (int){ int }) }
b: (int){ 2 }
b: (_|_){
// [eval] listOfCloseds.0: field `b` not allowed:
// ./in.cue:2:21
// ./in.cue:5:10
// ./in.cue:13:1
// ./in.cue:16:4
}
}
}
Foo: (struct){
Expand Down
34 changes: 18 additions & 16 deletions cue/testdata/definitions/037_closing_with_comprehensions.txtar
Expand Up @@ -106,14 +106,13 @@ a: _|_ // field "f3" not allowed in closed struct
Errors:
#D: cannot mix bulk optional fields with dynamic fields, embeddings, or comprehensions within the same struct
#E: field `f3` not allowed:
./in.cue:1:1
./in.cue:1:5
./in.cue:27:10
./in.cue:28:24
./in.cue:27:5
./in.cue:29:3
a: field `f3` not allowed:
./in.cue:1:1
./in.cue:1:5
./in.cue:4:10
./in.cue:4:5
./in.cue:4:11

Result:
(_|_){
Expand All @@ -133,22 +132,25 @@ Result:
f1: (int){ int }
}
#E: (_|_){
// [eval] #E: field `f3` not allowed:
// ./in.cue:1:1
// ./in.cue:1:5
// ./in.cue:27:10
// ./in.cue:28:24
// [eval]
f1: (int){ int }
f2: (int){ int }
f3: (int){ int }
f3: (_|_){
// [eval] #E: field `f3` not allowed:
// ./in.cue:1:5
// ./in.cue:27:5
// ./in.cue:29:3
}
}
a: (_|_){
// [eval] a: field `f3` not allowed:
// ./in.cue:1:1
// ./in.cue:1:5
// ./in.cue:4:10
// [eval]
f1: (int){ int }
f2: (int){ int }
f3: (int){ int }
f3: (_|_){
// [eval] a: field `f3` not allowed:
// ./in.cue:1:5
// ./in.cue:4:5
// ./in.cue:4:11
}
}
}

0 comments on commit 62528c3

Please sign in to comment.