all: remove weak field support

Weak fields were the predecessor to extensions (many many years ago) and were
entirely removed from Google’s production usage by now. (The corresponding field
in descriptor.proto was always documented as “// For Google-internal migration
only. Do not use.”)

Before this change, Go Protobuf still contained support for weak fields behind
the `protolegacy` build tag.

The `protolegacy` build tag was always documented as not being part of the
compatibility agreement:

// WARNING: The compatibility agreement covers nothing provided by this flag.
// As such, functionality may suddenly be removed or changed at our discretion.
const ProtoLegacy = protoLegacy

Fixes golang/protobuf#1666

Change-Id: Ie1675424bc80d9f44345ccb96a858ef847ee1018
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/641655
Reviewed-by: Chressie Himpel <chressie@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Stapelberg 2025-01-09 12:53:37 +01:00
parent 89b5638ae9
commit e677ef98d5
53 changed files with 828 additions and 2072 deletions

View File

@ -56,27 +56,11 @@ func TestAnnotations(t *testing.T) {
&descriptorpb.GeneratedCodeInfo_Annotation{ &descriptorpb.GeneratedCodeInfo_Annotation{
Path: []int32{int32(genid.FileDescriptorProto_MessageType_field_number), 0, int32(genid.DescriptorProto_Field_field_number), 0}, Path: []int32{int32(genid.FileDescriptorProto_MessageType_field_number), 0, int32(genid.DescriptorProto_Field_field_number), 0},
}, },
}, {
"\t", "XXX_weak_M", " ",
&descriptorpb.GeneratedCodeInfo_Annotation{
Path: []int32{int32(genid.FileDescriptorProto_MessageType_field_number), 0, int32(genid.DescriptorProto_Field_field_number), 1},
},
}, { }, {
"func (x *AnnotationsTestMessage) ", "GetAnnotationsTestField", "() string {", "func (x *AnnotationsTestMessage) ", "GetAnnotationsTestField", "() string {",
&descriptorpb.GeneratedCodeInfo_Annotation{ &descriptorpb.GeneratedCodeInfo_Annotation{
Path: []int32{int32(genid.FileDescriptorProto_MessageType_field_number), 0, int32(genid.DescriptorProto_Field_field_number), 0}, Path: []int32{int32(genid.FileDescriptorProto_MessageType_field_number), 0, int32(genid.DescriptorProto_Field_field_number), 0},
}, },
}, {
"func (x *AnnotationsTestMessage) ", "GetM", "() proto.Message {",
&descriptorpb.GeneratedCodeInfo_Annotation{
Path: []int32{int32(genid.FileDescriptorProto_MessageType_field_number), 0, int32(genid.DescriptorProto_Field_field_number), 1},
},
}, {
"func (x *AnnotationsTestMessage) ", "SetM", "(v proto.Message) {",
&descriptorpb.GeneratedCodeInfo_Annotation{
Path: []int32{int32(genid.FileDescriptorProto_MessageType_field_number), 0, int32(genid.DescriptorProto_Field_field_number), 1},
Semantic: descriptorpb.GeneratedCodeInfo_Annotation_SET.Enum(),
},
}} { }} {
s := want.prefix + want.text + want.suffix s := want.prefix + want.text + want.suffix
pos := bytes.Index(sourceFile, []byte(s)) pos := bytes.Index(sourceFile, []byte(s))

View File

@ -126,7 +126,6 @@ type messageInfo struct {
isTracked bool isTracked bool
noInterface bool noInterface bool
hasWeak bool
} }
func newMessageInfo(f *fileInfo, message *protogen.Message) *messageInfo { func newMessageInfo(f *fileInfo, message *protogen.Message) *messageInfo {
@ -134,9 +133,6 @@ func newMessageInfo(f *fileInfo, message *protogen.Message) *messageInfo {
m.genRawDescMethod = true m.genRawDescMethod = true
m.genExtRangeMethod = true m.genExtRangeMethod = true
m.isTracked = isTrackedMessage(m) m.isTracked = isTrackedMessage(m)
for _, field := range m.Fields {
m.hasWeak = m.hasWeak || field.Desc.IsWeak()
}
opaqueNewMessageInfoHook(f, m) opaqueNewMessageInfoHook(f, m)
return m return m
} }

View File

@ -215,12 +215,10 @@ func genImport(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, imp
// Don't generate imports or aliases for types in the same Go package. // Don't generate imports or aliases for types in the same Go package.
return return
} }
// Generate imports for all non-weak dependencies, even if they are not // Generate imports for all dependencies, even if they are not
// referenced, because other code and tools depend on having the // referenced, because other code and tools depend on having the
// full transitive closure of protocol buffer types in the binary. // full transitive closure of protocol buffer types in the binary.
if !imp.IsWeak {
g.Import(impFile.GoImportPath) g.Import(impFile.GoImportPath)
}
if !imp.IsPublic { if !imp.IsPublic {
return return
} }
@ -440,10 +438,6 @@ func genMessageInternalFields(g *protogen.GeneratedFile, f *fileInfo, m *message
sf.append(genid.State_goname) sf.append(genid.State_goname)
g.P(genid.SizeCache_goname, " ", protoimplPackage.Ident("SizeCache")) g.P(genid.SizeCache_goname, " ", protoimplPackage.Ident("SizeCache"))
sf.append(genid.SizeCache_goname) sf.append(genid.SizeCache_goname)
if m.hasWeak {
g.P(genid.WeakFields_goname, " ", protoimplPackage.Ident("WeakFields"))
sf.append(genid.WeakFields_goname)
}
g.P(genid.UnknownFields_goname, " ", protoimplPackage.Ident("UnknownFields")) g.P(genid.UnknownFields_goname, " ", protoimplPackage.Ident("UnknownFields"))
sf.append(genid.UnknownFields_goname) sf.append(genid.UnknownFields_goname)
if m.Desc.ExtensionRanges().Len() > 0 { if m.Desc.ExtensionRanges().Len() > 0 {
@ -508,9 +502,6 @@ func genMessageField(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, fie
} }
name := field.GoName name := field.GoName
if field.Desc.IsWeak() {
name = genid.WeakFieldPrefix_goname + name
}
g.AnnotateSymbol(m.GoIdent.GoName+"."+name, protogen.Annotation{Location: field.Location}) g.AnnotateSymbol(m.GoIdent.GoName+"."+name, protogen.Annotation{Location: field.Location})
leadingComments := appendDeprecationSuffix(field.Comments.Leading, leadingComments := appendDeprecationSuffix(field.Comments.Leading,
field.Desc.ParentFile(), field.Desc.ParentFile(),
@ -590,7 +581,6 @@ func genMessageDefaultDecls(g *protogen.GeneratedFile, f *fileInfo, m *messageIn
func genMessageMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo) { func genMessageMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo) {
genMessageBaseMethods(g, f, m) genMessageBaseMethods(g, f, m)
genMessageGetterMethods(g, f, m) genMessageGetterMethods(g, f, m)
genMessageSetterMethods(g, f, m)
} }
func genMessageBaseMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo) { func genMessageBaseMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo) {
@ -655,17 +645,6 @@ func genMessageGetterMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageI
field.Desc.ParentFile(), field.Desc.ParentFile(),
field.Desc.Options().(*descriptorpb.FieldOptions).GetDeprecated()) field.Desc.Options().(*descriptorpb.FieldOptions).GetDeprecated())
switch { switch {
case field.Desc.IsWeak():
g.P(leadingComments, "func (x *", m.GoIdent, ") Get", field.GoName, "() ", protoPackage.Ident("Message"), "{")
g.P("var w ", protoimplPackage.Ident("WeakFields"))
g.P("if x != nil {")
g.P("w = x.", genid.WeakFields_goname)
if m.isTracked {
g.P("_ = x.", genid.WeakFieldPrefix_goname+field.GoName)
}
g.P("}")
g.P("return ", protoimplPackage.Ident("X"), ".GetWeak(w, ", field.Desc.Number(), ", ", strconv.Quote(string(field.Message.Desc.FullName())), ")")
g.P("}")
case field.Oneof != nil && !field.Oneof.Desc.IsSynthetic(): case field.Oneof != nil && !field.Oneof.Desc.IsSynthetic():
g.P(leadingComments, "func (x *", m.GoIdent, ") Get", field.GoName, "() ", goType, " {") g.P(leadingComments, "func (x *", m.GoIdent, ") Get", field.GoName, "() ", goType, " {")
g.P("if x, ok := x.Get", field.Oneof.GoName, "().(*", field.GoIdent, "); ok {") g.P("if x, ok := x.Get", field.Oneof.GoName, "().(*", field.GoIdent, "); ok {")
@ -693,43 +672,10 @@ func genMessageGetterMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageI
} }
} }
func genMessageSetterMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo) {
for _, field := range m.Fields {
if !field.Desc.IsWeak() {
continue
}
genNoInterfacePragma(g, m.noInterface)
g.AnnotateSymbol(m.GoIdent.GoName+".Set"+field.GoName, protogen.Annotation{
Location: field.Location,
Semantic: descriptorpb.GeneratedCodeInfo_Annotation_SET.Enum(),
})
leadingComments := appendDeprecationSuffix("",
field.Desc.ParentFile(),
field.Desc.Options().(*descriptorpb.FieldOptions).GetDeprecated())
g.P(leadingComments, "func (x *", m.GoIdent, ") Set", field.GoName, "(v ", protoPackage.Ident("Message"), ") {")
g.P("var w *", protoimplPackage.Ident("WeakFields"))
g.P("if x != nil {")
g.P("w = &x.", genid.WeakFields_goname)
if m.isTracked {
g.P("_ = x.", genid.WeakFieldPrefix_goname+field.GoName)
}
g.P("}")
g.P(protoimplPackage.Ident("X"), ".SetWeak(w, ", field.Desc.Number(), ", ", strconv.Quote(string(field.Message.Desc.FullName())), ", v)")
g.P("}")
g.P()
}
}
// fieldGoType returns the Go type used for a field. // fieldGoType returns the Go type used for a field.
// //
// If it returns pointer=true, the struct field is a pointer to the type. // If it returns pointer=true, the struct field is a pointer to the type.
func fieldGoType(g *protogen.GeneratedFile, f *fileInfo, field *protogen.Field) (goType string, pointer bool) { func fieldGoType(g *protogen.GeneratedFile, f *fileInfo, field *protogen.Field) (goType string, pointer bool) {
if field.Desc.IsWeak() {
return "struct{}", false
}
pointer = field.Desc.HasPresence() pointer = field.Desc.HasPresence()
switch field.Desc.Kind() { switch field.Desc.Kind() {
case protoreflect.BoolKind: case protoreflect.BoolKind:

View File

@ -6,7 +6,6 @@ package internal_gengo
import ( import (
"fmt" "fmt"
"strconv"
"strings" "strings"
"unicode" "unicode"
"unicode/utf8" "unicode/utf8"
@ -109,14 +108,11 @@ func opaqueGenMessageField(g *protogen.GeneratedFile, f *fileInfo, message *mess
} }
name := field.GoName name := field.GoName
if field.Desc.IsWeak() { if message.isOpaque() {
g.P("// Deprecated: Do not use. This will be deleted in the near future.")
name = genid.WeakFieldPrefix_goname + name
} else if message.isOpaque() {
name = "xxx_hidden_" + name name = "xxx_hidden_" + name
} }
if message.isOpaque() && !field.Desc.IsWeak() { if message.isOpaque() {
g.P(name, " ", goType, tags) g.P(name, " ", goType, tags)
sf.append(name) sf.append(name)
if message.isTracked { if message.isTracked {
@ -205,10 +201,6 @@ func opaqueGenMessageInternalFields(g *protogen.GeneratedFile, f *fileInfo, mess
g.P("XXX_presence [", (opaqueNumPresenceFields(message)+31)/32, "]uint32") g.P("XXX_presence [", (opaqueNumPresenceFields(message)+31)/32, "]uint32")
sf.append("XXX_presence") sf.append("XXX_presence")
} }
if message.hasWeak {
g.P(genid.WeakFields_goname, " ", protoimplPackage.Ident("WeakFields"))
sf.append(genid.WeakFields_goname)
}
if message.Desc.ExtensionRanges().Len() > 0 { if message.Desc.ExtensionRanges().Len() > 0 {
g.P(genid.ExtensionFields_goname, " ", protoimplPackage.Ident("ExtensionFields")) g.P(genid.ExtensionFields_goname, " ", protoimplPackage.Ident("ExtensionFields"))
sf.append(genid.ExtensionFields_goname) sf.append(genid.ExtensionFields_goname)
@ -233,8 +225,8 @@ func opaqueGenMessageMethods(g *protogen.GeneratedFile, f *fileInfo, message *me
opaqueGenGet(g, f, message, field) opaqueGenGet(g, f, message, field)
} }
for _, field := range message.Fields { for _, field := range message.Fields {
// For the plain open mode, we only have set methods for weak fields. // For the plain open mode, we do not have setters.
if message.isOpen() && !field.Desc.IsWeak() { if message.isOpen() {
continue continue
} }
opaqueGenSet(g, f, message, field) opaqueGenSet(g, f, message, field)
@ -313,22 +305,6 @@ func opaqueGenGet(g *protogen.GeneratedFile, f *fileInfo, message *messageInfo,
fieldtrackNoInterface(g, message.isTracked) fieldtrackNoInterface(g, message.isTracked)
g.AnnotateSymbol(message.GoIdent.GoName+"."+getterName, protogen.Annotation{Location: field.Location}) g.AnnotateSymbol(message.GoIdent.GoName+"."+getterName, protogen.Annotation{Location: field.Location})
// Weak field.
if field.Desc.IsWeak() {
g.P(leadingComments, "func (x *", message.GoIdent, ") ", getterName, "() ", protoPackage.Ident("Message"), "{")
g.P("var w ", protoimplPackage.Ident("WeakFields"))
g.P("if x != nil {")
g.P("w = x.", genid.WeakFields_goname)
if message.isTracked {
g.P("_ = x.", genid.WeakFieldPrefix_goname+field.GoName)
}
g.P("}")
g.P("return ", protoimplPackage.Ident("X"), ".GetWeak(w, ", field.Desc.Number(), ", ", strconv.Quote(string(field.Message.Desc.FullName())), ")")
g.P("}")
g.P()
return
}
defaultValue := fieldDefaultValue(g, f, message, field) defaultValue := fieldDefaultValue(g, f, message, field)
// Oneof field. // Oneof field.
@ -485,22 +461,6 @@ func opaqueGenSet(g *protogen.GeneratedFile, f *fileInfo, message *messageInfo,
}) })
fieldtrackNoInterface(g, message.noInterface) fieldtrackNoInterface(g, message.noInterface)
// Weak field.
if field.Desc.IsWeak() {
g.P(leadingComments, "func (x *", message.GoIdent, ") ", setterName, "(v ", protoPackage.Ident("Message"), ") {")
g.P("var w *", protoimplPackage.Ident("WeakFields"))
g.P("if x != nil {")
g.P("w = &x.", genid.WeakFields_goname)
if message.isTracked {
g.P("_ = x.", genid.WeakFieldPrefix_goname+field.GoName)
}
g.P("}")
g.P(protoimplPackage.Ident("X"), ".SetWeak(w, ", field.Desc.Number(), ", ", strconv.Quote(string(field.Message.Desc.FullName())), ", v)")
g.P("}")
g.P()
return
}
// Oneof field. // Oneof field.
if oneof := field.Oneof; oneof != nil && !oneof.Desc.IsSynthetic() { if oneof := field.Oneof; oneof != nil && !oneof.Desc.IsSynthetic() {
g.P(leadingComments, "func (x *", message.GoIdent, ") ", setterName, "(v ", goType, ") {") g.P(leadingComments, "func (x *", message.GoIdent, ") ", setterName, "(v ", goType, ") {")
@ -610,7 +570,7 @@ func opaqueGenSet(g *protogen.GeneratedFile, f *fileInfo, message *messageInfo,
// is always true for lazy message types. It is also true for all scalar fields. // is always true for lazy message types. It is also true for all scalar fields.
// repeated, map or message fields are not using the presence map. // repeated, map or message fields are not using the presence map.
func usePresence(message *messageInfo, field *protogen.Field) bool { func usePresence(message *messageInfo, field *protogen.Field) bool {
if !message.isOpaque() || field.Desc.IsWeak() { if !message.isOpaque() {
return false return false
} }
return opaqueFieldNeedsPresenceArray(message, field) return opaqueFieldNeedsPresenceArray(message, field)
@ -635,22 +595,6 @@ func opaqueGenHas(g *protogen.GeneratedFile, f *fileInfo, message *messageInfo,
g.AnnotateSymbol(message.GoIdent.GoName+"."+hasserName, protogen.Annotation{Location: field.Location}) g.AnnotateSymbol(message.GoIdent.GoName+"."+hasserName, protogen.Annotation{Location: field.Location})
fieldtrackNoInterface(g, message.noInterface) fieldtrackNoInterface(g, message.noInterface)
// Weak field.
if field.Desc.IsWeak() {
g.P(leadingComments, "func (x *", message.GoIdent, ") ", hasserName, "() bool {")
g.P("var w ", protoimplPackage.Ident("WeakFields"))
g.P("if x != nil {")
g.P("w = x.", genid.WeakFields_goname)
if message.isTracked {
g.P("_ = x.", genid.WeakFieldPrefix_goname+field.GoName)
}
g.P("}")
g.P("return ", protoimplPackage.Ident("X"), ".HasWeak(w, ", field.Desc.Number(), ")")
g.P("}")
g.P()
return
}
// Oneof field. // Oneof field.
if oneof := field.Oneof; oneof != nil && !oneof.Desc.IsSynthetic() { if oneof := field.Oneof; oneof != nil && !oneof.Desc.IsSynthetic() {
g.P(leadingComments, "func (x *", message.GoIdent, ") ", hasserName, "() bool {") g.P(leadingComments, "func (x *", message.GoIdent, ") ", hasserName, "() bool {")
@ -719,22 +663,6 @@ func opaqueGenClear(g *protogen.GeneratedFile, f *fileInfo, message *messageInfo
}) })
fieldtrackNoInterface(g, message.noInterface) fieldtrackNoInterface(g, message.noInterface)
// Weak field.
if field.Desc.IsWeak() {
g.P(leadingComments, "func (x *", message.GoIdent, ") ", clearerName, "() {")
g.P("var w *", protoimplPackage.Ident("WeakFields"))
g.P("if x != nil {")
g.P("w = &x.", genid.WeakFields_goname)
if message.isTracked {
g.P("_ = x.", genid.WeakFieldPrefix_goname+field.GoName)
}
g.P("}")
g.P(protoimplPackage.Ident("X"), ".ClearWeak(w, ", field.Desc.Number(), ")")
g.P("}")
g.P()
return
}
// Oneof field. // Oneof field.
if oneof := field.Oneof; oneof != nil && !oneof.Desc.IsSynthetic() { if oneof := field.Oneof; oneof != nil && !oneof.Desc.IsSynthetic() {
g.P(leadingComments, "func (x *", message.GoIdent, ") ", clearerName, "() {") g.P(leadingComments, "func (x *", message.GoIdent, ") ", clearerName, "() {")
@ -937,9 +865,6 @@ func opaqueGenMessageBuilder(g *protogen.GeneratedFile, f *fileInfo, message *me
g.P() g.P()
for _, field := range message.Fields { for _, field := range message.Fields {
oneof := field.Oneof oneof := field.Oneof
if oneof == nil && field.Desc.IsWeak() {
continue
}
goType, pointer := opaqueBuilderFieldGoType(g, f, message, field) goType, pointer := opaqueBuilderFieldGoType(g, f, message, field)
if pointer { if pointer {
@ -1001,9 +926,6 @@ func opaqueGenBuildMethod(g *protogen.GeneratedFile, f *fileInfo, message *messa
for _, field := range message.Fields { for _, field := range message.Fields {
oneof := field.Oneof oneof := field.Oneof
if oneof == nil && field.Desc.IsWeak() {
continue
}
if oneof != nil && !oneof.Desc.IsSynthetic() { if oneof != nil && !oneof.Desc.IsSynthetic() {
qual := "" qual := ""
if fieldDefaultValue(g, f, message, field) != "nil" { if fieldDefaultValue(g, f, message, field) != "nil" {
@ -1136,10 +1058,6 @@ func opaqueGenOneofWrapperTypes(g *protogen.GeneratedFile, f *fileInfo, message
// //
// If it returns pointer=true, the struct field is a pointer to the type. // If it returns pointer=true, the struct field is a pointer to the type.
func opaqueFieldGoType(g *protogen.GeneratedFile, f *fileInfo, message *messageInfo, field *protogen.Field) (goType string, pointer bool) { func opaqueFieldGoType(g *protogen.GeneratedFile, f *fileInfo, message *messageInfo, field *protogen.Field) (goType string, pointer bool) {
if field.Desc.IsWeak() {
return "struct{}", false
}
pointer = true pointer = true
switch field.Desc.Kind() { switch field.Desc.Kind() {
case protoreflect.BoolKind: case protoreflect.BoolKind:

View File

@ -89,9 +89,6 @@ func genReflectFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f
depOffsets = append(depOffsets, offsetEntry{len(depIdxs), "field type_name"}) depOffsets = append(depOffsets, offsetEntry{len(depIdxs), "field type_name"})
for _, message := range f.allMessages { for _, message := range f.allMessages {
for _, field := range message.Fields { for _, field := range message.Fields {
if field.Desc.IsWeak() {
continue
}
source := string(field.Desc.FullName()) source := string(field.Desc.FullName())
genEnum(field.Enum, source+":type_name") genEnum(field.Enum, source+":type_name")
genMessage(field.Message, source+":type_name") genMessage(field.Message, source+":type_name")

View File

@ -8,7 +8,6 @@
package annotations package annotations
import ( import (
proto "google.golang.org/protobuf/proto"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect" reflect "reflect"
@ -72,9 +71,6 @@ func (AnnotationsTestEnum) EnumDescriptor() ([]byte, []int) {
type AnnotationsTestMessage struct { type AnnotationsTestMessage struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
AnnotationsTestField *string `protobuf:"bytes,1,opt,name=AnnotationsTestField" json:"AnnotationsTestField,omitempty"` AnnotationsTestField *string `protobuf:"bytes,1,opt,name=AnnotationsTestField" json:"AnnotationsTestField,omitempty"`
// Deprecated: Do not use. This will be deleted in the near future.
XXX_weak_M struct{} `protobuf:"bytes,2,opt,name=m,weak=fmt.M" json:"m,omitempty"`
weakFields protoimpl.WeakFields
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@ -116,22 +112,6 @@ func (x *AnnotationsTestMessage) GetAnnotationsTestField() string {
return "" return ""
} }
func (x *AnnotationsTestMessage) GetM() proto.Message {
var w protoimpl.WeakFields
if x != nil {
w = x.weakFields
}
return protoimpl.X.GetWeak(w, 2, "fmt.M")
}
func (x *AnnotationsTestMessage) SetM(v proto.Message) {
var w *protoimpl.WeakFields
if x != nil {
w = &x.weakFields
}
protoimpl.X.SetWeak(w, 2, "fmt.M", v)
}
var File_cmd_protoc_gen_go_testdata_annotations_annotations_proto protoreflect.FileDescriptor var File_cmd_protoc_gen_go_testdata_annotations_annotations_proto protoreflect.FileDescriptor
var file_cmd_protoc_gen_go_testdata_annotations_annotations_proto_rawDesc = string([]byte{ var file_cmd_protoc_gen_go_testdata_annotations_annotations_proto_rawDesc = string([]byte{
@ -140,24 +120,20 @@ var file_cmd_protoc_gen_go_testdata_annotations_annotations_proto_rawDesc = stri
0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1a, 0x67, 0x6f, 0x70, 0x72, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1a, 0x67, 0x6f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2e, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2e, 0x61, 0x6e, 0x6e, 0x6f, 0x74,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x2e, 0x63, 0x6d, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x4c, 0x0a, 0x16, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61,
0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x67, 0x6f, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61,
0x74, 0x61, 0x2f, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x2f, 0x66, 0x6d, 0x74, 0x2f, 0x6d,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x66, 0x0a, 0x16, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x73, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x12, 0x32, 0x0a, 0x14, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x54, 0x12, 0x32, 0x0a, 0x14, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x54,
0x65, 0x73, 0x74, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x65, 0x73, 0x74, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14,
0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x54, 0x65, 0x73, 0x74, 0x46, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x54, 0x65, 0x73, 0x74, 0x46,
0x69, 0x65, 0x6c, 0x64, 0x12, 0x18, 0x0a, 0x01, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x69, 0x65, 0x6c, 0x64, 0x2a, 0x36, 0x0a, 0x13, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69,
0x06, 0x2e, 0x66, 0x6d, 0x74, 0x2e, 0x4d, 0x42, 0x02, 0x50, 0x01, 0x52, 0x01, 0x6d, 0x2a, 0x36, 0x6f, 0x6e, 0x73, 0x54, 0x65, 0x73, 0x74, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x1f, 0x0a, 0x1b, 0x41,
0x0a, 0x13, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x54, 0x65, 0x73, 0x4e, 0x4e, 0x4f, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x53, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f,
0x74, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x1f, 0x0a, 0x1b, 0x41, 0x4e, 0x4e, 0x4f, 0x54, 0x41, 0x54, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x56, 0x41, 0x4c, 0x55, 0x45, 0x10, 0x00, 0x42, 0x43, 0x5a, 0x41,
0x49, 0x4f, 0x4e, 0x53, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x56, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72,
0x41, 0x4c, 0x55, 0x45, 0x10, 0x00, 0x42, 0x43, 0x5a, 0x41, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x70,
0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x67, 0x6f, 0x2f, 0x74, 0x65, 0x73,
0x6f, 0x62, 0x75, 0x66, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x74, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x67, 0x65, 0x6e, 0x2d, 0x67, 0x6f, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x73,
0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x58, 0x00,
}) })
var ( var (

View File

@ -1 +1 @@
annotation:{path:5 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:529 end:548} annotation:{path:5 path:0 path:2 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:565 end:612} annotation:{path:4 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:1971 end:1993} annotation:{path:4 path:0 path:2 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:2070 end:2090} annotation:{path:4 path:0 path:2 path:1 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:2273 end:2283} annotation:{path:4 path:0 path:2 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:3454 end:3477} annotation:{path:4 path:0 path:2 path:1 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:3620 end:3624} annotation:{path:4 path:0 path:2 path:1 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:3787 end:3791 semantic:SET} annotation:{path:5 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:487 end:506} annotation:{path:5 path:0 path:2 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:523 end:570} annotation:{path:4 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:1929 end:1951} annotation:{path:4 path:0 path:2 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:2028 end:2048} annotation:{path:4 path:0 path:2 path:0 source_file:"cmd/protoc-gen-go/testdata/annotations/annotations.proto" begin:3235 end:3258}

View File

@ -6,14 +6,10 @@ syntax = "proto2";
package goproto.protoc.annotations; package goproto.protoc.annotations;
import weak "cmd/protoc-gen-go/testdata/imports/fmt/m.proto";
option go_package = "google.golang.org/protobuf/cmd/protoc-gen-go/testdata/annotations"; option go_package = "google.golang.org/protobuf/cmd/protoc-gen-go/testdata/annotations";
message AnnotationsTestMessage { message AnnotationsTestMessage {
optional string AnnotationsTestField = 1; optional string AnnotationsTestField = 1;
optional fmt.M m = 2 [weak = true];
} }
enum AnnotationsTestEnum { enum AnnotationsTestEnum {

View File

@ -124,25 +124,6 @@ func (field *Field) getterName() (getter, compat string) {
// setterName returns the (possibly mangled) name of the generated Set method, // setterName returns the (possibly mangled) name of the generated Set method,
// along with the backwards-compatible name (if needed). // along with the backwards-compatible name (if needed).
func (field *Field) setterName() (setter, compat string) { func (field *Field) setterName() (setter, compat string) {
// TODO(b/359846588): remove weak field support?
if field.Desc.IsWeak() && field.Parent.APILevel != gofeaturespb.GoFeatures_API_OPAQUE {
switch field.Parent.APILevel {
case gofeaturespb.GoFeatures_API_OPEN:
return "Set" + field.GoName, ""
default:
var infix string
if field.hasConflictHybrid {
infix = "_"
}
orig := "Set" + infix + field.camelCase
mangled := "Set" + field.GoName
if mangled == orig {
mangled = ""
}
return orig, mangled
}
}
return field.methodName("Set"), "" return field.methodName("Set"), ""
} }

View File

@ -192,11 +192,6 @@ func (d decoder) unmarshalMessage(m protoreflect.Message, skipTypeURL bool) erro
fd = fieldDescs.ByTextName(name) fd = fieldDescs.ByTextName(name)
} }
} }
if flags.ProtoLegacyWeak {
if fd != nil && fd.IsWeak() && fd.Message().IsPlaceholder() {
fd = nil // reset since the weak reference is not linked in
}
}
if fd == nil { if fd == nil {
// Field is unknown. // Field is unknown.

View File

@ -16,7 +16,6 @@ import (
"google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/reflect/protoregistry"
testpb "google.golang.org/protobuf/internal/testprotos/test" testpb "google.golang.org/protobuf/internal/testprotos/test"
weakpb "google.golang.org/protobuf/internal/testprotos/test/weak1"
pb2 "google.golang.org/protobuf/internal/testprotos/textpb2" pb2 "google.golang.org/protobuf/internal/testprotos/textpb2"
pb3 "google.golang.org/protobuf/internal/testprotos/textpb3" pb3 "google.golang.org/protobuf/internal/testprotos/textpb3"
pbeditions "google.golang.org/protobuf/internal/testprotos/textpbeditions" pbeditions "google.golang.org/protobuf/internal/testprotos/textpbeditions"
@ -2675,22 +2674,6 @@ func TestUnmarshal(t *testing.T) {
10: 101, 10: 101,
}, },
}, },
}, {
desc: "weak fields",
inputMessage: &testpb.TestWeak{},
inputText: `{"weak_message1":{"a":1}}`,
wantMessage: func() *testpb.TestWeak {
m := new(testpb.TestWeak)
m.SetWeakMessage1(&weakpb.WeakImportMessage1{A: proto.Int32(1)})
return m
}(),
skip: !flags.ProtoLegacyWeak,
}, {
desc: "weak fields; unknown field",
inputMessage: &testpb.TestWeak{},
inputText: `{"weak_message1":{"a":1}, "weak_message2":{"a":1}}`,
wantErr: `unknown field "weak_message2"`, // weak_message2 is unknown since the package containing it is not imported
skip: !flags.ProtoLegacyWeak,
}, { }, {
desc: "just at recursion limit: nested messages", desc: "just at recursion limit: nested messages",
inputMessage: &testpb.TestAllTypes{}, inputMessage: &testpb.TestAllTypes{},

View File

@ -185,11 +185,6 @@ func (d decoder) unmarshalMessage(m protoreflect.Message, checkDelims bool) erro
} else if xtErr != nil && xtErr != protoregistry.NotFound { } else if xtErr != nil && xtErr != protoregistry.NotFound {
return d.newError(tok.Pos(), "unable to resolve [%s]: %v", tok.RawString(), xtErr) return d.newError(tok.Pos(), "unable to resolve [%s]: %v", tok.RawString(), xtErr)
} }
if flags.ProtoLegacyWeak {
if fd != nil && fd.IsWeak() && fd.Message().IsPlaceholder() {
fd = nil // reset since the weak reference is not linked in
}
}
// Handle unknown fields. // Handle unknown fields.
if fd == nil { if fd == nil {

View File

@ -16,8 +16,6 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/reflect/protoregistry"
testpb "google.golang.org/protobuf/internal/testprotos/test"
weakpb "google.golang.org/protobuf/internal/testprotos/test/weak1"
pb2 "google.golang.org/protobuf/internal/testprotos/textpb2" pb2 "google.golang.org/protobuf/internal/testprotos/textpb2"
pb3 "google.golang.org/protobuf/internal/testprotos/textpb3" pb3 "google.golang.org/protobuf/internal/testprotos/textpb3"
pbeditions "google.golang.org/protobuf/internal/testprotos/textpbeditions" pbeditions "google.golang.org/protobuf/internal/testprotos/textpbeditions"
@ -1616,22 +1614,6 @@ unknown: ""
type_url: "pb2.Nested" type_url: "pb2.Nested"
`, `,
wantErr: "(line 3:1): conflict with [pb2.Nested] field", wantErr: "(line 3:1): conflict with [pb2.Nested] field",
}, {
desc: "weak fields",
inputMessage: &testpb.TestWeak{},
inputText: `weak_message1:{a:1}`,
wantMessage: func() *testpb.TestWeak {
m := new(testpb.TestWeak)
m.SetWeakMessage1(&weakpb.WeakImportMessage1{A: proto.Int32(1)})
return m
}(),
skip: !flags.ProtoLegacyWeak,
}, {
desc: "weak fields; unknown field",
inputMessage: &testpb.TestWeak{},
inputText: `weak_message1:{a:1} weak_message2:{a:1}`,
wantErr: "unknown field: weak_message2", // weak_message2 is unknown since the package containing it is not imported
skip: !flags.ProtoLegacyWeak,
}} }}
for _, msg := range makeMessages(protobuild.Message{}, for _, msg := range makeMessages(protobuild.Message{},

View File

@ -26,7 +26,7 @@ var byteType = reflect.TypeOf(byte(0))
// The type is the underlying field type (e.g., a repeated field may be // The type is the underlying field type (e.g., a repeated field may be
// represented by []T, but the Go type passed in is just T). // represented by []T, but the Go type passed in is just T).
// A list of enum value descriptors must be provided for enum fields. // A list of enum value descriptors must be provided for enum fields.
// This does not populate the Enum or Message (except for weak message). // This does not populate the Enum or Message.
// //
// This function is a best effort attempt; parsing errors are ignored. // This function is a best effort attempt; parsing errors are ignored.
func Unmarshal(tag string, goType reflect.Type, evs protoreflect.EnumValueDescriptors) protoreflect.FieldDescriptor { func Unmarshal(tag string, goType reflect.Type, evs protoreflect.EnumValueDescriptors) protoreflect.FieldDescriptor {
@ -109,9 +109,6 @@ func Unmarshal(tag string, goType reflect.Type, evs protoreflect.EnumValueDescri
} }
case s == "packed": case s == "packed":
f.L1.EditionFeatures.IsPacked = true f.L1.EditionFeatures.IsPacked = true
case strings.HasPrefix(s, "weak="):
f.L1.IsWeak = true
f.L1.Message = filedesc.PlaceholderMessage(protoreflect.FullName(s[len("weak="):]))
case strings.HasPrefix(s, "def="): case strings.HasPrefix(s, "def="):
// The default tag is special in that everything afterwards is the // The default tag is special in that everything afterwards is the
// default regardless of the presence of commas. // default regardless of the presence of commas.
@ -183,9 +180,6 @@ func Marshal(fd protoreflect.FieldDescriptor, enumName string) string {
// the exact same semantics from the previous generator. // the exact same semantics from the previous generator.
tag = append(tag, "json="+jsonName) tag = append(tag, "json="+jsonName)
} }
if fd.IsWeak() {
tag = append(tag, "weak="+string(fd.Message().FullName()))
}
// The previous implementation does not tag extension fields as proto3, // The previous implementation does not tag extension fields as proto3,
// even when the field is defined in a proto3 file. Match that behavior // even when the field is defined in a proto3 file. Match that behavior
// for consistency. // for consistency.

View File

@ -15,7 +15,6 @@ import (
"google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoreflect"
testpb "google.golang.org/protobuf/internal/testprotos/test" testpb "google.golang.org/protobuf/internal/testprotos/test"
_ "google.golang.org/protobuf/internal/testprotos/test/weak1"
"google.golang.org/protobuf/types/descriptorpb" "google.golang.org/protobuf/types/descriptorpb"
) )
@ -57,6 +56,8 @@ func TestInit(t *testing.T) {
descPkg.Append("FileDescriptorProto.edition"): true, descPkg.Append("FileDescriptorProto.edition"): true,
descPkg.Append("FileDescriptorProto.edition_enum"): true, descPkg.Append("FileDescriptorProto.edition_enum"): true,
descPkg.Append("FileDescriptorProto.edition_deprecated"): true, descPkg.Append("FileDescriptorProto.edition_deprecated"): true,
// Support for weak fields has been removed.
descPkg.Append("FileDescriptorProto.weak_dependency"): true,
// Impossible to test proto3 optional in a proto2 file. // Impossible to test proto3 optional in a proto2 file.
descPkg.Append("FieldDescriptorProto.proto3_optional"): true, descPkg.Append("FieldDescriptorProto.proto3_optional"): true,
@ -111,29 +112,3 @@ func visitFields(m protoreflect.Message, f func(protoreflect.FieldDescriptor)) {
return true return true
}) })
} }
func TestWeakInit(t *testing.T) {
// We do not expect to get a placeholder since weak1 is imported.
fd1 := testFile.Messages().ByName("TestWeak").Fields().ByName("weak_message1")
if got, want := fd1.IsWeak(), true; got != want {
t.Errorf("field %v: IsWeak() = %v, want %v", fd1.FullName(), got, want)
}
if got, want := fd1.Message().IsPlaceholder(), false; got != want {
t.Errorf("field %v: Message.IsPlaceholder() = %v, want %v", fd1.FullName(), got, want)
}
if got, want := fd1.Message().Fields().Len(), 1; got != want {
t.Errorf("field %v: Message().Fields().Len() == %d, want %d", fd1.FullName(), got, want)
}
// We do expect to get a placeholder since weak2 is not imported.
fd2 := testFile.Messages().ByName("TestWeak").Fields().ByName("weak_message2")
if got, want := fd2.IsWeak(), true; got != want {
t.Errorf("field %v: IsWeak() = %v, want %v", fd2.FullName(), got, want)
}
if got, want := fd2.Message().IsPlaceholder(), true; got != want {
t.Errorf("field %v: Message.IsPlaceholder() = %v, want %v", fd2.FullName(), got, want)
}
if got, want := fd2.Message().Fields().Len(), 0; got != want {
t.Errorf("field %v: Message().Fields().Len() == %d, want %d", fd2.FullName(), got, want)
}
}

View File

@ -19,7 +19,6 @@ import (
"google.golang.org/protobuf/internal/pragma" "google.golang.org/protobuf/internal/pragma"
"google.golang.org/protobuf/internal/strs" "google.golang.org/protobuf/internal/strs"
"google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
) )
// Edition is an Enum for proto2.Edition // Edition is an Enum for proto2.Edition
@ -275,7 +274,6 @@ type (
Kind protoreflect.Kind Kind protoreflect.Kind
StringName stringName StringName stringName
IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto
IsWeak bool // promoted from google.protobuf.FieldOptions
IsLazy bool // promoted from google.protobuf.FieldOptions IsLazy bool // promoted from google.protobuf.FieldOptions
Default defaultValue Default defaultValue
ContainingOneof protoreflect.OneofDescriptor // must be consistent with Message.Oneofs.Fields ContainingOneof protoreflect.OneofDescriptor // must be consistent with Message.Oneofs.Fields
@ -369,7 +367,7 @@ func (fd *Field) IsPacked() bool {
return fd.L1.EditionFeatures.IsPacked return fd.L1.EditionFeatures.IsPacked
} }
func (fd *Field) IsExtension() bool { return false } func (fd *Field) IsExtension() bool { return false }
func (fd *Field) IsWeak() bool { return fd.L1.IsWeak } func (fd *Field) IsWeak() bool { return false }
func (fd *Field) IsLazy() bool { return fd.L1.IsLazy } func (fd *Field) IsLazy() bool { return fd.L1.IsLazy }
func (fd *Field) IsList() bool { return fd.Cardinality() == protoreflect.Repeated && !fd.IsMap() } func (fd *Field) IsList() bool { return fd.Cardinality() == protoreflect.Repeated && !fd.IsMap() }
func (fd *Field) IsMap() bool { return fd.Message() != nil && fd.Message().IsMapEntry() } func (fd *Field) IsMap() bool { return fd.Message() != nil && fd.Message().IsMapEntry() }
@ -396,11 +394,6 @@ func (fd *Field) Enum() protoreflect.EnumDescriptor {
return fd.L1.Enum return fd.L1.Enum
} }
func (fd *Field) Message() protoreflect.MessageDescriptor { func (fd *Field) Message() protoreflect.MessageDescriptor {
if fd.L1.IsWeak {
if d, _ := protoregistry.GlobalFiles.FindDescriptorByName(fd.L1.Message.FullName()); d != nil {
return d.(protoreflect.MessageDescriptor)
}
}
return fd.L1.Message return fd.L1.Message
} }
func (fd *Field) IsMapEntry() bool { func (fd *Field) IsMapEntry() bool {

View File

@ -32,11 +32,6 @@ func (file *File) resolveMessages() {
for j := range md.L2.Fields.List { for j := range md.L2.Fields.List {
fd := &md.L2.Fields.List[j] fd := &md.L2.Fields.List[j]
// Weak fields are resolved upon actual use.
if fd.L1.IsWeak {
continue
}
// Resolve message field dependency. // Resolve message field dependency.
switch fd.L1.Kind { switch fd.L1.Kind {
case protoreflect.EnumKind: case protoreflect.EnumKind:
@ -150,8 +145,6 @@ func (fd *File) unmarshalFull(b []byte) {
switch num { switch num {
case genid.FileDescriptorProto_PublicDependency_field_number: case genid.FileDescriptorProto_PublicDependency_field_number:
fd.L2.Imports[v].IsPublic = true fd.L2.Imports[v].IsPublic = true
case genid.FileDescriptorProto_WeakDependency_field_number:
fd.L2.Imports[v].IsWeak = true
} }
case protowire.BytesType: case protowire.BytesType:
v, m := protowire.ConsumeBytes(b) v, m := protowire.ConsumeBytes(b)
@ -502,8 +495,6 @@ func (fd *Field) unmarshalOptions(b []byte) {
switch num { switch num {
case genid.FieldOptions_Packed_field_number: case genid.FieldOptions_Packed_field_number:
fd.L1.EditionFeatures.IsPacked = protowire.DecodeBool(v) fd.L1.EditionFeatures.IsPacked = protowire.DecodeBool(v)
case genid.FieldOptions_Weak_field_number:
fd.L1.IsWeak = protowire.DecodeBool(v)
case genid.FieldOptions_Lazy_field_number: case genid.FieldOptions_Lazy_field_number:
fd.L1.IsLazy = protowire.DecodeBool(v) fd.L1.IsLazy = protowire.DecodeBool(v)
case FieldOptions_EnforceUTF8: case FieldOptions_EnforceUTF8:

View File

@ -63,7 +63,7 @@ type Builder struct {
// message declarations in "flattened ordering". // message declarations in "flattened ordering".
// //
// Dependencies are Go types for enums or messages referenced by // Dependencies are Go types for enums or messages referenced by
// message fields (excluding weak fields), for parent extended messages of // message fields, for parent extended messages of
// extension fields, for enums or messages referenced by extension fields, // extension fields, for enums or messages referenced by extension fields,
// and for input and output messages referenced by service methods. // and for input and output messages referenced by service methods.
// Dependencies must come after declarations, but the ordering of // Dependencies must come after declarations, but the ordering of

View File

@ -6,7 +6,7 @@
package flags package flags
// ProtoLegacy specifies whether to enable support for legacy functionality // ProtoLegacy specifies whether to enable support for legacy functionality
// such as MessageSets, weak fields, and various other obscure behavior // such as MessageSets, and various other obscure behavior
// that is necessary to maintain backwards compatibility with proto1 or // that is necessary to maintain backwards compatibility with proto1 or
// the pre-release variants of proto2 and proto3. // the pre-release variants of proto2 and proto3.
// //
@ -22,8 +22,3 @@ const ProtoLegacy = protoLegacy
// extension fields at unmarshal time, but defers creating the message // extension fields at unmarshal time, but defers creating the message
// structure until the extension is first accessed. // structure until the extension is first accessed.
const LazyUnmarshalExtensions = ProtoLegacy const LazyUnmarshalExtensions = ProtoLegacy
// ProtoLegacyWeak specifies whether to enable support for weak fields.
// This flag was split out of ProtoLegacy in preparation for removing
// support for weak fields (independent of the other protolegacy features).
const ProtoLegacyWeak = ProtoLegacy

View File

@ -11,15 +11,10 @@ const (
SizeCache_goname = "sizeCache" SizeCache_goname = "sizeCache"
SizeCacheA_goname = "XXX_sizecache" SizeCacheA_goname = "XXX_sizecache"
WeakFields_goname = "weakFields"
WeakFieldsA_goname = "XXX_weak"
UnknownFields_goname = "unknownFields" UnknownFields_goname = "unknownFields"
UnknownFieldsA_goname = "XXX_unrecognized" UnknownFieldsA_goname = "XXX_unrecognized"
ExtensionFields_goname = "extensionFields" ExtensionFields_goname = "extensionFields"
ExtensionFieldsA_goname = "XXX_InternalExtensions" ExtensionFieldsA_goname = "XXX_InternalExtensions"
ExtensionFieldsB_goname = "XXX_extensions" ExtensionFieldsB_goname = "XXX_extensions"
WeakFieldPrefix_goname = "XXX_weak_"
) )

View File

@ -5,15 +5,12 @@
package impl package impl
import ( import (
"fmt"
"reflect" "reflect"
"sync"
"google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/errors" "google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/runtime/protoiface" "google.golang.org/protobuf/runtime/protoiface"
) )
@ -121,78 +118,6 @@ func (mi *MessageInfo) initOneofFieldCoders(od protoreflect.OneofDescriptor, si
} }
} }
func makeWeakMessageFieldCoder(fd protoreflect.FieldDescriptor) pointerCoderFuncs {
var once sync.Once
var messageType protoreflect.MessageType
lazyInit := func() {
once.Do(func() {
messageName := fd.Message().FullName()
messageType, _ = protoregistry.GlobalTypes.FindMessageByName(messageName)
})
}
return pointerCoderFuncs{
size: func(p pointer, f *coderFieldInfo, opts marshalOptions) int {
m, ok := p.WeakFields().get(f.num)
if !ok {
return 0
}
lazyInit()
if messageType == nil {
panic(fmt.Sprintf("weak message %v is not linked in", fd.Message().FullName()))
}
return sizeMessage(m, f.tagsize, opts)
},
marshal: func(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
m, ok := p.WeakFields().get(f.num)
if !ok {
return b, nil
}
lazyInit()
if messageType == nil {
panic(fmt.Sprintf("weak message %v is not linked in", fd.Message().FullName()))
}
return appendMessage(b, m, f.wiretag, opts)
},
unmarshal: func(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (unmarshalOutput, error) {
fs := p.WeakFields()
m, ok := fs.get(f.num)
if !ok {
lazyInit()
if messageType == nil {
return unmarshalOutput{}, errUnknown
}
m = messageType.New().Interface()
fs.set(f.num, m)
}
return consumeMessage(b, m, wtyp, opts)
},
isInit: func(p pointer, f *coderFieldInfo) error {
m, ok := p.WeakFields().get(f.num)
if !ok {
return nil
}
return proto.CheckInitialized(m)
},
merge: func(dst, src pointer, f *coderFieldInfo, opts mergeOptions) {
sm, ok := src.WeakFields().get(f.num)
if !ok {
return
}
dm, ok := dst.WeakFields().get(f.num)
if !ok {
lazyInit()
if messageType == nil {
panic(fmt.Sprintf("weak message %v is not linked in", fd.Message().FullName()))
}
dm = messageType.New().Interface()
dst.WeakFields().set(f.num, dm)
}
opts.Merge(dm, sm)
},
}
}
func makeMessageFieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) pointerCoderFuncs { func makeMessageFieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) pointerCoderFuncs {
if mi := getMessageInfo(ft); mi != nil { if mi := getMessageInfo(ft); mi != nil {
funcs := pointerCoderFuncs{ funcs := pointerCoderFuncs{

View File

@ -119,9 +119,6 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
} }
case isOneof: case isOneof:
fieldOffset = offsetOf(fs) fieldOffset = offsetOf(fs)
case fd.IsWeak():
fieldOffset = si.weakOffset
funcs = makeWeakMessageFieldCoder(fd)
default: default:
fieldOffset = offsetOf(fs) fieldOffset = offsetOf(fs)
childMessage, funcs = fieldCoder(fd, ft) childMessage, funcs = fieldCoder(fd, ft)

View File

@ -46,9 +46,6 @@ func (mi *MessageInfo) makeOpaqueCoderMethods(t reflect.Type, si opaqueStructInf
switch { switch {
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic(): case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
fieldOffset = offsetOf(fs) fieldOffset = offsetOf(fs)
case fd.IsWeak():
fieldOffset = si.weakOffset
funcs = makeWeakMessageFieldCoder(fd)
case fd.Message() != nil && !fd.IsMap(): case fd.Message() != nil && !fd.IsMap():
fieldOffset = offsetOf(fs) fieldOffset = offsetOf(fs)
if fd.IsList() { if fd.IsList() {

View File

@ -131,7 +131,7 @@ func (mi *MessageInfo) skipField(b []byte, f *coderFieldInfo, wtyp protowire.Typ
fmi := f.validation.mi fmi := f.validation.mi
if fmi == nil { if fmi == nil {
fd := mi.Desc.Fields().ByNumber(f.num) fd := mi.Desc.Fields().ByNumber(f.num)
if fd == nil || !fd.IsWeak() { if fd == nil {
return out, ValidationUnknown return out, ValidationUnknown
} }
messageName := fd.Message().FullName() messageName := fd.Message().FullName()

View File

@ -310,12 +310,9 @@ func aberrantAppendField(md *filedesc.Message, goType reflect.Type, tag, tagKey,
fd.L0.Parent = md fd.L0.Parent = md
fd.L0.Index = n fd.L0.Index = n
if fd.L1.IsWeak || fd.L1.EditionFeatures.IsPacked { if fd.L1.EditionFeatures.IsPacked {
fd.L1.Options = func() protoreflect.ProtoMessage { fd.L1.Options = func() protoreflect.ProtoMessage {
opts := descopts.Field.ProtoReflect().New() opts := descopts.Field.ProtoReflect().New()
if fd.L1.IsWeak {
opts.Set(opts.Descriptor().Fields().ByName("weak"), protoreflect.ValueOfBool(true))
}
if fd.L1.EditionFeatures.IsPacked { if fd.L1.EditionFeatures.IsPacked {
opts.Set(opts.Descriptor().Fields().ByName("packed"), protoreflect.ValueOfBool(fd.L1.EditionFeatures.IsPacked)) opts.Set(opts.Descriptor().Fields().ByName("packed"), protoreflect.ValueOfBool(fd.L1.EditionFeatures.IsPacked))
} }

View File

@ -14,7 +14,6 @@ import (
"google.golang.org/protobuf/internal/genid" "google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
) )
// MessageInfo provides protobuf related functionality for a given Go type // MessageInfo provides protobuf related functionality for a given Go type
@ -120,7 +119,6 @@ type (
var ( var (
sizecacheType = reflect.TypeOf(SizeCache(0)) sizecacheType = reflect.TypeOf(SizeCache(0))
weakFieldsType = reflect.TypeOf(WeakFields(nil))
unknownFieldsAType = reflect.TypeOf(unknownFieldsA(nil)) unknownFieldsAType = reflect.TypeOf(unknownFieldsA(nil))
unknownFieldsBType = reflect.TypeOf(unknownFieldsB(nil)) unknownFieldsBType = reflect.TypeOf(unknownFieldsB(nil))
extensionFieldsType = reflect.TypeOf(ExtensionFields(nil)) extensionFieldsType = reflect.TypeOf(ExtensionFields(nil))
@ -129,8 +127,6 @@ var (
type structInfo struct { type structInfo struct {
sizecacheOffset offset sizecacheOffset offset
sizecacheType reflect.Type sizecacheType reflect.Type
weakOffset offset
weakType reflect.Type
unknownOffset offset unknownOffset offset
unknownType reflect.Type unknownType reflect.Type
extensionOffset offset extensionOffset offset
@ -148,7 +144,6 @@ type structInfo struct {
func (mi *MessageInfo) makeStructInfo(t reflect.Type) structInfo { func (mi *MessageInfo) makeStructInfo(t reflect.Type) structInfo {
si := structInfo{ si := structInfo{
sizecacheOffset: invalidOffset, sizecacheOffset: invalidOffset,
weakOffset: invalidOffset,
unknownOffset: invalidOffset, unknownOffset: invalidOffset,
extensionOffset: invalidOffset, extensionOffset: invalidOffset,
lazyOffset: invalidOffset, lazyOffset: invalidOffset,
@ -168,11 +163,6 @@ fieldLoop:
si.sizecacheOffset = offsetOf(f) si.sizecacheOffset = offsetOf(f)
si.sizecacheType = f.Type si.sizecacheType = f.Type
} }
case genid.WeakFields_goname, genid.WeakFieldsA_goname:
if f.Type == weakFieldsType {
si.weakOffset = offsetOf(f)
si.weakType = f.Type
}
case genid.UnknownFields_goname, genid.UnknownFieldsA_goname: case genid.UnknownFields_goname, genid.UnknownFieldsA_goname:
if f.Type == unknownFieldsAType || f.Type == unknownFieldsBType { if f.Type == unknownFieldsAType || f.Type == unknownFieldsBType {
si.unknownOffset = offsetOf(f) si.unknownOffset = offsetOf(f)
@ -256,9 +246,6 @@ func (mi *MessageInfo) Message(i int) protoreflect.MessageType {
mi.init() mi.init()
fd := mi.Desc.Fields().Get(i) fd := mi.Desc.Fields().Get(i)
switch { switch {
case fd.IsWeak():
mt, _ := protoregistry.GlobalTypes.FindMessageByName(fd.Message().FullName())
return mt
case fd.IsMap(): case fd.IsMap():
return mapEntryType{fd.Message(), mi.fieldTypes[fd.Number()]} return mapEntryType{fd.Message(), mi.fieldTypes[fd.Number()]}
default: default:

View File

@ -56,9 +56,6 @@ func opaqueInitHook(mi *MessageInfo) bool {
usePresence, _ := usePresenceForField(si, fd) usePresence, _ := usePresenceForField(si, fd)
switch { switch {
case fd.IsWeak():
// Weak fields are no different for opaque.
fi = fieldInfoForWeakMessage(fd, si.weakOffset)
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic(): case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
// Oneofs are no different for opaque. // Oneofs are no different for opaque.
fi = fieldInfoForOneof(fd, si.oneofsByName[fd.ContainingOneof().Name()], mi.Exporter, si.oneofWrappersByNumber[fd.Number()]) fi = fieldInfoForOneof(fd, si.oneofsByName[fd.ContainingOneof().Name()], mi.Exporter, si.oneofWrappersByNumber[fd.Number()])
@ -620,8 +617,6 @@ func usePresenceForField(si opaqueStructInfo, fd protoreflect.FieldDescriptor) (
switch { switch {
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic(): case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
return false, false return false, false
case fd.IsWeak():
return false, false
case fd.IsMap(): case fd.IsMap():
return false, false return false, false
case fd.Kind() == protoreflect.MessageKind || fd.Kind() == protoreflect.GroupKind: case fd.Kind() == protoreflect.MessageKind || fd.Kind() == protoreflect.GroupKind:

View File

@ -72,8 +72,6 @@ func (mi *MessageInfo) makeKnownFieldsFunc(si structInfo) {
fi = fieldInfoForMap(fd, fs, mi.Exporter) fi = fieldInfoForMap(fd, fs, mi.Exporter)
case fd.IsList(): case fd.IsList():
fi = fieldInfoForList(fd, fs, mi.Exporter) fi = fieldInfoForList(fd, fs, mi.Exporter)
case fd.IsWeak():
fi = fieldInfoForWeakMessage(fd, si.weakOffset)
case fd.Message() != nil: case fd.Message() != nil:
fi = fieldInfoForMessage(fd, fs, mi.Exporter) fi = fieldInfoForMessage(fd, fs, mi.Exporter)
default: default:
@ -219,9 +217,6 @@ func (mi *MessageInfo) makeFieldTypes(si structInfo) {
} }
case fd.Message() != nil: case fd.Message() != nil:
ft = fs.Type ft = fs.Type
if fd.IsWeak() {
ft = nil
}
isMessage = true isMessage = true
} }
if isMessage && ft != nil && ft.Kind() != reflect.Ptr { if isMessage && ft != nil && ft.Kind() != reflect.Ptr {

View File

@ -8,11 +8,8 @@ import (
"fmt" "fmt"
"math" "math"
"reflect" "reflect"
"sync"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
) )
type fieldInfo struct { type fieldInfo struct {
@ -332,79 +329,6 @@ func fieldInfoForScalar(fd protoreflect.FieldDescriptor, fs reflect.StructField,
} }
} }
func fieldInfoForWeakMessage(fd protoreflect.FieldDescriptor, weakOffset offset) fieldInfo {
if !flags.ProtoLegacyWeak {
panic("no support for proto1 weak fields")
}
var once sync.Once
var messageType protoreflect.MessageType
lazyInit := func() {
once.Do(func() {
messageName := fd.Message().FullName()
messageType, _ = protoregistry.GlobalTypes.FindMessageByName(messageName)
if messageType == nil {
panic(fmt.Sprintf("weak message %v for field %v is not linked in", messageName, fd.FullName()))
}
})
}
num := fd.Number()
return fieldInfo{
fieldDesc: fd,
has: func(p pointer) bool {
if p.IsNil() {
return false
}
_, ok := p.Apply(weakOffset).WeakFields().get(num)
return ok
},
clear: func(p pointer) {
p.Apply(weakOffset).WeakFields().clear(num)
},
get: func(p pointer) protoreflect.Value {
lazyInit()
if p.IsNil() {
return protoreflect.ValueOfMessage(messageType.Zero())
}
m, ok := p.Apply(weakOffset).WeakFields().get(num)
if !ok {
return protoreflect.ValueOfMessage(messageType.Zero())
}
return protoreflect.ValueOfMessage(m.ProtoReflect())
},
set: func(p pointer, v protoreflect.Value) {
lazyInit()
m := v.Message()
if m.Descriptor() != messageType.Descriptor() {
if got, want := m.Descriptor().FullName(), messageType.Descriptor().FullName(); got != want {
panic(fmt.Sprintf("field %v has mismatching message descriptor: got %v, want %v", fd.FullName(), got, want))
}
panic(fmt.Sprintf("field %v has mismatching message descriptor: %v", fd.FullName(), m.Descriptor().FullName()))
}
p.Apply(weakOffset).WeakFields().set(num, m.Interface())
},
mutable: func(p pointer) protoreflect.Value {
lazyInit()
fs := p.Apply(weakOffset).WeakFields()
m, ok := fs.get(num)
if !ok {
m = messageType.New().Interface()
fs.set(num, m)
}
return protoreflect.ValueOfMessage(m.ProtoReflect())
},
newMessage: func() protoreflect.Message {
lazyInit()
return messageType.New()
},
newField: func() protoreflect.Value {
lazyInit()
return protoreflect.ValueOfMessage(messageType.New())
},
}
}
func fieldInfoForMessage(fd protoreflect.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo { func fieldInfoForMessage(fd protoreflect.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
ft := fs.Type ft := fs.Type
conv := NewConverter(ft, fd) conv := NewConverter(ft, fd)

View File

@ -111,7 +111,6 @@ func (p pointer) StringSlice() *[]string { return (*[]string)(p.p
func (p pointer) Bytes() *[]byte { return (*[]byte)(p.p) } func (p pointer) Bytes() *[]byte { return (*[]byte)(p.p) }
func (p pointer) BytesPtr() **[]byte { return (**[]byte)(p.p) } func (p pointer) BytesPtr() **[]byte { return (**[]byte)(p.p) }
func (p pointer) BytesSlice() *[][]byte { return (*[][]byte)(p.p) } func (p pointer) BytesSlice() *[][]byte { return (*[][]byte)(p.p) }
func (p pointer) WeakFields() *weakFields { return (*weakFields)(p.p) }
func (p pointer) Extensions() *map[int32]ExtensionField { return (*map[int32]ExtensionField)(p.p) } func (p pointer) Extensions() *map[int32]ExtensionField { return (*map[int32]ExtensionField)(p.p) }
func (p pointer) LazyInfoPtr() **protolazy.XXX_lazyUnmarshalInfo { func (p pointer) LazyInfoPtr() **protolazy.XXX_lazyUnmarshalInfo {
return (**protolazy.XXX_lazyUnmarshalInfo)(p.p) return (**protolazy.XXX_lazyUnmarshalInfo)(p.p)

View File

@ -211,9 +211,7 @@ func newValidationInfo(fd protoreflect.FieldDescriptor, ft reflect.Type) validat
switch fd.Kind() { switch fd.Kind() {
case protoreflect.MessageKind: case protoreflect.MessageKind:
vi.typ = validationTypeMessage vi.typ = validationTypeMessage
if !fd.IsWeak() {
vi.mi = getMessageInfo(ft) vi.mi = getMessageInfo(ft)
}
case protoreflect.GroupKind: case protoreflect.GroupKind:
vi.typ = validationTypeGroup vi.typ = validationTypeGroup
vi.mi = getMessageInfo(ft) vi.mi = getMessageInfo(ft)
@ -320,26 +318,6 @@ State:
} }
if f != nil { if f != nil {
vi = f.validation vi = f.validation
if vi.typ == validationTypeMessage && vi.mi == nil {
// Probable weak field.
//
// TODO: Consider storing the results of this lookup somewhere
// rather than recomputing it on every validation.
fd := st.mi.Desc.Fields().ByNumber(num)
if fd == nil || !fd.IsWeak() {
break
}
messageName := fd.Message().FullName()
messageType, err := protoregistry.GlobalTypes.FindMessageByName(messageName)
switch err {
case nil:
vi.mi, _ = messageType.(*MessageInfo)
case protoregistry.NotFound:
vi.typ = validationTypeBytes
default:
return out, ValidationUnknown
}
}
break break
} }
// Possible extension field. // Possible extension field.

View File

@ -1,74 +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 impl
import (
"fmt"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
// weakFields adds methods to the exported WeakFields type for internal use.
//
// The exported type is an alias to an unnamed type, so methods can't be
// defined directly on it.
type weakFields WeakFields
func (w weakFields) get(num protoreflect.FieldNumber) (protoreflect.ProtoMessage, bool) {
m, ok := w[int32(num)]
return m, ok
}
func (w *weakFields) set(num protoreflect.FieldNumber, m protoreflect.ProtoMessage) {
if *w == nil {
*w = make(weakFields)
}
(*w)[int32(num)] = m
}
func (w *weakFields) clear(num protoreflect.FieldNumber) {
delete(*w, int32(num))
}
func (Export) HasWeak(w WeakFields, num protoreflect.FieldNumber) bool {
_, ok := w[int32(num)]
return ok
}
func (Export) ClearWeak(w *WeakFields, num protoreflect.FieldNumber) {
delete(*w, int32(num))
}
func (Export) GetWeak(w WeakFields, num protoreflect.FieldNumber, name protoreflect.FullName) protoreflect.ProtoMessage {
if m, ok := w[int32(num)]; ok {
return m
}
mt, _ := protoregistry.GlobalTypes.FindMessageByName(name)
if mt == nil {
panic(fmt.Sprintf("message %v for weak field is not linked in", name))
}
return mt.Zero().Interface()
}
func (Export) SetWeak(w *WeakFields, num protoreflect.FieldNumber, name protoreflect.FullName, m protoreflect.ProtoMessage) {
if m != nil {
mt, _ := protoregistry.GlobalTypes.FindMessageByName(name)
if mt == nil {
panic(fmt.Sprintf("message %v for weak field is not linked in", name))
}
if mt != m.ProtoReflect().Type() {
panic(fmt.Sprintf("invalid message type for weak field: got %T, want %T", m, mt.Zero().Interface()))
}
}
if m == nil || !m.ProtoReflect().IsValid() {
delete(*w, int32(num))
return
}
if *w == nil {
*w = make(weakFields)
}
(*w)[int32(num)] = m
}

View File

@ -10,7 +10,6 @@ package fieldtrack
import ( import (
_ "google.golang.org/protobuf/internal/testprotos/annotation" _ "google.golang.org/protobuf/internal/testprotos/annotation"
test "google.golang.org/protobuf/internal/testprotos/test" test "google.golang.org/protobuf/internal/testprotos/test"
proto "google.golang.org/protobuf/proto"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect" reflect "reflect"
@ -71,11 +70,6 @@ type TestFieldTrack struct {
MapStringBytes map[string][]byte `protobuf:"bytes,55,rep,name=map_string_bytes,json=mapStringBytes" json:"map_string_bytes,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value" go:"track"` MapStringBytes map[string][]byte `protobuf:"bytes,55,rep,name=map_string_bytes,json=mapStringBytes" json:"map_string_bytes,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value" go:"track"`
MapStringEnum map[string]test.TestAllTypes_NestedEnum `protobuf:"bytes,56,rep,name=map_string_enum,json=mapStringEnum" json:"map_string_enum,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value,enum=goproto.proto.test.TestAllTypes_NestedEnum" go:"track"` MapStringEnum map[string]test.TestAllTypes_NestedEnum `protobuf:"bytes,56,rep,name=map_string_enum,json=mapStringEnum" json:"map_string_enum,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value,enum=goproto.proto.test.TestAllTypes_NestedEnum" go:"track"`
MapStringMessage map[string]*test.TestAllTypes_NestedMessage `protobuf:"bytes,57,rep,name=map_string_message,json=mapStringMessage" json:"map_string_message,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value" go:"track"` MapStringMessage map[string]*test.TestAllTypes_NestedMessage `protobuf:"bytes,57,rep,name=map_string_message,json=mapStringMessage" json:"map_string_message,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value" go:"track"`
// Deprecated: Do not use. This will be deleted in the near future.
XXX_weak_WeakMessage1 struct{} `protobuf:"bytes,100,opt,name=weak_message1,json=weakMessage1,weak=goproto.proto.test.weak.WeakImportMessage1" json:"weak_message1,omitempty" go:"track"`
// Deprecated: Do not use. This will be deleted in the near future.
XXX_weak_WeakMessage2 struct{} `protobuf:"bytes,101,opt,name=weak_message2,json=weakMessage2,weak=goproto.proto.test.weak.WeakImportMessage2" json:"weak_message2,omitempty" go:"track"`
weakFields protoimpl.WeakFields
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@ -518,44 +512,6 @@ func (x *TestFieldTrack) GetMapStringMessage() map[string]*test.TestAllTypes_Nes
return nil return nil
} }
//go:nointerface
func (x *TestFieldTrack) GetWeakMessage1() proto.Message {
var w protoimpl.WeakFields
if x != nil {
w = x.weakFields
_ = x.XXX_weak_WeakMessage1
}
return protoimpl.X.GetWeak(w, 100, "goproto.proto.test.weak.WeakImportMessage1")
}
//go:nointerface
func (x *TestFieldTrack) GetWeakMessage2() proto.Message {
var w protoimpl.WeakFields
if x != nil {
w = x.weakFields
_ = x.XXX_weak_WeakMessage2
}
return protoimpl.X.GetWeak(w, 101, "goproto.proto.test.weak.WeakImportMessage2")
}
func (x *TestFieldTrack) SetWeakMessage1(v proto.Message) {
var w *protoimpl.WeakFields
if x != nil {
w = &x.weakFields
_ = x.XXX_weak_WeakMessage1
}
protoimpl.X.SetWeak(w, 100, "goproto.proto.test.weak.WeakImportMessage1", v)
}
func (x *TestFieldTrack) SetWeakMessage2(v proto.Message) {
var w *protoimpl.WeakFields
if x != nil {
w = &x.weakFields
_ = x.XXX_weak_WeakMessage2
}
protoimpl.X.SetWeak(w, 101, "goproto.proto.test.weak.WeakImportMessage2", v)
}
var File_internal_testprotos_fieldtrack_fieldtrack_proto protoreflect.FileDescriptor var File_internal_testprotos_fieldtrack_fieldtrack_proto protoreflect.FileDescriptor
var file_internal_testprotos_fieldtrack_fieldtrack_proto_rawDesc = string([]byte{ var file_internal_testprotos_fieldtrack_fieldtrack_proto_rawDesc = string([]byte{
@ -563,18 +519,12 @@ var file_internal_testprotos_fieldtrack_fieldtrack_proto_rawDesc = string([]byte
0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x74, 0x72, 0x61, 0x63, 0x6b,
0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x12, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x6f, 0x12, 0x12, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x2e, 0x74, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f,
0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f,
0x77, 0x65, 0x61, 0x6b, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x77, 0x65, 0x61, 0x6b, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f,
0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f,
0x77, 0x65, 0x61, 0x6b, 0x32, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x77, 0x65, 0x61, 0x6b, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f,
0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x23, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x23, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c,
0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74,
0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xfe, 0x24, 0x0a, 0x0e, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd2, 0x23, 0x0a, 0x0e,
0x54, 0x65, 0x73, 0x74, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x12, 0x25, 0x54, 0x65, 0x73, 0x74, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x12, 0x25,
0x0a, 0x0e, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x5f, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x0a, 0x0e, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x5f, 0x69, 0x6e, 0x74, 0x33, 0x32,
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c,
@ -781,100 +731,89 @@ var file_internal_testprotos_fieldtrack_fieldtrack_proto_rawDesc = string([]byte
0x74, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x74, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x54, 0x72, 0x61, 0x63, 0x6b,
0x2e, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x2e, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x10, 0x6d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x10, 0x6d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e,
0x67, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x54, 0x0a, 0x0d, 0x77, 0x65, 0x61, 0x6b, 0x67, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x41, 0x0a, 0x13, 0x4d, 0x61, 0x70, 0x53,
0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x31, 0x18, 0x64, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x49, 0x6e, 0x74, 0x33, 0x32, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12,
0x2b, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65,
0x74, 0x65, 0x73, 0x74, 0x2e, 0x77, 0x65, 0x61, 0x6b, 0x2e, 0x57, 0x65, 0x61, 0x6b, 0x49, 0x6d, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05,
0x70, 0x6f, 0x72, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x31, 0x42, 0x02, 0x50, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x41, 0x0a, 0x13, 0x4d,
0x52, 0x0c, 0x77, 0x65, 0x61, 0x6b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x31, 0x12, 0x54, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x49, 0x6e, 0x74, 0x36, 0x34, 0x45, 0x6e, 0x74,
0x0a, 0x0d, 0x77, 0x65, 0x61, 0x6b, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x18,
0x65, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x77, 0x65, 0x61, 0x6b, 0x2e,
0x57, 0x65, 0x61, 0x6b, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x32, 0x42, 0x02, 0x50, 0x01, 0x52, 0x0c, 0x77, 0x65, 0x61, 0x6b, 0x4d, 0x65, 0x73, 0x73,
0x61, 0x67, 0x65, 0x32, 0x1a, 0x41, 0x0a, 0x13, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e,
0x67, 0x49, 0x6e, 0x74, 0x33, 0x32, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b,
0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x41, 0x0a, 0x13, 0x4d, 0x61, 0x70, 0x53, 0x74,
0x72, 0x69, 0x6e, 0x67, 0x49, 0x6e, 0x74, 0x36, 0x34, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10,
0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79,
0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61,
0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x45, 0x6e, 0x74,
0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20,
0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42,
0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55, 0x69, 0x6e, 0x74, 0x36, 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55, 0x69, 0x6e, 0x74, 0x33,
0x34, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x32, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02,
0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55,
0x69, 0x6e, 0x74, 0x33, 0x32, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65,
0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05,
0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x11, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x76, 0x61, 0x6c,
0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72,
0x69, 0x6e, 0x67, 0x53, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x69, 0x6e, 0x67, 0x53, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10,
0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79,
0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x12, 0x52, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x11, 0x52,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x43, 0x0a, 0x15, 0x4d, 0x61, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61,
0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x46, 0x69, 0x78, 0x65, 0x64, 0x33, 0x32, 0x45, 0x6e, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x45, 0x6e, 0x74,
0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20,
0x20, 0x01, 0x28, 0x07, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x01, 0x28, 0x12, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x43,
0x43, 0x0a, 0x15, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x46, 0x69, 0x78, 0x65, 0x0a, 0x15, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x46, 0x69, 0x78, 0x65, 0x64,
0x33, 0x32, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c,
0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x07, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a,
0x02, 0x38, 0x01, 0x1a, 0x43, 0x0a, 0x15, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67,
0x46, 0x69, 0x78, 0x65, 0x64, 0x36, 0x34, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14,
0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x06, 0x52, 0x05, 0x76,
0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x44, 0x0a, 0x16, 0x4d, 0x61, 0x70, 0x53,
0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x66, 0x69, 0x78, 0x65, 0x64, 0x33, 0x32, 0x45, 0x6e, 0x74,
0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20,
0x01, 0x28, 0x0f, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x44,
0x0a, 0x16, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x66, 0x69, 0x78, 0x65,
0x64, 0x36, 0x34, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x64, 0x36, 0x34, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x06, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x10, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x3a, 0x02, 0x38, 0x01, 0x1a, 0x44, 0x0a, 0x16, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x41, 0x0a, 0x13, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e,
0x67, 0x53, 0x66, 0x69, 0x78, 0x65, 0x64, 0x33, 0x32, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x67, 0x46, 0x6c, 0x6f, 0x61, 0x74, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b,
0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79,
0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0f, 0x52,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x44, 0x0a, 0x16, 0x4d, 0x61,
0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x66, 0x69, 0x78, 0x65, 0x64, 0x36, 0x34, 0x45,
0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18,
0x02, 0x20, 0x01, 0x28, 0x10, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01,
0x1a, 0x41, 0x0a, 0x13, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x46, 0x6c, 0x6f,
0x61, 0x74, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c,
0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a,
0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67,
0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b,
0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x40, 0x0a, 0x12, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74,
0x72, 0x69, 0x6e, 0x67, 0x42, 0x6f, 0x6f, 0x6c, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x72, 0x69, 0x6e, 0x67, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12,
0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65,
0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01,
0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x40, 0x0a, 0x12, 0x4d,
0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x42, 0x6f, 0x6f, 0x6c, 0x45, 0x6e, 0x74, 0x72,
0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x41, 0x0a, 0x28, 0x08, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a,
0x13, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x42, 0x79, 0x74, 0x65, 0x73, 0x45, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67,
0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01,
0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38,
0x1a, 0x6d, 0x0a, 0x12, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x45, 0x6e, 0x75, 0x01, 0x1a, 0x41, 0x0a, 0x13, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x42, 0x79,
0x6d, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x74, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x41, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2b, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x65, 0x73, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x6d, 0x0a, 0x12, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e,
0x74, 0x41, 0x6c, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x67, 0x45, 0x6e, 0x75, 0x6d, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65,
0x45, 0x6e, 0x75, 0x6d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x41, 0x0a, 0x05,
0x73, 0x0a, 0x15, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x65, 0x73, 0x73, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2b, 0x2e, 0x67, 0x6f,
0x61, 0x67, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x65, 0x73, 0x74,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x44, 0x0a, 0x05, 0x76, 0x61, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x4e, 0x65,
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x73, 0x74, 0x65, 0x64, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a,
0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x02, 0x38, 0x01, 0x1a, 0x73, 0x0a, 0x15, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67,
0x65, 0x73, 0x74, 0x41, 0x6c, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x4e, 0x65, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x44,
0x3a, 0x02, 0x38, 0x01, 0x3a, 0x06, 0xa8, 0xe0, 0xcd, 0x8e, 0x01, 0x01, 0x42, 0x3b, 0x5a, 0x39, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2e, 0x2e,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x65,
0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x73, 0x74, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x6c, 0x54, 0x79, 0x70, 0x65, 0x73, 0x2e,
0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x66, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x05, 0x76,
0x69, 0x65, 0x6c, 0x64, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x58, 0x00, 0x58, 0x01, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x3a, 0x06, 0xa8, 0xe0, 0xcd, 0x8e, 0x01, 0x01,
0x42, 0x3b, 0x5a, 0x39, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e,
0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x69,
0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x73, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x74, 0x72, 0x61, 0x63, 0x6b,
}) })
var ( var (

View File

@ -6,9 +6,6 @@ syntax = "proto2";
package goproto.proto.test; package goproto.proto.test;
import weak "internal/testprotos/test/weak1/test_weak.proto";
import weak "internal/testprotos/test/weak2/test_weak.proto";
import "internal/testprotos/annotation/annotation.proto"; import "internal/testprotos/annotation/annotation.proto";
import "internal/testprotos/test/test.proto"; import "internal/testprotos/test/test.proto";
@ -71,9 +68,4 @@ message TestFieldTrack {
map<string, goproto.proto.test.TestAllTypes.NestedEnum> map_string_enum = 56; map<string, goproto.proto.test.TestAllTypes.NestedEnum> map_string_enum = 56;
map<string, goproto.proto.test.TestAllTypes.NestedMessage> map<string, goproto.proto.test.TestAllTypes.NestedMessage>
map_string_message = 57; map_string_message = 57;
optional goproto.proto.test.weak.WeakImportMessage1 weak_message1 = 100
[weak = true];
optional goproto.proto.test.weak.WeakImportMessage2 weak_message2 = 101
[weak = true];
} }

File diff suppressed because it is too large Load Diff

View File

@ -8,9 +8,6 @@ package goproto.proto.test;
import public "internal/testprotos/test/test_public.proto"; import public "internal/testprotos/test/test_public.proto";
import weak "internal/testprotos/test/weak1/test_weak.proto";
import weak "internal/testprotos/test/weak2/test_weak.proto";
import "internal/testprotos/enums/enums.proto"; import "internal/testprotos/enums/enums.proto";
import "internal/testprotos/required/required.proto"; import "internal/testprotos/required/required.proto";
import "internal/testprotos/test/test_import.proto"; import "internal/testprotos/test/test_import.proto";
@ -402,13 +399,6 @@ message TestRequiredLazy {
optional TestRequired optional_lazy_message = 1 [lazy = true]; optional TestRequired optional_lazy_message = 1 [lazy = true];
} }
message TestWeak {
optional goproto.proto.test.weak.WeakImportMessage1 weak_message1 = 1
[weak = true];
optional goproto.proto.test.weak.WeakImportMessage2 weak_message2 = 2
[weak = true];
}
message TestPackedTypes { message TestPackedTypes {
repeated int32 packed_int32 = 90 [packed = true]; repeated int32 packed_int32 = 90 [packed = true];
repeated int64 packed_int64 = 91 [packed = true]; repeated int64 packed_int64 = 91 [packed = true];

View File

@ -1,124 +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.
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: internal/testprotos/test/weak1/test_weak.proto
package weak1
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
type WeakImportMessage1 struct {
state protoimpl.MessageState `protogen:"open.v1"`
A *int32 `protobuf:"varint,1,req,name=a" json:"a,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *WeakImportMessage1) Reset() {
*x = WeakImportMessage1{}
mi := &file_internal_testprotos_test_weak1_test_weak_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *WeakImportMessage1) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*WeakImportMessage1) ProtoMessage() {}
func (x *WeakImportMessage1) ProtoReflect() protoreflect.Message {
mi := &file_internal_testprotos_test_weak1_test_weak_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use WeakImportMessage1.ProtoReflect.Descriptor instead.
func (*WeakImportMessage1) Descriptor() ([]byte, []int) {
return file_internal_testprotos_test_weak1_test_weak_proto_rawDescGZIP(), []int{0}
}
func (x *WeakImportMessage1) GetA() int32 {
if x != nil && x.A != nil {
return *x.A
}
return 0
}
var File_internal_testprotos_test_weak1_test_weak_proto protoreflect.FileDescriptor
var file_internal_testprotos_test_weak1_test_weak_proto_rawDesc = string([]byte{
0x0a, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x77, 0x65, 0x61, 0x6b, 0x31,
0x2f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x77, 0x65, 0x61, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x12, 0x17, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x74, 0x65, 0x73, 0x74, 0x2e, 0x77, 0x65, 0x61, 0x6b, 0x22, 0x22, 0x0a, 0x12, 0x57, 0x65, 0x61,
0x6b, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x31, 0x12,
0x0c, 0x0a, 0x01, 0x61, 0x18, 0x01, 0x20, 0x02, 0x28, 0x05, 0x52, 0x01, 0x61, 0x42, 0x3b, 0x5a,
0x39, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f,
0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x69, 0x6e, 0x74, 0x65,
0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f,
0x74, 0x65, 0x73, 0x74, 0x2f, 0x77, 0x65, 0x61, 0x6b, 0x31,
})
var (
file_internal_testprotos_test_weak1_test_weak_proto_rawDescOnce sync.Once
file_internal_testprotos_test_weak1_test_weak_proto_rawDescData []byte
)
func file_internal_testprotos_test_weak1_test_weak_proto_rawDescGZIP() []byte {
file_internal_testprotos_test_weak1_test_weak_proto_rawDescOnce.Do(func() {
file_internal_testprotos_test_weak1_test_weak_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_internal_testprotos_test_weak1_test_weak_proto_rawDesc), len(file_internal_testprotos_test_weak1_test_weak_proto_rawDesc)))
})
return file_internal_testprotos_test_weak1_test_weak_proto_rawDescData
}
var file_internal_testprotos_test_weak1_test_weak_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_internal_testprotos_test_weak1_test_weak_proto_goTypes = []any{
(*WeakImportMessage1)(nil), // 0: goproto.proto.test.weak.WeakImportMessage1
}
var file_internal_testprotos_test_weak1_test_weak_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_internal_testprotos_test_weak1_test_weak_proto_init() }
func file_internal_testprotos_test_weak1_test_weak_proto_init() {
if File_internal_testprotos_test_weak1_test_weak_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_internal_testprotos_test_weak1_test_weak_proto_rawDesc), len(file_internal_testprotos_test_weak1_test_weak_proto_rawDesc)),
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_internal_testprotos_test_weak1_test_weak_proto_goTypes,
DependencyIndexes: file_internal_testprotos_test_weak1_test_weak_proto_depIdxs,
MessageInfos: file_internal_testprotos_test_weak1_test_weak_proto_msgTypes,
}.Build()
File_internal_testprotos_test_weak1_test_weak_proto = out.File
file_internal_testprotos_test_weak1_test_weak_proto_goTypes = nil
file_internal_testprotos_test_weak1_test_weak_proto_depIdxs = nil
}

View File

@ -1,13 +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.
syntax = "proto2";
package goproto.proto.test.weak;
option go_package = "google.golang.org/protobuf/internal/testprotos/test/weak1";
message WeakImportMessage1 {
required int32 a = 1;
}

View File

@ -1,124 +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.
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: internal/testprotos/test/weak2/test_weak.proto
package weak2
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
type WeakImportMessage2 struct {
state protoimpl.MessageState `protogen:"open.v1"`
A *int32 `protobuf:"varint,1,req,name=a" json:"a,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *WeakImportMessage2) Reset() {
*x = WeakImportMessage2{}
mi := &file_internal_testprotos_test_weak2_test_weak_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *WeakImportMessage2) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*WeakImportMessage2) ProtoMessage() {}
func (x *WeakImportMessage2) ProtoReflect() protoreflect.Message {
mi := &file_internal_testprotos_test_weak2_test_weak_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use WeakImportMessage2.ProtoReflect.Descriptor instead.
func (*WeakImportMessage2) Descriptor() ([]byte, []int) {
return file_internal_testprotos_test_weak2_test_weak_proto_rawDescGZIP(), []int{0}
}
func (x *WeakImportMessage2) GetA() int32 {
if x != nil && x.A != nil {
return *x.A
}
return 0
}
var File_internal_testprotos_test_weak2_test_weak_proto protoreflect.FileDescriptor
var file_internal_testprotos_test_weak2_test_weak_proto_rawDesc = string([]byte{
0x0a, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x77, 0x65, 0x61, 0x6b, 0x32,
0x2f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x77, 0x65, 0x61, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x12, 0x17, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x74, 0x65, 0x73, 0x74, 0x2e, 0x77, 0x65, 0x61, 0x6b, 0x22, 0x22, 0x0a, 0x12, 0x57, 0x65, 0x61,
0x6b, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x12,
0x0c, 0x0a, 0x01, 0x61, 0x18, 0x01, 0x20, 0x02, 0x28, 0x05, 0x52, 0x01, 0x61, 0x42, 0x3b, 0x5a,
0x39, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f,
0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x69, 0x6e, 0x74, 0x65,
0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f,
0x74, 0x65, 0x73, 0x74, 0x2f, 0x77, 0x65, 0x61, 0x6b, 0x32,
})
var (
file_internal_testprotos_test_weak2_test_weak_proto_rawDescOnce sync.Once
file_internal_testprotos_test_weak2_test_weak_proto_rawDescData []byte
)
func file_internal_testprotos_test_weak2_test_weak_proto_rawDescGZIP() []byte {
file_internal_testprotos_test_weak2_test_weak_proto_rawDescOnce.Do(func() {
file_internal_testprotos_test_weak2_test_weak_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_internal_testprotos_test_weak2_test_weak_proto_rawDesc), len(file_internal_testprotos_test_weak2_test_weak_proto_rawDesc)))
})
return file_internal_testprotos_test_weak2_test_weak_proto_rawDescData
}
var file_internal_testprotos_test_weak2_test_weak_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_internal_testprotos_test_weak2_test_weak_proto_goTypes = []any{
(*WeakImportMessage2)(nil), // 0: goproto.proto.test.weak.WeakImportMessage2
}
var file_internal_testprotos_test_weak2_test_weak_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_internal_testprotos_test_weak2_test_weak_proto_init() }
func file_internal_testprotos_test_weak2_test_weak_proto_init() {
if File_internal_testprotos_test_weak2_test_weak_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_internal_testprotos_test_weak2_test_weak_proto_rawDesc), len(file_internal_testprotos_test_weak2_test_weak_proto_rawDesc)),
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_internal_testprotos_test_weak2_test_weak_proto_goTypes,
DependencyIndexes: file_internal_testprotos_test_weak2_test_weak_proto_depIdxs,
MessageInfos: file_internal_testprotos_test_weak2_test_weak_proto_msgTypes,
}.Build()
File_internal_testprotos_test_weak2_test_weak_proto = out.File
file_internal_testprotos_test_weak2_test_weak_proto_goTypes = nil
file_internal_testprotos_test_weak2_test_weak_proto_depIdxs = nil
}

View File

@ -1,13 +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.
syntax = "proto2";
package goproto.proto.test.weak;
option go_package = "google.golang.org/protobuf/internal/testprotos/test/weak2";
message WeakImportMessage2 {
required int32 a = 1;
}

View File

@ -10,11 +10,9 @@ import (
"testing" "testing"
"google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
testpb "google.golang.org/protobuf/internal/testprotos/test" testpb "google.golang.org/protobuf/internal/testprotos/test"
weakpb "google.golang.org/protobuf/internal/testprotos/test/weak1"
testeditionspb "google.golang.org/protobuf/internal/testprotos/testeditions" testeditionspb "google.golang.org/protobuf/internal/testprotos/testeditions"
) )
@ -70,28 +68,6 @@ func TestCheckInitializedErrors(t *testing.T) {
}, },
}, },
want: `goproto.proto.testeditions.TestRequired.required_field`, want: `goproto.proto.testeditions.TestRequired.required_field`,
}, {
m: &testpb.TestWeak{},
want: `<nil>`,
skip: !flags.ProtoLegacyWeak,
}, {
m: func() proto.Message {
m := &testpb.TestWeak{}
m.SetWeakMessage1(&weakpb.WeakImportMessage1{})
return m
}(),
want: `goproto.proto.test.weak.WeakImportMessage1.a`,
skip: !flags.ProtoLegacyWeak,
}, {
m: func() proto.Message {
m := &testpb.TestWeak{}
m.SetWeakMessage1(&weakpb.WeakImportMessage1{
A: proto.Int32(1),
})
return m
}(),
want: `<nil>`,
skip: !flags.ProtoLegacyWeak,
}} }}
for _, tt := range tests { for _, tt := range tests {

View File

@ -8,7 +8,6 @@ import (
"google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/encoding/messageset" "google.golang.org/protobuf/internal/encoding/messageset"
"google.golang.org/protobuf/internal/errors" "google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/internal/genid" "google.golang.org/protobuf/internal/genid"
"google.golang.org/protobuf/internal/pragma" "google.golang.org/protobuf/internal/pragma"
"google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoreflect"
@ -172,10 +171,6 @@ func (o UnmarshalOptions) unmarshalMessageSlow(b []byte, m protoreflect.Message)
var err error var err error
if fd == nil { if fd == nil {
err = errUnknown err = errUnknown
} else if flags.ProtoLegacyWeak {
if fd.IsWeak() && fd.Message().IsPlaceholder() {
err = errUnknown // weak referent is not linked in
}
} }
// Parse the field value. // Parse the field value.

View File

@ -22,7 +22,6 @@ import (
_ "google.golang.org/protobuf/internal/testprotos/required" _ "google.golang.org/protobuf/internal/testprotos/required"
_ "google.golang.org/protobuf/internal/testprotos/required/required_opaque" _ "google.golang.org/protobuf/internal/testprotos/required/required_opaque"
_ "google.golang.org/protobuf/internal/testprotos/test" _ "google.golang.org/protobuf/internal/testprotos/test"
_ "google.golang.org/protobuf/internal/testprotos/test/weak1"
_ "google.golang.org/protobuf/internal/testprotos/test3" _ "google.golang.org/protobuf/internal/testprotos/test3"
_ "google.golang.org/protobuf/internal/testprotos/testeditions/testeditions_hybrid" _ "google.golang.org/protobuf/internal/testprotos/testeditions/testeditions_hybrid"
_ "google.golang.org/protobuf/internal/testprotos/testeditions/testeditions_opaque" _ "google.golang.org/protobuf/internal/testprotos/testeditions/testeditions_opaque"

View File

@ -1,125 +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 proto_test
import (
"testing"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/internal/protobuild"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protopack"
testpb "google.golang.org/protobuf/internal/testprotos/test"
weakpb "google.golang.org/protobuf/internal/testprotos/test/weak1"
)
func init() {
if flags.ProtoLegacyWeak {
testValidMessages = append(testValidMessages, testWeakValidMessages...)
testInvalidMessages = append(testInvalidMessages, testWeakInvalidMessages...)
testMerges = append(testMerges, testWeakMerges...)
}
}
var testWeakValidMessages = []testProto{
{
desc: "weak message",
decodeTo: []proto.Message{
func() proto.Message {
if !flags.ProtoLegacyWeak {
return nil
}
m := &testpb.TestWeak{}
m.SetWeakMessage1(&weakpb.WeakImportMessage1{
A: proto.Int32(1000),
})
m.ProtoReflect().SetUnknown(protopack.Message{
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(2000),
}),
}.Marshal())
return m
}(),
},
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(1000),
}),
protopack.Tag{2, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(2000),
}),
}.Marshal(),
},
}
var testWeakInvalidMessages = []testProto{
{
desc: "invalid field number 0 in weak message",
decodeTo: []proto.Message{(*testpb.TestWeak)(nil)},
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{0, protopack.VarintType}, protopack.Varint(1000),
}),
}.Marshal(),
},
}
var testWeakMerges = []testMerge{
{
desc: "clone weak message",
src: protobuild.Message{
"weak_message1": protobuild.Message{
"a": 1,
},
},
types: []proto.Message{&testpb.TestWeak{}},
}, {
desc: "merge weak message",
dst: protobuild.Message{
"weak_message1": protobuild.Message{
"a": 1,
},
},
src: protobuild.Message{
"weak_message1": protobuild.Message{
"a": 2,
},
},
want: protobuild.Message{
"weak_message1": protobuild.Message{
"a": 2,
},
},
types: []proto.Message{&testpb.TestWeak{}},
},
}
func TestWeakNil(t *testing.T) {
if !flags.ProtoLegacyWeak {
t.SkipNow()
}
m := new(testpb.TestWeak)
if v, ok := m.GetWeakMessage1().(*weakpb.WeakImportMessage1); !ok || v != nil {
t.Errorf("m.GetWeakMessage1() = type %[1]T(%[1]v), want (*weakpb.WeakImportMessage1)", v)
}
}
func TestWeakMarshalNil(t *testing.T) {
if !flags.ProtoLegacyWeak {
t.SkipNow()
}
m := new(testpb.TestWeak)
m.SetWeakMessage1(nil)
if b, err := proto.Marshal(m); err != nil || len(b) != 0 {
t.Errorf("Marshal(weak field set to nil) = [%x], %v; want [], nil", b, err)
}
m.SetWeakMessage1((*weakpb.WeakImportMessage1)(nil))
if b, err := proto.Marshal(m); err != nil || len(b) != 0 {
t.Errorf("Marshal(weak field set to typed nil) = [%x], %v; want [], nil", b, err)
}
}

View File

@ -132,17 +132,11 @@ func (o FileOptions) New(fd *descriptorpb.FileDescriptorProto, r Resolver) (prot
} }
f.L2.Imports[i].IsPublic = true f.L2.Imports[i].IsPublic = true
} }
for _, i := range fd.GetWeakDependency() {
if !(0 <= i && int(i) < len(f.L2.Imports)) || f.L2.Imports[i].IsWeak {
return nil, errors.New("invalid or duplicate weak import index: %d", i)
}
f.L2.Imports[i].IsWeak = true
}
imps := importSet{f.Path(): true} imps := importSet{f.Path(): true}
for i, path := range fd.GetDependency() { for i, path := range fd.GetDependency() {
imp := &f.L2.Imports[i] imp := &f.L2.Imports[i]
f, err := r.FindFileByPath(path) f, err := r.FindFileByPath(path)
if err == protoregistry.NotFound && (o.AllowUnresolvable || imp.IsWeak) { if err == protoregistry.NotFound && o.AllowUnresolvable {
f = filedesc.PlaceholderFile(path) f = filedesc.PlaceholderFile(path)
} else if err != nil { } else if err != nil {
return nil, errors.New("could not resolve import %q: %v", path, err) return nil, errors.New("could not resolve import %q: %v", path, err)

View File

@ -149,7 +149,6 @@ func (r descsByName) initFieldsFromDescriptorProto(fds []*descriptorpb.FieldDesc
if opts := fd.GetOptions(); opts != nil { if opts := fd.GetOptions(); opts != nil {
opts = proto.Clone(opts).(*descriptorpb.FieldOptions) opts = proto.Clone(opts).(*descriptorpb.FieldOptions)
f.L1.Options = func() protoreflect.ProtoMessage { return opts } f.L1.Options = func() protoreflect.ProtoMessage { return opts }
f.L1.IsWeak = opts.GetWeak()
f.L1.IsLazy = opts.GetLazy() f.L1.IsLazy = opts.GetLazy()
if opts.Packed != nil { if opts.Packed != nil {
f.L1.EditionFeatures.IsPacked = opts.GetPacked() f.L1.EditionFeatures.IsPacked = opts.GetPacked()

View File

@ -43,7 +43,7 @@ func (r *resolver) resolveMessageDependencies(ms []filedesc.Message, mds []*desc
o.L1.Fields.List = append(o.L1.Fields.List, f) o.L1.Fields.List = append(o.L1.Fields.List, f)
} }
if f.L1.Kind, f.L1.Enum, f.L1.Message, err = r.findTarget(f.Kind(), f.Parent().FullName(), partialName(fd.GetTypeName()), f.IsWeak()); err != nil { if f.L1.Kind, f.L1.Enum, f.L1.Message, err = r.findTarget(f.Kind(), f.Parent().FullName(), partialName(fd.GetTypeName())); err != nil {
return errors.New("message field %q cannot resolve type: %v", f.FullName(), err) return errors.New("message field %q cannot resolve type: %v", f.FullName(), err)
} }
if f.L1.Kind == protoreflect.GroupKind && (f.IsMap() || f.IsMapEntry()) { if f.L1.Kind == protoreflect.GroupKind && (f.IsMap() || f.IsMapEntry()) {
@ -73,10 +73,10 @@ func (r *resolver) resolveMessageDependencies(ms []filedesc.Message, mds []*desc
func (r *resolver) resolveExtensionDependencies(xs []filedesc.Extension, xds []*descriptorpb.FieldDescriptorProto) (err error) { func (r *resolver) resolveExtensionDependencies(xs []filedesc.Extension, xds []*descriptorpb.FieldDescriptorProto) (err error) {
for i, xd := range xds { for i, xd := range xds {
x := &xs[i] x := &xs[i]
if x.L1.Extendee, err = r.findMessageDescriptor(x.Parent().FullName(), partialName(xd.GetExtendee()), false); err != nil { if x.L1.Extendee, err = r.findMessageDescriptor(x.Parent().FullName(), partialName(xd.GetExtendee())); err != nil {
return errors.New("extension field %q cannot resolve extendee: %v", x.FullName(), err) return errors.New("extension field %q cannot resolve extendee: %v", x.FullName(), err)
} }
if x.L1.Kind, x.L2.Enum, x.L2.Message, err = r.findTarget(x.Kind(), x.Parent().FullName(), partialName(xd.GetTypeName()), false); err != nil { if x.L1.Kind, x.L2.Enum, x.L2.Message, err = r.findTarget(x.Kind(), x.Parent().FullName(), partialName(xd.GetTypeName())); err != nil {
return errors.New("extension field %q cannot resolve type: %v", x.FullName(), err) return errors.New("extension field %q cannot resolve type: %v", x.FullName(), err)
} }
if xd.DefaultValue != nil { if xd.DefaultValue != nil {
@ -95,11 +95,11 @@ func (r *resolver) resolveServiceDependencies(ss []filedesc.Service, sds []*desc
s := &ss[i] s := &ss[i]
for j, md := range sd.GetMethod() { for j, md := range sd.GetMethod() {
m := &s.L2.Methods.List[j] m := &s.L2.Methods.List[j]
m.L1.Input, err = r.findMessageDescriptor(m.Parent().FullName(), partialName(md.GetInputType()), false) m.L1.Input, err = r.findMessageDescriptor(m.Parent().FullName(), partialName(md.GetInputType()))
if err != nil { if err != nil {
return errors.New("service method %q cannot resolve input: %v", m.FullName(), err) return errors.New("service method %q cannot resolve input: %v", m.FullName(), err)
} }
m.L1.Output, err = r.findMessageDescriptor(s.FullName(), partialName(md.GetOutputType()), false) m.L1.Output, err = r.findMessageDescriptor(s.FullName(), partialName(md.GetOutputType()))
if err != nil { if err != nil {
return errors.New("service method %q cannot resolve output: %v", m.FullName(), err) return errors.New("service method %q cannot resolve output: %v", m.FullName(), err)
} }
@ -111,16 +111,16 @@ func (r *resolver) resolveServiceDependencies(ss []filedesc.Service, sds []*desc
// findTarget finds an enum or message descriptor if k is an enum, message, // findTarget finds an enum or message descriptor if k is an enum, message,
// group, or unknown. If unknown, and the name could be resolved, the kind // group, or unknown. If unknown, and the name could be resolved, the kind
// returned kind is set based on the type of the resolved descriptor. // returned kind is set based on the type of the resolved descriptor.
func (r *resolver) findTarget(k protoreflect.Kind, scope protoreflect.FullName, ref partialName, isWeak bool) (protoreflect.Kind, protoreflect.EnumDescriptor, protoreflect.MessageDescriptor, error) { func (r *resolver) findTarget(k protoreflect.Kind, scope protoreflect.FullName, ref partialName) (protoreflect.Kind, protoreflect.EnumDescriptor, protoreflect.MessageDescriptor, error) {
switch k { switch k {
case protoreflect.EnumKind: case protoreflect.EnumKind:
ed, err := r.findEnumDescriptor(scope, ref, isWeak) ed, err := r.findEnumDescriptor(scope, ref)
if err != nil { if err != nil {
return 0, nil, nil, err return 0, nil, nil, err
} }
return k, ed, nil, nil return k, ed, nil, nil
case protoreflect.MessageKind, protoreflect.GroupKind: case protoreflect.MessageKind, protoreflect.GroupKind:
md, err := r.findMessageDescriptor(scope, ref, isWeak) md, err := r.findMessageDescriptor(scope, ref)
if err != nil { if err != nil {
return 0, nil, nil, err return 0, nil, nil, err
} }
@ -129,7 +129,7 @@ func (r *resolver) findTarget(k protoreflect.Kind, scope protoreflect.FullName,
// Handle unspecified kinds (possible with parsers that operate // Handle unspecified kinds (possible with parsers that operate
// on a per-file basis without knowledge of dependencies). // on a per-file basis without knowledge of dependencies).
d, err := r.findDescriptor(scope, ref) d, err := r.findDescriptor(scope, ref)
if err == protoregistry.NotFound && (r.allowUnresolvable || isWeak) { if err == protoregistry.NotFound && r.allowUnresolvable {
return k, filedesc.PlaceholderEnum(ref.FullName()), filedesc.PlaceholderMessage(ref.FullName()), nil return k, filedesc.PlaceholderEnum(ref.FullName()), filedesc.PlaceholderMessage(ref.FullName()), nil
} else if err == protoregistry.NotFound { } else if err == protoregistry.NotFound {
return 0, nil, nil, errors.New("%q not found", ref.FullName()) return 0, nil, nil, errors.New("%q not found", ref.FullName())
@ -206,9 +206,9 @@ func (r *resolver) findDescriptor(scope protoreflect.FullName, ref partialName)
} }
} }
func (r *resolver) findEnumDescriptor(scope protoreflect.FullName, ref partialName, isWeak bool) (protoreflect.EnumDescriptor, error) { func (r *resolver) findEnumDescriptor(scope protoreflect.FullName, ref partialName) (protoreflect.EnumDescriptor, error) {
d, err := r.findDescriptor(scope, ref) d, err := r.findDescriptor(scope, ref)
if err == protoregistry.NotFound && (r.allowUnresolvable || isWeak) { if err == protoregistry.NotFound && r.allowUnresolvable {
return filedesc.PlaceholderEnum(ref.FullName()), nil return filedesc.PlaceholderEnum(ref.FullName()), nil
} else if err == protoregistry.NotFound { } else if err == protoregistry.NotFound {
return nil, errors.New("%q not found", ref.FullName()) return nil, errors.New("%q not found", ref.FullName())
@ -222,9 +222,9 @@ func (r *resolver) findEnumDescriptor(scope protoreflect.FullName, ref partialNa
return ed, nil return ed, nil
} }
func (r *resolver) findMessageDescriptor(scope protoreflect.FullName, ref partialName, isWeak bool) (protoreflect.MessageDescriptor, error) { func (r *resolver) findMessageDescriptor(scope protoreflect.FullName, ref partialName) (protoreflect.MessageDescriptor, error) {
d, err := r.findDescriptor(scope, ref) d, err := r.findDescriptor(scope, ref)
if err == protoregistry.NotFound && (r.allowUnresolvable || isWeak) { if err == protoregistry.NotFound && r.allowUnresolvable {
return filedesc.PlaceholderMessage(ref.FullName()), nil return filedesc.PlaceholderMessage(ref.FullName()), nil
} else if err == protoregistry.NotFound { } else if err == protoregistry.NotFound {
return nil, errors.New("%q not found", ref.FullName()) return nil, errors.New("%q not found", ref.FullName())

View File

@ -149,12 +149,6 @@ func validateMessageDeclarations(file *filedesc.File, ms []filedesc.Message, mds
return errors.New("message field %q under proto3 optional semantics must be within a single element oneof", f.FullName()) return errors.New("message field %q under proto3 optional semantics must be within a single element oneof", f.FullName())
} }
} }
if f.IsWeak() && !flags.ProtoLegacyWeak {
return errors.New("message field %q is a weak field, which is a legacy proto1 feature that is no longer supported", f.FullName())
}
if f.IsWeak() && (!f.HasPresence() || !isOptionalMessage(f) || f.ContainingOneof() != nil) {
return errors.New("message field %q may only be weak for an optional message", f.FullName())
}
if f.IsPacked() && !isPackable(f) { if f.IsPacked() && !isPackable(f) {
return errors.New("message field %q is not packable", f.FullName()) return errors.New("message field %q is not packable", f.FullName())
} }
@ -199,9 +193,6 @@ func validateMessageDeclarations(file *filedesc.File, ms []filedesc.Message, mds
if f.Cardinality() != protoreflect.Optional { if f.Cardinality() != protoreflect.Optional {
return errors.New("message field %q belongs in a oneof and must be optional", f.FullName()) return errors.New("message field %q belongs in a oneof and must be optional", f.FullName())
} }
if f.IsWeak() {
return errors.New("message field %q belongs in a oneof and must not be a weak reference", f.FullName())
}
} }
} }
@ -254,9 +245,6 @@ func validateExtensionDeclarations(f *filedesc.File, xs []filedesc.Extension, xd
return errors.New("extension field %q has an invalid number: %d", x.FullName(), x.Number()) return errors.New("extension field %q has an invalid number: %d", x.FullName(), x.Number())
} }
} }
if xd.GetOptions().GetWeak() {
return errors.New("extension field %q cannot be a weak reference", x.FullName())
}
if x.IsPacked() && !isPackable(x) { if x.IsPacked() && !isPackable(x) {
return errors.New("extension field %q is not packable", x.FullName()) return errors.New("extension field %q is not packable", x.FullName())
} }

View File

@ -173,24 +173,6 @@ func TestNewFile(t *testing.T) {
`), `),
inOpts: FileOptions{AllowUnresolvable: true}, inOpts: FileOptions{AllowUnresolvable: true},
wantErr: `already imported "dep.proto"`, wantErr: `already imported "dep.proto"`,
}, {
label: "invalid weak import",
inDesc: mustParseFile(`
name: "test.proto"
dependency: "dep.proto"
weak_dependency: [-23]
`),
inOpts: FileOptions{AllowUnresolvable: true},
wantErr: `invalid or duplicate weak import index: -23`,
}, {
label: "normal weak and public import",
inDesc: mustParseFile(`
name: "test.proto"
dependency: "dep.proto"
weak_dependency: [0]
public_dependency: [0]
`),
inOpts: FileOptions{AllowUnresolvable: true},
}, { }, {
label: "import public indirect dependency duplicate", label: "import public indirect dependency duplicate",
inDeps: []*descriptorpb.FileDescriptorProto{ inDeps: []*descriptorpb.FileDescriptorProto{

View File

@ -32,9 +32,6 @@ func ToFileDescriptorProto(file protoreflect.FileDescriptor) *descriptorpb.FileD
if imp.IsPublic { if imp.IsPublic {
p.PublicDependency = append(p.PublicDependency, int32(i)) p.PublicDependency = append(p.PublicDependency, int32(i))
} }
if imp.IsWeak {
p.WeakDependency = append(p.WeakDependency, int32(i))
}
} }
for i, locs := 0, file.SourceLocations(); i < locs.Len(); i++ { for i, locs := 0, file.SourceLocations(); i < locs.Len(); i++ {
loc := locs.Get(i) loc := locs.Get(i)

View File

@ -68,7 +68,7 @@ type Descriptor interface {
// dependency is not resolved, in which case only name information is known. // dependency is not resolved, in which case only name information is known.
// //
// Placeholder types may only be returned by the following accessors // Placeholder types may only be returned by the following accessors
// as a result of unresolved dependencies or weak imports: // as a result of unresolved dependencies:
// //
// ╔═══════════════════════════════════╤═════════════════════╗ // ╔═══════════════════════════════════╤═════════════════════╗
// ║ Accessor │ Descriptor ║ // ║ Accessor │ Descriptor ║
@ -168,11 +168,7 @@ type FileImport struct {
// The current file and the imported file must be within proto package. // The current file and the imported file must be within proto package.
IsPublic bool IsPublic bool
// IsWeak reports whether this is a weak import, which does not impose // Deprecated: support for weak fields has been removed.
// a direct dependency on the target file.
//
// Weak imports are a legacy proto1 feature. Equivalent behavior is
// achieved using proto2 extension fields or proto3 Any messages.
IsWeak bool IsWeak bool
} }
@ -325,9 +321,7 @@ type FieldDescriptor interface {
// specified in the source .proto file. // specified in the source .proto file.
HasOptionalKeyword() bool HasOptionalKeyword() bool
// IsWeak reports whether this is a weak field, which does not impose a // Deprecated: support for weak fields has been removed.
// direct dependency on the target type.
// If true, then Message returns a placeholder type.
IsWeak() bool IsWeak() bool
// IsPacked reports whether repeated primitive numeric kinds should be // IsPacked reports whether repeated primitive numeric kinds should be

View File

@ -878,9 +878,6 @@ func populateMessage(m protoreflect.Message, n seed, stack []protoreflect.Messag
stack = append(stack, md) stack = append(stack, md)
for i := 0; i < md.Fields().Len(); i++ { for i := 0; i < md.Fields().Len(); i++ {
fd := md.Fields().Get(i) fd := md.Fields().Get(i)
if fd.IsWeak() {
continue
}
m.Set(fd, newValue(m, fd, newSeed(n, i), stack)) m.Set(fd, newValue(m, fd, newSeed(n, i), stack))
} }
return protoreflect.ValueOfMessage(m) return protoreflect.ValueOfMessage(m)

View File

@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"testing" "testing"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/runtime/protoimpl" "google.golang.org/protobuf/runtime/protoimpl"
"google.golang.org/protobuf/testing/prototest" "google.golang.org/protobuf/testing/prototest"
@ -17,8 +16,6 @@ import (
legacypb "google.golang.org/protobuf/internal/testprotos/legacy" legacypb "google.golang.org/protobuf/internal/testprotos/legacy"
legacy1pb "google.golang.org/protobuf/internal/testprotos/legacy/proto2_20160225_2fc053c5" legacy1pb "google.golang.org/protobuf/internal/testprotos/legacy/proto2_20160225_2fc053c5"
testpb "google.golang.org/protobuf/internal/testprotos/test" testpb "google.golang.org/protobuf/internal/testprotos/test"
_ "google.golang.org/protobuf/internal/testprotos/test/weak1"
_ "google.golang.org/protobuf/internal/testprotos/test/weak2"
test3pb "google.golang.org/protobuf/internal/testprotos/test3" test3pb "google.golang.org/protobuf/internal/testprotos/test3"
testeditionspb "google.golang.org/protobuf/internal/testprotos/testeditions" testeditionspb "google.golang.org/protobuf/internal/testprotos/testeditions"
) )
@ -36,9 +33,6 @@ func Test(t *testing.T) {
(*legacypb.Legacy)(nil), (*legacypb.Legacy)(nil),
protoimpl.X.MessageOf((*legacy1pb.Message)(nil)).Interface(), protoimpl.X.MessageOf((*legacy1pb.Message)(nil)).Interface(),
} }
if flags.ProtoLegacyWeak {
ms = append(ms, (*testpb.TestWeak)(nil))
}
for _, m := range ms { for _, m := range ms {
t.Run(fmt.Sprintf("%T", m), func(t *testing.T) { t.Run(fmt.Sprintf("%T", m), func(t *testing.T) {