Skip to content

Commit

Permalink
cue: remove the hidden Value.Subsumes method
Browse files Browse the repository at this point in the history
It has been deprecated in favor of Value.Subsume, which takes options
and returns an error with details, since early 2020.

We can also remove subsume.Profile.Check, which was only used here,
as well as a TestX debug func which seems to have intended to use
the subsume.Profile.Value method, which returns a method.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I17bb4d5d9be7e88e4d5df1b3bb4e58c9ee31b81b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202285
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan committed Oct 10, 2024
1 parent d170b1c commit 80ddde3
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 86 deletions.
16 changes: 0 additions & 16 deletions cue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1839,22 +1839,6 @@ func (v Value) Subsume(w Value, opts ...Option) error {
return p.Value(ctx, v.v, w.v)
}

// Deprecated: use [Value.Subsume].
//
// Subsumes reports whether w is an instance of v.
//
// Without options, Subsumes checks whether v is a backwards compatible schema
// of w.
//
// By default, Subsumes tests whether two values are compatible
// Value v and w must be obtained from the same build.
// TODO: remove this requirement.
func (v hiddenValue) Subsumes(w Value) bool {
ctx := v.ctx()
p := subsume.Profile{Defaults: true}
return p.Check(ctx, v.v, w.v)
}

func allowed(ctx *adt.OpContext, parent, n *adt.Vertex) *adt.Bottom {
if !parent.IsClosedList() && !parent.IsClosedStruct() {
return nil
Expand Down
63 changes: 0 additions & 63 deletions cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2089,69 +2089,6 @@ func TestSubsume(t *testing.T) {
}
}

func TestSubsumes(t *testing.T) {
a := []string{"a"}
b := []string{"b"}
testCases := []struct {
value string
pathA []string
pathB []string
want bool
}{{
value: `4`,
want: true,
}, {
value: `a: string, b: "foo"`,
pathA: a,
pathB: b,
want: true,
}, {
value: `a: string, b: "foo"`,
pathA: b,
pathB: a,
want: false,
}, {
value: `a: {a: string, b: 4}, b: {a: "foo", b: 4}`,
pathA: a,
pathB: b,
want: true,
}, {
value: `a: [string, 4], b: ["foo", 4]`,
pathA: a,
pathB: b,
want: true,
}, {
value: `a: [...string], b: ["foo"]`,
pathA: a,
pathB: b,
want: true,
}, {
value: `a: [...int], b: ["foo"]`,
pathA: a,
pathB: b,
want: false,
}, {
value: `
a: { action: "run", command: [...string] }
b: { action: "run", command: ["echo", "hello"] }
`,
pathA: a,
pathB: b,
want: true,
}}
for _, tc := range testCases {
cuetdtest.FullMatrix.Run(t, tc.value, func(t *testing.T, m *cuetdtest.M) {
v := getValue(m, tc.value)
a := v.Lookup(tc.pathA...)
b := v.Lookup(tc.pathB...)
got := a.Subsumes(b)
if got != tc.want {
t.Errorf("got %v (%v); want %v (%v)", got, a, tc.want, b)
}
})
}
}

func TestUnify(t *testing.T) {
a := "a"
b := "b"
Expand Down
6 changes: 0 additions & 6 deletions internal/core/subsume/subsume.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ func (p *Profile) Value(ctx *adt.OpContext, a, b adt.Value) errors.Error {
return nil // ignore errors here even if there are some.
}

// Check reports whether b is an instance of a.
func (p *Profile) Check(ctx *adt.OpContext, a, b adt.Value) bool {
s := subsumer{ctx: ctx, Profile: *p}
return s.values(a, b)
}

func isBottom(x adt.Node) bool {
b, _ := x.(*adt.Bottom)
return b != nil
Expand Down
2 changes: 1 addition & 1 deletion internal/core/subsume/subsume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestX(t *testing.T) {
b := parse(t, ctx, lt)

p := Profile{Defaults: true}
err := p.Check(ctx, a, b)
err := p.Value(ctx, a, b)
t.Error(err)
}

Expand Down

0 comments on commit 80ddde3

Please sign in to comment.