cue: rename Name to PkgName and add DisplayName

Name is too confusing a field.

Change-Id: Ie973fc5c153bfd5f69bf4b68682bc93d65c8d45b
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5182
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/builtin.go b/cue/builtin.go
index 99e8fff..5847d6a 100644
--- a/cue/builtin.go
+++ b/cue/builtin.go
@@ -347,7 +347,7 @@
 
 		i := sharedIndex.addInst(&Instance{
 			ImportPath: k,
-			Name:       path.Base(k),
+			PkgName:    path.Base(k),
 			rootStruct: e,
 			rootValue:  e,
 		})
diff --git a/cue/export.go b/cue/export.go
index 4767b83..f4e7133 100644
--- a/cue/export.go
+++ b/cue/export.go
@@ -56,8 +56,8 @@
 
 	file := &ast.File{}
 	if inst != nil {
-		if inst.Name != "" {
-			p := &ast.Package{Name: ast.NewIdent(inst.Name)}
+		if inst.PkgName != "" {
+			p := &ast.Package{Name: ast.NewIdent(inst.PkgName)}
 			file.Decls = append(file.Decls, p)
 			if m.docs {
 				for _, d := range inst.Doc() {
@@ -195,7 +195,7 @@
 	info, ok := p.imports[pkg]
 	short := info.short
 	if !ok {
-		short = inst.Name
+		short = inst.PkgName
 		if _, ok := p.top[p.ctx.label(short, true)]; ok && preferred != "" {
 			short = preferred
 			info.name = short
diff --git a/cue/instance.go b/cue/instance.go
index aea89a9..337acb0 100644
--- a/cue/instance.go
+++ b/cue/instance.go
@@ -36,9 +36,10 @@
 	// and the predeclared identifiers.
 	scope *structLit
 
-	ImportPath string
-	Dir        string
-	Name       string
+	ImportPath  string
+	Dir         string
+	PkgName     string
+	DisplayName string
 
 	Incomplete bool         // true if Pkg and all its dependencies are free of errors
 	Err        errors.Error // non-nil if the package had errors
@@ -80,7 +81,8 @@
 	if p != nil {
 		i.ImportPath = p.ImportPath
 		i.Dir = p.Dir
-		i.Name = p.PkgName
+		i.PkgName = p.PkgName
+		i.DisplayName = p.ImportPath
 		if p.Err != nil {
 			i.setListOrError(p.Err)
 		}
@@ -357,9 +359,9 @@
 		rootValue:  st,
 		inst:       nil,
 
-		// TODO: somehow indicate this is not an original
-		ImportPath: inst.ImportPath,
-		Name:       inst.Name,
+		// Omit ImportPath to indicate this is not an importable package.
+		Dir:        inst.Dir,
+		PkgName:    inst.PkgName,
 		Incomplete: inst.Incomplete,
 		Err:        err,
 
diff --git a/cue/marshal.go b/cue/marshal.go
index e8cc7f3..a1e3509 100644
--- a/cue/marshal.go
+++ b/cue/marshal.go
@@ -149,8 +149,8 @@
 				file.Decls = append(file.Decls, &ast.EmbedDecl{Expr: n.(ast.Expr)})
 			}
 		}
-		if i.Name != "" {
-			pkg := &ast.Package{Name: ast.NewIdent(i.Name)}
+		if i.PkgName != "" {
+			pkg := &ast.Package{Name: ast.NewIdent(i.PkgName)}
 			file.Decls = append([]ast.Decl{pkg}, file.Decls...)
 		}
 
diff --git a/encoding/gocode/generator.go b/encoding/gocode/generator.go
index f1e8166..b5f4476 100644
--- a/encoding/gocode/generator.go
+++ b/encoding/gocode/generator.go
@@ -111,7 +111,7 @@
 		typeMap: map[string]types.Type{},
 	}
 
-	pkgName := inst.Name
+	pkgName := inst.PkgName
 
 	if pkgPath != "" {
 		loadCfg := &packages.Config{