all: move v1 types over to the v2 repository

As a goal, v2 should not depend on v1. As another step towards that end,
we move all the types that used to be in the v1 protoapi package over to v2.

For now, we place MessageV1, ExtensionRangeV1, and ExtensionDescV1
in runtime/protoiface since these are types that generated messages will
probably have to reference forever. An alternative location could be
reflect/protoreflect, but it seems unfortunate to have to dirty the
namespace of that package with these types.

We move ExtensionFieldV1, ExtensionFieldsV1, and ExtensionFieldsOf
to internal/impl, since these are related to the implementation of a
generated message.

Since moving these types from v1 to v2 implies that the v1 protoapi
package is useless, we update all usages of v1 protoapi in the v2
repository to point to the relevant v2 type or functionality.

CL/168538 is the corresponding change to alter v1.
There will be a temporary build failure as it is not possible
to submit CL/168519 and CL/168538 atomically.

Change-Id: Ide4025c1b6af5b7f0696f4b65b988b4d10a50f0b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168519
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go
index 95e6611..cfa9e41 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -27,9 +27,14 @@
 )
 
 const (
-	mathPackage     = protogen.GoImportPath("math")
-	protoPackage    = protogen.GoImportPath("github.com/golang/protobuf/proto")
-	protoapiPackage = protogen.GoImportPath("github.com/golang/protobuf/protoapi")
+	mathPackage          = protogen.GoImportPath("math")
+	reflectPackage       = protogen.GoImportPath("reflect")
+	protoPackage         = protogen.GoImportPath("github.com/golang/protobuf/proto")
+	protoifacePackage    = protogen.GoImportPath("github.com/golang/protobuf/v2/runtime/protoiface")
+	protoimplPackage     = protogen.GoImportPath("github.com/golang/protobuf/v2/runtime/protoimpl")
+	protoreflectPackage  = protogen.GoImportPath("github.com/golang/protobuf/v2/reflect/protoreflect")
+	protoregistryPackage = protogen.GoImportPath("github.com/golang/protobuf/v2/reflect/protoregistry")
+	prototypePackage     = protogen.GoImportPath("github.com/golang/protobuf/v2/internal/prototype")
 )
 
 type fileInfo struct {
@@ -46,28 +51,6 @@
 	allExtensions    []*protogen.Extension
 }
 
-// protoPackage returns the package to import, which is either the protoPackage
-// or the protoapiPackage constant.
-//
-// This special casing exists because we are unable to move InternalMessageInfo
-// to protoapi since the implementation behind that logic is heavy and
-// too intricately connected to other parts of the proto package.
-// The descriptor proto is special in that it avoids using InternalMessageInfo
-// so that it is able to depend solely on protoapi and break its dependency
-// on the proto package. It is still semantically correct for descriptor to
-// avoid using InternalMessageInfo, but it does incur some performance penalty.
-// This is acceptable for descriptor, which is a single proto file and is not
-// known to be in the hot path for any code.
-//
-// TODO: Remove this special-casing when the table-driven implementation has
-// been ported over to v2.
-func (f *fileInfo) protoPackage() protogen.GoImportPath {
-	if isDescriptor(f.File) {
-		return protoapiPackage
-	}
-	return protoPackage
-}
-
 // GenerateFile generates the contents of a .pb.go file.
 func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.GeneratedFile {
 	filename := file.GeneratedFilenamePrefix + ".pb.go"
@@ -428,7 +411,7 @@
 			tags = append(tags, `protobuf_messageset:"1"`)
 		}
 		tags = append(tags, `json:"-"`)
-		g.P(f.protoPackage().Ident("XXX_InternalExtensions"), " `", strings.Join(tags, " "), "`")
+		g.P("XXX_InternalExtensions ", protoimplPackage.Ident("ExtensionFieldsV1"), " `", strings.Join(tags, " "), "`")
 	}
 	g.P("XXX_unrecognized []byte `json:\"-\"`")
 	g.P("XXX_sizecache int32 `json:\"-\"`")
@@ -444,7 +427,7 @@
 	if isDescriptor(f.File) {
 		g.P("func (m *", message.GoIdent, ") String() string { return ", protoimplPackage.Ident("X"), ".MessageStringOf(m) }")
 	} else {
-		g.P("func (m *", message.GoIdent, ") String() string { return ", f.protoPackage().Ident("CompactTextString"), "(m) }")
+		g.P("func (m *", message.GoIdent, ") String() string { return ", protoPackage.Ident("CompactTextString"), "(m) }")
 	}
 	// ProtoMessage
 	g.P("func (*", message.GoIdent, ") ProtoMessage() {}")
@@ -461,7 +444,7 @@
 
 	// ExtensionRangeArray
 	if extranges := message.Desc.ExtensionRanges(); extranges.Len() > 0 {
-		protoExtRange := f.protoPackage().Ident("ExtensionRange")
+		protoExtRange := protoifacePackage.Ident("ExtensionRangeV1")
 		extRangeVar := "extRange_" + message.GoIdent.GoName
 		g.P("var ", extRangeVar, " = []", protoExtRange, " {")
 		for i := 0; i < extranges.Len(); i++ {
@@ -696,7 +679,7 @@
 		return
 	}
 
-	g.P("var ", extDecsVarName(f), " = []", f.protoPackage().Ident("ExtensionDesc"), "{")
+	g.P("var ", extDecsVarName(f), " = []", protoifacePackage.Ident("ExtensionDescV1"), "{")
 	for _, extension := range f.allExtensions {
 		// Special case for proto2 message sets: If this extension is extending
 		// proto2.bridge.MessageSet, and its final name component is "message_set_extension",