This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/core/eval: tweak to disjunction
Except for a small bug, that is also fixed in this CL, the new evaluator implemented disjunctions according to spec before this CL. The old evaluator, however, didn't... It turns out the semantics of the spec is somewhat awkward, though theoretically nicer. It seems like we do need to change the definition somewhat to make it less awkward, or at least come up with a good workaround before adopting the spec. This CL introduces a hack that mimic the old behavior for scalar values, where this is the most relevant. Change-Id: If58d27b4f4e9aa1a5ae8316cb774cf6b26c70796 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6655 Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
- Loading branch information
Showing
4 changed files
with
145 additions
and
22 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
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,68 @@ | ||
It turns out the semantics of the spec is somewhat awkward, | ||
though theoretically nicer. It seems like we do need to change | ||
the definition somewhat to make it less awkward, or at least | ||
come up with a good workaround before adopting the spec. | ||
|
||
We have introduce a small hack to mimic the old behavior for scalar | ||
values. | ||
|
||
Note that the value of p below is now 2 (default), but should | ||
be the non-concrete 2 | int. | ||
|
||
Proof: | ||
p: *((*1 | int) & 2) | int // substitution of both P conjuncts in p | ||
p: *(*_|_ | 2) | int // U1: distribute conjuncts | ||
p: *_|_ | 2 | int // M2: remove mark | ||
p: 2 | int // value after removing default. | ||
|
||
-- in.cue -- | ||
|
||
Q: *1 | int | ||
q: *Q | int // 1 as expected | ||
|
||
P: *1 | int | ||
P: 2 | ||
p: *P | int // now 2, but should be (2 | int), according to the spec: | ||
|
||
|
||
s1: #Size & { min: 5 } | ||
|
||
#Size : { | ||
max: >min | *min | ||
res: uint | * 0 | ||
min: >res | *(1 + res) | ||
} | ||
-- out/eval -- | ||
(struct){ | ||
Q: (int){ |(*(int){ 1 }, (int){ int }) } | ||
q: (int){ |(*(int){ 1 }, (int){ int }) } | ||
P: (int){ 2 } | ||
p: (int){ |(*(int){ 2 }, (int){ int }) } | ||
s1: (#struct){ | ||
max: (number){ |(*(int){ 5 }, (number){ >5 }) } | ||
res: (int){ 0 } | ||
min: (int){ 5 } | ||
} | ||
#Size: (#struct){ | ||
max: (number){ |(*(int){ 1 }, (number){ >0 }, (number){ >1 }) } | ||
res: (int){ 0 } | ||
min: (number){ |(*(int){ 1 }, (number){ >0 }) } | ||
} | ||
} | ||
-- out/compile -- | ||
--- in.cue | ||
{ | ||
Q: (*1|int) | ||
q: (*〈0;Q〉|int) | ||
P: (*1|int) | ||
P: 2 | ||
p: (*〈0;P〉|int) | ||
s1: (〈0;#Size〉 & { | ||
min: 5 | ||
}) | ||
#Size: { | ||
max: (>〈0;min〉|*〈0;min〉) | ||
res: (&(int, >=0)|*0) | ||
min: (>〈0;res〉|*(1 + 〈0;res〉)) | ||
} | ||
} |
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