all: move v1 types over to the v2 repository

In CL/168519, we move all exported types in v1 protoapi over
to the v2 repository.

This CL does the other half of the move, where the moved logic is
deleted from protoapi. Since little logic remains in protoapi,
the package is being deleted, and remaining logic moved back into
the v1 proto package itself.

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: I3f233b56684357747e35ac6b83f3e0aa427b3152
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168538
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/go.mod b/go.mod
deleted file mode 100644
index dbcf032..0000000
--- a/go.mod
+++ /dev/null
@@ -1,3 +0,0 @@
-module github.com/golang/protobuf
-
-require github.com/golang/protobuf/v2 v2.0.0-20190320041633-559d47f1da45
diff --git a/go.sum b/go.sum
deleted file mode 100644
index d0211f0..0000000
--- a/go.sum
+++ /dev/null
@@ -1,5 +0,0 @@
-github.com/golang/protobuf v1.2.1-0.20190311233832-968e039ade03/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
-github.com/golang/protobuf/v2 v2.0.0-20190320041633-559d47f1da45 h1:UpSQcE2BQjlwjgUj1o+22OMRLUpeeTZNH1fuZN5lEv4=
-github.com/golang/protobuf/v2 v2.0.0-20190320041633-559d47f1da45/go.mod h1:memx26heJzlbv0kkl0yZyY1iCWPnh53PDfstsy8HCEg=
-github.com/google/go-cmp v0.2.1-0.20190312032427-6f77996f0c42 h1:q3pnF5JFBNRz8sRD+IRj7Y6DMyYGTNqnZ9axTbSfoNI=
-github.com/google/go-cmp v0.2.1-0.20190312032427-6f77996f0c42/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
diff --git a/internal/proto/common.go b/internal/proto/common.go
index d49c17c..93f5178 100644
--- a/internal/proto/common.go
+++ b/internal/proto/common.go
@@ -9,12 +9,11 @@
 // that they would otherwise be able to call directly.
 
 import (
-	"github.com/golang/protobuf/protoapi"
-
+	"github.com/golang/protobuf/v2/runtime/protoiface"
 	_ "github.com/golang/protobuf/v2/runtime/protolegacy"
 )
 
 type (
-	Message       = protoapi.Message
-	ExtensionDesc = protoapi.ExtensionDesc
+	Message       = protoiface.MessageV1
+	ExtensionDesc = protoiface.ExtensionDescV1
 )
diff --git a/proto/clone.go b/proto/clone.go
index 5f97f7a..2cb7009 100644
--- a/proto/clone.go
+++ b/proto/clone.go
@@ -13,7 +13,6 @@
 	"reflect"
 	"strings"
 
-	"github.com/golang/protobuf/protoapi"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -209,7 +208,7 @@
 	}
 }
 
-func mergeExtension(out, in protoapi.ExtensionFields) {
+func mergeExtension(out, in extensionFields) {
 	in.Range(func(extNum protoreflect.FieldNumber, eIn Extension) bool {
 		eOut := Extension{Desc: eIn.Desc}
 		if eIn.Value != nil {
diff --git a/proto/deprecated.go b/proto/deprecated.go
index da5b374..7db76d4 100644
--- a/proto/deprecated.go
+++ b/proto/deprecated.go
@@ -5,49 +5,69 @@
 package proto
 
 import (
+	"encoding/json"
 	"errors"
-
-	"github.com/golang/protobuf/protoapi"
+	"fmt"
+	"strconv"
 )
 
-// Deprecated: do not use.
+// Deprecated: Do not use.
 var ErrInternalBadWireType = errors.New("proto: internal error: bad wiretype for oneof")
 
-// Deprecated: do not use.
+// Deprecated: Do not use.
 type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
 
-// Deprecated: do not use.
+// Deprecated: Do not use.
 func GetStats() Stats { return Stats{} }
 
-// Deprecated: do not use.
+// Deprecated: Do not use.
 func MarshalMessageSet(interface{}) ([]byte, error) {
 	return nil, errors.New("proto: not implemented")
 }
 
-// Deprecated: do not use.
+// Deprecated: Do not use.
 func UnmarshalMessageSet([]byte, interface{}) error {
 	return errors.New("proto: not implemented")
 }
 
-// Deprecated: do not use.
+// Deprecated: Do not use.
 func MarshalMessageSetJSON(interface{}) ([]byte, error) {
 	return nil, errors.New("proto: not implemented")
 }
 
-// Deprecated: do not use.
+// Deprecated: Do not use.
 func UnmarshalMessageSetJSON([]byte, interface{}) error {
 	return errors.New("proto: not implemented")
 }
 
-// Deprecated: do not use.
+// Deprecated: Do not use.
 func RegisterMessageSetType(Message, int32, string) {}
 
-// Deprecated: do not use.
+// Deprecated: Do not use.
 func EnumName(m map[int32]string, v int32) string {
-	return protoapi.EnumName(m, v)
+	if s, ok := m[v]; ok {
+		return s
+	}
+	return strconv.Itoa(int(v))
 }
 
-// Deprecated: do not use.
-func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
-	return protoapi.UnmarshalJSONEnum(m, data, enumName)
+// Deprecated: Do not use.
+func UnmarshalJSONEnum(m map[string]int32, b []byte, enumName string) (int32, error) {
+	if b[0] == '"' {
+		var s string
+		if err := json.Unmarshal(b, &s); err != nil {
+			return 0, fmt.Errorf("proto: invalid input for enum %v: %s", enumName, b)
+		}
+		v, ok := m[s]
+		if !ok {
+			return 0, fmt.Errorf("proto: invalid value for enum %v: %s", enumName, b)
+		}
+		return v, nil
+	} else {
+		var v int32
+		if err := json.Unmarshal(b, &v); err != nil {
+			return 0, fmt.Errorf("proto: invalid input for enum %v: %s", enumName, b)
+		}
+		return v, nil
+	}
 }
diff --git a/proto/equal.go b/proto/equal.go
index 29ae49b..04da80a 100644
--- a/proto/equal.go
+++ b/proto/equal.go
@@ -12,8 +12,8 @@
 	"reflect"
 	"strings"
 
-	"github.com/golang/protobuf/protoapi"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
+	"github.com/golang/protobuf/v2/runtime/protoimpl"
 )
 
 /*
@@ -94,8 +94,8 @@
 
 	if em1 := v1.FieldByName("XXX_InternalExtensions"); em1.IsValid() {
 		em2 := v2.FieldByName("XXX_InternalExtensions")
-		m1 := protoapi.ExtensionFieldsOf(em1.Addr().Interface())
-		m2 := protoapi.ExtensionFieldsOf(em2.Addr().Interface())
+		m1 := protoimpl.X.ExtensionFieldsOf(em1.Addr().Interface())
+		m2 := protoimpl.X.ExtensionFieldsOf(em2.Addr().Interface())
 		if !equalExtensions(v1.Type(), m1, m2) {
 			return false
 		}
@@ -103,8 +103,8 @@
 
 	if em1 := v1.FieldByName("XXX_extensions"); em1.IsValid() {
 		em2 := v2.FieldByName("XXX_extensions")
-		m1 := protoapi.ExtensionFieldsOf(em1.Addr().Interface())
-		m2 := protoapi.ExtensionFieldsOf(em2.Addr().Interface())
+		m1 := protoimpl.X.ExtensionFieldsOf(em1.Addr().Interface())
+		m2 := protoimpl.X.ExtensionFieldsOf(em2.Addr().Interface())
 		if !equalExtensions(v1.Type(), m1, m2) {
 			return false
 		}
@@ -207,7 +207,7 @@
 	return false
 }
 
-func equalExtensions(base reflect.Type, em1, em2 protoapi.ExtensionFields) bool {
+func equalExtensions(base reflect.Type, em1, em2 extensionFields) bool {
 	if em1.Len() != em2.Len() {
 		return false
 	}
diff --git a/proto/extensions.go b/proto/extensions.go
index 3923707..836619d 100644
--- a/proto/extensions.go
+++ b/proto/extensions.go
@@ -15,14 +15,15 @@
 	"reflect"
 	"sync"
 
-	"github.com/golang/protobuf/protoapi"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
+	"github.com/golang/protobuf/v2/runtime/protoiface"
+	"github.com/golang/protobuf/v2/runtime/protoimpl"
 )
 
 // ErrMissingExtension is the error returned by GetExtension if the named extension is not in the message.
 var ErrMissingExtension = errors.New("proto: missing extension")
 
-func extendable(p interface{}) (protoapi.ExtensionFields, error) {
+func extendable(p interface{}) (extensionFields, error) {
 	type extendableProto interface {
 		Message
 		ExtensionRangeArray() []ExtensionRange
@@ -32,10 +33,10 @@
 		if v.Kind() == reflect.Ptr && !v.IsNil() {
 			v = v.Elem()
 			if v := v.FieldByName("XXX_InternalExtensions"); v.IsValid() {
-				return protoapi.ExtensionFieldsOf(v.Addr().Interface()), nil
+				return protoimpl.X.ExtensionFieldsOf(v.Addr().Interface()), nil
 			}
 			if v := v.FieldByName("XXX_extensions"); v.IsValid() {
-				return protoapi.ExtensionFieldsOf(v.Addr().Interface()), nil
+				return protoimpl.X.ExtensionFieldsOf(v.Addr().Interface()), nil
 			}
 		}
 	}
@@ -47,10 +48,10 @@
 var errNotExtendable = errors.New("proto: not an extendable proto.Message")
 
 type (
-	ExtensionRange         = protoapi.ExtensionRange
-	ExtensionDesc          = protoapi.ExtensionDesc
-	Extension              = protoapi.ExtensionField
-	XXX_InternalExtensions = protoapi.XXX_InternalExtensions
+	ExtensionRange         = protoiface.ExtensionRangeV1
+	ExtensionDesc          = protoiface.ExtensionDescV1
+	Extension              = protoimpl.ExtensionFieldV1
+	XXX_InternalExtensions = protoimpl.ExtensionFieldsV1
 )
 
 func isRepeatedExtension(ed *ExtensionDesc) bool {
diff --git a/proto/lib.go b/proto/lib.go
index 1906a2a..e82e138 100644
--- a/proto/lib.go
+++ b/proto/lib.go
@@ -15,13 +15,25 @@
 	"strconv"
 	"sync"
 
-	// Add a bogus dependency on the v2 API to ensure the Go toolchain does not
-	// remove our dependency from the go.mod file.
-	_ "github.com/golang/protobuf/v2/reflect/protoreflect"
-
-	"github.com/golang/protobuf/protoapi"
+	"github.com/golang/protobuf/v2/reflect/protoreflect"
+	"github.com/golang/protobuf/v2/runtime/protoiface"
+	"github.com/golang/protobuf/v2/runtime/protoimpl"
 )
 
+type extensionFields = interface {
+	Len() int
+	Has(protoreflect.FieldNumber) bool
+	Get(protoreflect.FieldNumber) protoimpl.ExtensionFieldV1
+	Set(protoreflect.FieldNumber, protoimpl.ExtensionFieldV1)
+	Clear(protoreflect.FieldNumber)
+	Range(f func(protoreflect.FieldNumber, protoimpl.ExtensionFieldV1) bool)
+
+	// HasInit and Locker are used by v1 GetExtension to provide
+	// an artificial degree of concurrent safety.
+	HasInit() bool
+	sync.Locker
+}
+
 // RequiredNotSetError is an error type returned by either Marshal or Unmarshal.
 // Marshal reports this when a required field is not initialized.
 // Unmarshal reports this when a required field is missing from the wire data.
@@ -84,7 +96,7 @@
 }
 
 // Message is implemented by generated protocol buffer messages.
-type Message = protoapi.Message
+type Message = protoiface.MessageV1
 
 var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem()
 
diff --git a/proto/message_set.go b/proto/message_set.go
index 19a1a00..2878bdf 100644
--- a/proto/message_set.go
+++ b/proto/message_set.go
@@ -11,8 +11,8 @@
 import (
 	"errors"
 
-	"github.com/golang/protobuf/protoapi"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
+	"github.com/golang/protobuf/v2/runtime/protoimpl"
 )
 
 // errNoMessageTypeID occurs when a protocol buffer does not have a message type ID.
@@ -118,7 +118,7 @@
 // unmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
 // It is called by Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
 func unmarshalMessageSet(buf []byte, exts interface{}) error {
-	m := protoapi.ExtensionFieldsOf(exts)
+	m := protoimpl.X.ExtensionFieldsOf(exts)
 
 	ms := new(messageSet)
 	if err := Unmarshal(buf, ms); err != nil {
diff --git a/proto/table_marshal.go b/proto/table_marshal.go
index aefee64..303c1ea 100644
--- a/proto/table_marshal.go
+++ b/proto/table_marshal.go
@@ -16,8 +16,8 @@
 	"sync/atomic"
 	"unicode/utf8"
 
-	"github.com/golang/protobuf/protoapi"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
+	"github.com/golang/protobuf/v2/runtime/protoimpl"
 )
 
 // a sizer takes a pointer to a field and the size of its tag, computes the size of
@@ -2366,7 +2366,7 @@
 
 // sizeExtensions computes the size of encoded data for a XXX_InternalExtensions field.
 func (u *marshalInfo) sizeExtensions(ext *XXX_InternalExtensions) int {
-	m := protoapi.ExtensionFieldsOf(ext)
+	m := protoimpl.X.ExtensionFieldsOf(ext)
 	if !m.HasInit() {
 		return 0
 	}
@@ -2395,7 +2395,7 @@
 
 // appendExtensions marshals a XXX_InternalExtensions field to the end of byte slice b.
 func (u *marshalInfo) appendExtensions(b []byte, ext *XXX_InternalExtensions, deterministic bool) ([]byte, error) {
-	m := protoapi.ExtensionFieldsOf(ext)
+	m := protoimpl.X.ExtensionFieldsOf(ext)
 	if !m.HasInit() {
 		return b, nil
 	}
@@ -2475,7 +2475,7 @@
 // sizeMessageSet computes the size of encoded data for a XXX_InternalExtensions field
 // in message set format (above).
 func (u *marshalInfo) sizeMessageSet(ext *XXX_InternalExtensions) int {
-	m := protoapi.ExtensionFieldsOf(ext)
+	m := protoimpl.X.ExtensionFieldsOf(ext)
 	if !m.HasInit() {
 		return 0
 	}
@@ -2511,7 +2511,7 @@
 // appendMessageSet marshals a XXX_InternalExtensions field in message set format (above)
 // to the end of byte slice b.
 func (u *marshalInfo) appendMessageSet(b []byte, ext *XXX_InternalExtensions, deterministic bool) ([]byte, error) {
-	m := protoapi.ExtensionFieldsOf(ext)
+	m := protoimpl.X.ExtensionFieldsOf(ext)
 	if !m.HasInit() {
 		return b, nil
 	}
diff --git a/proto/table_unmarshal.go b/proto/table_unmarshal.go
index 104f375..ae4395f 100644
--- a/proto/table_unmarshal.go
+++ b/proto/table_unmarshal.go
@@ -16,8 +16,8 @@
 	"sync/atomic"
 	"unicode/utf8"
 
-	"github.com/golang/protobuf/protoapi"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
+	"github.com/golang/protobuf/v2/runtime/protoimpl"
 )
 
 // Unmarshal is the entry point from the generated .pb.go files.
@@ -187,20 +187,20 @@
 		// Keep unrecognized data around.
 		// maybe in extensions, maybe in the unrecognized field.
 		z := m.offset(u.unrecognized).toBytes()
-		var emap protoapi.ExtensionFields
+		var emap extensionFields
 		var e Extension
 		for _, r := range u.extensionRanges {
 			if uint64(r.Start) <= tag && tag <= uint64(r.End) {
 				if u.extensions.IsValid() {
 					mp := m.offset(u.extensions).toExtensions()
-					emap = protoapi.ExtensionFieldsOf(mp)
+					emap = protoimpl.X.ExtensionFieldsOf(mp)
 					e = emap.Get(protoreflect.FieldNumber(tag))
 					z = &e.Raw
 					break
 				}
 				if u.oldExtensions.IsValid() {
 					p := m.offset(u.oldExtensions).toOldExtensions()
-					emap = protoapi.ExtensionFieldsOf(p)
+					emap = protoimpl.X.ExtensionFieldsOf(p)
 					e = emap.Get(protoreflect.FieldNumber(tag))
 					z = &e.Raw
 					break
diff --git a/proto/text.go b/proto/text.go
index ad0652b..dfd3e92 100644
--- a/proto/text.go
+++ b/proto/text.go
@@ -19,7 +19,6 @@
 	"sort"
 	"strings"
 
-	"github.com/golang/protobuf/protoapi"
 	"github.com/golang/protobuf/v2/reflect/protoreflect"
 )
 
@@ -817,7 +816,3 @@
 
 // CompactTextString is the same as CompactText, but returns the string directly.
 func CompactTextString(pb Message) string { return compactTextMarshaler.Text(pb) }
-
-func init() {
-	protoapi.CompactTextString = CompactTextString
-}
diff --git a/protoapi/api.go b/protoapi/api.go
deleted file mode 100644
index 1cae07b..0000000
--- a/protoapi/api.go
+++ /dev/null
@@ -1,242 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package protoapi contains the set of types referenced by generated messages.
-//
-// WARNING: This package should only ever be imported by generated messages.
-// The compatibility agreement covers nothing except for functionality needed
-// to keep existing generated messages operational.
-package protoapi
-
-import (
-	"fmt"
-	"sync"
-
-	"github.com/golang/protobuf/v2/reflect/protoreflect"
-)
-
-// TODO: How to handle Registration during the v1 to v2 switchover?
-
-type (
-	Message interface {
-		Reset()
-		String() string
-		ProtoMessage()
-	}
-
-	ExtensionRange struct {
-		Start, End int32 // both inclusive
-	}
-
-	ExtensionDesc struct {
-		// Type is the descriptor type for the extension field using the v2 API.
-		// If populated, the information in this field takes precedence over
-		// all other fields in ExtensionDesc.
-		Type protoreflect.ExtensionType
-
-		// ExtendedType is a typed nil-pointer to the parent message type that
-		// is being extended. It is possible for this to be unpopulated in v2
-		// since the message may no longer implement the v1 Message interface.
-		//
-		// Deprecated: Use Type.ExtendedType instead.
-		ExtendedType Message
-
-		// ExtensionType is zero value of the extension type.
-		//
-		// For historical reasons, reflect.TypeOf(ExtensionType) and Type.GoType
-		// may not be identical:
-		//	* for scalars (except []byte), where ExtensionType uses *T,
-		//	while Type.GoType uses T.
-		//	* for repeated fields, where ExtensionType uses []T,
-		//	while Type.GoType uses *[]T.
-		//
-		// Deprecated: Use Type.GoType instead.
-		ExtensionType interface{}
-
-		// Field is the field number of the extension.
-		//
-		// Deprecated: Use Type.Number instead.
-		Field int32 // field number
-
-		// Name is the fully qualified name of extension.
-		//
-		// Deprecated: Use Type.FullName instead.
-		Name string
-
-		// Tag is the protobuf struct tag used in the v1 API.
-		//
-		// Deprecated: Do not use.
-		Tag string
-
-		// Filename is the proto filename in which the extension is defined.
-		//
-		// Deprecated: Use Type.Parent to ascend to the top-most parent and use
-		// protoreflect.FileDescriptor.Path.
-		Filename string
-	}
-
-	ExtensionFields        extensionFields
-	ExtensionField         extensionField
-	XXX_InternalExtensions extensionSyncMap
-)
-
-// ExtensionFieldsOf returns an ExtensionFields abstraction over various
-// internal representations of extension fields.
-func ExtensionFieldsOf(p interface{}) ExtensionFields {
-	switch p := p.(type) {
-	case *map[int32]ExtensionField:
-		return (*extensionMap)(p)
-	case *XXX_InternalExtensions:
-		return (*extensionSyncMap)(p)
-	default:
-		panic(fmt.Sprintf("invalid extension fields type: %T", p))
-	}
-}
-
-type extensionFields interface {
-	Len() int
-	Has(protoreflect.FieldNumber) bool
-	Get(protoreflect.FieldNumber) ExtensionField
-	Set(protoreflect.FieldNumber, ExtensionField)
-	Clear(protoreflect.FieldNumber)
-	Range(f func(protoreflect.FieldNumber, ExtensionField) bool)
-
-	// HasInit and Locker are used by v1 GetExtension to provide
-	// an artificial degree of concurrent safety.
-	HasInit() bool
-	sync.Locker
-}
-
-type extensionField struct {
-	// When an extension is stored in a message using SetExtension
-	// only desc and value are set. When the message is marshaled
-	// Raw will be set to the encoded form of the message.
-	//
-	// When a message is unmarshaled and contains extensions, each
-	// extension will have only Raw set. When such an extension is
-	// accessed using GetExtension (or GetExtensions) desc and value
-	// will be set.
-	Desc *ExtensionDesc // TODO: switch to protoreflect.ExtensionType
-
-	// Value is a concrete value for the extension field. Let the type of
-	// Desc.ExtensionType be the "API type" and the type of Value be the
-	// "storage type". The API type and storage type are the same except:
-	//	* for scalars (except []byte), where the API type uses *T,
-	//	while the storage type uses T.
-	//	* for repeated fields, where the API type uses []T,
-	//	while the storage type uses *[]T.
-	//
-	// The reason for the divergence is so that the storage type more naturally
-	// matches what is expected of when retrieving the values through the
-	// protobuf reflection APIs.
-	//
-	// The Value may only be populated if Desc is also populated.
-	Value interface{} // TODO: switch to protoreflect.Value
-
-	// Raw is the raw encoded bytes for the extension field.
-	// It is possible for Raw to be populated irrespective of whether the
-	// other fields are populated.
-	Raw []byte // TODO: switch to protoreflect.RawFields
-}
-
-type extensionSyncMap struct {
-	p *struct {
-		mu sync.Mutex
-		m  extensionMap
-	}
-}
-
-func (m extensionSyncMap) Len() int {
-	if m.p == nil {
-		return 0
-	}
-	return m.p.m.Len()
-}
-func (m extensionSyncMap) Has(n protoreflect.FieldNumber) bool {
-	if m.p == nil {
-		return false
-	}
-	return m.p.m.Has(n)
-}
-func (m extensionSyncMap) Get(n protoreflect.FieldNumber) ExtensionField {
-	if m.p == nil {
-		return ExtensionField{}
-	}
-	return m.p.m.Get(n)
-}
-func (m *extensionSyncMap) Set(n protoreflect.FieldNumber, x ExtensionField) {
-	if m.p == nil {
-		m.p = new(struct {
-			mu sync.Mutex
-			m  extensionMap
-		})
-	}
-	m.p.m.Set(n, x)
-}
-func (m extensionSyncMap) Clear(n protoreflect.FieldNumber) {
-	if m.p == nil {
-		return
-	}
-	m.p.m.Clear(n)
-}
-func (m extensionSyncMap) Range(f func(protoreflect.FieldNumber, ExtensionField) bool) {
-	if m.p == nil {
-		return
-	}
-	m.p.m.Range(f)
-}
-
-func (m extensionSyncMap) HasInit() bool {
-	return m.p != nil
-}
-func (m extensionSyncMap) Lock() {
-	m.p.mu.Lock()
-}
-func (m extensionSyncMap) Unlock() {
-	m.p.mu.Unlock()
-}
-
-type extensionMap map[int32]ExtensionField
-
-func (m extensionMap) Len() int {
-	return len(m)
-}
-func (m extensionMap) Has(n protoreflect.FieldNumber) bool {
-	_, ok := m[int32(n)]
-	return ok
-}
-func (m extensionMap) Get(n protoreflect.FieldNumber) ExtensionField {
-	return m[int32(n)]
-}
-func (m *extensionMap) Set(n protoreflect.FieldNumber, x ExtensionField) {
-	if *m == nil {
-		*m = make(map[int32]ExtensionField)
-	}
-	(*m)[int32(n)] = x
-}
-func (m *extensionMap) Clear(n protoreflect.FieldNumber) {
-	delete(*m, int32(n))
-}
-func (m extensionMap) Range(f func(protoreflect.FieldNumber, ExtensionField) bool) {
-	for n, x := range m {
-		if !f(protoreflect.FieldNumber(n), x) {
-			return
-		}
-	}
-}
-
-var globalLock sync.Mutex
-
-func (m extensionMap) HasInit() bool {
-	return m != nil
-}
-func (m extensionMap) Lock() {
-	if !m.HasInit() {
-		panic("cannot lock an uninitialized map")
-	}
-	globalLock.Lock()
-}
-func (m extensionMap) Unlock() {
-	globalLock.Unlock()
-}
diff --git a/protoapi/impl.go b/protoapi/impl.go
deleted file mode 100644
index 460b592..0000000
--- a/protoapi/impl.go
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package protoapi
-
-import (
-	"encoding/binary"
-	"encoding/json"
-	"fmt"
-	"hash/crc32"
-	"math"
-	"strconv"
-)
-
-// TODO: Are these the final signatures that we want?
-
-// EnumName is a helper function to simplify printing protocol buffer enums
-// by name.  Given an enum map and a value, it returns a useful string.
-func EnumName(m map[int32]string, v int32) string {
-	s, ok := m[v]
-	if ok {
-		return s
-	}
-	return strconv.Itoa(int(v))
-}
-
-// UnmarshalJSONEnum is a helper function to simplify recovering enum int values
-// from their JSON-encoded representation. Given a map from the enum's symbolic
-// names to its int values, and a byte buffer containing the JSON-encoded
-// value, it returns an int32 that can be cast to the enum type by the caller.
-//
-// The function can deal with both JSON representations, numeric and symbolic.
-func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
-	if data[0] == '"' {
-		// New style: enums are strings.
-		var repr string
-		if err := json.Unmarshal(data, &repr); err != nil {
-			return -1, err
-		}
-		val, ok := m[repr]
-		if !ok {
-			return 0, fmt.Errorf("unrecognized enum %s value %q", enumName, repr)
-		}
-		return val, nil
-	}
-	// Old style: enums are ints.
-	var val int32
-	if err := json.Unmarshal(data, &val); err != nil {
-		return 0, fmt.Errorf("cannot unmarshal %#q into enum %s", data, enumName)
-	}
-	return val, nil
-}
-
-// CompressGZIP compresses the input as a GZIP-encoded file.
-// The current implementation does no compression.
-func CompressGZIP(in []byte) (out []byte) {
-	// RFC 1952, section 2.3.1.
-	var gzipHeader = [10]byte{0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff}
-
-	// RFC 1951, section 3.2.4.
-	var blockHeader [5]byte
-	const maxBlockSize = math.MaxUint16
-	numBlocks := 1 + len(in)/maxBlockSize
-
-	// RFC 1952, section 2.3.1.
-	var gzipFooter [8]byte
-	binary.LittleEndian.PutUint32(gzipFooter[0:4], crc32.ChecksumIEEE(in))
-	binary.LittleEndian.PutUint32(gzipFooter[4:8], uint32(len(in)))
-
-	// Encode the input without compression using raw DEFLATE blocks.
-	out = make([]byte, 0, len(gzipHeader)+len(blockHeader)*numBlocks+len(in)+len(gzipFooter))
-	out = append(out, gzipHeader[:]...)
-	for blockHeader[0] == 0 {
-		blockSize := maxBlockSize
-		if blockSize > len(in) {
-			blockHeader[0] = 0x01 // final bit per RFC 1951, section 3.2.3.
-			blockSize = len(in)
-		}
-		binary.LittleEndian.PutUint16(blockHeader[1:3], uint16(blockSize)^0x0000)
-		binary.LittleEndian.PutUint16(blockHeader[3:5], uint16(blockSize)^0xffff)
-		out = append(out, blockHeader[:]...)
-		out = append(out, in[:blockSize]...)
-		in = in[blockSize:]
-	}
-	out = append(out, gzipFooter[:]...)
-	return out
-}
-
-// TODO: Remove this when v2 textpb is available.
-var CompactTextString func(Message) string
diff --git a/protoapi/impl_test.go b/protoapi/impl_test.go
deleted file mode 100644
index bc73ed7..0000000
--- a/protoapi/impl_test.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package protoapi
-
-import (
-	"bytes"
-	"compress/gzip"
-	"io/ioutil"
-	"math"
-	"strings"
-	"testing"
-)
-
-func TestCompressGZIP(t *testing.T) {
-	tests := []string{
-		"",
-		"a",
-		"ab",
-		"abc",
-		strings.Repeat("a", math.MaxUint16-1),
-		strings.Repeat("b", math.MaxUint16),
-		strings.Repeat("c", math.MaxUint16+1),
-		strings.Repeat("abcdefghijklmnopqrstuvwxyz", math.MaxUint16-13),
-	}
-	for _, want := range tests {
-		rb := bytes.NewReader(CompressGZIP([]byte(want)))
-		zr, err := gzip.NewReader(rb)
-		if err != nil {
-			t.Errorf("unexpected gzip.NewReader error: %v", err)
-		}
-		b, err := ioutil.ReadAll(zr)
-		if err != nil {
-			t.Errorf("unexpected ioutil.ReadAll error: %v", err)
-		}
-		if got := string(b); got != want {
-			t.Errorf("output mismatch: got %q, want %q", got, want)
-		}
-	}
-}