-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/trim: implement trim for evalv3
Trim now works on the result of evaluation for evalv3. This new implementation only works for evalv3, and does not alter any code paths for evalv2 and the existing trim. The new implementation addresses all known bugs with trim. Signed-off-by: Matthew Sackman <[email protected]> Change-Id: If814b5f66ce2ea3ce37ddcbec71eb38f1bc97216 Dispatch-Trailer: {"type":"trybot","CL":1208658,"patchset":5,"ref":"refs/changes/58/1208658/5","targetBranch":"master"}
- Loading branch information
1 parent
64abb36
commit 9938e1c
Showing
78 changed files
with
3,372 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
exec cue mod init | ||
|
||
# -- evalv3 -- | ||
env CUE_EXPERIMENT=evalv3=1 | ||
exec cue trim -o - ./... | ||
cmp stdout expect-stdout-v3 | ||
|
||
# -- evalv2 -- | ||
env CUE_EXPERIMENT=evalv3=0 | ||
exec cue trim -o - ./... | ||
cmp stdout expect-stdout-v2 | ||
|
||
-- a.cue -- | ||
package p | ||
|
||
x: y: int | ||
x: z: int | ||
-- b/b.cue -- | ||
package p | ||
|
||
x: y: 7 | ||
-- c/c.cue -- | ||
package p | ||
|
||
x: z: 6 | ||
-- expect-stdout-v3 -- | ||
package p | ||
|
||
x: y: int | ||
x: z: int | ||
package p | ||
|
||
x: y: int | ||
x: z: int | ||
package p | ||
|
||
x: y: 7 | ||
package p | ||
|
||
x: y: int | ||
x: z: int | ||
package p | ||
|
||
x: z: 6 | ||
-- expect-stdout-v2 -- | ||
package p | ||
|
||
x: y: int | ||
x: z: int | ||
package p | ||
|
||
x: y: int | ||
x: z: int | ||
package p | ||
|
||
x: y: 7 | ||
package p | ||
|
||
x: y: int | ||
x: z: int | ||
package p | ||
|
||
x: z: 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
TODO. This should get simplified in the same way as 6, but | ||
doesn't. Possible bug in evaluator. | ||
|
||
-- a.cue -- | ||
<10 | ||
7 | ||
-- out/trim -- | ||
== a.cue | ||
<10 | ||
7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Similar to 9, but with list instead of struct. Note the simplification | ||
of the pattern too. | ||
|
||
See also 60. | ||
|
||
-- a.cue -- | ||
d: [ | ||
{name: "jack", age: 5}, | ||
{name: "gill", age: >4}, | ||
{name: "hilbert", age: int}, | ||
] | ||
d: [...{name: string, age: 5, age: number}] | ||
-- out/trim-v3 -- | ||
== a.cue | ||
d: [ | ||
{name: "jack"}, | ||
{name: "gill"}, | ||
{name: "hilbert"}, | ||
] | ||
d: [...{name: string, age: 5}] | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -4,4 +4,4 @@ | ||
{name: "gill"}, | ||
{name: "hilbert"}, | ||
] | ||
-d: [...{name: string, age: 5, age: number}] | ||
+d: [...{name: string, age: 5}] | ||
-- out/trim -- | ||
== a.cue | ||
d: [ | ||
{name: "jack"}, | ||
{name: "gill"}, | ||
{name: "hilbert"}, | ||
] | ||
d: [...{name: string, age: 5, age: number}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Explicit unification of structs can lead to simplification. | ||
Contrast with 4. | ||
|
||
-- a.cue -- | ||
x: {a: bool, b: "hi"} & {a: true, b: string} | ||
-- out/trim-v3 -- | ||
== a.cue | ||
x: {b: "hi"} & {a: true} | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -1,2 +1,2 @@ | ||
== a.cue | ||
-x: {a: bool, b: "hi"} & {a: true, b: string} | ||
+x: {b: "hi"} & {a: true} | ||
-- out/trim -- | ||
== a.cue | ||
x: {a: bool, b: "hi"} & {a: true, b: string} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
A variant of 11, with fields slightly rearranged. We do not currently | ||
simplify explicit unification where one side is top. | ||
|
||
-- a.cue -- | ||
x: {a: bool, b: string} & {a: true, b: "hi"} | ||
-- out/trim-v3 -- | ||
== a.cue | ||
x: _ & {a: true, b: "hi"} | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -1,2 +1,2 @@ | ||
== a.cue | ||
-x: {a: bool, b: string} & {a: true, b: "hi"} | ||
+x: _ & {a: true, b: "hi"} | ||
-- out/trim -- | ||
== a.cue | ||
x: {a: bool, b: string} & {a: true, b: "hi"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
A variant of 12, to ensure the ellipsis does not prevent | ||
simplification of the struct to top. | ||
|
||
-- a.cue -- | ||
x: {a: bool, b: string, ...} & {a: true, b: "hi"} | ||
-- out/trim-v3 -- | ||
== a.cue | ||
x: _ & {a: true, b: "hi"} | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -1,2 +1,2 @@ | ||
== a.cue | ||
-x: {a: bool, b: string, ...} & {a: true, b: "hi"} | ||
+x: _ & {a: true, b: "hi"} | ||
-- out/trim -- | ||
== a.cue | ||
x: {a: bool, b: string, ...} & {a: true, b: "hi"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Further variation on 11: make sure patterns are kept, even if they're | ||
not used. | ||
|
||
-- a.cue -- | ||
x: {a: bool, b: string, [>"b"]: int} & {a: true, b: "hi"} | ||
-- out/trim-v3 -- | ||
== a.cue | ||
x: {[>"b"]: int} & {a: true, b: "hi"} | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -1,2 +1,2 @@ | ||
== a.cue | ||
-x: {a: bool, b: string, [>"b"]: int} & {a: true, b: "hi"} | ||
+x: {[>"b"]: int} & {a: true, b: "hi"} | ||
-- out/trim -- | ||
== a.cue | ||
x: {a: bool, b: string, [>"b"]: int} & {a: true, b: "hi"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Similar to 11, but with lists: explicit unification of lists can lead | ||
to simplification. | ||
|
||
-- a.cue -- | ||
x: [int, int, int] & [9, 8, 7] | ||
-- out/trim-v3 -- | ||
== a.cue | ||
x: [_, _, _] & [9, 8, 7] | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -1,2 +1,2 @@ | ||
== a.cue | ||
-x: [int, int, int] & [9, 8, 7] | ||
+x: [_, _, _] & [9, 8, 7] | ||
-- out/trim -- | ||
== a.cue | ||
x: [int, int, int] & [9, 8, 7] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Like 11, but using a let comprehension. For trim, the let | ||
comprehension is treated the same as a field. I.e. in this case, it's | ||
no different to s: {a: bool, b: "hi"}, and so no simplification can | ||
occur. | ||
|
||
-- a.cue -- | ||
let s = {a: bool, b: "hi"} | ||
x: s & {a: true, b: string} | ||
-- out/trim-v3 -- | ||
== a.cue | ||
let s = {a: bool, b: "hi"} | ||
x: s & {a: true} | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -1,3 +1,3 @@ | ||
== a.cue | ||
let s = {a: bool, b: "hi"} | ||
-x: s & {a: true, b: string} | ||
+x: s & {a: true} | ||
-- out/trim -- | ||
== a.cue | ||
let s = {a: bool, b: "hi"} | ||
x: s & {a: true, b: string} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Variant of 9, but with more complex field expressions. As before, we | ||
must ignore the conjuncts from the pattern when simplifying the | ||
fields, so that we don't accidentally remove the entire field. | ||
|
||
-- a.cue -- | ||
d: { | ||
jack: {age: 5, age: 5} | ||
gill: {age: 5} | ||
hilbert: {age: 5} & {age: 5} | ||
[string]: {age: 5} | ||
} | ||
-- out/trim-v3 -- | ||
== a.cue | ||
d: { | ||
jack: _ | ||
gill: _ | ||
hilbert: _ & _ | ||
[string]: {age: 5} | ||
} | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -1,7 +1,7 @@ | ||
== a.cue | ||
d: { | ||
- jack: {} | ||
- gill: {} | ||
- hilbert: {} & {} | ||
+ jack: _ | ||
+ gill: _ | ||
+ hilbert: _ & _ | ||
[string]: {age: 5} | ||
} | ||
-- out/trim -- | ||
== a.cue | ||
d: { | ||
jack: {} | ||
gill: {} | ||
hilbert: {} & {} | ||
[string]: {age: 5} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Make sure we keep patterns for lists too. | ||
-- a.cue -- | ||
x: [...string] | ||
-- out/trim -- | ||
== a.cue | ||
x: [...string] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Make sure we keep *all* of a pattern, not just its root. | ||
-- a.cue -- | ||
x: [string]: a: b: c: d: _ | ||
-- out/trim -- | ||
== a.cue | ||
x: [string]: a: b: c: d: _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
TODO: This should get simplified in the same way as 3, but | ||
doesn't. Possible bug in evaluator. | ||
|
||
-- a.cue -- | ||
string | ||
"hi" | ||
-- out/trim -- | ||
== a.cue | ||
string | ||
"hi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Simplifications can occur within definitions, but we must be sure to | ||
keep the ellipsis. | ||
|
||
-- a.cue -- | ||
let #x = {a: int, b: {c: 5, c: >4, ...}} | ||
y: #x & {a: 4, b: {c: int}} | ||
z: #x & {a: 4, b: {c: int, d: "hi"}} | ||
-- out/trim-v3 -- | ||
== a.cue | ||
let #x = {a: int, b: {c: 5, ...}} | ||
y: #x & {a: 4} | ||
z: #x & {a: 4, b: {d: "hi"}} | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -1,4 +1,4 @@ | ||
== a.cue | ||
-let #x = {a: int, b: {c: 5, c: >4, ...}} | ||
-y: #x & {a: 4, b: {c: int}} | ||
-z: #x & {a: 4, b: {c: int, d: "hi"}} | ||
+let #x = {a: int, b: {c: 5, ...}} | ||
+y: #x & {a: 4} | ||
+z: #x & {a: 4, b: {d: "hi"}} | ||
-- out/trim -- | ||
== a.cue | ||
let #x = {a: int, b: {c: 5, c: >4, ...}} | ||
y: #x & {a: 4, b: {c: int}} | ||
z: #x & {a: 4, b: {c: int, d: "hi"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
We do no simplification of arguments to function calls. This includes | ||
close, which appears in the AST as a normal CallExpr. | ||
|
||
-- a.cue -- | ||
y: close({a: int, b: {c: string}}) & {a: 4, b: {c: "hi"}} | ||
z: close({a: int, b: {c: string}} & {a: 4, b: {c: "hi"}}) | ||
-- out/trim -- | ||
== a.cue | ||
y: close({a: int, b: {c: string}}) & {a: 4, b: {c: "hi"}} | ||
z: close({a: int, b: {c: string}} & {a: 4, b: {c: "hi"}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
As with 21, make sure we don't do simplification of arguments to | ||
function calls - we've not just special-cased "close". | ||
|
||
-- a.cue -- | ||
let x = close | ||
y: x({a: 5}) | ||
z: y & {a: int} | ||
-- out/trim-v3 -- | ||
== a.cue | ||
let x = close | ||
y: x({a: 5}) | ||
z: y & _ | ||
-- diff/-out/trim-v3<==>+out/trim -- | ||
diff old new | ||
--- old | ||
+++ new | ||
@@ -1,4 +1,4 @@ | ||
== a.cue | ||
let x = close | ||
y: x({a: 5}) | ||
-z: y & {a: int} | ||
+z: y & _ | ||
-- out/trim -- | ||
== a.cue | ||
let x = close | ||
y: x({a: 5}) | ||
z: y & {a: int} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- a.cue -- | ||
x: (2 + 3) & (1 + 4) | ||
-- out/trim -- | ||
== a.cue | ||
x: (2 + 3) & (1 + 4) |
Oops, something went wrong.