-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
evaluator: incorrect behaviour when choosing defaults #3296
Comments
So, I think we have this situation, following the details of https://cuelang.org/docs/reference/spec/#default-values
but I think this step isn't happening. I.e. we don't seem to be tracking that The result is that we pass into the
whereas we should be attempting |
My hunch is that the following happens. Some time after evaluation starts, we realise can't make any more "progress". At that point, we have the following facts (I leave out the
At this point, my intuition is that what we should do is choose a default for Instead what I think currently happens is that we "erase" the reference to
Then the default for
At which point we can evaluate the original
This reduces down to:
without us even needing to revert to choosing a default for Even if something else is happening here, I think the lack of spec clarity with respect to when defaults are chosen and when references are "erased" is a problem. Here is an interesting follow-up example on the sequencing of default selection:
In this case we should again get an error as the result, but we would choose defaults for
and not be able to make any further progress. Because of the mutual references, neither default selection orders before the other, so we choose defaults for both simultaneously. At which point we know:
Now we can evaluate the
and hence error. |
Here's another example, maybe related, which had a similar effect, but only with the old evaluator:
With the old evaluator
which similarly fails to validate if vetted along with the original. With Maybe the original example in this issue should also be a cycle error? |
For me, this is the key problem: it is not clear (to me?) what If the latter option is chosen, note that in general, if |
... but clearly, if
FWIW my understanding is that this is (or should be) the case.
If In general if I see a reference, ISTM that it should always refer to the final value of the thing referred to. Thus I believe that the original example should be an error of some kind (whether conflict or cycle I'm not quite sure). |
Ah yes, sorry - too sleepy this morning and I'm leaving out the
With the exception of references to definitions, yes? |
No. Definitions are special only in that they recursively close their value on use of the definition, i.e. a reference to it. Otherwise, all fields (regardless of definition or not, hidden or not) unify in the same way, and a reference to a field is to the resulting/ultimate constraints "gathered" by that field. I think one of the confusing points with this issue as I mentioned in #3296 (comment) is that it appears that a "copy" of |
Yep, after much discussion and thought, I'm happy I'm in a less confused state wrt definitions etc. |
Defaults are not picked by taking a reference. Moreover, terms within a marked default that themselves are disjunctions have their defaults erased. The spec is quite explicit about this, although it could use more examples. Binary operators resolve a references to a scalar, so in this case the reference to So |
This is definitely not the case. The |
Not to properly respond to any of the points above, rather just note down an observation based on my reading of the thread: namely that if I see:
there are at least two possible "interpretations" for the reader:
Per Marcel, the spec and implementation is currently adhering to 1. My observation is that because of these two "interpretations" for the reader, then we at least have a visual ambiguity as to what it means to write As such, I'm wondering if we need to tease apart these two situations with different syntax/other. I leave this very much as an incomplete thought/comment... mainly to not forget where I got to so that I can come back to it later. |
I had a good exchange with @rogpeppe that ended up touching on the topics raised in my previous comment. Specifically the ambiguity of the following with respect to the original intent of the user:
In that conversation I noted that the following "sketch" would seem to fix the ambiguity, by making it it explicit what is meant by the user:
See #943 (comment) for an explanation of the hypothesised @rogpeppe also brought up the suggestion that a
|
FWIW I'm not sure it would be quite the same. For a start, I don't think that For example:
At least with the semantics I'm supposing for |
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
What did you expect to see?
A passing test (for some variation perhaps of the error messages).
What did you see instead?
The output of
b: 1
cannot be correct given thata: 5
, andb
is constrained such thatb: a | *4
.To confirm: the exact same behaviour is seen with
CUE_EXPERIMENT=evalv3
, i.e. the bug exists in both old and new evaluator implementations.Another observation: there is nowhere in the spec where we can refer to try and reason about what the behaviour should be here.
The text was updated successfully, but these errors were encountered: