Skip to content

Commit e7a696c

Browse files
committed
designs/language: simplify validator logic
Change-Id: I74bc93f8e514b62e6165ec27355312c73476f73c Signed-off-by: Marcel van Lohuizen <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/proposal/+/1208901 TryBot-Result: CUEcueckoo <[email protected]>
1 parent 2aa0589 commit e7a696c

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
# Remove some Validator Rewriting
3+
4+
## Objective
5+
6+
To improve the predictability and consistency of CUE’s validator behavior by disallowing the unification of two non-concrete values into a concrete value. This eliminates inconsistencies in bound simplifications and simplifies reasoning about constraint reductions.
7+
8+
## Background
9+
10+
CUE currently allows reductions of some constraints into concrete values. This behavior, while convenient in some cases, introduces inconsistencies and unpredictability in constraint resolution.
11+
12+
For example:
13+
14+
```cue
15+
int & >=1 && <2
16+
```
17+
18+
can be reduced to:
19+
20+
```cue
21+
1
22+
```
23+
24+
Even though this is a straightforward case, it may still be surprising to users.
25+
26+
### Example of problematic case
27+
28+
There are also less straightforward cases.
29+
30+
```cue
31+
a: *1 | int
32+
a: <max
33+
max: int
34+
```
35+
36+
Results in:
37+
38+
```cue
39+
min: (*1 | int) & <max
40+
max: int
41+
```
42+
43+
Since `max` is not a concrete value, `<max` remains unresolved, preventing a concrete resolution of `min`.
44+
45+
The following case, however, demonstrates some possibly undesirable simplifications:
46+
```cue
47+
min: *1 | int
48+
min: <max
49+
max: >min
50+
```
51+
52+
In this case, it simplifies perhaps unexpectedly to
53+
```cue
54+
min: 1 // default taken
55+
max: >1
56+
```
57+
58+
CUE simplifies bounds in some cases. For instance, it rewrites `<= (<3)` to `<3`
59+
to `<3` resulting in a concrete bound, even though the argument to the bound
60+
was not concrete.
61+
62+
In this case, CUE simplifies `< (>min)` to `number`, which unifies with both disjuncts, giving the perhaps somewhat surprising result.
63+
64+
So here we saw that resolutions can differ more than expected based son some small change, where the result depends on whether bound simplification is implemented and how accurate this implementation is.
65+
66+
### Interaction with other (upcoming) proposals
67+
68+
We intend to make the use of `==` legal for comparing CUE values of different types. This opens up the possibility of having structured map keys, a principled approach to associative lists, as well as allowing `==` as a validator for concrete values.
69+
70+
The use of `==` as a unary operator has many applications. However, it is also an obvious candidate for the kind of simplification we are proposing to eliminate. For instance, `== 3` could trivially be simplified to `3`.
71+
72+
This proposal removes the inconsistencies that would result from such applying implicit simplifications in some cases, but not in others.
73+
74+
75+
## Proposal
76+
77+
* Disallow unification of two non-concrete values into a concrete value. For instance: `>=1 & <2 & int` should not simplify to `1`.
78+
79+
* Disallow the simplification of non-concrete validators. For instance, `<=(<3)` should not simplify to `<3`, but rather be an (incomplete) error.
80+
81+
For clarity, we will keep allowing simplifications of the unification of two concrete validators, like `<3 & <5` to `<3`.
82+
83+
84+
## Design Details
85+
86+
The implementation of this proposal will mostly consist of deleting or disabling swats of code in the internal packages `adt` and `export`.
87+
88+
Note that we can still safely keep the simplification of the unification of two concrete validators to non-concrete values, like `<3 & <5` to `<3`, as this will not alter semantics in any way by removing relationships.
89+
90+
91+
### Backward Compatibility Concerns
92+
93+
The resulting change may lead to CUE configurations to not resolve where they previously would. In some cases this may expose bugs in the configuration, in other a desired simplification effect may be lost.
94+
95+
An initial investigation on Unity show zero changes as a result of this proposal. We could still provide a backwards compatibility mode, but would disable this by default immediately on first rollout.
96+
97+
### Performance Considerations
98+
99+
Not having to simplify bounds might lead to slightly improved performance. However, there is a possibility that the lack of resulting elimination might expand the search space. Either way, we expect the impact to be minimal.
100+
101+
102+
## Alternatives Considered
103+
104+
### 1. Implementing Comprehensive Bound Simplifications
105+
- Would require full coverage of all possible simplifications.
106+
- Extremely complex and still may not guarantee consistency.
107+
108+
### 2. Leaving Current Behavior Unchanged
109+
- Continues existing inconsistencies.
110+
- Forces users to manually work around unpredictable behavior.
111+
112+
The proposed approach (removing non-concrete simplifications) offers the best balance between predictability, maintainability, and usability.
113+
114+

0 commit comments

Comments
 (0)