all: switch to using cue port

NOTE: this will break the build. The next CL will fix it. Merging
the two CLs introduces too much noice though.

Change-Id: Ica115283924926ede8ee7c4b3265d5d98838bdae
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6657
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/add.go b/cmd/cue/cmd/add.go
index d13035c..812e642 100644
--- a/cmd/cue/cmd/add.go
+++ b/cmd/cue/cmd/add.go
@@ -27,12 +27,12 @@
 
 	"github.com/spf13/cobra"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/build"
 	"cuelang.org/go/cue/format"
 	"cuelang.org/go/cue/load"
 	"cuelang.org/go/cue/parser"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 func newAddCmd(c *Command) *cobra.Command {
diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go
index 2121d11..c63e2b5 100644
--- a/cmd/cue/cmd/common.go
+++ b/cmd/cue/cmd/common.go
@@ -25,7 +25,6 @@
 	"golang.org/x/text/language"
 	"golang.org/x/text/message"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/build"
 	"cuelang.org/go/cue/errors"
@@ -35,6 +34,7 @@
 	"cuelang.org/go/internal"
 	"cuelang.org/go/internal/encoding"
 	"cuelang.org/go/internal/filetypes"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Disallow
@@ -223,7 +223,7 @@
 		if inst.Err != nil {
 			return &streamingIterator{e: inst.Err}
 		}
-		i.r = internal.GetRuntime(inst).(*cue.Runtime)
+		i.r = internal.GetRuntimeNew(inst).(*cue.Runtime)
 		if b.schema == nil {
 			i.base = inst.Value()
 		} else {
diff --git a/cmd/cue/cmd/custom.go b/cmd/cue/cmd/custom.go
index 9a6976c..7bd85f0 100644
--- a/cmd/cue/cmd/custom.go
+++ b/cmd/cue/cmd/custom.go
@@ -28,9 +28,9 @@
 	"github.com/spf13/cobra"
 	"golang.org/x/sync/errgroup"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 	itask "cuelang.org/go/internal/task"
 	"cuelang.org/go/internal/walk"
 	_ "cuelang.org/go/pkg/tool/cli" // Register tasks
diff --git a/cmd/cue/cmd/eval.go b/cmd/cue/cmd/eval.go
index 8d94aa8..bcbf383 100644
--- a/cmd/cue/cmd/eval.go
+++ b/cmd/cue/cmd/eval.go
@@ -19,12 +19,12 @@
 
 	"github.com/spf13/cobra"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/format"
 	"cuelang.org/go/internal"
 	"cuelang.org/go/internal/encoding"
 	"cuelang.org/go/internal/filetypes"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // newEvalCmd creates a new eval command
diff --git a/cmd/cue/cmd/orphans.go b/cmd/cue/cmd/orphans.go
index de54d92..eb5ca75 100644
--- a/cmd/cue/cmd/orphans.go
+++ b/cmd/cue/cmd/orphans.go
@@ -20,7 +20,6 @@
 	"regexp"
 	"strconv"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/ast/astutil"
 	"cuelang.org/go/cue/build"
@@ -29,6 +28,7 @@
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal"
 	"cuelang.org/go/internal/encoding"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // This file contains logic for placing orphan files within a CUE namespace.
diff --git a/cmd/cue/cmd/tags.go b/cmd/cue/cmd/tags.go
index 00912ef..5d4beec 100644
--- a/cmd/cue/cmd/tags.go
+++ b/cmd/cue/cmd/tags.go
@@ -17,13 +17,13 @@
 import (
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/build"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal"
 	"cuelang.org/go/internal/cli"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 func decorateInstances(cmd *Command, tags []string, a []*build.Instance) {
diff --git a/cmd/cue/cmd/vet.go b/cmd/cue/cmd/vet.go
index deb623d..8020055 100644
--- a/cmd/cue/cmd/vet.go
+++ b/cmd/cue/cmd/vet.go
@@ -18,8 +18,8 @@
 	"github.com/spf13/cobra"
 	"golang.org/x/text/message"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/errors"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 const vetDoc = `vet validates CUE and other data files
diff --git a/cue/ast/astutil/file_test.go b/cue/ast/astutil/file_test.go
index a6aeb59..773e93e 100644
--- a/cue/ast/astutil/file_test.go
+++ b/cue/ast/astutil/file_test.go
@@ -18,11 +18,11 @@
 	"strings"
 	"testing"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/ast/astutil"
 	"cuelang.org/go/cue/format"
 	"cuelang.org/go/cue/token"
+	"cuelang.org/go/internal/legacy/cue"
 	"github.com/google/go-cmp/cmp"
 )
 
diff --git a/cue/build.go b/cue/build.go
index 9f86daf..d7849c9 100644
--- a/cue/build.go
+++ b/cue/build.go
@@ -38,7 +38,7 @@
 }
 
 func init() {
-	internal.GetRuntime = func(instance interface{}) interface{} {
+	internal.GetRuntimeOld = func(instance interface{}) interface{} {
 		switch x := instance.(type) {
 		case Value:
 			return &Runtime{idx: x.idx}
@@ -51,7 +51,7 @@
 		}
 	}
 
-	internal.CheckAndForkRuntime = func(runtime, value interface{}) interface{} {
+	internal.CheckAndForkRuntimeOld = func(runtime, value interface{}) interface{} {
 		r := runtime.(*Runtime)
 		idx := value.(Value).ctx().index
 		if idx != r.idx {
diff --git a/cue/builtins.go b/cue/builtins.go
index 290ab79..7581fda 100644
--- a/cue/builtins.go
+++ b/cue/builtins.go
@@ -612,7 +612,7 @@
 						if !json.Valid(b) {
 							return false, fmt.Errorf("json: invalid JSON")
 						}
-						r := internal.GetRuntime(v).(*Runtime)
+						r := internal.GetRuntimeOld(v).(*Runtime)
 						inst, err := r.Compile("json.Validate", b)
 						if err != nil {
 							return false, err
@@ -709,7 +709,7 @@
 						if err != nil {
 							return false, err
 						}
-						r := internal.GetRuntime(v).(*Runtime)
+						r := internal.GetRuntimeOld(v).(*Runtime)
 						for {
 							expr, err := d.Decode()
 							if err != nil {
@@ -748,7 +748,7 @@
 						if err != nil {
 							return false, err
 						}
-						r := internal.GetRuntime(v).(*Runtime)
+						r := internal.GetRuntimeOld(v).(*Runtime)
 						for {
 							expr, err := d.Decode()
 							if err != nil {
diff --git a/cue/load/loader_test.go b/cue/load/loader_test.go
index f3c4ec0..a77936c 100644
--- a/cue/load/loader_test.go
+++ b/cue/load/loader_test.go
@@ -26,8 +26,8 @@
 
 	"github.com/kylelemons/godebug/diff"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/format"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/str"
 )
 
diff --git a/cuego/cuego.go b/cuego/cuego.go
index f2460a3..d666fe7 100644
--- a/cuego/cuego.go
+++ b/cuego/cuego.go
@@ -19,9 +19,9 @@
 	"reflect"
 	"sync"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/parser"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // DefaultContext is the shared context used with top-level functions.
diff --git a/encoding/gocode/generator.go b/encoding/gocode/generator.go
index b5f4476..eef0216 100644
--- a/encoding/gocode/generator.go
+++ b/encoding/gocode/generator.go
@@ -24,9 +24,9 @@
 
 	"golang.org/x/tools/go/packages"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Config defines options for generation Go code.
@@ -159,7 +159,7 @@
 		g.decl(iter.Label(), iter.Value())
 	}
 
-	r := internal.GetRuntime(inst).(*cue.Runtime)
+	r := internal.GetRuntimeNew(inst).(*cue.Runtime)
 	b, err = r.Marshal(inst)
 	g.addErr(err)
 
diff --git a/encoding/gocode/generator_test.go b/encoding/gocode/generator_test.go
index 85780cc..e639db0 100644
--- a/encoding/gocode/generator_test.go
+++ b/encoding/gocode/generator_test.go
@@ -25,9 +25,9 @@
 
 	"github.com/kylelemons/godebug/diff"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/load"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 var update = flag.Bool("update", false, "update test files")
diff --git a/encoding/gocode/gocodec/codec.go b/encoding/gocode/gocodec/codec.go
index bd4b083..268b509 100644
--- a/encoding/gocode/gocodec/codec.go
+++ b/encoding/gocode/gocodec/codec.go
@@ -23,8 +23,8 @@
 import (
 	"sync"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Config has no options yet, but is defined for future extensibility.
@@ -177,5 +177,5 @@
 }
 
 func checkAndForkRuntime(r *cue.Runtime, v cue.Value) *cue.Runtime {
-	return internal.CheckAndForkRuntime(r, v).(*cue.Runtime)
+	return internal.CheckAndForkRuntimeNew(r, v).(*cue.Runtime)
 }
diff --git a/encoding/gocode/gocodec/codec_test.go b/encoding/gocode/gocodec/codec_test.go
index 731747d..712580a 100644
--- a/encoding/gocode/gocodec/codec_test.go
+++ b/encoding/gocode/gocodec/codec_test.go
@@ -22,7 +22,7 @@
 	"github.com/google/go-cmp/cmp"
 	"github.com/kr/pretty"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 type Sum struct {
diff --git a/encoding/gocode/templates.go b/encoding/gocode/templates.go
index 22fb940..7a766c8 100644
--- a/encoding/gocode/templates.go
+++ b/encoding/gocode/templates.go
@@ -26,7 +26,7 @@
 import (
 	"fmt"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/encoding/gocode/gocodec"
 )
 
diff --git a/encoding/gocode/testdata/pkg1/cue_gen.go b/encoding/gocode/testdata/pkg1/cue_gen.go
index ab8ac04..38d42d2 100644
--- a/encoding/gocode/testdata/pkg1/cue_gen.go
+++ b/encoding/gocode/testdata/pkg1/cue_gen.go
@@ -5,8 +5,8 @@
 import (
 	"fmt"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/encoding/gocode/gocodec"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 var cuegenvalMyStruct = cuegenMake("MyStruct", &MyStruct{})
diff --git a/encoding/gocode/testdata/pkg2/cue_gen.go b/encoding/gocode/testdata/pkg2/cue_gen.go
index 927bf6e..6cd4325 100644
--- a/encoding/gocode/testdata/pkg2/cue_gen.go
+++ b/encoding/gocode/testdata/pkg2/cue_gen.go
@@ -5,8 +5,8 @@
 import (
 	"fmt"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/encoding/gocode/gocodec"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 var cuegenvalImportMe = cuegenMake("ImportMe", &ImportMe{})
diff --git a/encoding/json/json.go b/encoding/json/json.go
index 50b9726..f795802 100644
--- a/encoding/json/json.go
+++ b/encoding/json/json.go
@@ -21,13 +21,13 @@
 	"strconv"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/ast/astutil"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/literal"
 	"cuelang.org/go/cue/parser"
 	"cuelang.org/go/cue/token"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/pkg/encoding/json"
 )
 
diff --git a/encoding/jsonschema/constraints.go b/encoding/jsonschema/constraints.go
index ef941e2..7eeaf63 100644
--- a/encoding/jsonschema/constraints.go
+++ b/encoding/jsonschema/constraints.go
@@ -20,11 +20,11 @@
 	"path"
 	"regexp"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // TODO: skip invalid regexps containing ?! and foes.
diff --git a/encoding/jsonschema/decode.go b/encoding/jsonschema/decode.go
index 54f8fd6..a1d1144 100644
--- a/encoding/jsonschema/decode.go
+++ b/encoding/jsonschema/decode.go
@@ -24,12 +24,12 @@
 	"sort"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/ast/astutil"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // rootDefs defines the top-level name of the map of definitions that do not
diff --git a/encoding/jsonschema/decode_test.go b/encoding/jsonschema/decode_test.go
index adc5bd6..08ed07f 100644
--- a/encoding/jsonschema/decode_test.go
+++ b/encoding/jsonschema/decode_test.go
@@ -24,13 +24,13 @@
 	"strings"
 	"testing"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/format"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/encoding/json"
 	"cuelang.org/go/encoding/yaml"
+	"cuelang.org/go/internal/legacy/cue"
 	"github.com/google/go-cmp/cmp"
 	"github.com/stretchr/testify/assert"
 	"golang.org/x/tools/txtar"
diff --git a/encoding/jsonschema/jsonschema.go b/encoding/jsonschema/jsonschema.go
index 9e81b73..6451157 100644
--- a/encoding/jsonschema/jsonschema.go
+++ b/encoding/jsonschema/jsonschema.go
@@ -31,9 +31,9 @@
 package jsonschema
 
 import (
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/token"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Extract converts JSON Schema data into an equivalent CUE representation.
diff --git a/encoding/jsonschema/ref.go b/encoding/jsonschema/ref.go
index 26443fe..c57253c 100644
--- a/encoding/jsonschema/ref.go
+++ b/encoding/jsonschema/ref.go
@@ -20,11 +20,11 @@
 	"strconv"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 func (d *decoder) parseRef(p token.Pos, str string) []string {
diff --git a/encoding/openapi/build.go b/encoding/openapi/build.go
index c1453d6..5a7bff8 100644
--- a/encoding/openapi/build.go
+++ b/encoding/openapi/build.go
@@ -23,11 +23,11 @@
 	"strconv"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 	"golang.org/x/xerrors"
 )
 
diff --git a/encoding/openapi/crd.go b/encoding/openapi/crd.go
index 7251b43..7e691fa 100644
--- a/encoding/openapi/crd.go
+++ b/encoding/openapi/crd.go
@@ -44,8 +44,8 @@
 //
 
 import (
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // newCoreBuilder returns a builder that represents a structural schema.
diff --git a/encoding/openapi/decode.go b/encoding/openapi/decode.go
index a8a61b8..b45100a 100644
--- a/encoding/openapi/decode.go
+++ b/encoding/openapi/decode.go
@@ -17,12 +17,12 @@
 import (
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/encoding/jsonschema"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Extract converts OpenAPI definitions to an equivalent CUE representation.
diff --git a/encoding/openapi/decode_test.go b/encoding/openapi/decode_test.go
index 8a6d8a8..b3d417d 100644
--- a/encoding/openapi/decode_test.go
+++ b/encoding/openapi/decode_test.go
@@ -27,12 +27,12 @@
 	"github.com/stretchr/testify/assert"
 	"golang.org/x/tools/txtar"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/format"
 	"cuelang.org/go/encoding/json"
 	"cuelang.org/go/encoding/openapi"
 	"cuelang.org/go/encoding/yaml"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // TestDecode reads the testdata/*.txtar files, converts the contained
diff --git a/encoding/openapi/openapi.go b/encoding/openapi/openapi.go
index f26cff6..463d758 100644
--- a/encoding/openapi/openapi.go
+++ b/encoding/openapi/openapi.go
@@ -19,11 +19,11 @@
 	"fmt"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/token"
 	cuejson "cuelang.org/go/encoding/json"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // A Config defines options for converting CUE to and from OpenAPI.
diff --git a/encoding/openapi/openapi_test.go b/encoding/openapi/openapi_test.go
index e8c3705..c8134f2 100644
--- a/encoding/openapi/openapi_test.go
+++ b/encoding/openapi/openapi_test.go
@@ -25,11 +25,11 @@
 
 	"github.com/kylelemons/godebug/diff"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/load"
 	"cuelang.org/go/encoding/openapi"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 var update *bool = flag.Bool("update", false, "update the test output")
diff --git a/encoding/openapi/types.go b/encoding/openapi/types.go
index f262681..b86c3ac 100644
--- a/encoding/openapi/types.go
+++ b/encoding/openapi/types.go
@@ -20,11 +20,11 @@
 
 	"github.com/cockroachdb/apd/v2"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/format"
 	"cuelang.org/go/cue/literal"
 	"cuelang.org/go/cue/token"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#data-types
diff --git a/encoding/yaml/yaml.go b/encoding/yaml/yaml.go
index 0787077..e038776 100644
--- a/encoding/yaml/yaml.go
+++ b/encoding/yaml/yaml.go
@@ -20,9 +20,9 @@
 	"bytes"
 	"io"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	cueyaml "cuelang.org/go/internal/encoding/yaml"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/third_party/yaml"
 	pkgyaml "cuelang.org/go/pkg/encoding/yaml"
 )
diff --git a/encoding/yaml/yaml_test.go b/encoding/yaml/yaml_test.go
index 304b488..b9e4e38 100644
--- a/encoding/yaml/yaml_test.go
+++ b/encoding/yaml/yaml_test.go
@@ -18,9 +18,9 @@
 	"strings"
 	"testing"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/format"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 func TestYAML(t *testing.T) {
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index f6ffd25..404b43d 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -17,11 +17,11 @@
 import (
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/parser"
 	"cuelang.org/go/cue/token"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 func ParseValue(pos token.Pos, name, str string, k cue.Kind) (x ast.Expr, errs errors.Error) {
diff --git a/internal/diff/diff.go b/internal/diff/diff.go
index b11946b..98f6b44 100644
--- a/internal/diff/diff.go
+++ b/internal/diff/diff.go
@@ -17,9 +17,9 @@
 import (
 	"strconv"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Profile configures a diff operation.
diff --git a/internal/diff/diff_test.go b/internal/diff/diff_test.go
index c994bd6..9f87f27 100644
--- a/internal/diff/diff_test.go
+++ b/internal/diff/diff_test.go
@@ -18,7 +18,7 @@
 	"bytes"
 	"testing"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 func TestDiff(t *testing.T) {
diff --git a/internal/diff/print.go b/internal/diff/print.go
index ebe2d10..8493d35 100644
--- a/internal/diff/print.go
+++ b/internal/diff/print.go
@@ -18,9 +18,9 @@
 	"fmt"
 	"io"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/format"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Print the differences between two structs represented by an edit script.
diff --git a/internal/encoding/detect.go b/internal/encoding/detect.go
index b125a3f..25537db 100644
--- a/internal/encoding/detect.go
+++ b/internal/encoding/detect.go
@@ -19,8 +19,8 @@
 	"path"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/build"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Detect detects the interpretation.
diff --git a/internal/encoding/detect_test.go b/internal/encoding/detect_test.go
index bdb1b9b..5850761 100644
--- a/internal/encoding/detect_test.go
+++ b/internal/encoding/detect_test.go
@@ -17,8 +17,8 @@
 import (
 	"testing"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/build"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 func TestDetect(t *testing.T) {
diff --git a/internal/encoding/encoder.go b/internal/encoding/encoder.go
index fbb019f..31f0b0b 100644
--- a/internal/encoding/encoder.go
+++ b/internal/encoding/encoder.go
@@ -21,7 +21,6 @@
 	"os"
 	"path/filepath"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/build"
 	"cuelang.org/go/cue/errors"
@@ -30,6 +29,7 @@
 	"cuelang.org/go/encoding/openapi"
 	"cuelang.org/go/internal"
 	"cuelang.org/go/internal/filetypes"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/pkg/encoding/yaml"
 )
 
diff --git a/internal/encoding/encoding.go b/internal/encoding/encoding.go
index 8606bcb..875ac21 100644
--- a/internal/encoding/encoding.go
+++ b/internal/encoding/encoding.go
@@ -26,7 +26,6 @@
 	"os"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/build"
 	"cuelang.org/go/cue/errors"
@@ -39,6 +38,7 @@
 	"cuelang.org/go/encoding/protobuf"
 	"cuelang.org/go/internal"
 	"cuelang.org/go/internal/filetypes"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/third_party/yaml"
 	"golang.org/x/text/encoding/unicode"
 	"golang.org/x/text/transform"
diff --git a/internal/filetypes/filetypes.go b/internal/filetypes/filetypes.go
index 4e291af..c03c1a8 100644
--- a/internal/filetypes/filetypes.go
+++ b/internal/filetypes/filetypes.go
@@ -20,10 +20,10 @@
 	"path/filepath"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/build"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/token"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Mode indicate the base mode of operation and indicates a different set of
diff --git a/internal/filetypes/gen.go b/internal/filetypes/gen.go
index f0b9f03..6430ff9 100644
--- a/internal/filetypes/gen.go
+++ b/internal/filetypes/gen.go
@@ -21,9 +21,9 @@
 	"log"
 	"os"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/load"
 	"cuelang.org/go/encoding/gocode"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 func main() {
diff --git a/internal/filetypes/types.go b/internal/filetypes/types.go
index fdbcc21..b1653e9 100644
--- a/internal/filetypes/types.go
+++ b/internal/filetypes/types.go
@@ -5,8 +5,8 @@
 import (
 	"fmt"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/encoding/gocode/gocodec"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 var cuegenCodec, cuegenInstance = func() (*gocodec.Codec, *cue.Instance) {
diff --git a/internal/internal.go b/internal/internal.go
index d4e31dc..934c455 100644
--- a/internal/internal.go
+++ b/internal/internal.go
@@ -72,7 +72,7 @@
 var UnifyBuiltin func(v interface{}, kind string) interface{}
 
 // GetRuntime reports the runtime for an Instance or Value.
-var GetRuntime func(instance interface{}) interface{}
+var GetRuntimeOld func(instance interface{}) interface{}
 
 // GetRuntime reports the runtime for an Instance or Value.
 var GetRuntimeNew func(instance interface{}) interface{}
@@ -87,7 +87,7 @@
 // CheckAndForkRuntime checks that value is created using runtime, panicking
 // if it does not, and returns a forked runtime that will discard additional
 // keys.
-var CheckAndForkRuntime func(runtime, value interface{}) interface{}
+var CheckAndForkRuntimeOld func(runtime, value interface{}) interface{}
 
 // CheckAndForkRuntime checks that value is created using runtime, panicking
 // if it does not, and returns a forked runtime that will discard additional
diff --git a/internal/task/task.go b/internal/task/task.go
index a6a54d2..5322a47 100644
--- a/internal/task/task.go
+++ b/internal/task/task.go
@@ -20,8 +20,8 @@
 	"io"
 	"sync"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/errors"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // A Context provides context for running a task.
diff --git a/internal/walk/walk.go b/internal/walk/walk.go
index 8e3c9f9..b74f56e 100644
--- a/internal/walk/walk.go
+++ b/internal/walk/walk.go
@@ -21,7 +21,7 @@
 // satisfactory API has been established, it can be made public.
 package walk
 
-import "cuelang.org/go/cue"
+import "cuelang.org/go/internal/legacy/cue"
 
 // TODO:
 // - allow overriding options for descendants.
diff --git a/pkg/encoding/base64/manual.go b/pkg/encoding/base64/manual.go
index b292424..178f105 100644
--- a/pkg/encoding/base64/manual.go
+++ b/pkg/encoding/base64/manual.go
@@ -19,7 +19,7 @@
 	"encoding/base64"
 	"fmt"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // EncodedLen returns the length in bytes of the base64 encoding
diff --git a/pkg/encoding/csv/manual.go b/pkg/encoding/csv/manual.go
index 99e2cf1..f8b31d0 100644
--- a/pkg/encoding/csv/manual.go
+++ b/pkg/encoding/csv/manual.go
@@ -19,7 +19,7 @@
 	"encoding/csv"
 	"io"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Encode encode the given list of lists to CSV.
diff --git a/pkg/encoding/json/manual.go b/pkg/encoding/json/manual.go
index 6ba9956..591724b 100644
--- a/pkg/encoding/json/manual.go
+++ b/pkg/encoding/json/manual.go
@@ -19,10 +19,10 @@
 	"encoding/json"
 	"fmt"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/parser"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Compact generates the JSON-encoded src with insignificant space characters
@@ -109,7 +109,7 @@
 	if !json.Valid(b) {
 		return false, fmt.Errorf("json: invalid JSON")
 	}
-	r := internal.GetRuntime(v).(*cue.Runtime)
+	r := internal.GetRuntimeNew(v).(*cue.Runtime)
 	inst, err := r.Compile("json.Validate", b)
 	if err != nil {
 		return false, err
diff --git a/pkg/encoding/yaml/manual.go b/pkg/encoding/yaml/manual.go
index 6d60842..16d6d38 100644
--- a/pkg/encoding/yaml/manual.go
+++ b/pkg/encoding/yaml/manual.go
@@ -18,10 +18,10 @@
 	"bytes"
 	"io"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/internal"
 	cueyaml "cuelang.org/go/internal/encoding/yaml"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/third_party/yaml"
 )
 
@@ -79,7 +79,7 @@
 	if err != nil {
 		return false, err
 	}
-	r := internal.GetRuntime(v).(*cue.Runtime)
+	r := internal.GetRuntimeNew(v).(*cue.Runtime)
 	for {
 		expr, err := d.Decode()
 		if err != nil {
@@ -123,7 +123,7 @@
 	if err != nil {
 		return false, err
 	}
-	r := internal.GetRuntime(v).(*cue.Runtime)
+	r := internal.GetRuntimeNew(v).(*cue.Runtime)
 	for {
 		expr, err := d.Decode()
 		if err != nil {
diff --git a/pkg/list/list.go b/pkg/list/list.go
index be8493b..db6c2d3 100644
--- a/pkg/list/list.go
+++ b/pkg/list/list.go
@@ -19,7 +19,7 @@
 	"fmt"
 	"sort"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Drop reports the suffix of list x after the first n elements,
diff --git a/pkg/list/sort.go b/pkg/list/sort.go
index ac33f4f..f39a407 100644
--- a/pkg/list/sort.go
+++ b/pkg/list/sort.go
@@ -21,7 +21,7 @@
 import (
 	"sort"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // valueSorter defines a sort.Interface; implemented in cue/builtinutil.go.
diff --git a/pkg/net/host.go b/pkg/net/host.go
index 6018da4..9a357c7 100644
--- a/pkg/net/host.go
+++ b/pkg/net/host.go
@@ -22,7 +22,7 @@
 
 	"golang.org/x/net/idna"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 var idnaProfile = idna.New(
diff --git a/pkg/net/ip.go b/pkg/net/ip.go
index 6b658e3..5f9aeef 100644
--- a/pkg/net/ip.go
+++ b/pkg/net/ip.go
@@ -19,7 +19,7 @@
 	"fmt"
 	"net"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // IP address lengths (bytes).
diff --git a/pkg/struct/struct.go b/pkg/struct/struct.go
index 00094e1..5b51254 100644
--- a/pkg/struct/struct.go
+++ b/pkg/struct/struct.go
@@ -16,7 +16,7 @@
 package structs
 
 import (
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // MinFields validates the minimum number of fields that are part of a struct.
diff --git a/pkg/text/tabwriter/manual.go b/pkg/text/tabwriter/manual.go
index 42f90aa..5512565 100644
--- a/pkg/text/tabwriter/manual.go
+++ b/pkg/text/tabwriter/manual.go
@@ -19,7 +19,7 @@
 	"fmt"
 	"text/tabwriter"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Write formats text in columns. See golang.org/pkg/text/tabwriter for more
diff --git a/pkg/text/template/manual.go b/pkg/text/template/manual.go
index 646f5e8..fd8116c 100644
--- a/pkg/text/template/manual.go
+++ b/pkg/text/template/manual.go
@@ -18,7 +18,7 @@
 	"bytes"
 	"text/template"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // Execute executes a Go-style template.
diff --git a/pkg/tool/cli/cli.go b/pkg/tool/cli/cli.go
index 8ba4878..01d9e28 100644
--- a/pkg/tool/cli/cli.go
+++ b/pkg/tool/cli/cli.go
@@ -20,7 +20,7 @@
 import (
 	"fmt"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/task"
 )
 
diff --git a/pkg/tool/exec/exec.go b/pkg/tool/exec/exec.go
index 62c2cec..c29e754 100644
--- a/pkg/tool/exec/exec.go
+++ b/pkg/tool/exec/exec.go
@@ -24,8 +24,8 @@
 
 	"golang.org/x/xerrors"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/errors"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/task"
 )
 
diff --git a/pkg/tool/exec/exec_test.go b/pkg/tool/exec/exec_test.go
index 69e9484..eaf21c6 100644
--- a/pkg/tool/exec/exec_test.go
+++ b/pkg/tool/exec/exec_test.go
@@ -20,7 +20,7 @@
 
 	"github.com/google/go-cmp/cmp"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/task"
 )
 
diff --git a/pkg/tool/file/file.go b/pkg/tool/file/file.go
index 7c206ca..bfdb8f0 100644
--- a/pkg/tool/file/file.go
+++ b/pkg/tool/file/file.go
@@ -22,7 +22,7 @@
 	"os"
 	"path/filepath"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/task"
 )
 
diff --git a/pkg/tool/file/file_test.go b/pkg/tool/file/file_test.go
index c9bc38f..aa04bdd 100644
--- a/pkg/tool/file/file_test.go
+++ b/pkg/tool/file/file_test.go
@@ -22,9 +22,9 @@
 	"reflect"
 	"testing"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/parser"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/task"
 )
 
diff --git a/pkg/tool/http/http.go b/pkg/tool/http/http.go
index 4c6f9e6..b7c5f23 100644
--- a/pkg/tool/http/http.go
+++ b/pkg/tool/http/http.go
@@ -22,7 +22,7 @@
 	"io/ioutil"
 	"net/http"
 
-	"cuelang.org/go/cue"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/task"
 )
 
diff --git a/pkg/tool/os/env.go b/pkg/tool/os/env.go
index 0d0a535..137a08c 100644
--- a/pkg/tool/os/env.go
+++ b/pkg/tool/os/env.go
@@ -21,10 +21,10 @@
 	"os"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/internal/cli"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/task"
 )
 
diff --git a/pkg/tool/os/env_test.go b/pkg/tool/os/env_test.go
index 8a6d9fb..1a1d636 100644
--- a/pkg/tool/os/env_test.go
+++ b/pkg/tool/os/env_test.go
@@ -21,12 +21,12 @@
 	"github.com/google/go-cmp/cmp"
 	"github.com/google/go-cmp/cmp/cmpopts"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/errors"
 	"cuelang.org/go/cue/parser"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 	"cuelang.org/go/internal/task"
 )
 
diff --git a/tools/trim/trim.go b/tools/trim/trim.go
index b355f2f..3df93ab 100644
--- a/tools/trim/trim.go
+++ b/tools/trim/trim.go
@@ -62,10 +62,10 @@
 	"strconv"
 	"strings"
 
-	"cuelang.org/go/cue"
 	"cuelang.org/go/cue/ast"
 	"cuelang.org/go/cue/token"
 	"cuelang.org/go/internal"
+	"cuelang.org/go/internal/legacy/cue"
 )
 
 // TODO: