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

eval: regression in closedness handling with disjunctions #3706

Open
myitcv opened this issue Jan 29, 2025 · 3 comments
Open

eval: regression in closedness handling with disjunctions #3706

myitcv opened this issue Jan 29, 2025 · 3 comments
Labels
evaluator evalv3 issues affecting only the evaluator version 3 NeedsInvestigation

Comments

@myitcv
Copy link
Member

myitcv commented Jan 29, 2025

What version of CUE are you using (cue version)?

$ cue version
cue version v0.0.0-20250128173939-870bfc2bb495

go version go1.23.2
      -buildmode exe
       -compiler gc
  DefaultGODEBUG asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
         GOARM64 v8.0
             vcs git
    vcs.revision 870bfc2bb495f05faed7c65ec51109b9eed1762c
        vcs.time 2025-01-28T17:39:39Z
    vcs.modified false
cue.lang.version v0.12.0

Does this issue reproduce with the latest release?

Yes

What did you do?

# evalv2
env CUE_EXPERIMENT=evalv3=0
exec cue vet -c -d '#site' schema.cue site.json

# evalv3
env CUE_EXPERIMENT=evalv3=1
exec cue vet -c -d '#site' schema.cue site.json

-- schema.cue --
package preprocessor

#site: {
	_kind: {
		kind!: string
	}

	#sanitiser:  _kind & (#patternSanitiser | #ellipsisSanitiser)
	#comparator: _kind & (#patternComparator | #unstableLineOrderComparator)

	#patternSanitiser: {
		kind:     "patternSanitiser"
		pattern?: string
	}

	#patternComparator: {
		kind:     "patternComparator"
		pattern?: string
	}

	#ellipsisSanitiser: {
		kind: "ellipsisSanitiser"
	}

	#unstableLineOrderComparator: {
		kind: "unstableLineOrderComparator"
	}

	sanitiser?:  #sanitiser
	comparator?: #comparator
}
-- site.json --
{
  "comparator": {
    "kind": "patternComparator",
    "pattern": "expr"
  },
  "sanitiser": {
    "kind": "patternSanitiser",
    "pattern": "expr"
  }
}

What did you expect to see?

Passing test.

What did you see instead?

# evalv2 (0.453s)
# evalv3 (0.451s)
> env CUE_EXPERIMENT=evalv3=1
> exec go run cuelang.org/go/cmd/cue vet -c -d '#site' schema.cue site.json
[stderr]
sanitiser: 2 errors in empty disjunction:
sanitiser.kind: conflicting values "ellipsisSanitiser" and "patternSanitiser":
    ./schema.cue:22:9
    ./site.json:7:13
sanitiser.pattern: field not allowed:
    ./site.json:8:5
exit status 1
[exit status 1]
FAIL: /tmp/testscript2499769875/repro.txtar/script.txtar:10: unexpected command failure

This bisects to 45e3256

@myitcv myitcv added evaluator evalv3 issues affecting only the evaluator version 3 NeedsInvestigation labels Jan 29, 2025
@mvdan
Copy link
Member

mvdan commented Jan 29, 2025

Here is the same testscript but slightly simplified:

# With the old evaluator.
env CUE_EXPERIMENT=evalv3=0
exec cue vet -c -d '#site' input.cue data.json

# With the new evaluator.
env CUE_EXPERIMENT=evalv3=1
exec cue vet -c -d '#site' input.cue data.json

-- input.cue --
package preprocessor

#site: {
	_kind: kind!: string

	#foo: _kind & (#foo1 | #foo2)
	#bar: _kind & (#bar1 | #bar2)

	#foo1: {
		kind:       "foo1"
		foo1field?: string
	}
	#foo2: {
		kind: "foo2"
	}

	#bar1: {
		kind:       "bar1"
		bar1field?: string
	}
	#bar2: {
		kind: "bar2"
	}

	foo?: #foo
	bar?: #bar
}
-- data.json --
{
  "foo": {
    "kind": "foo1",
    "foo1field": "expr"
  },
  "bar": {
    "kind": "bar1",
    "bar1field": "expr"
  }
}

As of 870bfc2:

# With the old evaluator. (0.011s)
> env CUE_EXPERIMENT=evalv3=0
> exec cue vet -c -d '#site' input.cue data.json
# With the new evaluator. (0.039s)
> env CUE_EXPERIMENT=evalv3=1
> exec cue vet -c -d '#site' input.cue data.json
[stderr]
bar: 2 errors in empty disjunction:
bar.bar1field: field not allowed:
    ./data.json:8:5
bar.kind: conflicting values "bar2" and "bar1":
    ./data.json:7:13
    ./input.cue:22:9
bar.bar1field: field not allowed:
    ./input.cue:7:17
    ./data.json:8:5
[exit status 1]

And here's a slight alteration which, as far as I can tell, should be equivalent. But, surprisingly enough, it fixes evalv3... and breaks evalv2!

# With the old evaluator.
env CUE_EXPERIMENT=evalv3=0
exec cue vet -c -d '#site' input.cue data.json

# With the new evaluator.
env CUE_EXPERIMENT=evalv3=1
exec cue vet -c -d '#site' input.cue data.json

-- input.cue --
package preprocessor

#site: {
	#kind: {
		kind!: string
		...
	}

	foo?: #kind & (#foo1 | #foo2)
	bar?: #kind & (#bar1 | #bar2)

	#foo1: {
		kind:       "foo1"
		foo1field?: string
	}
	#foo2: kind: "foo2"

	#bar1: {
		kind:       "bar1"
		bar1field?: string
	}
	#bar2: kind: "bar2"
}
-- data.json --
{
  "foo": {
    "kind": "foo1",
    "foo1field": "expr"
  },
  "bar": {
    "kind": "bar1",
    "pattern2": "expr"
  }
}
# With the old evaluator. (0.010s)
> env CUE_EXPERIMENT=evalv3=0
> exec cue vet -c -d '#site' input.cue data.json
[stderr]
bar: 2 errors in empty disjunction:
bar.kind: conflicting values "bar2" and "bar1":
    ./data.json:7:13
    ./input.cue:10:25
    ./input.cue:22:15
bar.pattern2: field not allowed:
    ./data.json:8:5
    ./input.cue:3:8
    ./input.cue:6:3
    ./input.cue:10:8
    ./input.cue:10:17
    ./input.cue:18:9
[exit status 1]
FAIL: repro-evalv3.txtar:3: unexpected command failure
# With the new evaluator. (0.036s)
> env CUE_EXPERIMENT=evalv3=1
> exec cue vet -c -d '#site' input.cue data.json

@rogpeppe
Copy link
Member

rogpeppe commented Jan 29, 2025

Here's a simpler repo. Looks like the reference to the inner #site._kind field is closing it up (adding a ... fixes the issue).

# With the old evaluator.
env CUE_EXPERIMENT=evalv3=0
exec cue vet -c -d '#site' input.cue data.json

# With the new evaluator.
env CUE_EXPERIMENT=evalv3=1
exec cue vet -c -d '#site' input.cue data.json

-- input.cue --
package preprocessor

#site: {
	_kind: kind!: string

	bar?: _kind & {
		kind!:       "bar1"
		bar1field?: string
	}
}
-- data.json --
{
  "bar": {
    "kind": "bar1",
    "bar1field": "expr"
  }
}

Output:

# With the old evaluator. (0.013s)
# With the new evaluator. (0.048s)
> env CUE_EXPERIMENT=evalv3=1
> exec cue vet -c -d '#site' input.cue data.json
[stderr]
bar.bar1field: field not allowed:
    ./data.json:4:5
    ./input.cue:8:3
[exit status 1]
FAIL: /tmp/x.txtar:7: unexpected command failure

@myitcv
Copy link
Member Author

myitcv commented Feb 5, 2025

FYI this is blocking the preprocessor (used to build the cuelang.org site) from migrating to use evalv3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
evaluator evalv3 issues affecting only the evaluator version 3 NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

3 participants