cue: remove MakeValue

This is now less obviously hidden in Encode.

Change-Id: Ic3905f2f7b5b48dfed7b95e79ad9f0556ad96aff
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9424
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
diff --git a/cue/context.go b/cue/context.go
index f9726f3..1ff8163 100644
--- a/cue/context.go
+++ b/cue/context.go
@@ -212,6 +212,10 @@
 // The returned Value will represent an error, accessible through Err, if any
 // error occurred.
 func (c *Context) Encode(x interface{}, option ...EncodeOption) Value {
+	switch v := x.(type) {
+	case adt.Value:
+		return newValueRoot(c.index(), c.ctx(), v)
+	}
 	var options encodeOptions
 	options.process(option)
 
diff --git a/cue/types.go b/cue/types.go
index 81af9a3..86ac88e 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -632,17 +632,6 @@
 	return makeValue(v.idx, n)
 }
 
-// MakeValue converts an adt.Value and given OpContext to a Value. The context
-// must be directly or indirectly obtained from the NewRuntime defined in this
-// package and it will panic if this is not the case.
-//
-// For internal use only.
-func MakeValue(ctx *adt.OpContext, v adt.Value) Value {
-	index := ctx.Impl().(*runtime.Runtime)
-
-	return newValueRoot(index, newContext(index), v)
-}
-
 func makeValue(idx *runtime.Runtime, v *adt.Vertex) Value {
 	if v.Status() == 0 || v.BaseValue == nil {
 		panic(fmt.Sprintf("not properly initialized (state: %v, value: %T)",
diff --git a/internal/core/dep/dep_test.go b/internal/core/dep/dep_test.go
index 449279b..c1c0330 100644
--- a/internal/core/dep/dep_test.go
+++ b/internal/core/dep/dep_test.go
@@ -72,7 +72,7 @@
 
 			t.Run(tc.name, func(sub *testing.T) {
 				tc.fn(ctxt, n, func(d dep.Dependency) error {
-					str := cue.MakeValue(ctxt, d.Node).Path().String()
+					str := value.Make(ctxt, d.Node).Path().String()
 					if i := d.Import(); i != nil {
 						path := i.ImportPath.StringValue(ctxt)
 						str = fmt.Sprintf("%q.%s", path, str)
@@ -114,7 +114,7 @@
 	deps := []string{}
 
 	_ = dep.VisitFields(ctxt, n, func(d dep.Dependency) error {
-		str := cue.MakeValue(ctxt, d.Node).Path().String()
+		str := value.Make(ctxt, d.Node).Path().String()
 		if i := d.Import(); i != nil {
 			path := i.ImportPath.StringValue(ctxt)
 			str = fmt.Sprintf("%q.%s", path, str)
diff --git a/internal/value/value.go b/internal/value/value.go
index f5a4662..a91343b 100644
--- a/internal/value/value.go
+++ b/internal/value/value.go
@@ -39,6 +39,11 @@
 }
 
 // TODO:
+// Make wraps cue.MakeValue.
+func Make(ctx *adt.OpContext, v adt.Value) cue.Value {
+	return (*cue.Context)(ctx.Impl().(*runtime.Runtime)).Encode(v)
+}
+
 //
 // func Make(r *runtime.Runtime, v *adt.Vertex) cue.Value {
 // 	return cue.Value{}
diff --git a/pkg/internal/context.go b/pkg/internal/context.go
index 9aa29ae..a8ff4fd 100644
--- a/pkg/internal/context.go
+++ b/pkg/internal/context.go
@@ -21,6 +21,7 @@
 	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal/core/adt"
+	"cuelang.org/go/internal/value"
 	"github.com/cockroachdb/apd/v2"
 )
 
@@ -48,7 +49,7 @@
 }
 
 func (c *CallCtxt) Value(i int) cue.Value {
-	v := cue.MakeValue(c.ctx, c.args[i])
+	v := value.Make(c.ctx, c.args[i])
 	// TODO: remove default
 	// v, _ = v.Default()
 	if !v.IsConcrete() {
@@ -58,7 +59,7 @@
 }
 
 func (c *CallCtxt) Struct(i int) *cue.Struct {
-	v := cue.MakeValue(c.ctx, c.args[i])
+	v := value.Make(c.ctx, c.args[i])
 	s, err := v.Struct()
 	if err != nil {
 		c.invalidArgType(c.args[i], i, "struct", err)
@@ -76,7 +77,7 @@
 
 func (c *CallCtxt) intValue(i, bits int, typ string) int64 {
 	arg := c.args[i]
-	x := cue.MakeValue(c.ctx, arg)
+	x := value.Make(c.ctx, arg)
 	n, err := x.Int(nil)
 	if err != nil {
 		c.invalidArgType(arg, i, typ, err)
@@ -98,7 +99,7 @@
 func (c *CallCtxt) Uint64(i int) uint64 { return uint64(c.uintValue(i, 64, "uint64")) }
 
 func (c *CallCtxt) uintValue(i, bits int, typ string) uint64 {
-	x := cue.MakeValue(c.ctx, c.args[i])
+	x := value.Make(c.ctx, c.args[i])
 	n, err := x.Int(nil)
 	if err != nil || n.Sign() < 0 {
 		c.invalidArgType(c.args[i], i, typ, err)
@@ -113,7 +114,7 @@
 }
 
 func (c *CallCtxt) Decimal(i int) *apd.Decimal {
-	x := cue.MakeValue(c.ctx, c.args[i])
+	x := value.Make(c.ctx, c.args[i])
 	if _, err := x.MantExp(nil); err != nil {
 		c.invalidArgType(c.args[i], i, "Decimal", err)
 		return nil
@@ -122,7 +123,7 @@
 }
 
 func (c *CallCtxt) Float64(i int) float64 {
-	x := cue.MakeValue(c.ctx, c.args[i])
+	x := value.Make(c.ctx, c.args[i])
 	res, err := x.Float64()
 	if err != nil {
 		c.invalidArgType(c.args[i], i, "float64", err)
@@ -132,7 +133,7 @@
 }
 
 func (c *CallCtxt) BigInt(i int) *big.Int {
-	x := cue.MakeValue(c.ctx, c.args[i])
+	x := value.Make(c.ctx, c.args[i])
 	n, err := x.Int(nil)
 	if err != nil {
 		c.invalidArgType(c.args[i], i, "int", err)
@@ -144,7 +145,7 @@
 var ten = big.NewInt(10)
 
 func (c *CallCtxt) BigFloat(i int) *big.Float {
-	x := cue.MakeValue(c.ctx, c.args[i])
+	x := value.Make(c.ctx, c.args[i])
 	var mant big.Int
 	exp, err := x.MantExp(&mant)
 	if err != nil {
@@ -163,7 +164,7 @@
 
 func (c *CallCtxt) String(i int) string {
 	// TODO: use Evaluate instead.
-	x := cue.MakeValue(c.ctx, c.args[i])
+	x := value.Make(c.ctx, c.args[i])
 	v, err := x.String()
 	if err != nil {
 		c.invalidArgType(c.args[i], i, "string", err)
@@ -173,7 +174,7 @@
 }
 
 func (c *CallCtxt) Bytes(i int) []byte {
-	x := cue.MakeValue(c.ctx, c.args[i])
+	x := value.Make(c.ctx, c.args[i])
 	v, err := x.Bytes()
 	if err != nil {
 		c.invalidArgType(c.args[i], i, "bytes", err)
@@ -183,7 +184,7 @@
 }
 
 func (c *CallCtxt) Reader(i int) io.Reader {
-	x := cue.MakeValue(c.ctx, c.args[i])
+	x := value.Make(c.ctx, c.args[i])
 	// TODO: optimize for string and bytes cases
 	r, err := x.Reader()
 	if err != nil {
@@ -194,7 +195,7 @@
 }
 
 func (c *CallCtxt) Bool(i int) bool {
-	x := cue.MakeValue(c.ctx, c.args[i])
+	x := value.Make(c.ctx, c.args[i])
 	b, err := x.Bool()
 	if err != nil {
 		c.invalidArgType(c.args[i], i, "bool", err)
@@ -205,7 +206,7 @@
 
 func (c *CallCtxt) List(i int) (a []cue.Value) {
 	arg := c.args[i]
-	x := cue.MakeValue(c.ctx, arg)
+	x := value.Make(c.ctx, arg)
 	v, err := x.List()
 	if err != nil {
 		c.invalidArgType(c.args[i], i, "list", err)
@@ -219,7 +220,7 @@
 
 func (c *CallCtxt) Iter(i int) (a cue.Iterator) {
 	arg := c.args[i]
-	x := cue.MakeValue(c.ctx, arg)
+	x := value.Make(c.ctx, arg)
 	v, err := x.List()
 	if err != nil {
 		c.invalidArgType(c.args[i], i, "list", err)
diff --git a/tools/flow/run.go b/tools/flow/run.go
index 91336b1..bf61786 100644
--- a/tools/flow/run.go
+++ b/tools/flow/run.go
@@ -26,7 +26,6 @@
 // future tasks may be long running, as discussed above.
 
 import (
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/internal/core/adt"
 	"cuelang.org/go/internal/core/eval"
@@ -153,7 +152,7 @@
 	v := &adt.Vertex{Conjuncts: c.conjuncts}
 	v.Finalize(c.opCtx)
 
-	c.inst = cue.MakeValue(c.opCtx, v)
+	c.inst = value.Make(c.opCtx, v)
 	c.valueSeqNum = c.conjunctSeq
 	return true
 }
diff --git a/tools/flow/tasks.go b/tools/flow/tasks.go
index a09e680..519a386 100644
--- a/tools/flow/tasks.go
+++ b/tools/flow/tasks.go
@@ -192,7 +192,7 @@
 		}
 
 		if !d.IsRoot() {
-			v := cue.MakeValue(c.opCtx, n)
+			v := value.Make(c.opCtx, n)
 
 			if t := c.getTask(nil, v); t != nil {
 				return t
@@ -225,7 +225,7 @@
 		depTask := c.findImpliedTask(d)
 		if depTask != nil {
 			if depTask != cycleMarker {
-				v := cue.MakeValue(c.opCtx, d.Node)
+				v := value.Make(c.opCtx, d.Node)
 				t.addDep(v.Path().String(), depTask)
 			}
 			return nil
@@ -245,7 +245,7 @@
 }
 
 func (c *Controller) inRoot(n *adt.Vertex) bool {
-	path := cue.MakeValue(c.opCtx, n).Path().Selectors()
+	path := value.Make(c.opCtx, n).Path().Selectors()
 	root := c.cfg.Root.Selectors()
 	if len(path) < len(root) {
 		return false