Skip to content

Commit 40a6bcd

Browse files
committed
cue: remove dead code
Change-Id: Ie7700e845d50cf0a6ae54d77ee41f597f992fbc8 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6861 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 304b02e commit 40a6bcd

File tree

5 files changed

+2
-244
lines changed

5 files changed

+2
-244
lines changed

cue/builtin.go

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -171,50 +171,6 @@ func mustParseConstBuiltin(ctx *context, name, val string) adt.Expr {
171171

172172
}
173173

174-
var lenBuiltin = &builtin{
175-
Name: "len",
176-
Params: []kind{stringKind | bytesKind | listKind | structKind},
177-
Result: intKind,
178-
Func: func(c *callCtxt) {
179-
v := c.value(0)
180-
switch k := v.IncompleteKind(); k {
181-
case StructKind:
182-
s, err := v.structValData(c.ctx)
183-
if err != nil {
184-
c.ret = err
185-
break
186-
}
187-
c.ret = s.Len()
188-
case ListKind:
189-
i := 0
190-
iter, err := v.List()
191-
if err != nil {
192-
c.ret = err
193-
break
194-
}
195-
for ; iter.Next(); i++ {
196-
}
197-
c.ret = i
198-
case BytesKind:
199-
b, err := v.Bytes()
200-
if err != nil {
201-
c.ret = err
202-
break
203-
}
204-
c.ret = len(b)
205-
case StringKind:
206-
s, err := v.String()
207-
if err != nil {
208-
c.ret = err
209-
break
210-
}
211-
c.ret = len(s)
212-
default:
213-
c.ret = c.ctx.opCtx.Newf("invalid argument type %v", k)
214-
}
215-
},
216-
}
217-
218174
func pos(n adt.Node) (p token.Pos) {
219175
if n == nil {
220176
return
@@ -226,71 +182,6 @@ func pos(n adt.Node) (p token.Pos) {
226182
return src.Pos()
227183
}
228184

229-
var closeBuiltin = &builtin{
230-
Name: "close",
231-
Params: []kind{structKind},
232-
Result: structKind,
233-
Func: func(c *callCtxt) {
234-
s, ok := c.args[0].(*adt.Vertex)
235-
if !ok {
236-
c.ret = errors.Newf(pos(c.args[0]), "struct argument must be concrete")
237-
return
238-
}
239-
if s.IsClosed(c.ctx.opCtx) {
240-
c.ret = s
241-
} else {
242-
v := *s
243-
v.Closed = nil // TODO: set dedicated Closer.
244-
c.ret = &v
245-
}
246-
},
247-
}
248-
249-
var andBuiltin = &builtin{
250-
Name: "and",
251-
Params: []kind{listKind},
252-
Result: intKind,
253-
Func: func(c *callCtxt) {
254-
iter := c.iter(0)
255-
if !iter.Next() {
256-
c.ret = &top{}
257-
return
258-
}
259-
var u adt.Expr = iter.Value().v
260-
for iter.Next() {
261-
u = &adt.BinaryExpr{Op: adt.AndOp, X: u, Y: iter.Value().v}
262-
}
263-
c.ret = u
264-
},
265-
}
266-
267-
var orBuiltin = &builtin{
268-
Name: "or",
269-
Params: []kind{listKind},
270-
Result: intKind,
271-
Func: func(c *callCtxt) {
272-
iter := c.iter(0)
273-
d := []adt.Disjunct{}
274-
for iter.Next() {
275-
d = append(d, adt.Disjunct{iter.Value().v, false})
276-
}
277-
c.ret = &adt.DisjunctionExpr{nil, d, false}
278-
if len(d) == 0 {
279-
// TODO(manifest): This should not be unconditionally incomplete,
280-
// but it requires results from comprehensions and all to have
281-
// some special status. Maybe this can be solved by having results
282-
// of list comprehensions be open if they result from iterating over
283-
// an open list or struct. This would actually be exactly what
284-
// that means. The error here could then only add an incomplete
285-
// status if the source is open.
286-
c.ret = &adt.Bottom{
287-
Code: adt.IncompleteError,
288-
Err: errors.Newf(c.Pos(), "empty list in call to or"),
289-
}
290-
}
291-
},
292-
}
293-
294185
func (x *builtin) name(ctx *context) string {
295186
if x.pkg == 0 {
296187
return x.Name
@@ -430,10 +321,6 @@ func initBuiltins(pkgs map[string]*builtinPkg) {
430321
}
431322
}
432323

433-
func getBuiltinShorthandPkg(ctx *context, shorthand string) *structLit {
434-
return getBuiltinPkg(ctx, "-/"+shorthand)
435-
}
436-
437324
func getBuiltinPkg(ctx *context, path string) *structLit {
438325
p, ok := builtins[path]
439326
if !ok {

cue/errors.go

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
package cue
1616

1717
import (
18-
"fmt"
19-
"reflect"
20-
2118
"cuelang.org/go/cue/errors"
2219
"cuelang.org/go/cue/token"
2320
"cuelang.org/go/internal/core/adt"
@@ -77,29 +74,10 @@ func (e *valueError) Path() (a []string) {
7774
type errCode = adt.ErrorCode
7875

7976
const (
80-
codeNone errCode = 0
81-
codeFatal = adt.EvalError
82-
codeNotExist = adt.NotExistError
83-
codeTypeError = adt.EvalError
84-
codeIncomplete = adt.IncompleteError
85-
codeUser = adt.UserError
86-
codeCycle = adt.CycleError
77+
codeNotExist = adt.NotExistError
78+
codeIncomplete = adt.IncompleteError
8779
)
8880

89-
func isIncomplete(v value) bool {
90-
if err, ok := v.(*bottom); ok {
91-
return err.Code == codeIncomplete || err.Code == codeCycle
92-
}
93-
return false
94-
}
95-
96-
func isLiteralBottom(v value) bool {
97-
if err, ok := v.(*bottom); ok {
98-
return err.Code == codeUser
99-
}
100-
return false
101-
}
102-
10381
var errNotExists = &adt.Bottom{
10482
Code: codeNotExist,
10583
Err: errors.Newf(token.NoPos, "undefined value"),
@@ -148,35 +126,3 @@ outer:
148126
}
149127
return e
150128
}
151-
152-
func fixArg(idx *index, x interface{}) interface{} {
153-
switch x.(type) {
154-
case uint, int, string:
155-
return x
156-
case value:
157-
return x
158-
}
159-
t := reflect.TypeOf(x)
160-
// Store all non-ptr types as is, as they cannot change.
161-
if k := t.Kind(); k == reflect.String || k <= reflect.Complex128 {
162-
return x
163-
}
164-
return fmt.Sprint(x)
165-
}
166-
167-
func isBottom(x adt.Node) bool {
168-
if x == nil {
169-
return true
170-
}
171-
b, _ := x.(*adt.Bottom)
172-
return b != nil
173-
}
174-
175-
func firstBottom(v ...value) *bottom {
176-
for _, b := range v {
177-
if isBottom(b) {
178-
return b.(*bottom)
179-
}
180-
}
181-
return nil
182-
}

cue/op.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,6 @@ const (
6161
InterpolationOp = adt.InterpolationOp
6262
)
6363

64-
var opToOp = map[op]Op{
65-
opUnify: AndOp,
66-
// TODO(eval): opUnifyUnchecked is not the same as opUnify and should have its own
67-
// category, if needed. More likely opUnifyUnchecked, should be
68-
// represented as a separate embedding method.
69-
opUnifyUnchecked: AndOp,
70-
opDisjunction: OrOp,
71-
opLand: BooleanAndOp,
72-
opLor: BooleanOrOp,
73-
opEql: EqualOp,
74-
opNot: NotOp,
75-
opNeq: NotEqualOp,
76-
opLss: LessThanOp,
77-
opLeq: LessThanEqualOp,
78-
opGtr: GreaterThanOp,
79-
opGeq: GreaterThanEqualOp,
80-
opMat: RegexMatchOp,
81-
opNMat: NotRegexMatchOp,
82-
opAdd: AddOp,
83-
opSub: SubtractOp,
84-
opMul: MultiplyOp,
85-
opQuo: FloatQuotientOp,
86-
opIQuo: IntQuotientOp,
87-
opIRem: IntRemainderOp,
88-
opIDiv: IntDivideOp,
89-
opIMod: IntModuloOp,
90-
}
91-
92-
func opIn(op op, anyOf ...op) bool {
93-
for _, o := range anyOf {
94-
if o == op {
95-
return true
96-
}
97-
}
98-
return false
99-
}
100-
10164
// isCmp reports whether an op is a comparator.
10265
func (op op) isCmp() bool {
10366
return opEql <= op && op <= opGeq

cue/resolve_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package cue
1717
import (
1818
"strings"
1919
"testing"
20-
21-
"cuelang.org/go/internal/core/adt"
2220
)
2321

2422
func TestX(t *testing.T) {
@@ -30,33 +28,3 @@ func TestX(t *testing.T) {
3028
t.Skip()
3129
}
3230
}
33-
34-
// var traceOn = flag.Bool("debug", false, "enable tracing")
35-
36-
// func compileFileWithErrors(t *testing.T, body string) (*context, *structLit, error) {
37-
// t.Helper()
38-
// ctx, inst, err := compileInstance(t, body)
39-
// return ctx, inst.root, err
40-
// }
41-
42-
// func compileFile(t *testing.T, body string) (*context, *structLit) {
43-
// t.Helper()
44-
// ctx, inst, errs := compileInstance(t, body)
45-
// if errs != nil {
46-
// t.Fatal(errs)
47-
// }
48-
// return ctx, inst.root
49-
// }
50-
51-
func compileInstance(t *testing.T, body string) (*context, *Instance, error) {
52-
var r Runtime
53-
inst, err := r.Compile("test", body)
54-
55-
if err != nil {
56-
x := newInstance(newIndex(sharedIndex), nil, &adt.Vertex{})
57-
ctx := x.newContext()
58-
return ctx, x, err
59-
}
60-
61-
return r.index().newContext(), inst, nil
62-
}

cue/types_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,9 +2950,3 @@ func compactRawStr(v Value) string {
29502950
cfg := &debug.Config{Compact: true, Raw: true}
29512951
return debug.NodeString(ctx.opCtx, v.v, cfg)
29522952
}
2953-
2954-
func compactValueStr(v Value) string {
2955-
ctx := v.ctx()
2956-
cfg := &debug.Config{Compact: true}
2957-
return debug.NodeString(ctx.opCtx, v.v, cfg)
2958-
}

0 commit comments

Comments
 (0)