internal/prototype: move from reflect/prototype

The prototype package was initially used by generated reflection support,
but has now been replaced by internal/fileinit.
Eventually, this functionality should be deleted and re-written in terms
of other components in the repo.

Usages that prototype currently provides (but should be moved) are:
* Constructing standalone messages and enums, which is behavior we should
provide in reflect/protodesc. The google.protobuf.{Enum,Type} are well-known
proto messages designed for this purpose.
* Constructing placeholder files, enums, and messages.
* Consructing protoreflect.{Message,Enum,Extension}Types, which are protobuf
descriptors with associated Go type information.

Change-Id: Id7dbefff952682781b439aa555508c59b2629f9e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167383
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2019-03-13 12:56:39 -07:00 committed by Joe Tsai
parent cf4f80a2cc
commit 990b9f5919
35 changed files with 23 additions and 20 deletions

View File

@ -27,7 +27,7 @@ const (
reflectPackage = protogen.GoImportPath("reflect")
protoimplPackage = protogen.GoImportPath("github.com/golang/protobuf/v2/runtime/protoimpl")
protoreflectPackage = protogen.GoImportPath("github.com/golang/protobuf/v2/reflect/protoreflect")
prototypePackage = protogen.GoImportPath("github.com/golang/protobuf/v2/reflect/prototype")
prototypePackage = protogen.GoImportPath("github.com/golang/protobuf/v2/internal/prototype")
)
// TODO: Add support for proto options.

View File

@ -40,7 +40,7 @@ func main() {
chdirRoot()
writeSource("internal/fileinit/desc_list_gen.go", generateFileinitDescList())
writeSource("proto/decode_gen.go", generateProtoDecode())
writeSource("reflect/prototype/protofile_list_gen.go", generateListTypes())
writeSource("internal/prototype/protofile_list_gen.go", generateListTypes())
}
// chdirRoot changes the working directory to the repository root.

View File

@ -19,9 +19,9 @@ import (
"github.com/golang/protobuf/v2/internal/encoding/pack"
"github.com/golang/protobuf/v2/internal/encoding/wire"
"github.com/golang/protobuf/v2/internal/prototype"
"github.com/golang/protobuf/v2/internal/scalar"
"github.com/golang/protobuf/v2/reflect/protoreflect"
"github.com/golang/protobuf/v2/reflect/prototype"
descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
)

View File

@ -12,8 +12,8 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
)
func TestFields(t *testing.T) {

View File

@ -11,8 +11,8 @@ import (
"math"
"testing"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
cmp "github.com/google/go-cmp/cmp"
)

View File

@ -12,9 +12,9 @@ import (
"strings"
defval "github.com/golang/protobuf/v2/internal/encoding/defval"
ptype "github.com/golang/protobuf/v2/internal/prototype"
scalar "github.com/golang/protobuf/v2/internal/scalar"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
)

View File

@ -8,8 +8,8 @@ import (
"reflect"
"testing"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)

View File

@ -14,10 +14,10 @@ import (
"sync"
pragma "github.com/golang/protobuf/v2/internal/pragma"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pfmt "github.com/golang/protobuf/v2/internal/typefmt"
"github.com/golang/protobuf/v2/proto"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
)
// FileBuilder construct a protoreflect.FileDescriptor from the

View File

@ -13,9 +13,9 @@ import (
defval "github.com/golang/protobuf/v2/internal/encoding/defval"
wire "github.com/golang/protobuf/v2/internal/encoding/wire"
pimpl "github.com/golang/protobuf/v2/internal/impl"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pvalue "github.com/golang/protobuf/v2/internal/value"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
)
func (file *fileDesc) lazyInit() *fileLazy {

View File

@ -5,8 +5,8 @@
package impl
import (
ptype "github.com/golang/protobuf/v2/internal/prototype"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
)
// Export is a zero-length named type that exists only to export a set of

View File

@ -14,9 +14,9 @@ import (
pack "github.com/golang/protobuf/v2/internal/encoding/pack"
pimpl "github.com/golang/protobuf/v2/internal/impl"
pragma "github.com/golang/protobuf/v2/internal/pragma"
ptype "github.com/golang/protobuf/v2/internal/prototype"
scalar "github.com/golang/protobuf/v2/internal/scalar"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
cmp "github.com/google/go-cmp/cmp"
cmpopts "github.com/google/go-cmp/cmp/cmpopts"

View File

@ -13,10 +13,10 @@ import (
protoV1 "github.com/golang/protobuf/proto"
pimpl "github.com/golang/protobuf/v2/internal/impl"
ptype "github.com/golang/protobuf/v2/internal/prototype"
scalar "github.com/golang/protobuf/v2/internal/scalar"
pvalue "github.com/golang/protobuf/v2/internal/value"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
cmp "github.com/google/go-cmp/cmp"
cmpopts "github.com/google/go-cmp/cmp/cmpopts"

View File

@ -10,9 +10,9 @@ import (
"reflect"
"sync"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pvalue "github.com/golang/protobuf/v2/internal/value"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
)

View File

@ -12,10 +12,10 @@ import (
papi "github.com/golang/protobuf/protoapi"
ptag "github.com/golang/protobuf/v2/internal/encoding/tag"
pimpl "github.com/golang/protobuf/v2/internal/impl"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pfmt "github.com/golang/protobuf/v2/internal/typefmt"
pvalue "github.com/golang/protobuf/v2/internal/value"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
)
// extensionDescKey is a comparable version of protoapi.ExtensionDesc

View File

@ -9,8 +9,8 @@ import (
papi "github.com/golang/protobuf/protoapi"
pimpl "github.com/golang/protobuf/v2/internal/impl"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
// The legacy package must be imported prior to use of any legacy messages.
// TODO: Remove this when protoV1 registers these hooks for you.

View File

@ -13,9 +13,9 @@ import (
ptag "github.com/golang/protobuf/v2/internal/encoding/tag"
pimpl "github.com/golang/protobuf/v2/internal/impl"
ptype "github.com/golang/protobuf/v2/internal/prototype"
scalar "github.com/golang/protobuf/v2/internal/scalar"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
)

View File

@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// TODO: Delete this package and re-write functionality to depend on
// reflect/protodesc and internal/fileinit.
// Package prototype provides builders to construct protobuf types that
// implement the interfaces defined in the protoreflect package.
//

View File

@ -14,10 +14,10 @@ import (
protoV1 "github.com/golang/protobuf/proto"
detrand "github.com/golang/protobuf/v2/internal/detrand"
ptype "github.com/golang/protobuf/v2/internal/prototype"
scalar "github.com/golang/protobuf/v2/internal/scalar"
pdesc "github.com/golang/protobuf/v2/reflect/protodesc"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
)

View File

@ -12,9 +12,9 @@ import (
"github.com/golang/protobuf/v2/internal/encoding/defval"
"github.com/golang/protobuf/v2/internal/errors"
"github.com/golang/protobuf/v2/internal/prototype"
"github.com/golang/protobuf/v2/reflect/protoreflect"
"github.com/golang/protobuf/v2/reflect/protoregistry"
"github.com/golang/protobuf/v2/reflect/prototype"
descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
)

View File

@ -14,9 +14,9 @@ import (
"github.com/golang/protobuf/protoapi"
"github.com/golang/protobuf/v2/internal/legacy"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pref "github.com/golang/protobuf/v2/reflect/protoreflect"
preg "github.com/golang/protobuf/v2/reflect/protoregistry"
ptype "github.com/golang/protobuf/v2/reflect/prototype"
testpb "github.com/golang/protobuf/v2/reflect/protoregistry/testprotos"
)

View File

@ -5,8 +5,8 @@ package descriptor_proto
import (
protoapi "github.com/golang/protobuf/protoapi"
prototype "github.com/golang/protobuf/v2/internal/prototype"
protoreflect "github.com/golang/protobuf/v2/reflect/protoreflect"
prototype "github.com/golang/protobuf/v2/reflect/prototype"
protoimpl "github.com/golang/protobuf/v2/runtime/protoimpl"
reflect "reflect"
)