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

sortfields does not sort some struct fields in cue eval when there are cyclic references #3622

Open
mvdan opened this issue Dec 11, 2024 · 0 comments

Comments

@mvdan
Copy link
Member

mvdan commented Dec 11, 2024

Note that this issue is related to #3621, as evalv3 runs into cyclic reference errors with the input below, where evalv2 does not. It's possible that that's causing CUE_DEBUG=sortfields to not work properly. However, if cue eval is producing some CUE output, I would expect all fields to be sorted, even if the output is not complete or contains errors such as missing references.

env CUE_DEBUG=sortfields

# With the old evaluator.
env CUE_EXPERIMENT=evalv3=0
exec cue eval

# With the new evaluator.
env CUE_EXPERIMENT=evalv3=1
exec cue eval

-- input.cue --
package p

resource: {
	outer: [Name=string]: name: Name
	if true {
		inner: inner2: {
			name:           "Employees"
			description:    "All employees"
			privacy:        "secret"
			create_default: false
		}
		outer: outer2: {
			bar: (inner.inner2.name)
		}
	}
}

As of 0e99c20:

> env CUE_DEBUG=sortfields
# With the old evaluator. (0.010s)
> env CUE_EXPERIMENT=evalv3=0
> exec cue eval
[stdout]
resource: {
    inner: {
        inner2: {
            create_default: false
            description:    "All employees"
            name:           "Employees"
            privacy:        "secret"
        }
    }
    outer: {
        outer2: {
            bar:  "Employees"
            name: "outer2"
        }
    }
}
# With the new evaluator. (0.030s)
> env CUE_EXPERIMENT=evalv3=1
> exec cue eval
[stdout]
resource: {
    outer: {
        [Name=string]: {
            name: Name
        }
    }
    if true {
        inner: {
            inner2: {
                name:           "Employees"
                description:    "All employees"
                privacy:        "secret"
                create_default: false
            }
        }
        outer: {
            outer2: {
                bar: inner.inner2.name
            }
        }
    }
}

The output is slightly different in general, which is fine - cue eval does not follow a strict behavior so there are differences between v2 and v3. However, inner2's fields are properly sorted on evalv2, wheras they are not sorted on evalv3.

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

1 participant