cmd/protoc-gen-go: generate for v2-only dependencies
This removes yet another set of dependencies of v2 on v1.
The only remaining dependency are in the _test.go files,
primarily for proto.Equal.
Changes made:
* cmd/protoc-gen-go no longer generates any functionality that depends
on the v1 package, and instead only depends on v2.
* internal/fileinit.FileBuilder.MessageOutputTypes is switched from
protoreflect.MessageType to protoimpl.MessageType since the
implementation must be fully inialized before registration occurs.
* The test for internal/legacy/file_test.go is switched to a legacy_test
package to avoid a cyclic dependency.
This requires Load{Enum,Message,File}Desc to be exported.
Change-Id: I43e2fe64cff4eea204258ce11e791aca5eb6e569
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/169298
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/fileinit/desc.go b/internal/fileinit/desc.go
index e375e3f..73004d3 100644
--- a/internal/fileinit/desc.go
+++ b/internal/fileinit/desc.go
@@ -13,6 +13,7 @@
"reflect"
"sync"
+ pimpl "github.com/golang/protobuf/v2/internal/impl"
pragma "github.com/golang/protobuf/v2/internal/pragma"
ptype "github.com/golang/protobuf/v2/internal/prototype"
pfmt "github.com/golang/protobuf/v2/internal/typefmt"
@@ -110,7 +111,7 @@
// MessageOutputTypes is where Init stores all initialized message types
// in "flattened ordering". This includes slots for map entry messages,
// which are skipped over.
- MessageOutputTypes []pref.MessageType
+ MessageOutputTypes []pimpl.MessageType
// ExtensionOutputTypes is where Init stores all initialized extension types
// in "flattened ordering".
ExtensionOutputTypes []pref.ExtensionType
@@ -138,12 +139,19 @@
}
// Copy type descriptors to the output.
+ //
+ // While iterating over the messages, we also determine whether the message
+ // is a map entry type.
+ messageGoTypes := fb.GoTypes[len(fd.allEnums):][:len(fd.allMessages)]
for i := range fd.allEnums {
fb.EnumOutputTypes[i] = &fd.allEnums[i]
}
for i := range fd.allMessages {
- if mt, _ := fd.allMessages[i].asDesc().(pref.MessageType); mt != nil {
- fb.MessageOutputTypes[i] = mt
+ if messageGoTypes[i] == nil {
+ fd.allMessages[i].isMapEntry = true
+ } else {
+ fb.MessageOutputTypes[i].GoType = reflect.TypeOf(messageGoTypes[i])
+ fb.MessageOutputTypes[i].PBType = fd.allMessages[i].asDesc().(pref.MessageType)
}
}
for i := range fd.allExtensions {
diff --git a/internal/fileinit/desc_init.go b/internal/fileinit/desc_init.go
index d1310a4..f339b0d 100644
--- a/internal/fileinit/desc_init.go
+++ b/internal/fileinit/desc_init.go
@@ -19,13 +19,6 @@
file.initDecls(len(fb.EnumOutputTypes), len(fb.MessageOutputTypes), len(fb.ExtensionOutputTypes))
file.unmarshalSeed(fb.RawDescriptor)
- // Determine which message descriptors represent map entries based on the
- // lack of an associated Go type.
- messageDecls := file.GoTypes[len(file.allEnums):]
- for i := range file.allMessages {
- file.allMessages[i].isMapEntry = messageDecls[i] == nil
- }
-
// Extended message dependencies are eagerly handled since registration
// needs this information at program init time.
for i := range file.allExtensions {