go/internal/gcimporter: stub support importing/exporting constant kind

Add placeholder support for importing/exporting constant kind in the Go
1.18 export data format.

Also eliminate the redundant iimport.iexportVersion field.

For golang/go#45837

Change-Id: I94dbcadde0fae55788ce1a139a2760276f644630
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358035
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
diff --git a/go/internal/gcimporter/iexport.go b/go/internal/gcimporter/iexport.go
index 2411aa3..b4d51f3 100644
--- a/go/internal/gcimporter/iexport.go
+++ b/go/internal/gcimporter/iexport.go
@@ -700,6 +700,9 @@
 
 func (w *exportWriter) value(typ types.Type, v constant.Value) {
 	w.typ(typ, nil)
+	if w.p.version >= iexportVersionGo1_18 {
+		w.int64(int64(v.Kind()))
+	}
 
 	switch b := typ.Underlying().(*types.Basic); b.Info() & types.IsConstType {
 	case types.IsBoolean:
diff --git a/go/internal/gcimporter/iexport_go118_test.go b/go/internal/gcimporter/iexport_go118_test.go
index c2c81a0..2dc5cc1 100644
--- a/go/internal/gcimporter/iexport_go118_test.go
+++ b/go/internal/gcimporter/iexport_go118_test.go
@@ -40,6 +40,11 @@
 func ImplicitFunc[T ~int]() {}
 
 type ImplicitType[T ~int] int
+
+// Exercise constant import/export
+const C1 = 42
+const C2 int = 42
+const C3 float64 = 42
 `
 	testExportSrc(t, []byte(src))
 }
diff --git a/go/internal/gcimporter/iimport.go b/go/internal/gcimporter/iimport.go
index 984414b..3e31874 100644
--- a/go/internal/gcimporter/iimport.go
+++ b/go/internal/gcimporter/iimport.go
@@ -149,9 +149,8 @@
 	r.Seek(sLen+dLen, io.SeekCurrent)
 
 	p := iimporter{
-		exportVersion: version,
-		ipath:         path,
-		version:       int(version),
+		version: int(version),
+		ipath:   path,
 
 		stringData:  stringData,
 		stringCache: make(map[uint64]string),
@@ -255,9 +254,8 @@
 }
 
 type iimporter struct {
-	exportVersion int64
-	ipath         string
-	version       int
+	version int
+	ipath   string
 
 	stringData  []byte
 	stringCache map[uint64]string
@@ -428,7 +426,7 @@
 		// We need to "declare" a typeparam in order to have a name that
 		// can be referenced recursively (if needed) in the type param's
 		// bound.
-		if r.p.exportVersion < iexportVersionGenerics {
+		if r.p.version < iexportVersionGenerics {
 			errorf("unexpected type param type")
 		}
 		// Remove the "path" from the type param name that makes it unique
@@ -445,7 +443,7 @@
 		id := ident{r.currPkg.Name(), name}
 		r.p.tparamIndex[id] = t
 		var implicit bool
-		if r.p.exportVersion >= iexportVersionGo1_18 {
+		if r.p.version >= iexportVersionGo1_18 {
 			implicit = r.bool()
 		}
 		constraint := r.typ()
@@ -474,6 +472,10 @@
 
 func (r *importReader) value() (typ types.Type, val constant.Value) {
 	typ = r.typ()
+	if r.p.version >= iexportVersionGo1_18 {
+		// TODO: add support for using the kind.
+		_ = constant.Kind(r.int64())
+	}
 
 	switch b := typ.Underlying().(*types.Basic); b.Info() & types.IsConstType {
 	case types.IsBoolean:
@@ -616,7 +618,7 @@
 }
 
 func (r *importReader) pos() token.Pos {
-	if r.p.exportVersion >= iexportVersionPosCol {
+	if r.p.version >= iexportVersionPosCol {
 		r.posv1()
 	} else {
 		r.posv0()
@@ -746,7 +748,7 @@
 		return typ
 
 	case typeParamType:
-		if r.p.exportVersion < iexportVersionGenerics {
+		if r.p.version < iexportVersionGenerics {
 			errorf("unexpected type param type")
 		}
 		pkg, name := r.qualifiedIdent()
@@ -760,7 +762,7 @@
 		return r.p.tparamIndex[id]
 
 	case instanceType:
-		if r.p.exportVersion < iexportVersionGenerics {
+		if r.p.version < iexportVersionGenerics {
 			errorf("unexpected instantiation type")
 		}
 		// pos does not matter for instances: they are positioned on the original
@@ -779,7 +781,7 @@
 		return t
 
 	case unionType:
-		if r.p.exportVersion < iexportVersionGenerics {
+		if r.p.version < iexportVersionGenerics {
 			errorf("unexpected instantiation type")
 		}
 		terms := make([]*typeparams.Term, r.uint64())