Skip to content

Commit 1dcd350

Browse files
NoamTDmvdan
authored andcommitted
cuego: remove deprecated cue.Instance usage
*cue.Instance is deprecated and being replaced by cue.Value. This CL replaces the usage of a *cue.Instance by the equivalent cue.Context method. Updates #2480. Signed-off-by: Noam Dolovich <[email protected]> Change-Id: Idb1c4a3dab4144fe62bcb1f58deb926fb46082e0 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194691 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 690add3 commit 1dcd350

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

cuego/cuego.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (c *Context) Constrain(x interface{}, constraints string) error {
140140
return err
141141
}
142142

143-
v := instance.Eval(expr)
143+
v := runtime.BuildExpr(expr)
144144
if v.Err() != nil {
145145
return err
146146
}
@@ -158,19 +158,10 @@ func (c *Context) Constrain(x interface{}, constraints string) error {
158158
}
159159

160160
var (
161-
mutex sync.Mutex
162-
instance *cue.Instance
163-
runtime = cuecontext.New()
161+
mutex sync.Mutex
162+
runtime = cuecontext.New()
164163
)
165164

166-
func init() {
167-
var err error
168-
instance, err = value.ConvertToRuntime(runtime).Compile("<cuego>", "{}")
169-
if err != nil {
170-
panic(err)
171-
}
172-
}
173-
174165
// fromGoValue converts a Go value to CUE
175166
func fromGoValue(x interface{}, nilIsNull bool) (v cue.Value, err error) {
176167
// TODO: remove the need to have a lock here. We could use a new index (new

cuego/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
// A Complete will implicitly validate a struct.
5555
package cuego // import "cuelang.org/go/cuego"
5656

57-
// The first goal of this packages is to get the semantics right. After that,
57+
// The first goal of this package is to get the semantics right. After that,
5858
// there are a lot of performance gains to be made:
5959
// - cache the type info extracted during value (as opposed to type) conversion
6060
// - remove the usage of mutex for value conversions

0 commit comments

Comments
 (0)