-
Notifications
You must be signed in to change notification settings - Fork 287
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
Introducing pattern constraint causes "cue export" to spin indefinitely #1940
Comments
Note that replacing unification with embedding also induces the same problem. That is, if I write the following—with the aforementioned pattern constraint in place—this problem still occurs: _#AWSTFOutput: {
#Output
// ...
} Likewise, an inline pattern constraint here induces the problem too: _#AWSTFOutput: {
[string]: #OutputValue
// ...
} |
Here's a shorter version of the above example that seems to exhibit the same problem:
|
Analysis: it seems that when there is a "cross product" of a disjunction with itself, the cycle detection allows progressing one level deeper, which has the effect of causing quite significant expansion with each "cross product". The issue seems to be that the cycle context is not chained when computing disjunction cross products. It also seems related to another problem where tracked references (for cycle detection) were inadvertently deleted. This would compound the issue. A fix for that has been sent out. |
This will fix the performance issue by detecting cycles on the earliest possible point, preventing the combinatorial computation in the first place: |
This is no longer necessary with the latest tweaks in the cycle detection algorithm. Also, it could cause a hang in some cases. Oddly, this seems to deepen some of the cycles. Unity shows no performance impact, though. This is related to, although not a full solution for, Issue #1940 Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: Iaeee44a7652fa1dbf2e52dc91a1f62e582bf93c6 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/543656 Reviewed-by: Roger Peppe <rogpeppe@gmail.com> Unity-Result: CUEcueckoo <cueckoo@cuelang.org> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest release?
Yes, both in version 0.4.3 and the tip as of today (ad253ed).
What did you do?
I wrote a few definitions as described in preceding discussion in the "language" channel of the "CUE" Slack workspace, involving a recursive definition as part of describing Terraform's JSON output format. Building up from there, I wrote definitions for types, values of any type, values of a particular type, and documents with fields bearing values of those types.
Most of this works fine, up until when I try to use a pattern constraint to define that general document schema, where each of the field must bear one of these values. When I try, the cue export command spins using 2.5 CPUs for as long as twenty minutes. That's the longest I've let it run so far before killing it.
I'll share the definitions that I've written so far, together with a small JSON file that shows input data against which I'd unify these definitions.
CUE definitions
Note the comment in the source that reads "THIS IS THE PROBLEM." If I uncomment the line after it to read as follows, cue export gets stuck:
The same problem arises if I write the following:
That is, I'd like to express that
_#AWSTFOutput
is a JSON document produced by terraform output -json with a particular set of output values, such that each field in the JSON object must bear a value that conforms to#OutputValue
.Relaxing that pattern constraint to the following allows cue export to proceed:
However, that fails to satisfy my goal of describing a valid JSON object, as these values could be of any type.
What did you expect to see?
cue export should emit the JSON document as it was, very quickly, without complaining about any schema violations.
What did you see instead?
cue export consumes several CPUs for as long as I'll allow it to run, while emitting no output.
The text was updated successfully, but these errors were encountered: