Skip to content
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

for errors out on solvable cycles #779

Closed
cueckoo opened this issue Jul 3, 2021 · 2 comments
Closed

for errors out on solvable cycles #779

cueckoo opened this issue Jul 3, 2021 · 2 comments

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

Originally opened by @Ereski in cuelang/cue#779

Current master (2c86835)

Similar to the previous issues I've opened, this time it's for that is having trouble with cycles:

X: Y.message

STATE: {
    for k, v in Y {
        if k != "message" {
            "\(k)": v
        }
    }
}

Y: STATE & {
    message: X
}

This is a simple stateful bidirectional projection expressed in CUE (STATE is saved and restored as needed). In one way, Y is forked into X and STATE. In the other way, X and STATE are joined into Y. Two usage examples are:

X: "test"

STATE: {
    code: 101
}

and

Y: {
    message: "test"
    code: 101
}

Both of which errors out with a cycle error. Even defining X, STATE, and Y all at the same time causes a cycle error.

@cueckoo cueckoo added the cycle label Jul 3, 2021
@cueckoo cueckoo added this to the v0.4.x milestone Jul 3, 2021
@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @mpvl in cuelang/cue#779 (comment)

Another interesting one. :)

The cycle here is detected here because the for comprehension iterators over the the very struct in which it embeds.

Arguably, of course, that should be okay as long as it does not add new fields that then should have been used during evaluation.

FTR, in v0.2 the cycle check did not work correctly and this construct would produce inaccurate results.

@mpvl
Copy link
Member

mpvl commented Feb 21, 2022

@Ereski We could probably break this cycle if we allow comprehensions that insert fields in structs that are used as a source that do not introduce any new fields.

@cueckoo cueckoo closed this as completed in f1daf4b Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants