Преглед изворни кода

internal/impl: add MessageState to every generated message

We define MessageState, which is essentially an atomically set *MessageInfo.
By nesting this as the first field in every generated message, we can
implement the reflective methods on a *MessageState when obtained by
unsafe casting a concrete message pointer as a *MessageState.
The MessageInfo held by MessageState provides additional Go type information
to interpret the memory that comes after the contents of the MessageState.

Since we are nesting a MessageState in every message,
the memory use of every message instance grows by 8B.

On average, the body of ProtoReflect grows from 133B to 202B (+50%).
However, this is offset by XXX_Methods, which is 108B and
will be removed in a future CL. Taking into account the eventual removal
of XXX_Methods, this is a net reduction of 25%.

name          old time/op    new time/op    delta
Name/Value-4    70.3ns ± 2%    17.5ns ± 6%   -75.08%  (p=0.000 n=10+10)
Name/Nil-4      70.6ns ± 3%    33.4ns ± 2%   -52.66%  (p=0.000 n=10+10)

name          old alloc/op   new alloc/op   delta
Name/Value-4     16.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
Name/Nil-4       16.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)

name          old allocs/op  new allocs/op  delta
Name/Value-4      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Name/Nil-4        1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)

Change-Id: I92bd58dc681c57c92612fd5ba7fc066aea34e95a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/185460
Reviewed-by: Damien Neil <dneil@google.com>
Joe Tsai пре 6 година
родитељ
комит
82760ceffa
85 измењених фајлова са 7530 додато и 1728 уклоњено
  1. 28 6
      cmd/protoc-gen-go-grpc/testdata/grpc/grpc.pb.go
  2. 9 1
      cmd/protoc-gen-go/internal_gengo/main.go
  3. 15 2
      cmd/protoc-gen-go/internal_gengo/reflect.go
  4. 15 4
      cmd/protoc-gen-go/testdata/annotations/annotations.pb.go
  5. 1 1
      cmd/protoc-gen-go/testdata/annotations/annotations.pb.go.meta
  6. 85 19
      cmd/protoc-gen-go/testdata/comments/comments.pb.go
  7. 15 4
      cmd/protoc-gen-go/testdata/comments/deprecated.pb.go
  8. 31 9
      cmd/protoc-gen-go/testdata/extensions/base/base.pb.go
  9. 116 28
      cmd/protoc-gen-go/testdata/extensions/ext/ext.pb.go
  10. 15 4
      cmd/protoc-gen-go/testdata/extensions/extra/extra.pb.go
  11. 14 3
      cmd/protoc-gen-go/testdata/extensions/proto3/ext3.pb.go
  12. 29 7
      cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go
  13. 15 4
      cmd/protoc-gen-go/testdata/import_public/a.pb.go
  14. 15 4
      cmd/protoc-gen-go/testdata/import_public/b.pb.go
  15. 15 4
      cmd/protoc-gen-go/testdata/import_public/c.pb.go
  16. 31 9
      cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go
  17. 14 3
      cmd/protoc-gen-go/testdata/import_public/sub/b.pb.go
  18. 14 3
      cmd/protoc-gen-go/testdata/import_public/sub2/a.pb.go
  19. 14 3
      cmd/protoc-gen-go/testdata/imports/fmt/m.pb.go
  20. 29 7
      cmd/protoc-gen-go/testdata/imports/test_a_1/m1.pb.go
  21. 14 3
      cmd/protoc-gen-go/testdata/imports/test_a_1/m2.pb.go
  22. 14 3
      cmd/protoc-gen-go/testdata/imports/test_a_2/m3.pb.go
  23. 14 3
      cmd/protoc-gen-go/testdata/imports/test_a_2/m4.pb.go
  24. 14 3
      cmd/protoc-gen-go/testdata/imports/test_b_1/m1.pb.go
  25. 14 3
      cmd/protoc-gen-go/testdata/imports/test_b_1/m2.pb.go
  26. 15 4
      cmd/protoc-gen-go/testdata/imports/test_import_a1m1.pb.go
  27. 15 4
      cmd/protoc-gen-go/testdata/imports/test_import_a1m2.pb.go
  28. 15 4
      cmd/protoc-gen-go/testdata/imports/test_import_all.pb.go
  29. 15 4
      cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
  30. 15 4
      cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go
  31. 29 7
      cmd/protoc-gen-go/testdata/proto2/enum.pb.go
  32. 89 23
      cmd/protoc-gen-go/testdata/proto2/fields.pb.go
  33. 44 11
      cmd/protoc-gen-go/testdata/proto2/nested_messages.pb.go
  34. 15 4
      cmd/protoc-gen-go/testdata/proto2/proto2.pb.go
  35. 29 7
      cmd/protoc-gen-go/testdata/proto3/fields.pb.go
  36. 285 76
      encoding/testprotos/pb2/test.pb.go
  37. 105 28
      encoding/testprotos/pb3/test.pb.go
  38. 104 0
      internal/cmd/generate-types/impl.go
  39. 1 0
      internal/cmd/generate-types/main.go
  40. 15 251
      internal/impl/message.go
  41. 220 0
      internal/impl/message_reflect.go
  42. 190 0
      internal/impl/message_reflect_gen.go
  43. 71 0
      internal/impl/message_test.go
  44. 27 0
      internal/impl/pointer_reflect.go
  45. 36 0
      internal/impl/pointer_unsafe.go
  46. 15 4
      internal/testprotos/benchmarks/benchmarks.pb.go
  47. 30 8
      internal/testprotos/benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.go
  48. 30 8
      internal/testprotos/benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.pb.go
  49. 45 12
      internal/testprotos/benchmarks/datasets/google_message2/benchmark_message2.pb.go
  50. 379 74
      internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3.pb.go
  51. 385 70
      internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_1.pb.go
  52. 382 72
      internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_2.pb.go
  53. 385 70
      internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_3.pb.go
  54. 385 70
      internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_4.pb.go
  55. 385 70
      internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_5.pb.go
  56. 385 70
      internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_6.pb.go
  57. 146 36
      internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_7.pb.go
  58. 385 70
      internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4.pb.go
  59. 385 70
      internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_1.pb.go
  60. 385 70
      internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_2.pb.go
  61. 60 16
      internal/testprotos/conformance/conformance.pb.go
  62. 106 29
      internal/testprotos/conformance/test_messages_proto2.pb.go
  63. 45 12
      internal/testprotos/conformance/test_messages_proto3.pb.go
  64. 15 4
      internal/testprotos/irregular/test.pb.go
  65. 15 4
      internal/testprotos/legacy/legacy.pb.go
  66. 281 72
      internal/testprotos/test/test.pb.go
  67. 14 3
      internal/testprotos/test/test_import.pb.go
  68. 14 3
      internal/testprotos/test/test_public.pb.go
  69. 15 4
      internal/testprotos/test/weak/test_weak.pb.go
  70. 45 12
      internal/testprotos/test3/test.pb.go
  71. 14 3
      internal/testprotos/test3/test_import.pb.go
  72. 58 14
      reflect/protoregistry/testprotos/test.pb.go
  73. 2 0
      runtime/protoimpl/impl.go
  74. 365 92
      types/descriptorpb/descriptor.pb.go
  75. 15 4
      types/known/anypb/any.pb.go
  76. 45 12
      types/known/apipb/api.pb.go
  77. 15 4
      types/known/durationpb/duration.pb.go
  78. 14 3
      types/known/emptypb/empty.pb.go
  79. 15 4
      types/known/fieldmaskpb/field_mask.pb.go
  80. 15 4
      types/known/sourcecontextpb/source_context.pb.go
  81. 45 12
      types/known/structpb/struct.pb.go
  82. 15 4
      types/known/timestamppb/timestamp.pb.go
  83. 75 20
      types/known/typepb/type.pb.go
  84. 135 36
      types/known/wrapperspb/wrappers.pb.go
  85. 60 16
      types/pluginpb/plugin.pb.go

+ 28 - 6
cmd/protoc-gen-go-grpc/testdata/grpc/grpc.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type Request struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *Request) String() string {
 func (*Request) ProtoMessage() {}
 
 func (x *Request) ProtoReflect() protoreflect.Message {
-	return file_grpc_grpc_proto_msgTypes[0].MessageOf(x)
+	mi := &file_grpc_grpc_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Request) XXX_Methods() *protoiface.Methods {
+func (x *Request) XXX_Methods() *protoiface.Methods {
 	return file_grpc_grpc_proto_msgTypes[0].Methods()
 }
 
@@ -46,6 +55,7 @@ func (*Request) Descriptor() ([]byte, []int) {
 }
 
 type Response struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -61,10 +71,18 @@ func (x *Response) String() string {
 func (*Response) ProtoMessage() {}
 
 func (x *Response) ProtoReflect() protoreflect.Message {
-	return file_grpc_grpc_proto_msgTypes[1].MessageOf(x)
+	mi := &file_grpc_grpc_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Response) XXX_Methods() *protoiface.Methods {
+func (x *Response) XXX_Methods() *protoiface.Methods {
 	return file_grpc_grpc_proto_msgTypes[1].Methods()
 }
 
@@ -149,8 +167,10 @@ func file_grpc_grpc_proto_init() {
 		file_grpc_grpc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Request); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -159,8 +179,10 @@ func file_grpc_grpc_proto_init() {
 		file_grpc_grpc_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Response); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 9 - 1
cmd/protoc-gen-go/internal_gengo/main.go

@@ -48,10 +48,14 @@ const (
 	// ExtensionRangeArray method for messages that support extensions.
 	generateExtensionRangeMethods = true
 
-	// generateWKTMarkerMethods specifes whether to generate
+	// generateWKTMarkerMethods specifies whether to generate
 	// XXX_WellKnownType methods on well-known types.
 	generateWKTMarkerMethods = false
 
+	// generateMessateStateFields specifies whether to generate an unexported
+	// protoimpl.MessageState as the first field.
+	generateMessateStateFields = true
+
 	// generateNoUnkeyedLiteralFields specifies whether to generate
 	// the XXX_NoUnkeyedLiteral field.
 	generateNoUnkeyedLiteralFields = false
@@ -395,6 +399,10 @@ func genMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, me
 	g.Annotate(message.GoIdent.GoName, message.Location)
 	g.P("type ", message.GoIdent, " struct {")
 	sf := f.allMessageFieldsByPtr[message]
+	if generateMessateStateFields {
+		g.P("state ", protoimplPackage.Ident("MessageState"))
+		sf.append("state")
+	}
 	for _, field := range message.Fields {
 		if field.Oneof != nil {
 			// It would be a bit simpler to iterate over the oneofs below,

+ 15 - 2
cmd/protoc-gen-go/internal_gengo/reflect.go

@@ -293,12 +293,25 @@ func genReflectMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileI
 
 	// ProtoReflect method.
 	g.P("func (x *", message.GoIdent, ") ProtoReflect() ", protoreflectPackage.Ident("Message"), " {")
-	g.P("return ", typesVar, "[", idx, "].MessageOf(x)")
+	g.P("mi := &", typesVar, "[", idx, "]")
+	if generateMessateStateFields {
+		g.P("if ", protoimplPackage.Ident("UnsafeEnabled"), " && x != nil {")
+		g.P("ms := ", protoimplPackage.Ident("X"), ".MessageStateOf(", protoimplPackage.Ident("Pointer"), "(x))")
+		g.P("if ms.LoadMessageInfo() == nil {")
+		g.P("ms.StoreMessageInfo(mi)")
+		g.P("}")
+		g.P("return ms")
+		g.P("}")
+	}
+	g.P("return mi.MessageOf(x)")
 	g.P("}")
 	g.P()
-	g.P("func (m *", message.GoIdent, ") XXX_Methods() *", protoifacePackage.Ident("Methods"), " {")
+
+	// XXX_Methods method.
+	g.P("func (x *", message.GoIdent, ") XXX_Methods() *", protoifacePackage.Ident("Methods"), " {")
 	g.P("return ", typesVar, "[", idx, "].Methods()")
 	g.P("}")
+	g.P()
 }
 
 func fileVarName(f *protogen.File, suffix string) string {

+ 15 - 4
cmd/protoc-gen-go/testdata/annotations/annotations.pb.go

@@ -66,6 +66,7 @@ func (AnnotationsTestEnum) EnumDescriptor() ([]byte, []int) {
 }
 
 type AnnotationsTestMessage struct {
+	state                protoimpl.MessageState
 	AnnotationsTestField *string `protobuf:"bytes,1,opt,name=AnnotationsTestField" json:"AnnotationsTestField,omitempty"`
 	sizeCache            protoimpl.SizeCache
 	unknownFields        protoimpl.UnknownFields
@@ -82,10 +83,18 @@ func (x *AnnotationsTestMessage) String() string {
 func (*AnnotationsTestMessage) ProtoMessage() {}
 
 func (x *AnnotationsTestMessage) ProtoReflect() protoreflect.Message {
-	return file_annotations_annotations_proto_msgTypes[0].MessageOf(x)
+	mi := &file_annotations_annotations_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *AnnotationsTestMessage) XXX_Methods() *protoiface.Methods {
+func (x *AnnotationsTestMessage) XXX_Methods() *protoiface.Methods {
 	return file_annotations_annotations_proto_msgTypes[0].Methods()
 }
 
@@ -157,9 +166,11 @@ func file_annotations_annotations_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_annotations_annotations_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*AnnotationsTestMessage); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 1 - 1
cmd/protoc-gen-go/testdata/annotations/annotations.pb.go.meta

@@ -1 +1 @@
-annotation:{path:5 path:0 source_file:"annotations/annotations.proto" begin:631 end:650} annotation:{path:5 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:667 end:714} annotation:{path:4 path:0 source_file:"annotations/annotations.proto" begin:1821 end:1843} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:1854 end:1874} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:2796 end:2819}
+annotation:{path:5 path:0 source_file:"annotations/annotations.proto" begin:631 end:650} annotation:{path:5 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:667 end:714} annotation:{path:4 path:0 source_file:"annotations/annotations.proto" begin:1821 end:1843} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:1899 end:1919} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:3032 end:3055}

+ 85 - 19
cmd/protoc-gen-go/testdata/comments/comments.pb.go

@@ -21,6 +21,7 @@ const (
 
 // COMMENT: Message1
 type Message1 struct {
+	state protoimpl.MessageState
 	// COMMENT: Field1A
 	Field1A *string `protobuf:"bytes,1,opt,name=Field1A" json:"Field1A,omitempty"`
 	// COMMENT: Oneof1A
@@ -44,10 +45,18 @@ func (x *Message1) String() string {
 func (*Message1) ProtoMessage() {}
 
 func (x *Message1) ProtoReflect() protoreflect.Message {
-	return file_comments_comments_proto_msgTypes[0].MessageOf(x)
+	mi := &file_comments_comments_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message1) XXX_Methods() *protoiface.Methods {
+func (x *Message1) XXX_Methods() *protoiface.Methods {
 	return file_comments_comments_proto_msgTypes[0].Methods()
 }
 
@@ -89,6 +98,7 @@ func (*Message1_Oneof1AField1) isMessage1_Oneof1A() {}
 
 // COMMENT: Message2
 type Message2 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -104,10 +114,18 @@ func (x *Message2) String() string {
 func (*Message2) ProtoMessage() {}
 
 func (x *Message2) ProtoReflect() protoreflect.Message {
-	return file_comments_comments_proto_msgTypes[1].MessageOf(x)
+	mi := &file_comments_comments_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message2) XXX_Methods() *protoiface.Methods {
+func (x *Message2) XXX_Methods() *protoiface.Methods {
 	return file_comments_comments_proto_msgTypes[1].Methods()
 }
 
@@ -118,6 +136,7 @@ func (*Message2) Descriptor() ([]byte, []int) {
 
 // COMMENT: Message1A
 type Message1_Message1A struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -133,10 +152,18 @@ func (x *Message1_Message1A) String() string {
 func (*Message1_Message1A) ProtoMessage() {}
 
 func (x *Message1_Message1A) ProtoReflect() protoreflect.Message {
-	return file_comments_comments_proto_msgTypes[2].MessageOf(x)
+	mi := &file_comments_comments_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message1_Message1A) XXX_Methods() *protoiface.Methods {
+func (x *Message1_Message1A) XXX_Methods() *protoiface.Methods {
 	return file_comments_comments_proto_msgTypes[2].Methods()
 }
 
@@ -147,6 +174,7 @@ func (*Message1_Message1A) Descriptor() ([]byte, []int) {
 
 // COMMENT: Message1B
 type Message1_Message1B struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -162,10 +190,18 @@ func (x *Message1_Message1B) String() string {
 func (*Message1_Message1B) ProtoMessage() {}
 
 func (x *Message1_Message1B) ProtoReflect() protoreflect.Message {
-	return file_comments_comments_proto_msgTypes[3].MessageOf(x)
+	mi := &file_comments_comments_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message1_Message1B) XXX_Methods() *protoiface.Methods {
+func (x *Message1_Message1B) XXX_Methods() *protoiface.Methods {
 	return file_comments_comments_proto_msgTypes[3].Methods()
 }
 
@@ -176,6 +212,7 @@ func (*Message1_Message1B) Descriptor() ([]byte, []int) {
 
 // COMMENT: Message2A
 type Message2_Message2A struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -191,10 +228,18 @@ func (x *Message2_Message2A) String() string {
 func (*Message2_Message2A) ProtoMessage() {}
 
 func (x *Message2_Message2A) ProtoReflect() protoreflect.Message {
-	return file_comments_comments_proto_msgTypes[4].MessageOf(x)
+	mi := &file_comments_comments_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message2_Message2A) XXX_Methods() *protoiface.Methods {
+func (x *Message2_Message2A) XXX_Methods() *protoiface.Methods {
 	return file_comments_comments_proto_msgTypes[4].Methods()
 }
 
@@ -205,6 +250,7 @@ func (*Message2_Message2A) Descriptor() ([]byte, []int) {
 
 // COMMENT: Message2B
 type Message2_Message2B struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -220,10 +266,18 @@ func (x *Message2_Message2B) String() string {
 func (*Message2_Message2B) ProtoMessage() {}
 
 func (x *Message2_Message2B) ProtoReflect() protoreflect.Message {
-	return file_comments_comments_proto_msgTypes[5].MessageOf(x)
+	mi := &file_comments_comments_proto_msgTypes[5]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message2_Message2B) XXX_Methods() *protoiface.Methods {
+func (x *Message2_Message2B) XXX_Methods() *protoiface.Methods {
 	return file_comments_comments_proto_msgTypes[5].Methods()
 }
 
@@ -291,9 +345,11 @@ func file_comments_comments_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_comments_comments_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message1); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -302,8 +358,10 @@ func file_comments_comments_proto_init() {
 		file_comments_comments_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message2); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -312,8 +370,10 @@ func file_comments_comments_proto_init() {
 		file_comments_comments_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message1_Message1A); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -322,8 +382,10 @@ func file_comments_comments_proto_init() {
 		file_comments_comments_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message1_Message1B); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -332,8 +394,10 @@ func file_comments_comments_proto_init() {
 		file_comments_comments_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message2_Message2A); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -342,8 +406,10 @@ func file_comments_comments_proto_init() {
 		file_comments_comments_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message2_Message2B); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/comments/deprecated.pb.go

@@ -56,6 +56,7 @@ func (DeprecatedEnum) EnumDescriptor() ([]byte, []int) {
 
 // Deprecated: Do not use.
 type DeprecatedMessage struct {
+	state           protoimpl.MessageState
 	DeprecatedField string `protobuf:"bytes,1,opt,name=deprecated_field,json=deprecatedField,proto3" json:"deprecated_field,omitempty"` // Deprecated: Do not use.
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
@@ -72,10 +73,18 @@ func (x *DeprecatedMessage) String() string {
 func (*DeprecatedMessage) ProtoMessage() {}
 
 func (x *DeprecatedMessage) ProtoReflect() protoreflect.Message {
-	return file_comments_deprecated_proto_msgTypes[0].MessageOf(x)
+	mi := &file_comments_deprecated_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *DeprecatedMessage) XXX_Methods() *protoiface.Methods {
+func (x *DeprecatedMessage) XXX_Methods() *protoiface.Methods {
 	return file_comments_deprecated_proto_msgTypes[0].Methods()
 }
 
@@ -147,9 +156,11 @@ func file_comments_deprecated_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_comments_deprecated_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*DeprecatedMessage); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 31 - 9
cmd/protoc-gen-go/testdata/extensions/base/base.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type BaseMessage struct {
+	state           protoimpl.MessageState
 	Field           *string `protobuf:"bytes,1,opt,name=field" json:"field,omitempty"`
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
@@ -35,10 +36,18 @@ func (x *BaseMessage) String() string {
 func (*BaseMessage) ProtoMessage() {}
 
 func (x *BaseMessage) ProtoReflect() protoreflect.Message {
-	return file_extensions_base_base_proto_msgTypes[0].MessageOf(x)
+	mi := &file_extensions_base_base_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *BaseMessage) XXX_Methods() *protoiface.Methods {
+func (x *BaseMessage) XXX_Methods() *protoiface.Methods {
 	return file_extensions_base_base_proto_msgTypes[0].Methods()
 }
 
@@ -65,6 +74,7 @@ func (x *BaseMessage) GetField() string {
 }
 
 type MessageSetWireFormatMessage struct {
+	state           protoimpl.MessageState
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
 	extensionFields protoimpl.ExtensionFields
@@ -81,10 +91,18 @@ func (x *MessageSetWireFormatMessage) String() string {
 func (*MessageSetWireFormatMessage) ProtoMessage() {}
 
 func (x *MessageSetWireFormatMessage) ProtoReflect() protoreflect.Message {
-	return file_extensions_base_base_proto_msgTypes[1].MessageOf(x)
+	mi := &file_extensions_base_base_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *MessageSetWireFormatMessage) XXX_Methods() *protoiface.Methods {
+func (x *MessageSetWireFormatMessage) XXX_Methods() *protoiface.Methods {
 	return file_extensions_base_base_proto_msgTypes[1].Methods()
 }
 
@@ -155,11 +173,13 @@ func file_extensions_base_base_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_extensions_base_base_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*BaseMessage); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 3:
+				return &v.unknownFields
+			case 4:
 				return &v.extensionFields
 			default:
 				return nil
@@ -168,10 +188,12 @@ func file_extensions_base_base_proto_init() {
 		file_extensions_base_base_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*MessageSetWireFormatMessage); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 2:
+				return &v.unknownFields
+			case 3:
 				return &v.extensionFields
 			default:
 				return nil

+ 116 - 28
cmd/protoc-gen-go/testdata/extensions/ext/ext.pb.go

@@ -68,6 +68,7 @@ func (Enum) EnumDescriptor() ([]byte, []int) {
 }
 
 type Message struct {
+	state         protoimpl.MessageState
 	Data          []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -84,10 +85,18 @@ func (x *Message) String() string {
 func (*Message) ProtoMessage() {}
 
 func (x *Message) ProtoReflect() protoreflect.Message {
-	return file_extensions_ext_ext_proto_msgTypes[0].MessageOf(x)
+	mi := &file_extensions_ext_ext_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message) XXX_Methods() *protoiface.Methods {
+func (x *Message) XXX_Methods() *protoiface.Methods {
 	return file_extensions_ext_ext_proto_msgTypes[0].Methods()
 }
 
@@ -104,6 +113,7 @@ func (x *Message) GetData() []byte {
 }
 
 type ExtensionGroup struct {
+	state          protoimpl.MessageState
 	ExtensionGroup *string `protobuf:"bytes,120,opt,name=extension_group,json=extensionGroup" json:"extension_group,omitempty"`
 	sizeCache      protoimpl.SizeCache
 	unknownFields  protoimpl.UnknownFields
@@ -120,10 +130,18 @@ func (x *ExtensionGroup) String() string {
 func (*ExtensionGroup) ProtoMessage() {}
 
 func (x *ExtensionGroup) ProtoReflect() protoreflect.Message {
-	return file_extensions_ext_ext_proto_msgTypes[1].MessageOf(x)
+	mi := &file_extensions_ext_ext_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ExtensionGroup) XXX_Methods() *protoiface.Methods {
+func (x *ExtensionGroup) XXX_Methods() *protoiface.Methods {
 	return file_extensions_ext_ext_proto_msgTypes[1].Methods()
 }
 
@@ -141,6 +159,7 @@ func (x *ExtensionGroup) GetExtensionGroup() string {
 
 // Extend in the scope of another type.
 type ExtendingMessage struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -156,10 +175,18 @@ func (x *ExtendingMessage) String() string {
 func (*ExtendingMessage) ProtoMessage() {}
 
 func (x *ExtendingMessage) ProtoReflect() protoreflect.Message {
-	return file_extensions_ext_ext_proto_msgTypes[2].MessageOf(x)
+	mi := &file_extensions_ext_ext_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ExtendingMessage) XXX_Methods() *protoiface.Methods {
+func (x *ExtendingMessage) XXX_Methods() *protoiface.Methods {
 	return file_extensions_ext_ext_proto_msgTypes[2].Methods()
 }
 
@@ -169,6 +196,7 @@ func (*ExtendingMessage) Descriptor() ([]byte, []int) {
 }
 
 type RepeatedGroup struct {
+	state          protoimpl.MessageState
 	RepeatedXGroup []string `protobuf:"bytes,319,rep,name=repeated_x_group,json=repeatedXGroup" json:"repeated_x_group,omitempty"`
 	sizeCache      protoimpl.SizeCache
 	unknownFields  protoimpl.UnknownFields
@@ -185,10 +213,18 @@ func (x *RepeatedGroup) String() string {
 func (*RepeatedGroup) ProtoMessage() {}
 
 func (x *RepeatedGroup) ProtoReflect() protoreflect.Message {
-	return file_extensions_ext_ext_proto_msgTypes[3].MessageOf(x)
+	mi := &file_extensions_ext_ext_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *RepeatedGroup) XXX_Methods() *protoiface.Methods {
+func (x *RepeatedGroup) XXX_Methods() *protoiface.Methods {
 	return file_extensions_ext_ext_proto_msgTypes[3].Methods()
 }
 
@@ -206,6 +242,7 @@ func (x *RepeatedGroup) GetRepeatedXGroup() []string {
 
 // An extension of an extension.
 type Extendable struct {
+	state           protoimpl.MessageState
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
 	extensionFields protoimpl.ExtensionFields
@@ -222,10 +259,18 @@ func (x *Extendable) String() string {
 func (*Extendable) ProtoMessage() {}
 
 func (x *Extendable) ProtoReflect() protoreflect.Message {
-	return file_extensions_ext_ext_proto_msgTypes[4].MessageOf(x)
+	mi := &file_extensions_ext_ext_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Extendable) XXX_Methods() *protoiface.Methods {
+func (x *Extendable) XXX_Methods() *protoiface.Methods {
 	return file_extensions_ext_ext_proto_msgTypes[4].Methods()
 }
 
@@ -245,6 +290,7 @@ func (*Extendable) ExtensionRangeArray() []protoiface.ExtensionRangeV1 {
 
 // Message set wire format.
 type MessageSetWireFormatExtension struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -260,10 +306,18 @@ func (x *MessageSetWireFormatExtension) String() string {
 func (*MessageSetWireFormatExtension) ProtoMessage() {}
 
 func (x *MessageSetWireFormatExtension) ProtoReflect() protoreflect.Message {
-	return file_extensions_ext_ext_proto_msgTypes[5].MessageOf(x)
+	mi := &file_extensions_ext_ext_proto_msgTypes[5]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *MessageSetWireFormatExtension) XXX_Methods() *protoiface.Methods {
+func (x *MessageSetWireFormatExtension) XXX_Methods() *protoiface.Methods {
 	return file_extensions_ext_ext_proto_msgTypes[5].Methods()
 }
 
@@ -273,6 +327,7 @@ func (*MessageSetWireFormatExtension) Descriptor() ([]byte, []int) {
 }
 
 type Message_M struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -288,10 +343,18 @@ func (x *Message_M) String() string {
 func (*Message_M) ProtoMessage() {}
 
 func (x *Message_M) ProtoReflect() protoreflect.Message {
-	return file_extensions_ext_ext_proto_msgTypes[6].MessageOf(x)
+	mi := &file_extensions_ext_ext_proto_msgTypes[6]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message_M) XXX_Methods() *protoiface.Methods {
+func (x *Message_M) XXX_Methods() *protoiface.Methods {
 	return file_extensions_ext_ext_proto_msgTypes[6].Methods()
 }
 
@@ -301,6 +364,7 @@ func (*Message_M) Descriptor() ([]byte, []int) {
 }
 
 type ExtendingMessage_ExtendingMessageSubmessage struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -316,10 +380,18 @@ func (x *ExtendingMessage_ExtendingMessageSubmessage) String() string {
 func (*ExtendingMessage_ExtendingMessageSubmessage) ProtoMessage() {}
 
 func (x *ExtendingMessage_ExtendingMessageSubmessage) ProtoReflect() protoreflect.Message {
-	return file_extensions_ext_ext_proto_msgTypes[7].MessageOf(x)
+	mi := &file_extensions_ext_ext_proto_msgTypes[7]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ExtendingMessage_ExtendingMessageSubmessage) XXX_Methods() *protoiface.Methods {
+func (x *ExtendingMessage_ExtendingMessageSubmessage) XXX_Methods() *protoiface.Methods {
 	return file_extensions_ext_ext_proto_msgTypes[7].Methods()
 }
 
@@ -1233,9 +1305,11 @@ func file_extensions_ext_ext_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_extensions_ext_ext_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1243,9 +1317,11 @@ func file_extensions_ext_ext_proto_init() {
 		}
 		file_extensions_ext_ext_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ExtensionGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1254,8 +1330,10 @@ func file_extensions_ext_ext_proto_init() {
 		file_extensions_ext_ext_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ExtendingMessage); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1263,9 +1341,11 @@ func file_extensions_ext_ext_proto_init() {
 		}
 		file_extensions_ext_ext_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*RepeatedGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1274,10 +1354,12 @@ func file_extensions_ext_ext_proto_init() {
 		file_extensions_ext_ext_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Extendable); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 2:
+				return &v.unknownFields
+			case 3:
 				return &v.extensionFields
 			default:
 				return nil
@@ -1286,8 +1368,10 @@ func file_extensions_ext_ext_proto_init() {
 		file_extensions_ext_ext_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*MessageSetWireFormatExtension); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1296,8 +1380,10 @@ func file_extensions_ext_ext_proto_init() {
 		file_extensions_ext_ext_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message_M); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1306,8 +1392,10 @@ func file_extensions_ext_ext_proto_init() {
 		file_extensions_ext_ext_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ExtendingMessage_ExtendingMessageSubmessage); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/extensions/extra/extra.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type ExtraMessage struct {
+	state         protoimpl.MessageState
 	Data          []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -34,10 +35,18 @@ func (x *ExtraMessage) String() string {
 func (*ExtraMessage) ProtoMessage() {}
 
 func (x *ExtraMessage) ProtoReflect() protoreflect.Message {
-	return file_extensions_extra_extra_proto_msgTypes[0].MessageOf(x)
+	mi := &file_extensions_extra_extra_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ExtraMessage) XXX_Methods() *protoiface.Methods {
+func (x *ExtraMessage) XXX_Methods() *protoiface.Methods {
 	return file_extensions_extra_extra_proto_msgTypes[0].Methods()
 }
 
@@ -101,9 +110,11 @@ func file_extensions_extra_extra_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_extensions_extra_extra_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ExtraMessage); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
cmd/protoc-gen-go/testdata/extensions/proto3/ext3.pb.go

@@ -57,6 +57,7 @@ func (Enum) EnumDescriptor() ([]byte, []int) {
 }
 
 type Message struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -72,10 +73,18 @@ func (x *Message) String() string {
 func (*Message) ProtoMessage() {}
 
 func (x *Message) ProtoReflect() protoreflect.Message {
-	return file_extensions_proto3_ext3_proto_msgTypes[0].MessageOf(x)
+	mi := &file_extensions_proto3_ext3_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message) XXX_Methods() *protoiface.Methods {
+func (x *Message) XXX_Methods() *protoiface.Methods {
 	return file_extensions_proto3_ext3_proto_msgTypes[0].Methods()
 }
 
@@ -745,8 +754,10 @@ func file_extensions_proto3_ext3_proto_init() {
 		file_extensions_proto3_ext3_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 29 - 7
cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go

@@ -23,6 +23,7 @@ const (
 // This exists to demonstrate the current behavior and catch unintended
 // changes in it.
 type Message struct {
+	state protoimpl.MessageState
 	// Various CamelCase conversions.
 	FieldOne   *string `protobuf:"bytes,1,opt,name=field_one,json=fieldOne" json:"field_one,omitempty"`
 	FieldTwo   *string `protobuf:"bytes,2,opt,name=FieldTwo" json:"FieldTwo,omitempty"`
@@ -72,10 +73,18 @@ func (x *Message) String() string {
 func (*Message) ProtoMessage() {}
 
 func (x *Message) ProtoReflect() protoreflect.Message {
-	return file_fieldnames_fieldnames_proto_msgTypes[0].MessageOf(x)
+	mi := &file_fieldnames_fieldnames_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message) XXX_Methods() *protoiface.Methods {
+func (x *Message) XXX_Methods() *protoiface.Methods {
 	return file_fieldnames_fieldnames_proto_msgTypes[0].Methods()
 }
 
@@ -268,6 +277,7 @@ type Message_OneofMessageConflict_ struct {
 func (*Message_OneofMessageConflict_) isMessage_OneofConflictC() {}
 
 type Message_OneofMessageConflict struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -283,10 +293,18 @@ func (x *Message_OneofMessageConflict) String() string {
 func (*Message_OneofMessageConflict) ProtoMessage() {}
 
 func (x *Message_OneofMessageConflict) ProtoReflect() protoreflect.Message {
-	return file_fieldnames_fieldnames_proto_msgTypes[1].MessageOf(x)
+	mi := &file_fieldnames_fieldnames_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message_OneofMessageConflict) XXX_Methods() *protoiface.Methods {
+func (x *Message_OneofMessageConflict) XXX_Methods() *protoiface.Methods {
 	return file_fieldnames_fieldnames_proto_msgTypes[1].Methods()
 }
 
@@ -385,9 +403,11 @@ func file_fieldnames_fieldnames_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_fieldnames_fieldnames_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message); i {
-			case 17:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 18:
+				return &v.sizeCache
+			case 19:
 				return &v.unknownFields
 			default:
 				return nil
@@ -396,8 +416,10 @@ func file_fieldnames_fieldnames_proto_init() {
 		file_fieldnames_fieldnames_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message_OneofMessageConflict); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/import_public/a.pb.go

@@ -57,6 +57,7 @@ type M_Submessage_SubmessageOneofInt64 = sub.M_Submessage_SubmessageOneofInt64
 var E_ExtensionField = sub.E_ExtensionField
 
 type Public struct {
+	state         protoimpl.MessageState
 	M             *sub.M `protobuf:"bytes,1,opt,name=m" json:"m,omitempty"`
 	E             *sub.E `protobuf:"varint,2,opt,name=e,enum=goproto.protoc.import_public.sub.E" json:"e,omitempty"`
 	Local         *Local `protobuf:"bytes,3,opt,name=local" json:"local,omitempty"`
@@ -75,10 +76,18 @@ func (x *Public) String() string {
 func (*Public) ProtoMessage() {}
 
 func (x *Public) ProtoReflect() protoreflect.Message {
-	return file_import_public_a_proto_msgTypes[0].MessageOf(x)
+	mi := &file_import_public_a_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Public) XXX_Methods() *protoiface.Methods {
+func (x *Public) XXX_Methods() *protoiface.Methods {
 	return file_import_public_a_proto_msgTypes[0].Methods()
 }
 
@@ -174,9 +183,11 @@ func file_import_public_a_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_import_public_a_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Public); i {
-			case 3:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 4:
+				return &v.sizeCache
+			case 5:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/import_public/b.pb.go

@@ -19,6 +19,7 @@ const (
 )
 
 type Local struct {
+	state         protoimpl.MessageState
 	M             *sub.M `protobuf:"bytes,1,opt,name=m" json:"m,omitempty"`
 	E             *sub.E `protobuf:"varint,2,opt,name=e,enum=goproto.protoc.import_public.sub.E" json:"e,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -36,10 +37,18 @@ func (x *Local) String() string {
 func (*Local) ProtoMessage() {}
 
 func (x *Local) ProtoReflect() protoreflect.Message {
-	return file_import_public_b_proto_msgTypes[0].MessageOf(x)
+	mi := &file_import_public_b_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Local) XXX_Methods() *protoiface.Methods {
+func (x *Local) XXX_Methods() *protoiface.Methods {
 	return file_import_public_b_proto_msgTypes[0].Methods()
 }
 
@@ -120,9 +129,11 @@ func file_import_public_b_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_import_public_b_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Local); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/import_public/c.pb.go

@@ -19,6 +19,7 @@ const (
 )
 
 type UsingPublicImport struct {
+	state protoimpl.MessageState
 	// Local is declared in b.proto, which is a public import of a.proto.
 	Local *Local `protobuf:"bytes,1,opt,name=local" json:"local,omitempty"`
 	// Sub2Message is declared in sub2/a.proto, which is a public import of
@@ -39,10 +40,18 @@ func (x *UsingPublicImport) String() string {
 func (*UsingPublicImport) ProtoMessage() {}
 
 func (x *UsingPublicImport) ProtoReflect() protoreflect.Message {
-	return file_import_public_c_proto_msgTypes[0].MessageOf(x)
+	mi := &file_import_public_c_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *UsingPublicImport) XXX_Methods() *protoiface.Methods {
+func (x *UsingPublicImport) XXX_Methods() *protoiface.Methods {
 	return file_import_public_c_proto_msgTypes[0].Methods()
 }
 
@@ -126,9 +135,11 @@ func file_import_public_c_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_import_public_c_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*UsingPublicImport); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 31 - 9
cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go

@@ -166,6 +166,7 @@ func (M_Submessage_Submessage_Subenum) EnumDescriptor() ([]byte, []int) {
 }
 
 type M struct {
+	state protoimpl.MessageState
 	// Field using a type in the same Go package, but a different source file.
 	M2 *M2      `protobuf:"bytes,1,opt,name=m2" json:"m2,omitempty"`
 	S  *string  `protobuf:"bytes,4,opt,name=s,def=default" json:"s,omitempty"`
@@ -191,10 +192,18 @@ func (x *M) String() string {
 func (*M) ProtoMessage() {}
 
 func (x *M) ProtoReflect() protoreflect.Message {
-	return file_import_public_sub_a_proto_msgTypes[0].MessageOf(x)
+	mi := &file_import_public_sub_a_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M) XXX_Methods() *protoiface.Methods {
+func (x *M) XXX_Methods() *protoiface.Methods {
 	return file_import_public_sub_a_proto_msgTypes[0].Methods()
 }
 
@@ -283,6 +292,7 @@ func (*M_OneofInt32) isM_OneofField() {}
 func (*M_OneofInt64) isM_OneofField() {}
 
 type M_Submessage struct {
+	state protoimpl.MessageState
 	// Types that are valid to be assigned to SubmessageOneofField:
 	//	*M_Submessage_SubmessageOneofInt32
 	//	*M_Submessage_SubmessageOneofInt64
@@ -302,10 +312,18 @@ func (x *M_Submessage) String() string {
 func (*M_Submessage) ProtoMessage() {}
 
 func (x *M_Submessage) ProtoReflect() protoreflect.Message {
-	return file_import_public_sub_a_proto_msgTypes[1].MessageOf(x)
+	mi := &file_import_public_sub_a_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M_Submessage) XXX_Methods() *protoiface.Methods {
+func (x *M_Submessage) XXX_Methods() *protoiface.Methods {
 	return file_import_public_sub_a_proto_msgTypes[1].Methods()
 }
 
@@ -457,11 +475,13 @@ func file_import_public_sub_a_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_import_public_sub_a_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M); i {
-			case 5:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 6:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 7:
+				return &v.unknownFields
+			case 8:
 				return &v.extensionFields
 			default:
 				return nil
@@ -469,9 +489,11 @@ func file_import_public_sub_a_proto_init() {
 		}
 		file_import_public_sub_a_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M_Submessage); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
cmd/protoc-gen-go/testdata/import_public/sub/b.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type M2 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *M2) String() string {
 func (*M2) ProtoMessage() {}
 
 func (x *M2) ProtoReflect() protoreflect.Message {
-	return file_import_public_sub_b_proto_msgTypes[0].MessageOf(x)
+	mi := &file_import_public_sub_b_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M2) XXX_Methods() *protoiface.Methods {
+func (x *M2) XXX_Methods() *protoiface.Methods {
 	return file_import_public_sub_b_proto_msgTypes[0].Methods()
 }
 
@@ -92,8 +101,10 @@ func file_import_public_sub_b_proto_init() {
 		file_import_public_sub_b_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M2); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
cmd/protoc-gen-go/testdata/import_public/sub2/a.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type Sub2Message struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *Sub2Message) String() string {
 func (*Sub2Message) ProtoMessage() {}
 
 func (x *Sub2Message) ProtoReflect() protoreflect.Message {
-	return file_import_public_sub2_a_proto_msgTypes[0].MessageOf(x)
+	mi := &file_import_public_sub2_a_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Sub2Message) XXX_Methods() *protoiface.Methods {
+func (x *Sub2Message) XXX_Methods() *protoiface.Methods {
 	return file_import_public_sub2_a_proto_msgTypes[0].Methods()
 }
 
@@ -93,8 +102,10 @@ func file_import_public_sub2_a_proto_init() {
 		file_import_public_sub2_a_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Sub2Message); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
cmd/protoc-gen-go/testdata/imports/fmt/m.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type M struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *M) String() string {
 func (*M) ProtoMessage() {}
 
 func (x *M) ProtoReflect() protoreflect.Message {
-	return file_imports_fmt_m_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_fmt_m_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M) XXX_Methods() *protoiface.Methods {
+func (x *M) XXX_Methods() *protoiface.Methods {
 	return file_imports_fmt_m_proto_msgTypes[0].Methods()
 }
 
@@ -90,8 +99,10 @@ func file_imports_fmt_m_proto_init() {
 		file_imports_fmt_m_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 29 - 7
cmd/protoc-gen-go/testdata/imports/test_a_1/m1.pb.go

@@ -56,6 +56,7 @@ func (E1) EnumDescriptor() ([]byte, []int) {
 }
 
 type M1 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -71,10 +72,18 @@ func (x *M1) String() string {
 func (*M1) ProtoMessage() {}
 
 func (x *M1) ProtoReflect() protoreflect.Message {
-	return file_imports_test_a_1_m1_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_test_a_1_m1_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M1) XXX_Methods() *protoiface.Methods {
+func (x *M1) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_a_1_m1_proto_msgTypes[0].Methods()
 }
 
@@ -84,6 +93,7 @@ func (*M1) Descriptor() ([]byte, []int) {
 }
 
 type M1_1 struct {
+	state         protoimpl.MessageState
 	M1            *M1 `protobuf:"bytes,1,opt,name=m1,proto3" json:"m1,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -100,10 +110,18 @@ func (x *M1_1) String() string {
 func (*M1_1) ProtoMessage() {}
 
 func (x *M1_1) ProtoReflect() protoreflect.Message {
-	return file_imports_test_a_1_m1_proto_msgTypes[1].MessageOf(x)
+	mi := &file_imports_test_a_1_m1_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M1_1) XXX_Methods() *protoiface.Methods {
+func (x *M1_1) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_a_1_m1_proto_msgTypes[1].Methods()
 }
 
@@ -173,8 +191,10 @@ func file_imports_test_a_1_m1_proto_init() {
 		file_imports_test_a_1_m1_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M1); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -182,9 +202,11 @@ func file_imports_test_a_1_m1_proto_init() {
 		}
 		file_imports_test_a_1_m1_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M1_1); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
cmd/protoc-gen-go/testdata/imports/test_a_1/m2.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type M2 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *M2) String() string {
 func (*M2) ProtoMessage() {}
 
 func (x *M2) ProtoReflect() protoreflect.Message {
-	return file_imports_test_a_1_m2_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_test_a_1_m2_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M2) XXX_Methods() *protoiface.Methods {
+func (x *M2) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_a_1_m2_proto_msgTypes[0].Methods()
 }
 
@@ -91,8 +100,10 @@ func file_imports_test_a_1_m2_proto_init() {
 		file_imports_test_a_1_m2_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M2); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
cmd/protoc-gen-go/testdata/imports/test_a_2/m3.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type M3 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *M3) String() string {
 func (*M3) ProtoMessage() {}
 
 func (x *M3) ProtoReflect() protoreflect.Message {
-	return file_imports_test_a_2_m3_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_test_a_2_m3_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M3) XXX_Methods() *protoiface.Methods {
+func (x *M3) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_a_2_m3_proto_msgTypes[0].Methods()
 }
 
@@ -91,8 +100,10 @@ func file_imports_test_a_2_m3_proto_init() {
 		file_imports_test_a_2_m3_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M3); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
cmd/protoc-gen-go/testdata/imports/test_a_2/m4.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type M4 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *M4) String() string {
 func (*M4) ProtoMessage() {}
 
 func (x *M4) ProtoReflect() protoreflect.Message {
-	return file_imports_test_a_2_m4_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_test_a_2_m4_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M4) XXX_Methods() *protoiface.Methods {
+func (x *M4) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_a_2_m4_proto_msgTypes[0].Methods()
 }
 
@@ -91,8 +100,10 @@ func file_imports_test_a_2_m4_proto_init() {
 		file_imports_test_a_2_m4_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M4); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
cmd/protoc-gen-go/testdata/imports/test_b_1/m1.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type M1 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *M1) String() string {
 func (*M1) ProtoMessage() {}
 
 func (x *M1) ProtoReflect() protoreflect.Message {
-	return file_imports_test_b_1_m1_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_test_b_1_m1_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M1) XXX_Methods() *protoiface.Methods {
+func (x *M1) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_b_1_m1_proto_msgTypes[0].Methods()
 }
 
@@ -92,8 +101,10 @@ func file_imports_test_b_1_m1_proto_init() {
 		file_imports_test_b_1_m1_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M1); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
cmd/protoc-gen-go/testdata/imports/test_b_1/m2.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type M2 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *M2) String() string {
 func (*M2) ProtoMessage() {}
 
 func (x *M2) ProtoReflect() protoreflect.Message {
-	return file_imports_test_b_1_m2_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_test_b_1_m2_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *M2) XXX_Methods() *protoiface.Methods {
+func (x *M2) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_b_1_m2_proto_msgTypes[0].Methods()
 }
 
@@ -92,8 +101,10 @@ func file_imports_test_b_1_m2_proto_init() {
 		file_imports_test_b_1_m2_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*M2); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/imports/test_import_a1m1.pb.go

@@ -19,6 +19,7 @@ const (
 )
 
 type A1M1 struct {
+	state         protoimpl.MessageState
 	F             *test_a_1.M1 `protobuf:"bytes,1,opt,name=f,proto3" json:"f,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -35,10 +36,18 @@ func (x *A1M1) String() string {
 func (*A1M1) ProtoMessage() {}
 
 func (x *A1M1) ProtoReflect() protoreflect.Message {
-	return file_imports_test_import_a1m1_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_test_import_a1m1_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *A1M1) XXX_Methods() *protoiface.Methods {
+func (x *A1M1) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_import_a1m1_proto_msgTypes[0].Methods()
 }
 
@@ -104,9 +113,11 @@ func file_imports_test_import_a1m1_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_imports_test_import_a1m1_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*A1M1); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/imports/test_import_a1m2.pb.go

@@ -19,6 +19,7 @@ const (
 )
 
 type A1M2 struct {
+	state         protoimpl.MessageState
 	F             *test_a_1.M2 `protobuf:"bytes,1,opt,name=f,proto3" json:"f,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -35,10 +36,18 @@ func (x *A1M2) String() string {
 func (*A1M2) ProtoMessage() {}
 
 func (x *A1M2) ProtoReflect() protoreflect.Message {
-	return file_imports_test_import_a1m2_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_test_import_a1m2_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *A1M2) XXX_Methods() *protoiface.Methods {
+func (x *A1M2) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_import_a1m2_proto_msgTypes[0].Methods()
 }
 
@@ -104,9 +113,11 @@ func file_imports_test_import_a1m2_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_imports_test_import_a1m2_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*A1M2); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/imports/test_import_all.pb.go

@@ -22,6 +22,7 @@ const (
 )
 
 type All struct {
+	state         protoimpl.MessageState
 	Am1           *test_a_1.M1 `protobuf:"bytes,1,opt,name=am1,proto3" json:"am1,omitempty"`
 	Am2           *test_a_1.M2 `protobuf:"bytes,2,opt,name=am2,proto3" json:"am2,omitempty"`
 	Bm1           *test_b_1.M1 `protobuf:"bytes,5,opt,name=bm1,proto3" json:"bm1,omitempty"`
@@ -42,10 +43,18 @@ func (x *All) String() string {
 func (*All) ProtoMessage() {}
 
 func (x *All) ProtoReflect() protoreflect.Message {
-	return file_imports_test_import_all_proto_msgTypes[0].MessageOf(x)
+	mi := &file_imports_test_import_all_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *All) XXX_Methods() *protoiface.Methods {
+func (x *All) XXX_Methods() *protoiface.Methods {
 	return file_imports_test_import_all_proto_msgTypes[0].Methods()
 }
 
@@ -165,9 +174,11 @@ func file_imports_test_import_all_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_imports_test_import_all_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*All); i {
-			case 5:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 6:
+				return &v.sizeCache
+			case 7:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type Foo struct {
+	state protoimpl.MessageState
 	// Types that are valid to be assigned to Bar:
 	//	*Foo_GetBar
 	Bar           isFoo_Bar `protobuf_oneof:"bar"`
@@ -36,10 +37,18 @@ func (x *Foo) String() string {
 func (*Foo) ProtoMessage() {}
 
 func (x *Foo) ProtoReflect() protoreflect.Message {
-	return file_issue780_oneof_conflict_test_proto_msgTypes[0].MessageOf(x)
+	mi := &file_issue780_oneof_conflict_test_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Foo) XXX_Methods() *protoiface.Methods {
+func (x *Foo) XXX_Methods() *protoiface.Methods {
 	return file_issue780_oneof_conflict_test_proto_msgTypes[0].Methods()
 }
 
@@ -115,9 +124,11 @@ func file_issue780_oneof_conflict_test_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_issue780_oneof_conflict_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Foo); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go

@@ -66,6 +66,7 @@ func (Enum) EnumDescriptor() ([]byte, []int) {
 }
 
 type Message struct {
+	state         protoimpl.MessageState
 	StringField   *string `protobuf:"bytes,1,opt,name=string_field,json=stringField" json:"string_field,omitempty"`
 	EnumField     *Enum   `protobuf:"varint,2,opt,name=enum_field,json=enumField,enum=Enum,def=0" json:"enum_field,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -83,10 +84,18 @@ func (x *Message) String() string {
 func (*Message) ProtoMessage() {}
 
 func (x *Message) ProtoReflect() protoreflect.Message {
-	return file_nopackage_nopackage_proto_msgTypes[0].MessageOf(x)
+	mi := &file_nopackage_nopackage_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message) XXX_Methods() *protoiface.Methods {
+func (x *Message) XXX_Methods() *protoiface.Methods {
 	return file_nopackage_nopackage_proto_msgTypes[0].Methods()
 }
 
@@ -160,9 +169,11 @@ func file_nopackage_nopackage_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_nopackage_nopackage_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 29 - 7
cmd/protoc-gen-go/testdata/proto2/enum.pb.go

@@ -314,6 +314,7 @@ func (EnumContainerMessage1_EnumContainerMessage2_NestedEnumType2B) EnumDescript
 }
 
 type EnumContainerMessage1 struct {
+	state             protoimpl.MessageState
 	DefaultDuplicate1 *EnumType2 `protobuf:"varint,1,opt,name=default_duplicate1,json=defaultDuplicate1,enum=goproto.protoc.proto2.EnumType2,def=1" json:"default_duplicate1,omitempty"`
 	DefaultDuplicate2 *EnumType2 `protobuf:"varint,2,opt,name=default_duplicate2,json=defaultDuplicate2,enum=goproto.protoc.proto2.EnumType2,def=1" json:"default_duplicate2,omitempty"`
 	sizeCache         protoimpl.SizeCache
@@ -331,10 +332,18 @@ func (x *EnumContainerMessage1) String() string {
 func (*EnumContainerMessage1) ProtoMessage() {}
 
 func (x *EnumContainerMessage1) ProtoReflect() protoreflect.Message {
-	return file_proto2_enum_proto_msgTypes[0].MessageOf(x)
+	mi := &file_proto2_enum_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *EnumContainerMessage1) XXX_Methods() *protoiface.Methods {
+func (x *EnumContainerMessage1) XXX_Methods() *protoiface.Methods {
 	return file_proto2_enum_proto_msgTypes[0].Methods()
 }
 
@@ -361,6 +370,7 @@ func (x *EnumContainerMessage1) GetDefaultDuplicate2() EnumType2 {
 }
 
 type EnumContainerMessage1_EnumContainerMessage2 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -376,10 +386,18 @@ func (x *EnumContainerMessage1_EnumContainerMessage2) String() string {
 func (*EnumContainerMessage1_EnumContainerMessage2) ProtoMessage() {}
 
 func (x *EnumContainerMessage1_EnumContainerMessage2) ProtoReflect() protoreflect.Message {
-	return file_proto2_enum_proto_msgTypes[1].MessageOf(x)
+	mi := &file_proto2_enum_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *EnumContainerMessage1_EnumContainerMessage2) XXX_Methods() *protoiface.Methods {
+func (x *EnumContainerMessage1_EnumContainerMessage2) XXX_Methods() *protoiface.Methods {
 	return file_proto2_enum_proto_msgTypes[1].Methods()
 }
 
@@ -474,9 +492,11 @@ func file_proto2_enum_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_proto2_enum_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*EnumContainerMessage1); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -485,8 +505,10 @@ func file_proto2_enum_proto_init() {
 		file_proto2_enum_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*EnumContainerMessage1_EnumContainerMessage2); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 89 - 23
cmd/protoc-gen-go/testdata/proto2/fields.pb.go

@@ -70,6 +70,7 @@ func (FieldTestMessage_Enum) EnumDescriptor() ([]byte, []int) {
 }
 
 type FieldTestMessage struct {
+	state               protoimpl.MessageState
 	OptionalBool        *bool                                `protobuf:"varint,1,opt,name=optional_bool,json=optionalBool" json:"optional_bool,omitempty"`
 	OptionalEnum        *FieldTestMessage_Enum               `protobuf:"varint,2,opt,name=optional_enum,json=optionalEnum,enum=goproto.protoc.proto2.FieldTestMessage_Enum" json:"optional_enum,omitempty"`
 	OptionalInt32       *int32                               `protobuf:"varint,3,opt,name=optional_int32,json=optionalInt32" json:"optional_int32,omitempty"`
@@ -191,10 +192,18 @@ func (x *FieldTestMessage) String() string {
 func (*FieldTestMessage) ProtoMessage() {}
 
 func (x *FieldTestMessage) ProtoReflect() protoreflect.Message {
-	return file_proto2_fields_proto_msgTypes[0].MessageOf(x)
+	mi := &file_proto2_fields_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FieldTestMessage) XXX_Methods() *protoiface.Methods {
+func (x *FieldTestMessage) XXX_Methods() *protoiface.Methods {
 	return file_proto2_fields_proto_msgTypes[0].Methods()
 }
 
@@ -1094,6 +1103,7 @@ func (*FieldTestMessage_OneofTwo_1) isFieldTestMessage_OneofTwo() {}
 func (*FieldTestMessage_OneofTwo_2) isFieldTestMessage_OneofTwo() {}
 
 type FieldTestMessage_OptionalGroup struct {
+	state         protoimpl.MessageState
 	OptionalGroup *string `protobuf:"bytes,19,opt,name=optional_group,json=optionalGroup" json:"optional_group,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1110,10 +1120,18 @@ func (x *FieldTestMessage_OptionalGroup) String() string {
 func (*FieldTestMessage_OptionalGroup) ProtoMessage() {}
 
 func (x *FieldTestMessage_OptionalGroup) ProtoReflect() protoreflect.Message {
-	return file_proto2_fields_proto_msgTypes[1].MessageOf(x)
+	mi := &file_proto2_fields_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FieldTestMessage_OptionalGroup) XXX_Methods() *protoiface.Methods {
+func (x *FieldTestMessage_OptionalGroup) XXX_Methods() *protoiface.Methods {
 	return file_proto2_fields_proto_msgTypes[1].Methods()
 }
 
@@ -1130,6 +1148,7 @@ func (x *FieldTestMessage_OptionalGroup) GetOptionalGroup() string {
 }
 
 type FieldTestMessage_RequiredGroup struct {
+	state         protoimpl.MessageState
 	RequiredGroup *string `protobuf:"bytes,119,req,name=required_group,json=requiredGroup" json:"required_group,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1146,10 +1165,18 @@ func (x *FieldTestMessage_RequiredGroup) String() string {
 func (*FieldTestMessage_RequiredGroup) ProtoMessage() {}
 
 func (x *FieldTestMessage_RequiredGroup) ProtoReflect() protoreflect.Message {
-	return file_proto2_fields_proto_msgTypes[2].MessageOf(x)
+	mi := &file_proto2_fields_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FieldTestMessage_RequiredGroup) XXX_Methods() *protoiface.Methods {
+func (x *FieldTestMessage_RequiredGroup) XXX_Methods() *protoiface.Methods {
 	return file_proto2_fields_proto_msgTypes[2].Methods()
 }
 
@@ -1166,6 +1193,7 @@ func (x *FieldTestMessage_RequiredGroup) GetRequiredGroup() string {
 }
 
 type FieldTestMessage_RepeatedGroup struct {
+	state         protoimpl.MessageState
 	RepeatedGroup []string `protobuf:"bytes,219,rep,name=repeated_group,json=repeatedGroup" json:"repeated_group,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1182,10 +1210,18 @@ func (x *FieldTestMessage_RepeatedGroup) String() string {
 func (*FieldTestMessage_RepeatedGroup) ProtoMessage() {}
 
 func (x *FieldTestMessage_RepeatedGroup) ProtoReflect() protoreflect.Message {
-	return file_proto2_fields_proto_msgTypes[3].MessageOf(x)
+	mi := &file_proto2_fields_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FieldTestMessage_RepeatedGroup) XXX_Methods() *protoiface.Methods {
+func (x *FieldTestMessage_RepeatedGroup) XXX_Methods() *protoiface.Methods {
 	return file_proto2_fields_proto_msgTypes[3].Methods()
 }
 
@@ -1202,6 +1238,7 @@ func (x *FieldTestMessage_RepeatedGroup) GetRepeatedGroup() []string {
 }
 
 type FieldTestMessage_OneofGroup struct {
+	state           protoimpl.MessageState
 	OneofGroupField *string `protobuf:"bytes,619,opt,name=oneof_group_field,json=oneofGroupField" json:"oneof_group_field,omitempty"`
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
@@ -1218,10 +1255,18 @@ func (x *FieldTestMessage_OneofGroup) String() string {
 func (*FieldTestMessage_OneofGroup) ProtoMessage() {}
 
 func (x *FieldTestMessage_OneofGroup) ProtoReflect() protoreflect.Message {
-	return file_proto2_fields_proto_msgTypes[7].MessageOf(x)
+	mi := &file_proto2_fields_proto_msgTypes[7]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FieldTestMessage_OneofGroup) XXX_Methods() *protoiface.Methods {
+func (x *FieldTestMessage_OneofGroup) XXX_Methods() *protoiface.Methods {
 	return file_proto2_fields_proto_msgTypes[7].Methods()
 }
 
@@ -1238,6 +1283,7 @@ func (x *FieldTestMessage_OneofGroup) GetOneofGroupField() string {
 }
 
 type FieldTestMessage_Message struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -1253,10 +1299,18 @@ func (x *FieldTestMessage_Message) String() string {
 func (*FieldTestMessage_Message) ProtoMessage() {}
 
 func (x *FieldTestMessage_Message) ProtoReflect() protoreflect.Message {
-	return file_proto2_fields_proto_msgTypes[8].MessageOf(x)
+	mi := &file_proto2_fields_proto_msgTypes[8]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FieldTestMessage_Message) XXX_Methods() *protoiface.Methods {
+func (x *FieldTestMessage_Message) XXX_Methods() *protoiface.Methods {
 	return file_proto2_fields_proto_msgTypes[8].Methods()
 }
 
@@ -1700,9 +1754,11 @@ func file_proto2_fields_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_proto2_fields_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FieldTestMessage); i {
-			case 83:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 84:
+				return &v.sizeCache
+			case 85:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1710,9 +1766,11 @@ func file_proto2_fields_proto_init() {
 		}
 		file_proto2_fields_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FieldTestMessage_OptionalGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1720,9 +1778,11 @@ func file_proto2_fields_proto_init() {
 		}
 		file_proto2_fields_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FieldTestMessage_RequiredGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1730,9 +1790,11 @@ func file_proto2_fields_proto_init() {
 		}
 		file_proto2_fields_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FieldTestMessage_RepeatedGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1740,9 +1802,11 @@ func file_proto2_fields_proto_init() {
 		}
 		file_proto2_fields_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FieldTestMessage_OneofGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1751,8 +1815,10 @@ func file_proto2_fields_proto_init() {
 		file_proto2_fields_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FieldTestMessage_Message); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 44 - 11
cmd/protoc-gen-go/testdata/proto2/nested_messages.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type Layer1 struct {
+	state         protoimpl.MessageState
 	L2            *Layer1_Layer2        `protobuf:"bytes,1,opt,name=l2" json:"l2,omitempty"`
 	L3            *Layer1_Layer2_Layer3 `protobuf:"bytes,2,opt,name=l3" json:"l3,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -35,10 +36,18 @@ func (x *Layer1) String() string {
 func (*Layer1) ProtoMessage() {}
 
 func (x *Layer1) ProtoReflect() protoreflect.Message {
-	return file_proto2_nested_messages_proto_msgTypes[0].MessageOf(x)
+	mi := &file_proto2_nested_messages_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Layer1) XXX_Methods() *protoiface.Methods {
+func (x *Layer1) XXX_Methods() *protoiface.Methods {
 	return file_proto2_nested_messages_proto_msgTypes[0].Methods()
 }
 
@@ -62,6 +71,7 @@ func (x *Layer1) GetL3() *Layer1_Layer2_Layer3 {
 }
 
 type Layer1_Layer2 struct {
+	state         protoimpl.MessageState
 	L3            *Layer1_Layer2_Layer3 `protobuf:"bytes,1,opt,name=l3" json:"l3,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -78,10 +88,18 @@ func (x *Layer1_Layer2) String() string {
 func (*Layer1_Layer2) ProtoMessage() {}
 
 func (x *Layer1_Layer2) ProtoReflect() protoreflect.Message {
-	return file_proto2_nested_messages_proto_msgTypes[1].MessageOf(x)
+	mi := &file_proto2_nested_messages_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Layer1_Layer2) XXX_Methods() *protoiface.Methods {
+func (x *Layer1_Layer2) XXX_Methods() *protoiface.Methods {
 	return file_proto2_nested_messages_proto_msgTypes[1].Methods()
 }
 
@@ -98,6 +116,7 @@ func (x *Layer1_Layer2) GetL3() *Layer1_Layer2_Layer3 {
 }
 
 type Layer1_Layer2_Layer3 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -113,10 +132,18 @@ func (x *Layer1_Layer2_Layer3) String() string {
 func (*Layer1_Layer2_Layer3) ProtoMessage() {}
 
 func (x *Layer1_Layer2_Layer3) ProtoReflect() protoreflect.Message {
-	return file_proto2_nested_messages_proto_msgTypes[2].MessageOf(x)
+	mi := &file_proto2_nested_messages_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Layer1_Layer2_Layer3) XXX_Methods() *protoiface.Methods {
+func (x *Layer1_Layer2_Layer3) XXX_Methods() *protoiface.Methods {
 	return file_proto2_nested_messages_proto_msgTypes[2].Methods()
 }
 
@@ -188,9 +215,11 @@ func file_proto2_nested_messages_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_proto2_nested_messages_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Layer1); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -198,9 +227,11 @@ func file_proto2_nested_messages_proto_init() {
 		}
 		file_proto2_nested_messages_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Layer1_Layer2); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -209,8 +240,10 @@ func file_proto2_nested_messages_proto_init() {
 		file_proto2_nested_messages_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Layer1_Layer2_Layer3); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
cmd/protoc-gen-go/testdata/proto2/proto2.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type Message struct {
+	state         protoimpl.MessageState
 	I32           *int32   `protobuf:"varint,1,opt,name=i32" json:"i32,omitempty"`
 	M             *Message `protobuf:"bytes,2,opt,name=m" json:"m,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -35,10 +36,18 @@ func (x *Message) String() string {
 func (*Message) ProtoMessage() {}
 
 func (x *Message) ProtoReflect() protoreflect.Message {
-	return file_proto2_proto2_proto_msgTypes[0].MessageOf(x)
+	mi := &file_proto2_proto2_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message) XXX_Methods() *protoiface.Methods {
+func (x *Message) XXX_Methods() *protoiface.Methods {
 	return file_proto2_proto2_proto_msgTypes[0].Methods()
 }
 
@@ -111,9 +120,11 @@ func file_proto2_proto2_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_proto2_proto2_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 29 - 7
cmd/protoc-gen-go/testdata/proto3/fields.pb.go

@@ -56,6 +56,7 @@ func (FieldTestMessage_Enum) EnumDescriptor() ([]byte, []int) {
 }
 
 type FieldTestMessage struct {
+	state            protoimpl.MessageState
 	OptionalBool     string                               `protobuf:"bytes,1,opt,name=optional_bool,json=optionalBool,proto3" json:"optional_bool,omitempty"`
 	OptionalEnum     FieldTestMessage_Enum                `protobuf:"varint,2,opt,name=optional_enum,json=optionalEnum,proto3,enum=goproto.protoc.proto3.FieldTestMessage_Enum" json:"optional_enum,omitempty"`
 	OptionalInt32    int32                                `protobuf:"varint,3,opt,name=optional_int32,json=optionalInt32,proto3" json:"optional_int32,omitempty"`
@@ -108,10 +109,18 @@ func (x *FieldTestMessage) String() string {
 func (*FieldTestMessage) ProtoMessage() {}
 
 func (x *FieldTestMessage) ProtoReflect() protoreflect.Message {
-	return file_proto3_fields_proto_msgTypes[0].MessageOf(x)
+	mi := &file_proto3_fields_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FieldTestMessage) XXX_Methods() *protoiface.Methods {
+func (x *FieldTestMessage) XXX_Methods() *protoiface.Methods {
 	return file_proto3_fields_proto_msgTypes[0].Methods()
 }
 
@@ -380,6 +389,7 @@ func (x *FieldTestMessage) GetMapFixed64Enum() map[uint64]FieldTestMessage_Enum
 }
 
 type FieldTestMessage_Message struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -395,10 +405,18 @@ func (x *FieldTestMessage_Message) String() string {
 func (*FieldTestMessage_Message) ProtoMessage() {}
 
 func (x *FieldTestMessage_Message) ProtoReflect() protoreflect.Message {
-	return file_proto3_fields_proto_msgTypes[4].MessageOf(x)
+	mi := &file_proto3_fields_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FieldTestMessage_Message) XXX_Methods() *protoiface.Methods {
+func (x *FieldTestMessage_Message) XXX_Methods() *protoiface.Methods {
 	return file_proto3_fields_proto_msgTypes[4].Methods()
 }
 
@@ -608,9 +626,11 @@ func file_proto3_fields_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_proto3_fields_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FieldTestMessage); i {
-			case 37:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 38:
+				return &v.sizeCache
+			case 39:
 				return &v.unknownFields
 			default:
 				return nil
@@ -619,8 +639,10 @@ func file_proto3_fields_proto_init() {
 		file_proto3_fields_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FieldTestMessage_Message); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 285 - 76
encoding/testprotos/pb2/test.pb.go

@@ -133,6 +133,7 @@ func (Enums_NestedEnum) EnumDescriptor() ([]byte, []int) {
 
 // Scalars contains optional scalar fields.
 type Scalars struct {
+	state         protoimpl.MessageState
 	OptBool       *bool    `protobuf:"varint,1,opt,name=opt_bool,json=optBool" json:"opt_bool,omitempty"`
 	OptInt32      *int32   `protobuf:"varint,2,opt,name=opt_int32,json=optInt32" json:"opt_int32,omitempty"`
 	OptInt64      *int64   `protobuf:"varint,3,opt,name=opt_int64,json=optInt64" json:"opt_int64,omitempty"`
@@ -163,10 +164,18 @@ func (x *Scalars) String() string {
 func (*Scalars) ProtoMessage() {}
 
 func (x *Scalars) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[0].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Scalars) XXX_Methods() *protoiface.Methods {
+func (x *Scalars) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[0].Methods()
 }
 
@@ -282,6 +291,7 @@ func (x *Scalars) GetOptString() string {
 
 // Message contains enum fields.
 type Enums struct {
+	state         protoimpl.MessageState
 	OptEnum       *Enum              `protobuf:"varint,1,opt,name=opt_enum,json=optEnum,enum=pb2.Enum" json:"opt_enum,omitempty"`
 	RptEnum       []Enum             `protobuf:"varint,2,rep,name=rpt_enum,json=rptEnum,enum=pb2.Enum" json:"rpt_enum,omitempty"`
 	OptNestedEnum *Enums_NestedEnum  `protobuf:"varint,3,opt,name=opt_nested_enum,json=optNestedEnum,enum=pb2.Enums_NestedEnum" json:"opt_nested_enum,omitempty"`
@@ -301,10 +311,18 @@ func (x *Enums) String() string {
 func (*Enums) ProtoMessage() {}
 
 func (x *Enums) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[1].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Enums) XXX_Methods() *protoiface.Methods {
+func (x *Enums) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[1].Methods()
 }
 
@@ -343,6 +361,7 @@ func (x *Enums) GetRptNestedEnum() []Enums_NestedEnum {
 
 // Message contains repeated fields.
 type Repeats struct {
+	state         protoimpl.MessageState
 	RptBool       []bool    `protobuf:"varint,1,rep,name=rpt_bool,json=rptBool" json:"rpt_bool,omitempty"`
 	RptInt32      []int32   `protobuf:"varint,2,rep,name=rpt_int32,json=rptInt32" json:"rpt_int32,omitempty"`
 	RptInt64      []int64   `protobuf:"varint,3,rep,name=rpt_int64,json=rptInt64" json:"rpt_int64,omitempty"`
@@ -367,10 +386,18 @@ func (x *Repeats) String() string {
 func (*Repeats) ProtoMessage() {}
 
 func (x *Repeats) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[2].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Repeats) XXX_Methods() *protoiface.Methods {
+func (x *Repeats) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[2].Methods()
 }
 
@@ -444,6 +471,7 @@ func (x *Repeats) GetRptBytes() [][]byte {
 
 // Message type used as submessage.
 type Nested struct {
+	state         protoimpl.MessageState
 	OptString     *string `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
 	OptNested     *Nested `protobuf:"bytes,2,opt,name=opt_nested,json=optNested" json:"opt_nested,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -461,10 +489,18 @@ func (x *Nested) String() string {
 func (*Nested) ProtoMessage() {}
 
 func (x *Nested) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[3].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Nested) XXX_Methods() *protoiface.Methods {
+func (x *Nested) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[3].Methods()
 }
 
@@ -489,6 +525,7 @@ func (x *Nested) GetOptNested() *Nested {
 
 // Message contains message and group fields.
 type Nests struct {
+	state         protoimpl.MessageState
 	OptNested     *Nested           `protobuf:"bytes,1,opt,name=opt_nested,json=optNested" json:"opt_nested,omitempty"`
 	Optgroup      *Nests_OptGroup   `protobuf:"group,2,opt,name=OptGroup,json=optgroup" json:"optgroup,omitempty"`
 	RptNested     []*Nested         `protobuf:"bytes,4,rep,name=rpt_nested,json=rptNested" json:"rpt_nested,omitempty"`
@@ -508,10 +545,18 @@ func (x *Nests) String() string {
 func (*Nests) ProtoMessage() {}
 
 func (x *Nests) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[4].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Nests) XXX_Methods() *protoiface.Methods {
+func (x *Nests) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[4].Methods()
 }
 
@@ -550,6 +595,7 @@ func (x *Nests) GetRptgroup() []*Nests_RptGroup {
 
 // Message contains required fields.
 type Requireds struct {
+	state         protoimpl.MessageState
 	ReqBool       *bool    `protobuf:"varint,1,req,name=req_bool,json=reqBool" json:"req_bool,omitempty"`
 	ReqSfixed64   *int64   `protobuf:"fixed64,2,req,name=req_sfixed64,json=reqSfixed64" json:"req_sfixed64,omitempty"`
 	ReqDouble     *float64 `protobuf:"fixed64,3,req,name=req_double,json=reqDouble" json:"req_double,omitempty"`
@@ -571,10 +617,18 @@ func (x *Requireds) String() string {
 func (*Requireds) ProtoMessage() {}
 
 func (x *Requireds) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[5].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[5]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Requireds) XXX_Methods() *protoiface.Methods {
+func (x *Requireds) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[5].Methods()
 }
 
@@ -627,6 +681,7 @@ func (x *Requireds) GetReqNested() *Nested {
 
 // Message contains both required and optional fields.
 type PartialRequired struct {
+	state         protoimpl.MessageState
 	ReqString     *string `protobuf:"bytes,1,req,name=req_string,json=reqString" json:"req_string,omitempty"`
 	OptString     *string `protobuf:"bytes,2,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -644,10 +699,18 @@ func (x *PartialRequired) String() string {
 func (*PartialRequired) ProtoMessage() {}
 
 func (x *PartialRequired) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[6].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[6]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *PartialRequired) XXX_Methods() *protoiface.Methods {
+func (x *PartialRequired) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[6].Methods()
 }
 
@@ -671,6 +734,7 @@ func (x *PartialRequired) GetOptString() string {
 }
 
 type NestedWithRequired struct {
+	state         protoimpl.MessageState
 	ReqString     *string `protobuf:"bytes,1,req,name=req_string,json=reqString" json:"req_string,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -687,10 +751,18 @@ func (x *NestedWithRequired) String() string {
 func (*NestedWithRequired) ProtoMessage() {}
 
 func (x *NestedWithRequired) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[7].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[7]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *NestedWithRequired) XXX_Methods() *protoiface.Methods {
+func (x *NestedWithRequired) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[7].Methods()
 }
 
@@ -707,6 +779,7 @@ func (x *NestedWithRequired) GetReqString() string {
 }
 
 type IndirectRequired struct {
+	state       protoimpl.MessageState
 	OptNested   *NestedWithRequired            `protobuf:"bytes,1,opt,name=opt_nested,json=optNested" json:"opt_nested,omitempty"`
 	RptNested   []*NestedWithRequired          `protobuf:"bytes,2,rep,name=rpt_nested,json=rptNested" json:"rpt_nested,omitempty"`
 	StrToNested map[string]*NestedWithRequired `protobuf:"bytes,3,rep,name=str_to_nested,json=strToNested" json:"str_to_nested,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
@@ -728,10 +801,18 @@ func (x *IndirectRequired) String() string {
 func (*IndirectRequired) ProtoMessage() {}
 
 func (x *IndirectRequired) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[8].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[8]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *IndirectRequired) XXX_Methods() *protoiface.Methods {
+func (x *IndirectRequired) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[8].Methods()
 }
 
@@ -786,6 +867,7 @@ type IndirectRequired_OneofNested struct {
 func (*IndirectRequired_OneofNested) isIndirectRequired_Union() {}
 
 type Extensions struct {
+	state           protoimpl.MessageState
 	OptString       *string `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
 	OptBool         *bool   `protobuf:"varint,101,opt,name=opt_bool,json=optBool" json:"opt_bool,omitempty"`
 	OptInt32        *int32  `protobuf:"varint,2,opt,name=opt_int32,json=optInt32" json:"opt_int32,omitempty"`
@@ -805,10 +887,18 @@ func (x *Extensions) String() string {
 func (*Extensions) ProtoMessage() {}
 
 func (x *Extensions) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[9].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[9]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Extensions) XXX_Methods() *protoiface.Methods {
+func (x *Extensions) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[9].Methods()
 }
 
@@ -848,6 +938,7 @@ func (x *Extensions) GetOptInt32() int32 {
 }
 
 type ExtensionsContainer struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -863,10 +954,18 @@ func (x *ExtensionsContainer) String() string {
 func (*ExtensionsContainer) ProtoMessage() {}
 
 func (x *ExtensionsContainer) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[10].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[10]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ExtensionsContainer) XXX_Methods() *protoiface.Methods {
+func (x *ExtensionsContainer) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[10].Methods()
 }
 
@@ -876,6 +975,7 @@ func (*ExtensionsContainer) Descriptor() ([]byte, []int) {
 }
 
 type MessageSet struct {
+	state           protoimpl.MessageState
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
 	extensionFields protoimpl.ExtensionFields
@@ -892,10 +992,18 @@ func (x *MessageSet) String() string {
 func (*MessageSet) ProtoMessage() {}
 
 func (x *MessageSet) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[11].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[11]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *MessageSet) XXX_Methods() *protoiface.Methods {
+func (x *MessageSet) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[11].Methods()
 }
 
@@ -914,6 +1022,7 @@ func (*MessageSet) ExtensionRangeArray() []protoiface.ExtensionRangeV1 {
 }
 
 type MessageSetExtension struct {
+	state         protoimpl.MessageState
 	OptString     *string `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -930,10 +1039,18 @@ func (x *MessageSetExtension) String() string {
 func (*MessageSetExtension) ProtoMessage() {}
 
 func (x *MessageSetExtension) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[12].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[12]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *MessageSetExtension) XXX_Methods() *protoiface.Methods {
+func (x *MessageSetExtension) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[12].Methods()
 }
 
@@ -950,6 +1067,7 @@ func (x *MessageSetExtension) GetOptString() string {
 }
 
 type FakeMessageSet struct {
+	state           protoimpl.MessageState
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
 	extensionFields protoimpl.ExtensionFields
@@ -966,10 +1084,18 @@ func (x *FakeMessageSet) String() string {
 func (*FakeMessageSet) ProtoMessage() {}
 
 func (x *FakeMessageSet) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[13].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[13]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FakeMessageSet) XXX_Methods() *protoiface.Methods {
+func (x *FakeMessageSet) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[13].Methods()
 }
 
@@ -988,6 +1114,7 @@ func (*FakeMessageSet) ExtensionRangeArray() []protoiface.ExtensionRangeV1 {
 }
 
 type FakeMessageSetExtension struct {
+	state         protoimpl.MessageState
 	OptString     *string `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1004,10 +1131,18 @@ func (x *FakeMessageSetExtension) String() string {
 func (*FakeMessageSetExtension) ProtoMessage() {}
 
 func (x *FakeMessageSetExtension) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[14].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[14]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FakeMessageSetExtension) XXX_Methods() *protoiface.Methods {
+func (x *FakeMessageSetExtension) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[14].Methods()
 }
 
@@ -1025,6 +1160,7 @@ func (x *FakeMessageSetExtension) GetOptString() string {
 
 // Message contains well-known type fields.
 type KnownTypes struct {
+	state         protoimpl.MessageState
 	OptBool       *wrapperspb.BoolValue   `protobuf:"bytes,1,opt,name=opt_bool,json=optBool" json:"opt_bool,omitempty"`
 	OptInt32      *wrapperspb.Int32Value  `protobuf:"bytes,2,opt,name=opt_int32,json=optInt32" json:"opt_int32,omitempty"`
 	OptInt64      *wrapperspb.Int64Value  `protobuf:"bytes,3,opt,name=opt_int64,json=optInt64" json:"opt_int64,omitempty"`
@@ -1058,10 +1194,18 @@ func (x *KnownTypes) String() string {
 func (*KnownTypes) ProtoMessage() {}
 
 func (x *KnownTypes) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[15].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[15]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *KnownTypes) XXX_Methods() *protoiface.Methods {
+func (x *KnownTypes) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[15].Methods()
 }
 
@@ -1197,6 +1341,7 @@ func (x *KnownTypes) GetOptFieldmask() *fieldmaskpb.FieldMask {
 }
 
 type Nests_OptGroup struct {
+	state          protoimpl.MessageState
 	OptString      *string                        `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
 	OptNested      *Nested                        `protobuf:"bytes,2,opt,name=opt_nested,json=optNested" json:"opt_nested,omitempty"`
 	Optnestedgroup *Nests_OptGroup_OptNestedGroup `protobuf:"group,3,opt,name=OptNestedGroup,json=optnestedgroup" json:"optnestedgroup,omitempty"`
@@ -1215,10 +1360,18 @@ func (x *Nests_OptGroup) String() string {
 func (*Nests_OptGroup) ProtoMessage() {}
 
 func (x *Nests_OptGroup) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[16].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[16]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Nests_OptGroup) XXX_Methods() *protoiface.Methods {
+func (x *Nests_OptGroup) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[16].Methods()
 }
 
@@ -1249,6 +1402,7 @@ func (x *Nests_OptGroup) GetOptnestedgroup() *Nests_OptGroup_OptNestedGroup {
 }
 
 type Nests_RptGroup struct {
+	state         protoimpl.MessageState
 	RptString     []string `protobuf:"bytes,1,rep,name=rpt_string,json=rptString" json:"rpt_string,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1265,10 +1419,18 @@ func (x *Nests_RptGroup) String() string {
 func (*Nests_RptGroup) ProtoMessage() {}
 
 func (x *Nests_RptGroup) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[17].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[17]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Nests_RptGroup) XXX_Methods() *protoiface.Methods {
+func (x *Nests_RptGroup) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[17].Methods()
 }
 
@@ -1285,6 +1447,7 @@ func (x *Nests_RptGroup) GetRptString() []string {
 }
 
 type Nests_OptGroup_OptNestedGroup struct {
+	state         protoimpl.MessageState
 	OptFixed32    *uint32 `protobuf:"fixed32,1,opt,name=opt_fixed32,json=optFixed32" json:"opt_fixed32,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1301,10 +1464,18 @@ func (x *Nests_OptGroup_OptNestedGroup) String() string {
 func (*Nests_OptGroup_OptNestedGroup) ProtoMessage() {}
 
 func (x *Nests_OptGroup_OptNestedGroup) ProtoReflect() protoreflect.Message {
-	return file_pb2_test_proto_msgTypes[18].MessageOf(x)
+	mi := &file_pb2_test_proto_msgTypes[18]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Nests_OptGroup_OptNestedGroup) XXX_Methods() *protoiface.Methods {
+func (x *Nests_OptGroup_OptNestedGroup) XXX_Methods() *protoiface.Methods {
 	return file_pb2_test_proto_msgTypes[18].Methods()
 }
 
@@ -2043,9 +2214,11 @@ func file_pb2_test_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_pb2_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Scalars); i {
-			case 15:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 16:
+				return &v.sizeCache
+			case 17:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2053,9 +2226,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Enums); i {
-			case 4:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 5:
+				return &v.sizeCache
+			case 6:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2063,9 +2238,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Repeats); i {
-			case 9:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 10:
+				return &v.sizeCache
+			case 11:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2073,9 +2250,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Nested); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2083,9 +2262,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Nests); i {
-			case 4:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 5:
+				return &v.sizeCache
+			case 6:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2093,9 +2274,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Requireds); i {
-			case 6:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 7:
+				return &v.sizeCache
+			case 8:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2103,9 +2286,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*PartialRequired); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2113,9 +2298,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*NestedWithRequired); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2123,9 +2310,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*IndirectRequired); i {
-			case 4:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 5:
+				return &v.sizeCache
+			case 6:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2133,11 +2322,13 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Extensions); i {
-			case 3:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 4:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 5:
+				return &v.unknownFields
+			case 6:
 				return &v.extensionFields
 			default:
 				return nil
@@ -2146,8 +2337,10 @@ func file_pb2_test_proto_init() {
 		file_pb2_test_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ExtensionsContainer); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2156,10 +2349,12 @@ func file_pb2_test_proto_init() {
 		file_pb2_test_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*MessageSet); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 2:
+				return &v.unknownFields
+			case 3:
 				return &v.extensionFields
 			default:
 				return nil
@@ -2167,9 +2362,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*MessageSetExtension); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2178,10 +2375,12 @@ func file_pb2_test_proto_init() {
 		file_pb2_test_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FakeMessageSet); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 2:
+				return &v.unknownFields
+			case 3:
 				return &v.extensionFields
 			default:
 				return nil
@@ -2189,9 +2388,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FakeMessageSetExtension); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2199,9 +2400,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*KnownTypes); i {
-			case 18:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 19:
+				return &v.sizeCache
+			case 20:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2209,9 +2412,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Nests_OptGroup); i {
-			case 3:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 4:
+				return &v.sizeCache
+			case 5:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2219,9 +2424,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Nests_RptGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2229,9 +2436,11 @@ func file_pb2_test_proto_init() {
 		}
 		file_pb2_test_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Nests_OptGroup_OptNestedGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 105 - 28
encoding/testprotos/pb3/test.pb.go

@@ -112,6 +112,7 @@ func (Enums_NestedEnum) EnumDescriptor() ([]byte, []int) {
 
 // Scalars contains scalar field types.
 type Scalars struct {
+	state         protoimpl.MessageState
 	SBool         bool    `protobuf:"varint,1,opt,name=s_bool,json=sBool,proto3" json:"s_bool,omitempty"`
 	SInt32        int32   `protobuf:"varint,2,opt,name=s_int32,json=sInt32,proto3" json:"s_int32,omitempty"`
 	SInt64        int64   `protobuf:"varint,3,opt,name=s_int64,json=sInt64,proto3" json:"s_int64,omitempty"`
@@ -142,10 +143,18 @@ func (x *Scalars) String() string {
 func (*Scalars) ProtoMessage() {}
 
 func (x *Scalars) ProtoReflect() protoreflect.Message {
-	return file_pb3_test_proto_msgTypes[0].MessageOf(x)
+	mi := &file_pb3_test_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Scalars) XXX_Methods() *protoiface.Methods {
+func (x *Scalars) XXX_Methods() *protoiface.Methods {
 	return file_pb3_test_proto_msgTypes[0].Methods()
 }
 
@@ -261,6 +270,7 @@ func (x *Scalars) GetSString() string {
 
 // Message contains enum fields.
 type Enums struct {
+	state         protoimpl.MessageState
 	SEnum         Enum             `protobuf:"varint,1,opt,name=s_enum,json=sEnum,proto3,enum=pb3.Enum" json:"s_enum,omitempty"`
 	SNestedEnum   Enums_NestedEnum `protobuf:"varint,3,opt,name=s_nested_enum,json=sNestedEnum,proto3,enum=pb3.Enums_NestedEnum" json:"s_nested_enum,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -278,10 +288,18 @@ func (x *Enums) String() string {
 func (*Enums) ProtoMessage() {}
 
 func (x *Enums) ProtoReflect() protoreflect.Message {
-	return file_pb3_test_proto_msgTypes[1].MessageOf(x)
+	mi := &file_pb3_test_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Enums) XXX_Methods() *protoiface.Methods {
+func (x *Enums) XXX_Methods() *protoiface.Methods {
 	return file_pb3_test_proto_msgTypes[1].Methods()
 }
 
@@ -306,6 +324,7 @@ func (x *Enums) GetSNestedEnum() Enums_NestedEnum {
 
 // Message contains nested message field.
 type Nests struct {
+	state         protoimpl.MessageState
 	SNested       *Nested `protobuf:"bytes,2,opt,name=s_nested,json=sNested,proto3" json:"s_nested,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -322,10 +341,18 @@ func (x *Nests) String() string {
 func (*Nests) ProtoMessage() {}
 
 func (x *Nests) ProtoReflect() protoreflect.Message {
-	return file_pb3_test_proto_msgTypes[2].MessageOf(x)
+	mi := &file_pb3_test_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Nests) XXX_Methods() *protoiface.Methods {
+func (x *Nests) XXX_Methods() *protoiface.Methods {
 	return file_pb3_test_proto_msgTypes[2].Methods()
 }
 
@@ -343,6 +370,7 @@ func (x *Nests) GetSNested() *Nested {
 
 // Message type used as submessage.
 type Nested struct {
+	state         protoimpl.MessageState
 	SString       string  `protobuf:"bytes,1,opt,name=s_string,json=sString,proto3" json:"s_string,omitempty"`
 	SNested       *Nested `protobuf:"bytes,2,opt,name=s_nested,json=sNested,proto3" json:"s_nested,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -360,10 +388,18 @@ func (x *Nested) String() string {
 func (*Nested) ProtoMessage() {}
 
 func (x *Nested) ProtoReflect() protoreflect.Message {
-	return file_pb3_test_proto_msgTypes[3].MessageOf(x)
+	mi := &file_pb3_test_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Nested) XXX_Methods() *protoiface.Methods {
+func (x *Nested) XXX_Methods() *protoiface.Methods {
 	return file_pb3_test_proto_msgTypes[3].Methods()
 }
 
@@ -388,6 +424,7 @@ func (x *Nested) GetSNested() *Nested {
 
 // Message contains oneof field.
 type Oneofs struct {
+	state protoimpl.MessageState
 	// Types that are valid to be assigned to Union:
 	//	*Oneofs_OneofEnum
 	//	*Oneofs_OneofString
@@ -408,10 +445,18 @@ func (x *Oneofs) String() string {
 func (*Oneofs) ProtoMessage() {}
 
 func (x *Oneofs) ProtoReflect() protoreflect.Message {
-	return file_pb3_test_proto_msgTypes[4].MessageOf(x)
+	mi := &file_pb3_test_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Oneofs) XXX_Methods() *protoiface.Methods {
+func (x *Oneofs) XXX_Methods() *protoiface.Methods {
 	return file_pb3_test_proto_msgTypes[4].Methods()
 }
 
@@ -472,6 +517,7 @@ func (*Oneofs_OneofNested) isOneofs_Union() {}
 
 // Message contains map fields.
 type Maps struct {
+	state         protoimpl.MessageState
 	Int32ToStr    map[int32]string   `protobuf:"bytes,1,rep,name=int32_to_str,json=int32ToStr,proto3" json:"int32_to_str,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
 	BoolToUint32  map[bool]uint32    `protobuf:"bytes,2,rep,name=bool_to_uint32,json=boolToUint32,proto3" json:"bool_to_uint32,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
 	Uint64ToEnum  map[uint64]Enum    `protobuf:"bytes,3,rep,name=uint64_to_enum,json=uint64ToEnum,proto3" json:"uint64_to_enum,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3,enum=pb3.Enum"`
@@ -492,10 +538,18 @@ func (x *Maps) String() string {
 func (*Maps) ProtoMessage() {}
 
 func (x *Maps) ProtoReflect() protoreflect.Message {
-	return file_pb3_test_proto_msgTypes[5].MessageOf(x)
+	mi := &file_pb3_test_proto_msgTypes[5]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Maps) XXX_Methods() *protoiface.Methods {
+func (x *Maps) XXX_Methods() *protoiface.Methods {
 	return file_pb3_test_proto_msgTypes[5].Methods()
 }
 
@@ -541,6 +595,7 @@ func (x *Maps) GetStrToOneofs() map[string]*Oneofs {
 
 // Message for testing json_name option.
 type JSONNames struct {
+	state         protoimpl.MessageState
 	SString       string `protobuf:"bytes,1,opt,name=s_string,json=foo_bar,proto3" json:"s_string,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -557,10 +612,18 @@ func (x *JSONNames) String() string {
 func (*JSONNames) ProtoMessage() {}
 
 func (x *JSONNames) ProtoReflect() protoreflect.Message {
-	return file_pb3_test_proto_msgTypes[6].MessageOf(x)
+	mi := &file_pb3_test_proto_msgTypes[6]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *JSONNames) XXX_Methods() *protoiface.Methods {
+func (x *JSONNames) XXX_Methods() *protoiface.Methods {
 	return file_pb3_test_proto_msgTypes[6].Methods()
 }
 
@@ -748,9 +811,11 @@ func file_pb3_test_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_pb3_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Scalars); i {
-			case 15:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 16:
+				return &v.sizeCache
+			case 17:
 				return &v.unknownFields
 			default:
 				return nil
@@ -758,9 +823,11 @@ func file_pb3_test_proto_init() {
 		}
 		file_pb3_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Enums); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -768,9 +835,11 @@ func file_pb3_test_proto_init() {
 		}
 		file_pb3_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Nests); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -778,9 +847,11 @@ func file_pb3_test_proto_init() {
 		}
 		file_pb3_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Nested); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -788,9 +859,11 @@ func file_pb3_test_proto_init() {
 		}
 		file_pb3_test_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Oneofs); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -798,9 +871,11 @@ func file_pb3_test_proto_init() {
 		}
 		file_pb3_test_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Maps); i {
-			case 5:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 6:
+				return &v.sizeCache
+			case 7:
 				return &v.unknownFields
 			default:
 				return nil
@@ -808,9 +883,11 @@ func file_pb3_test_proto_init() {
 		}
 		file_pb3_test_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*JSONNames); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 104 - 0
internal/cmd/generate-types/impl.go

@@ -381,3 +381,107 @@ var wireTypes = map[protoreflect.Kind]wire.Type{
 {{end}}
 }
 `))
+
+func generateImplMessage() string {
+	return mustExecute(implMessageTemplate, []string{"messageState", "messageReflectWrapper"})
+}
+
+var implMessageTemplate = template.Must(template.New("").Parse(`
+{{range . -}}
+func (m *{{.}}) Descriptor() protoreflect.MessageDescriptor {
+	return m.mi.PBType.Descriptor()
+}
+func (m *{{.}}) New() protoreflect.Message {
+	return m.mi.PBType.New()
+}
+func (m *{{.}}) Interface() protoreflect.ProtoMessage {
+	{{if eq . "messageState" -}}
+	return m.ProtoUnwrap().(protoreflect.ProtoMessage)
+	{{- else -}}
+	if m, ok := m.ProtoUnwrap().(protoreflect.ProtoMessage); ok {
+		return m
+	}
+	return (*messageIfaceWrapper)(m)
+	{{- end -}}
+}
+func (m *{{.}}) ProtoUnwrap() interface{} {
+	return m.pointer().AsIfaceOf(m.mi.GoType.Elem())
+}
+
+func (m *{{.}}) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
+	m.mi.init()
+	for _, fi := range m.mi.fields {
+		if fi.has(m.pointer()) {
+			if !f(fi.fieldDesc, fi.get(m.pointer())) {
+				return
+			}
+		}
+	}
+	m.mi.extensionMap(m.pointer()).Range(f)
+}
+func (m *{{.}}) Has(fd protoreflect.FieldDescriptor) bool {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.has(m.pointer())
+	} else {
+		return m.mi.extensionMap(m.pointer()).Has(xt)
+	}
+}
+func (m *{{.}}) Clear(fd protoreflect.FieldDescriptor) {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		fi.clear(m.pointer())
+	} else {
+		m.mi.extensionMap(m.pointer()).Clear(xt)
+	}
+}
+func (m *{{.}}) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.get(m.pointer())
+	} else {
+		return m.mi.extensionMap(m.pointer()).Get(xt)
+	}
+}
+func (m *{{.}}) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		fi.set(m.pointer(), v)
+	} else {
+		m.mi.extensionMap(m.pointer()).Set(xt, v)
+	}
+}
+func (m *{{.}}) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.mutable(m.pointer())
+	} else {
+		return m.mi.extensionMap(m.pointer()).Mutable(xt)
+	}
+}
+func (m *{{.}}) NewMessage(fd protoreflect.FieldDescriptor) protoreflect.Message {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.newMessage()
+	} else {
+		return xt.New().Message()
+	}
+}
+func (m *{{.}}) WhichOneof(od protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
+	m.mi.init()
+	if oi := m.mi.oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
+		return od.Fields().ByNumber(oi.which(m.pointer()))
+	}
+	panic("invalid oneof descriptor")
+}
+func (m *{{.}}) GetUnknown() protoreflect.RawFields {
+	m.mi.init()
+	return m.mi.getUnknown(m.pointer())
+}
+func (m *{{.}}) SetUnknown(b protoreflect.RawFields) {
+	m.mi.init()
+	m.mi.setUnknown(m.pointer(), b)
+}
+
+{{end}}
+`))

+ 1 - 0
internal/cmd/generate-types/main.go

@@ -39,6 +39,7 @@ func main() {
 	chdirRoot()
 	writeSource("internal/filedesc/desc_list_gen.go", generateDescListTypes())
 	writeSource("internal/impl/codec_gen.go", generateImplCodec())
+	writeSource("internal/impl/message_reflect_gen.go", generateImplMessage())
 	writeSource("proto/decode_gen.go", generateProtoDecode())
 	writeSource("proto/encode_gen.go", generateProtoEncode())
 	writeSource("proto/size_gen.go", generateProtoSize())

+ 15 - 251
internal/impl/message.go

@@ -12,7 +12,6 @@ import (
 	"sync"
 	"sync/atomic"
 
-	pvalue "google.golang.org/protobuf/internal/value"
 	pref "google.golang.org/protobuf/reflect/protoreflect"
 	piface "google.golang.org/protobuf/runtime/protoiface"
 )
@@ -39,13 +38,7 @@ type MessageInfo struct {
 	initMu   sync.Mutex // protects all unexported fields
 	initDone uint32
 
-	fields map[pref.FieldNumber]*fieldInfo
-	oneofs map[pref.Name]*oneofInfo
-
-	getUnknown func(pointer) pref.RawFields
-	setUnknown func(pointer, pref.RawFields)
-
-	extensionMap func(pointer) *extensionMap
+	reflectMessageInfo
 
 	// Information used by the fast-path methods.
 	methods piface.Methods
@@ -55,6 +48,17 @@ type MessageInfo struct {
 	extensionFieldInfos   map[pref.ExtensionType]*extensionFieldInfo
 }
 
+type reflectMessageInfo struct {
+	fields map[pref.FieldNumber]*fieldInfo
+	oneofs map[pref.Name]*oneofInfo
+
+	getUnknown   func(pointer) pref.RawFields
+	setUnknown   func(pointer, pref.RawFields)
+	extensionMap func(pointer) *extensionMap
+
+	nilMessage atomicNilMessage
+}
+
 // exporter is a function that returns a reference to the ith field of v,
 // where v is a pointer to a struct. It returns nil if it does not support
 // exporting the requested field (e.g., already exported).
@@ -88,10 +92,9 @@ func (mi *MessageInfo) init() {
 	// This function is called in the hot path. Inline the sync.Once
 	// logic, since allocating a closure for Once.Do is expensive.
 	// Keep init small to ensure that it can be inlined.
-	if atomic.LoadUint32(&mi.initDone) == 1 {
-		return
+	if atomic.LoadUint32(&mi.initDone) == 0 {
+		mi.initOnce()
 	}
-	mi.initOnce()
 }
 
 func (mi *MessageInfo) initOnce() {
@@ -293,247 +296,8 @@ func (mi *MessageInfo) makeExtensionFieldsFunc(t reflect.Type, si structInfo) {
 	}
 }
 
-func (mi *MessageInfo) MessageOf(p interface{}) pref.Message {
-	return (*messageReflectWrapper)(mi.dataTypeOf(p))
-}
-
+// TODO: Move this to be on the reflect message instance.
 func (mi *MessageInfo) Methods() *piface.Methods {
 	mi.init()
 	return &mi.methods
 }
-
-func (mi *MessageInfo) dataTypeOf(p interface{}) *messageDataType {
-	// TODO: Remove this check? This API is primarily used by generated code,
-	// and should not violate this assumption. Leave this check in for now to
-	// provide some sanity checks during development. This can be removed if
-	// it proves to be detrimental to performance.
-	if reflect.TypeOf(p) != mi.GoType {
-		panic(fmt.Sprintf("type mismatch: got %T, want %v", p, mi.GoType))
-	}
-	return &messageDataType{pointerOfIface(p), mi}
-}
-
-// messageDataType is a tuple of a pointer to the message data and
-// a pointer to the message type.
-//
-// TODO: Unfortunately, we need to close over a pointer and MessageInfo,
-// which incurs an an allocation. This pair is similar to a Go interface,
-// which is essentially a tuple of the same thing. We can make this efficient
-// with reflect.NamedOf (see https://golang.org/issues/16522).
-//
-// With that hypothetical API, we could dynamically create a new named type
-// that has the same underlying type as MessageInfo.GoType, and
-// dynamically create methods that close over MessageInfo.
-// Since the new type would have the same underlying type, we could directly
-// convert between pointers of those types, giving us an efficient way to swap
-// out the method set.
-//
-// Barring the ability to dynamically create named types, the workaround is
-//	1. either to accept the cost of an allocation for this wrapper struct or
-//	2. generate more types and methods, at the expense of binary size increase.
-type messageDataType struct {
-	p  pointer
-	mi *MessageInfo
-}
-
-type messageReflectWrapper messageDataType
-
-func (m *messageReflectWrapper) Descriptor() pref.MessageDescriptor {
-	return m.mi.PBType.Descriptor()
-}
-func (m *messageReflectWrapper) New() pref.Message {
-	return m.mi.PBType.New()
-}
-func (m *messageReflectWrapper) Interface() pref.ProtoMessage {
-	if m, ok := m.ProtoUnwrap().(pref.ProtoMessage); ok {
-		return m
-	}
-	return (*messageIfaceWrapper)(m)
-}
-func (m *messageReflectWrapper) ProtoUnwrap() interface{} {
-	return m.p.AsIfaceOf(m.mi.GoType.Elem())
-}
-
-func (m *messageReflectWrapper) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
-	m.mi.init()
-	for _, fi := range m.mi.fields {
-		if fi.has(m.p) {
-			if !f(fi.fieldDesc, fi.get(m.p)) {
-				return
-			}
-		}
-	}
-	m.mi.extensionMap(m.p).Range(f)
-}
-func (m *messageReflectWrapper) Has(fd pref.FieldDescriptor) bool {
-	if fi, xt := m.checkField(fd); fi != nil {
-		return fi.has(m.p)
-	} else {
-		return m.mi.extensionMap(m.p).Has(xt)
-	}
-}
-func (m *messageReflectWrapper) Clear(fd pref.FieldDescriptor) {
-	if fi, xt := m.checkField(fd); fi != nil {
-		fi.clear(m.p)
-	} else {
-		m.mi.extensionMap(m.p).Clear(xt)
-	}
-}
-func (m *messageReflectWrapper) Get(fd pref.FieldDescriptor) pref.Value {
-	if fi, xt := m.checkField(fd); fi != nil {
-		return fi.get(m.p)
-	} else {
-		return m.mi.extensionMap(m.p).Get(xt)
-	}
-}
-func (m *messageReflectWrapper) Set(fd pref.FieldDescriptor, v pref.Value) {
-	if fi, xt := m.checkField(fd); fi != nil {
-		fi.set(m.p, v)
-	} else {
-		m.mi.extensionMap(m.p).Set(xt, v)
-	}
-}
-func (m *messageReflectWrapper) Mutable(fd pref.FieldDescriptor) pref.Value {
-	if fi, xt := m.checkField(fd); fi != nil {
-		return fi.mutable(m.p)
-	} else {
-		return m.mi.extensionMap(m.p).Mutable(xt)
-	}
-}
-func (m *messageReflectWrapper) NewMessage(fd pref.FieldDescriptor) pref.Message {
-	if fi, xt := m.checkField(fd); fi != nil {
-		return fi.newMessage()
-	} else {
-		return xt.New().Message()
-	}
-}
-func (m *messageReflectWrapper) WhichOneof(od pref.OneofDescriptor) pref.FieldDescriptor {
-	m.mi.init()
-	if oi := m.mi.oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
-		return od.Fields().ByNumber(oi.which(m.p))
-	}
-	panic("invalid oneof descriptor")
-}
-func (m *messageReflectWrapper) GetUnknown() pref.RawFields {
-	m.mi.init()
-	return m.mi.getUnknown(m.p)
-}
-func (m *messageReflectWrapper) SetUnknown(b pref.RawFields) {
-	m.mi.init()
-	m.mi.setUnknown(m.p, b)
-}
-
-// checkField verifies that the provided field descriptor is valid.
-// Exactly one of the returned values is populated.
-func (m *messageReflectWrapper) checkField(fd pref.FieldDescriptor) (*fieldInfo, pref.ExtensionType) {
-	m.mi.init()
-	if fi := m.mi.fields[fd.Number()]; fi != nil {
-		if fi.fieldDesc != fd {
-			panic("mismatching field descriptor")
-		}
-		return fi, nil
-	}
-	if fd.IsExtension() {
-		if fd.ContainingMessage().FullName() != m.mi.PBType.FullName() {
-			// TODO: Should this be exact containing message descriptor match?
-			panic("mismatching containing message")
-		}
-		if !m.mi.PBType.ExtensionRanges().Has(fd.Number()) {
-			panic("invalid extension field")
-		}
-		return nil, fd.(pref.ExtensionType)
-	}
-	panic("invalid field descriptor")
-}
-
-type extensionMap map[int32]ExtensionField
-
-func (m *extensionMap) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
-	if m != nil {
-		for _, x := range *m {
-			xt := x.GetType()
-			if !f(xt, xt.ValueOf(x.GetValue())) {
-				return
-			}
-		}
-	}
-}
-func (m *extensionMap) Has(xt pref.ExtensionType) (ok bool) {
-	if m != nil {
-		_, ok = (*m)[int32(xt.Number())]
-	}
-	return ok
-}
-func (m *extensionMap) Clear(xt pref.ExtensionType) {
-	delete(*m, int32(xt.Number()))
-}
-func (m *extensionMap) Get(xt pref.ExtensionType) pref.Value {
-	if m != nil {
-		if x, ok := (*m)[int32(xt.Number())]; ok {
-			return xt.ValueOf(x.GetValue())
-		}
-	}
-	if !isComposite(xt) {
-		return defaultValueOf(xt)
-	}
-	return frozenValueOf(xt.New())
-}
-func (m *extensionMap) Set(xt pref.ExtensionType, v pref.Value) {
-	if *m == nil {
-		*m = make(map[int32]ExtensionField)
-	}
-	var x ExtensionField
-	x.SetType(xt)
-	x.SetEagerValue(xt.InterfaceOf(v))
-	(*m)[int32(xt.Number())] = x
-}
-func (m *extensionMap) Mutable(xt pref.ExtensionType) pref.Value {
-	if !isComposite(xt) {
-		panic("invalid Mutable on field with non-composite type")
-	}
-	if x, ok := (*m)[int32(xt.Number())]; ok {
-		return xt.ValueOf(x.GetValue())
-	}
-	v := xt.New()
-	m.Set(xt, v)
-	return v
-}
-
-func isComposite(fd pref.FieldDescriptor) bool {
-	return fd.Kind() == pref.MessageKind || fd.Kind() == pref.GroupKind || fd.IsList() || fd.IsMap()
-}
-
-var _ pvalue.Unwrapper = (*messageReflectWrapper)(nil)
-
-type messageIfaceWrapper messageDataType
-
-func (m *messageIfaceWrapper) ProtoReflect() pref.Message {
-	return (*messageReflectWrapper)(m)
-}
-func (m *messageIfaceWrapper) XXX_Methods() *piface.Methods {
-	// TODO: Consider not recreating this on every call.
-	m.mi.init()
-	return &piface.Methods{
-		Flags:         piface.MethodFlagDeterministicMarshal,
-		MarshalAppend: m.marshalAppend,
-		Unmarshal:     m.unmarshal,
-		Size:          m.size,
-		IsInitialized: m.isInitialized,
-	}
-}
-func (m *messageIfaceWrapper) ProtoUnwrap() interface{} {
-	return m.p.AsIfaceOf(m.mi.GoType.Elem())
-}
-func (m *messageIfaceWrapper) marshalAppend(b []byte, _ pref.ProtoMessage, opts piface.MarshalOptions) ([]byte, error) {
-	return m.mi.marshalAppendPointer(b, m.p, newMarshalOptions(opts))
-}
-func (m *messageIfaceWrapper) unmarshal(b []byte, _ pref.ProtoMessage, opts piface.UnmarshalOptions) error {
-	_, err := m.mi.unmarshalPointer(b, m.p, 0, newUnmarshalOptions(opts))
-	return err
-}
-func (m *messageIfaceWrapper) size(msg pref.ProtoMessage) (size int) {
-	return m.mi.sizePointer(m.p, 0)
-}
-func (m *messageIfaceWrapper) isInitialized(_ pref.ProtoMessage) error {
-	return m.mi.isInitializedPointer(m.p)
-}

+ 220 - 0
internal/impl/message_reflect.go

@@ -0,0 +1,220 @@
+// 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"
+	"reflect"
+
+	"google.golang.org/protobuf/internal/pragma"
+	pvalue "google.golang.org/protobuf/internal/value"
+	pref "google.golang.org/protobuf/reflect/protoreflect"
+	piface "google.golang.org/protobuf/runtime/protoiface"
+)
+
+// MessageState is a data structure that is nested as the first field in a
+// concrete message. It provides a way to implement the ProtoReflect method
+// in an allocation-free way without needing to have a shadow Go type generated
+// for every message type. This technique only works using unsafe.
+//
+//
+// Example generated code:
+//
+//	type M struct {
+//		state protoimpl.MessageState
+//
+//		Field1 int32
+//		Field2 string
+//		Field3 *BarMessage
+//		...
+//	}
+//
+//	func (m *M) ProtoReflect() protoreflect.Message {
+//		mi := &file_fizz_buzz_proto_msgInfos[5]
+//		if protoimpl.UnsafeEnabled && m != nil {
+//			ms := protoimpl.X.MessageStateOf(Pointer(m))
+//			if ms.LoadMessageInfo() == nil {
+//				ms.StoreMessageInfo(mi)
+//			}
+//			return ms
+//		}
+//		return mi.MessageOf(m)
+//	}
+//
+// The MessageState type holds a *MessageInfo, which must be atomically set to
+// the message info associated with a given message instance.
+// By unsafely converting a *M into a *MessageState, the MessageState object
+// has access to all the information needed to implement protobuf reflection.
+// It has access to the message info as its first field, and a pointer to the
+// MessageState is identical to a pointer to the concrete message value.
+//
+//
+// Requirements:
+//	• The type M must implement protoreflect.ProtoMessage.
+//	• The address of m must not be nil.
+//	• The address of m and the address of m.state must be equal,
+//	even though they are different Go types.
+type MessageState struct {
+	pragma.NoUnkeyedLiterals
+	pragma.DoNotCompare
+	pragma.DoNotCopy
+
+	mi *MessageInfo
+}
+
+type messageState MessageState
+
+var (
+	_ pref.Message     = (*messageState)(nil)
+	_ pvalue.Unwrapper = (*messageState)(nil)
+)
+
+// messageDataType is a tuple of a pointer to the message data and
+// a pointer to the message type. It is a generalized way of providing a
+// reflective view over a message instance. The disadvantage of this approach
+// is the need to allocate this tuple of 16B.
+type messageDataType struct {
+	p  pointer
+	mi *MessageInfo
+}
+
+type (
+	messageIfaceWrapper   messageDataType
+	messageReflectWrapper messageDataType
+)
+
+var (
+	_ pref.Message      = (*messageReflectWrapper)(nil)
+	_ pvalue.Unwrapper  = (*messageReflectWrapper)(nil)
+	_ pref.ProtoMessage = (*messageIfaceWrapper)(nil)
+	_ pvalue.Unwrapper  = (*messageIfaceWrapper)(nil)
+)
+
+// MessageOf returns a reflective view over a message. The input must be a
+// pointer to a named Go struct. If the provided type has a ProtoReflect method,
+// it must be implemented by calling this method.
+func (mi *MessageInfo) MessageOf(m interface{}) pref.Message {
+	// TODO: Switch the input to be an opaque Pointer.
+	if reflect.TypeOf(m) != mi.GoType {
+		panic(fmt.Sprintf("type mismatch: got %T, want %v", m, mi.GoType))
+	}
+	p := pointerOfIface(m)
+	if p.IsNil() {
+		return mi.nilMessage.Init(mi)
+	}
+	return &messageReflectWrapper{p, mi}
+}
+
+func (m *messageReflectWrapper) pointer() pointer { return m.p }
+
+func (m *messageIfaceWrapper) ProtoReflect() pref.Message {
+	return (*messageReflectWrapper)(m)
+}
+func (m *messageIfaceWrapper) XXX_Methods() *piface.Methods {
+	// TODO: Consider not recreating this on every call.
+	m.mi.init()
+	return &piface.Methods{
+		Flags:         piface.MethodFlagDeterministicMarshal,
+		MarshalAppend: m.marshalAppend,
+		Unmarshal:     m.unmarshal,
+		Size:          m.size,
+		IsInitialized: m.isInitialized,
+	}
+}
+func (m *messageIfaceWrapper) ProtoUnwrap() interface{} {
+	return m.p.AsIfaceOf(m.mi.GoType.Elem())
+}
+func (m *messageIfaceWrapper) marshalAppend(b []byte, _ pref.ProtoMessage, opts piface.MarshalOptions) ([]byte, error) {
+	return m.mi.marshalAppendPointer(b, m.p, newMarshalOptions(opts))
+}
+func (m *messageIfaceWrapper) unmarshal(b []byte, _ pref.ProtoMessage, opts piface.UnmarshalOptions) error {
+	_, err := m.mi.unmarshalPointer(b, m.p, 0, newUnmarshalOptions(opts))
+	return err
+}
+func (m *messageIfaceWrapper) size(msg pref.ProtoMessage) (size int) {
+	return m.mi.sizePointer(m.p, 0)
+}
+func (m *messageIfaceWrapper) isInitialized(_ pref.ProtoMessage) error {
+	return m.mi.isInitializedPointer(m.p)
+}
+
+type extensionMap map[int32]ExtensionField
+
+func (m *extensionMap) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
+	if m != nil {
+		for _, x := range *m {
+			xt := x.GetType()
+			if !f(xt, xt.ValueOf(x.GetValue())) {
+				return
+			}
+		}
+	}
+}
+func (m *extensionMap) Has(xt pref.ExtensionType) (ok bool) {
+	if m != nil {
+		_, ok = (*m)[int32(xt.Number())]
+	}
+	return ok
+}
+func (m *extensionMap) Clear(xt pref.ExtensionType) {
+	delete(*m, int32(xt.Number()))
+}
+func (m *extensionMap) Get(xt pref.ExtensionType) pref.Value {
+	if m != nil {
+		if x, ok := (*m)[int32(xt.Number())]; ok {
+			return xt.ValueOf(x.GetValue())
+		}
+	}
+	if !isComposite(xt) {
+		return defaultValueOf(xt)
+	}
+	return frozenValueOf(xt.New())
+}
+func (m *extensionMap) Set(xt pref.ExtensionType, v pref.Value) {
+	if *m == nil {
+		*m = make(map[int32]ExtensionField)
+	}
+	var x ExtensionField
+	x.SetType(xt)
+	x.SetEagerValue(xt.InterfaceOf(v))
+	(*m)[int32(xt.Number())] = x
+}
+func (m *extensionMap) Mutable(xt pref.ExtensionType) pref.Value {
+	if !isComposite(xt) {
+		panic("invalid Mutable on field with non-composite type")
+	}
+	if x, ok := (*m)[int32(xt.Number())]; ok {
+		return xt.ValueOf(x.GetValue())
+	}
+	v := xt.New()
+	m.Set(xt, v)
+	return v
+}
+
+func isComposite(fd pref.FieldDescriptor) bool {
+	return fd.Kind() == pref.MessageKind || fd.Kind() == pref.GroupKind || fd.IsList() || fd.IsMap()
+}
+
+// checkField verifies that the provided field descriptor is valid.
+// Exactly one of the returned values is populated.
+func (mi *MessageInfo) checkField(fd pref.FieldDescriptor) (*fieldInfo, pref.ExtensionType) {
+	if fi := mi.fields[fd.Number()]; fi != nil {
+		if fi.fieldDesc != fd {
+			panic("mismatching field descriptor")
+		}
+		return fi, nil
+	}
+	if fd.IsExtension() {
+		if fd.ContainingMessage().FullName() != mi.PBType.FullName() {
+			// TODO: Should this be exact containing message descriptor match?
+			panic("mismatching containing message")
+		}
+		if !mi.PBType.ExtensionRanges().Has(fd.Number()) {
+			panic("invalid extension field")
+		}
+		return nil, fd.(pref.ExtensionType)
+	}
+	panic("invalid field descriptor")
+}

+ 190 - 0
internal/impl/message_reflect_gen.go

@@ -0,0 +1,190 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style.
+// license that can be found in the LICENSE file.
+
+// Code generated by generate-types. DO NOT EDIT.
+
+package impl
+
+import (
+	"google.golang.org/protobuf/reflect/protoreflect"
+)
+
+func (m *messageState) Descriptor() protoreflect.MessageDescriptor {
+	return m.mi.PBType.Descriptor()
+}
+func (m *messageState) New() protoreflect.Message {
+	return m.mi.PBType.New()
+}
+func (m *messageState) Interface() protoreflect.ProtoMessage {
+	return m.ProtoUnwrap().(protoreflect.ProtoMessage)
+}
+func (m *messageState) ProtoUnwrap() interface{} {
+	return m.pointer().AsIfaceOf(m.mi.GoType.Elem())
+}
+
+func (m *messageState) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
+	m.mi.init()
+	for _, fi := range m.mi.fields {
+		if fi.has(m.pointer()) {
+			if !f(fi.fieldDesc, fi.get(m.pointer())) {
+				return
+			}
+		}
+	}
+	m.mi.extensionMap(m.pointer()).Range(f)
+}
+func (m *messageState) Has(fd protoreflect.FieldDescriptor) bool {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.has(m.pointer())
+	} else {
+		return m.mi.extensionMap(m.pointer()).Has(xt)
+	}
+}
+func (m *messageState) Clear(fd protoreflect.FieldDescriptor) {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		fi.clear(m.pointer())
+	} else {
+		m.mi.extensionMap(m.pointer()).Clear(xt)
+	}
+}
+func (m *messageState) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.get(m.pointer())
+	} else {
+		return m.mi.extensionMap(m.pointer()).Get(xt)
+	}
+}
+func (m *messageState) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		fi.set(m.pointer(), v)
+	} else {
+		m.mi.extensionMap(m.pointer()).Set(xt, v)
+	}
+}
+func (m *messageState) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.mutable(m.pointer())
+	} else {
+		return m.mi.extensionMap(m.pointer()).Mutable(xt)
+	}
+}
+func (m *messageState) NewMessage(fd protoreflect.FieldDescriptor) protoreflect.Message {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.newMessage()
+	} else {
+		return xt.New().Message()
+	}
+}
+func (m *messageState) WhichOneof(od protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
+	m.mi.init()
+	if oi := m.mi.oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
+		return od.Fields().ByNumber(oi.which(m.pointer()))
+	}
+	panic("invalid oneof descriptor")
+}
+func (m *messageState) GetUnknown() protoreflect.RawFields {
+	m.mi.init()
+	return m.mi.getUnknown(m.pointer())
+}
+func (m *messageState) SetUnknown(b protoreflect.RawFields) {
+	m.mi.init()
+	m.mi.setUnknown(m.pointer(), b)
+}
+
+func (m *messageReflectWrapper) Descriptor() protoreflect.MessageDescriptor {
+	return m.mi.PBType.Descriptor()
+}
+func (m *messageReflectWrapper) New() protoreflect.Message {
+	return m.mi.PBType.New()
+}
+func (m *messageReflectWrapper) Interface() protoreflect.ProtoMessage {
+	if m, ok := m.ProtoUnwrap().(protoreflect.ProtoMessage); ok {
+		return m
+	}
+	return (*messageIfaceWrapper)(m)
+}
+func (m *messageReflectWrapper) ProtoUnwrap() interface{} {
+	return m.pointer().AsIfaceOf(m.mi.GoType.Elem())
+}
+
+func (m *messageReflectWrapper) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
+	m.mi.init()
+	for _, fi := range m.mi.fields {
+		if fi.has(m.pointer()) {
+			if !f(fi.fieldDesc, fi.get(m.pointer())) {
+				return
+			}
+		}
+	}
+	m.mi.extensionMap(m.pointer()).Range(f)
+}
+func (m *messageReflectWrapper) Has(fd protoreflect.FieldDescriptor) bool {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.has(m.pointer())
+	} else {
+		return m.mi.extensionMap(m.pointer()).Has(xt)
+	}
+}
+func (m *messageReflectWrapper) Clear(fd protoreflect.FieldDescriptor) {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		fi.clear(m.pointer())
+	} else {
+		m.mi.extensionMap(m.pointer()).Clear(xt)
+	}
+}
+func (m *messageReflectWrapper) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.get(m.pointer())
+	} else {
+		return m.mi.extensionMap(m.pointer()).Get(xt)
+	}
+}
+func (m *messageReflectWrapper) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value) {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		fi.set(m.pointer(), v)
+	} else {
+		m.mi.extensionMap(m.pointer()).Set(xt, v)
+	}
+}
+func (m *messageReflectWrapper) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.mutable(m.pointer())
+	} else {
+		return m.mi.extensionMap(m.pointer()).Mutable(xt)
+	}
+}
+func (m *messageReflectWrapper) NewMessage(fd protoreflect.FieldDescriptor) protoreflect.Message {
+	m.mi.init()
+	if fi, xt := m.mi.checkField(fd); fi != nil {
+		return fi.newMessage()
+	} else {
+		return xt.New().Message()
+	}
+}
+func (m *messageReflectWrapper) WhichOneof(od protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
+	m.mi.init()
+	if oi := m.mi.oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
+		return od.Fields().ByNumber(oi.which(m.pointer()))
+	}
+	panic("invalid oneof descriptor")
+}
+func (m *messageReflectWrapper) GetUnknown() protoreflect.RawFields {
+	m.mi.init()
+	return m.mi.getUnknown(m.pointer())
+}
+func (m *messageReflectWrapper) SetUnknown(b protoreflect.RawFields) {
+	m.mi.init()
+	m.mi.setUnknown(m.pointer(), b)
+}

+ 71 - 0
internal/impl/message_test.go

@@ -8,7 +8,9 @@ import (
 	"fmt"
 	"math"
 	"reflect"
+	"runtime"
 	"strings"
+	"sync"
 	"testing"
 
 	cmp "github.com/google/go-cmp/cmp"
@@ -23,6 +25,7 @@ import (
 	"google.golang.org/protobuf/reflect/prototype"
 
 	proto2_20180125 "google.golang.org/protobuf/internal/testprotos/legacy/proto2.v1.0.0-20180125-92554152"
+	testpb "google.golang.org/protobuf/internal/testprotos/test"
 	"google.golang.org/protobuf/types/descriptorpb"
 )
 
@@ -1435,3 +1438,71 @@ func (p path) String() string {
 	}
 	return strings.Join(ss, ".")
 }
+
+// The MessageState implementation makes the assumption that when a
+// concrete message is unsafe casted as a *MessageState, the Go GC does
+// not reclaim the memory for the remainder of the concrete message.
+func TestUnsafeAssumptions(t *testing.T) {
+	if !pimpl.UnsafeEnabled {
+		t.Skip()
+	}
+
+	var wg sync.WaitGroup
+	for i := 0; i < 10; i++ {
+		wg.Add(1)
+		go func() {
+			var ms [10]pref.Message
+
+			// Store the message only in its reflective form.
+			// Trigger the GC after each iteration.
+			for j := 0; j < 10; j++ {
+				ms[j] = (&testpb.TestAllTypes{
+					OptionalInt32: scalar.Int32(int32(j)),
+					OptionalFloat: scalar.Float32(float32(j)),
+					RepeatedInt32: []int32{int32(j)},
+					RepeatedFloat: []float32{float32(j)},
+					DefaultInt32:  scalar.Int32(int32(j)),
+					DefaultFloat:  scalar.Float32(float32(j)),
+				}).ProtoReflect()
+				runtime.GC()
+			}
+
+			// Convert the reflective form back into a concrete form.
+			// Verify that the values written previously are still the same.
+			for j := 0; j < 10; j++ {
+				switch m := ms[j].Interface().(*testpb.TestAllTypes); {
+				case m.GetOptionalInt32() != int32(j):
+				case m.GetOptionalFloat() != float32(j):
+				case m.GetRepeatedInt32()[0] != int32(j):
+				case m.GetRepeatedFloat()[0] != float32(j):
+				case m.GetDefaultInt32() != int32(j):
+				case m.GetDefaultFloat() != float32(j):
+				default:
+					continue
+				}
+				t.Error("memory corrupted detected")
+			}
+			defer wg.Done()
+		}()
+	}
+	wg.Wait()
+}
+
+func BenchmarkName(b *testing.B) {
+	var sink pref.FullName
+	b.Run("Value", func(b *testing.B) {
+		b.ReportAllocs()
+		m := new(descriptorpb.FileDescriptorProto)
+		for i := 0; i < b.N; i++ {
+			sink = m.ProtoReflect().Descriptor().FullName()
+		}
+	})
+	b.Run("Nil", func(b *testing.B) {
+		b.ReportAllocs()
+		m := (*descriptorpb.FileDescriptorProto)(nil)
+		for i := 0; i < b.N; i++ {
+			sink = m.ProtoReflect().Descriptor().FullName()
+		}
+	})
+	runtime.KeepAlive(sink)
+}

+ 27 - 0
internal/impl/pointer_reflect.go

@@ -9,10 +9,14 @@ package impl
 import (
 	"fmt"
 	"reflect"
+	"sync"
 )
 
 const UnsafeEnabled = false
 
+// Pointer is an opaque pointer type.
+type Pointer interface{}
+
 // offset represents the offset to a struct field, accessible from a pointer.
 // The offset is the field index into a struct.
 type offset struct {
@@ -46,6 +50,11 @@ var zeroOffset = offset{index: 0}
 // pointer is an abstract representation of a pointer to a struct or field.
 type pointer struct{ v reflect.Value }
 
+// pointerOf returns p as a pointer.
+func pointerOf(p Pointer) pointer {
+	return pointerOfIface(p)
+}
+
 // pointerOfValue returns v as a pointer.
 func pointerOfValue(v reflect.Value) pointer {
 	return pointer{v: v}
@@ -146,3 +155,21 @@ func (p pointer) AppendPointerSlice(v pointer) {
 func (p pointer) SetPointer(v pointer) {
 	p.v.Elem().Set(v.v)
 }
+
+func (Export) MessageStateOf(p Pointer) *messageState     { panic("not supported") }
+func (ms *messageState) pointer() pointer                 { panic("not supported") }
+func (ms *messageState) LoadMessageInfo() *MessageInfo    { panic("not supported") }
+func (ms *messageState) StoreMessageInfo(mi *MessageInfo) { panic("not supported") }
+
+type atomicNilMessage struct {
+	once sync.Once
+	m    messageReflectWrapper
+}
+
+func (m *atomicNilMessage) Init(mi *MessageInfo) *messageReflectWrapper {
+	m.once.Do(func() {
+		m.m.p = pointerOfIface(reflect.Zero(mi.GoType).Interface())
+		m.m.mi = mi
+	})
+	return &m.m
+}

+ 36 - 0
internal/impl/pointer_unsafe.go

@@ -8,11 +8,15 @@ package impl
 
 import (
 	"reflect"
+	"sync/atomic"
 	"unsafe"
 )
 
 const UnsafeEnabled = true
 
+// Pointer is an opaque pointer type.
+type Pointer unsafe.Pointer
+
 // offset represents the offset to a struct field, accessible from a pointer.
 // The offset is the byte offset to the field from the start of the struct.
 type offset uintptr
@@ -34,6 +38,11 @@ var zeroOffset = offset(0)
 // pointer is a pointer to a message struct or field.
 type pointer struct{ p unsafe.Pointer }
 
+// pointerOf returns p as a pointer.
+func pointerOf(p Pointer) pointer {
+	return pointer{p: unsafe.Pointer(p)}
+}
+
 // pointerOfValue returns v as a pointer.
 func pointerOfValue(v reflect.Value) pointer {
 	return pointer{p: unsafe.Pointer(v.Pointer())}
@@ -125,3 +134,30 @@ func (p pointer) AppendPointerSlice(v pointer) {
 func (p pointer) SetPointer(v pointer) {
 	*(*unsafe.Pointer)(p.p) = (unsafe.Pointer)(v.p)
 }
+
+// Static check that MessageState does not exceed the size of a pointer.
+const _ = uint(unsafe.Sizeof(unsafe.Pointer(nil)) - unsafe.Sizeof(MessageState{}))
+
+func (Export) MessageStateOf(p Pointer) *messageState {
+	// Super-tricky - see documentation on MessageState.
+	return (*messageState)(unsafe.Pointer(p))
+}
+func (ms *messageState) pointer() pointer {
+	// Super-tricky - see documentation on MessageState.
+	return pointer{p: unsafe.Pointer(ms)}
+}
+func (ms *messageState) LoadMessageInfo() *MessageInfo {
+	return (*MessageInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&ms.mi))))
+}
+func (ms *messageState) StoreMessageInfo(mi *MessageInfo) {
+	atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&ms.mi)), unsafe.Pointer(mi))
+}
+
+type atomicNilMessage struct{ m messageReflectWrapper }
+
+func (m *atomicNilMessage) Init(mi *MessageInfo) *messageReflectWrapper {
+	if (*messageReflectWrapper)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&m.m.mi)))) == nil {
+		atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&m.m.mi)), unsafe.Pointer(mi))
+	}
+	return &m.m
+}

+ 15 - 4
internal/testprotos/benchmarks/benchmarks.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type BenchmarkDataset struct {
+	state protoimpl.MessageState
 	// Name of the benchmark dataset.  This should be unique across all datasets.
 	// Should only contain word characters: [a-zA-Z0-9_]
 	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
@@ -58,10 +59,18 @@ func (x *BenchmarkDataset) String() string {
 func (*BenchmarkDataset) ProtoMessage() {}
 
 func (x *BenchmarkDataset) ProtoReflect() protoreflect.Message {
-	return file_benchmarks_proto_msgTypes[0].MessageOf(x)
+	mi := &file_benchmarks_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *BenchmarkDataset) XXX_Methods() *protoiface.Methods {
+func (x *BenchmarkDataset) XXX_Methods() *protoiface.Methods {
 	return file_benchmarks_proto_msgTypes[0].Methods()
 }
 
@@ -143,9 +152,11 @@ func file_benchmarks_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_benchmarks_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*BenchmarkDataset); i {
-			case 3:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 4:
+				return &v.sizeCache
+			case 5:
 				return &v.unknownFields
 			default:
 				return nil

+ 30 - 8
internal/testprotos/benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type GoogleMessage1 struct {
+	state         protoimpl.MessageState
 	Field1        *string                   `protobuf:"bytes,1,req,name=field1" json:"field1,omitempty"`
 	Field9        *string                   `protobuf:"bytes,9,opt,name=field9" json:"field9,omitempty"`
 	Field18       *string                   `protobuf:"bytes,18,opt,name=field18" json:"field18,omitempty"`
@@ -74,10 +75,18 @@ func (x *GoogleMessage1) String() string {
 func (*GoogleMessage1) ProtoMessage() {}
 
 func (x *GoogleMessage1) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_msgTypes[0].MessageOf(x)
+	mi := &file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *GoogleMessage1) XXX_Methods() *protoiface.Methods {
+func (x *GoogleMessage1) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_msgTypes[0].Methods()
 }
 
@@ -399,6 +408,7 @@ func (x *GoogleMessage1) GetField131() int32 {
 }
 
 type GoogleMessage1SubMessage struct {
+	state         protoimpl.MessageState
 	Field1        *int32  `protobuf:"varint,1,opt,name=field1,def=0" json:"field1,omitempty"`
 	Field2        *int32  `protobuf:"varint,2,opt,name=field2,def=0" json:"field2,omitempty"`
 	Field3        *int32  `protobuf:"varint,3,opt,name=field3,def=0" json:"field3,omitempty"`
@@ -434,10 +444,18 @@ func (x *GoogleMessage1SubMessage) String() string {
 func (*GoogleMessage1SubMessage) ProtoMessage() {}
 
 func (x *GoogleMessage1SubMessage) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_msgTypes[1].MessageOf(x)
+	mi := &file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *GoogleMessage1SubMessage) XXX_Methods() *protoiface.Methods {
+func (x *GoogleMessage1SubMessage) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_msgTypes[1].Methods()
 }
 
@@ -766,9 +784,11 @@ func file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_init()
 	if !protoimpl.UnsafeEnabled {
 		file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*GoogleMessage1); i {
-			case 41:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 42:
+				return &v.sizeCache
+			case 43:
 				return &v.unknownFields
 			default:
 				return nil
@@ -776,9 +796,11 @@ func file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_init()
 		}
 		file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*GoogleMessage1SubMessage); i {
-			case 20:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 21:
+				return &v.sizeCache
+			case 22:
 				return &v.unknownFields
 			default:
 				return nil

+ 30 - 8
internal/testprotos/benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type GoogleMessage1 struct {
+	state         protoimpl.MessageState
 	Field1        string                    `protobuf:"bytes,1,opt,name=field1,proto3" json:"field1,omitempty"`
 	Field9        string                    `protobuf:"bytes,9,opt,name=field9,proto3" json:"field9,omitempty"`
 	Field18       string                    `protobuf:"bytes,18,opt,name=field18,proto3" json:"field18,omitempty"`
@@ -74,10 +75,18 @@ func (x *GoogleMessage1) String() string {
 func (*GoogleMessage1) ProtoMessage() {}
 
 func (x *GoogleMessage1) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_msgTypes[0].MessageOf(x)
+	mi := &file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *GoogleMessage1) XXX_Methods() *protoiface.Methods {
+func (x *GoogleMessage1) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_msgTypes[0].Methods()
 }
 
@@ -374,6 +383,7 @@ func (x *GoogleMessage1) GetField131() int32 {
 }
 
 type GoogleMessage1SubMessage struct {
+	state         protoimpl.MessageState
 	Field1        int32  `protobuf:"varint,1,opt,name=field1,proto3" json:"field1,omitempty"`
 	Field2        int32  `protobuf:"varint,2,opt,name=field2,proto3" json:"field2,omitempty"`
 	Field3        int32  `protobuf:"varint,3,opt,name=field3,proto3" json:"field3,omitempty"`
@@ -409,10 +419,18 @@ func (x *GoogleMessage1SubMessage) String() string {
 func (*GoogleMessage1SubMessage) ProtoMessage() {}
 
 func (x *GoogleMessage1SubMessage) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_msgTypes[1].MessageOf(x)
+	mi := &file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *GoogleMessage1SubMessage) XXX_Methods() *protoiface.Methods {
+func (x *GoogleMessage1SubMessage) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_msgTypes[1].Methods()
 }
 
@@ -721,9 +739,11 @@ func file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_init()
 	if !protoimpl.UnsafeEnabled {
 		file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*GoogleMessage1); i {
-			case 41:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 42:
+				return &v.sizeCache
+			case 43:
 				return &v.unknownFields
 			default:
 				return nil
@@ -731,9 +751,11 @@ func file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_init()
 		}
 		file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*GoogleMessage1SubMessage); i {
-			case 20:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 21:
+				return &v.sizeCache
+			case 22:
 				return &v.unknownFields
 			default:
 				return nil

+ 45 - 12
internal/testprotos/benchmarks/datasets/google_message2/benchmark_message2.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type GoogleMessage2 struct {
+	state         protoimpl.MessageState
 	Field1        *string                  `protobuf:"bytes,1,opt,name=field1" json:"field1,omitempty"`
 	Field3        *int64                   `protobuf:"varint,3,opt,name=field3" json:"field3,omitempty"`
 	Field4        *int64                   `protobuf:"varint,4,opt,name=field4" json:"field4,omitempty"`
@@ -63,10 +64,18 @@ func (x *GoogleMessage2) String() string {
 func (*GoogleMessage2) ProtoMessage() {}
 
 func (x *GoogleMessage2) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message2_benchmark_message2_proto_msgTypes[0].MessageOf(x)
+	mi := &file_datasets_google_message2_benchmark_message2_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *GoogleMessage2) XXX_Methods() *protoiface.Methods {
+func (x *GoogleMessage2) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message2_benchmark_message2_proto_msgTypes[0].Methods()
 }
 
@@ -302,6 +311,7 @@ func (x *GoogleMessage2) GetField206() bool {
 }
 
 type GoogleMessage2GroupedMessage struct {
+	state         protoimpl.MessageState
 	Field1        *float32 `protobuf:"fixed32,1,opt,name=field1" json:"field1,omitempty"`
 	Field2        *float32 `protobuf:"fixed32,2,opt,name=field2" json:"field2,omitempty"`
 	Field3        *float32 `protobuf:"fixed32,3,opt,name=field3,def=0" json:"field3,omitempty"`
@@ -328,10 +338,18 @@ func (x *GoogleMessage2GroupedMessage) String() string {
 func (*GoogleMessage2GroupedMessage) ProtoMessage() {}
 
 func (x *GoogleMessage2GroupedMessage) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message2_benchmark_message2_proto_msgTypes[1].MessageOf(x)
+	mi := &file_datasets_google_message2_benchmark_message2_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *GoogleMessage2GroupedMessage) XXX_Methods() *protoiface.Methods {
+func (x *GoogleMessage2GroupedMessage) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message2_benchmark_message2_proto_msgTypes[1].Methods()
 }
 
@@ -422,6 +440,7 @@ func (x *GoogleMessage2GroupedMessage) GetField11() int64 {
 }
 
 type GoogleMessage2_Group1 struct {
+	state         protoimpl.MessageState
 	Field11       *float32                      `protobuf:"fixed32,11,req,name=field11" json:"field11,omitempty"`
 	Field26       *float32                      `protobuf:"fixed32,26,opt,name=field26" json:"field26,omitempty"`
 	Field12       *string                       `protobuf:"bytes,12,opt,name=field12" json:"field12,omitempty"`
@@ -453,10 +472,18 @@ func (x *GoogleMessage2_Group1) String() string {
 func (*GoogleMessage2_Group1) ProtoMessage() {}
 
 func (x *GoogleMessage2_Group1) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message2_benchmark_message2_proto_msgTypes[2].MessageOf(x)
+	mi := &file_datasets_google_message2_benchmark_message2_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *GoogleMessage2_Group1) XXX_Methods() *protoiface.Methods {
+func (x *GoogleMessage2_Group1) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message2_benchmark_message2_proto_msgTypes[2].Methods()
 }
 
@@ -741,9 +768,11 @@ func file_datasets_google_message2_benchmark_message2_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_datasets_google_message2_benchmark_message2_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*GoogleMessage2); i {
-			case 30:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 31:
+				return &v.sizeCache
+			case 32:
 				return &v.unknownFields
 			default:
 				return nil
@@ -751,9 +780,11 @@ func file_datasets_google_message2_benchmark_message2_proto_init() {
 		}
 		file_datasets_google_message2_benchmark_message2_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*GoogleMessage2GroupedMessage); i {
-			case 11:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 12:
+				return &v.sizeCache
+			case 13:
 				return &v.unknownFields
 			default:
 				return nil
@@ -761,9 +792,11 @@ func file_datasets_google_message2_benchmark_message2_proto_init() {
 		}
 		file_datasets_google_message2_benchmark_message2_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*GoogleMessage2_Group1); i {
-			case 16:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 17:
+				return &v.sizeCache
+			case 18:
 				return &v.unknownFields
 			default:
 				return nil

Разлика између датотеке није приказан због своје велике величине
+ 379 - 74
internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3.pb.go


Разлика између датотеке није приказан због своје велике величине
+ 385 - 70
internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_1.pb.go


Разлика између датотеке није приказан због своје велике величине
+ 382 - 72
internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_2.pb.go


Разлика између датотеке није приказан због своје велике величине
+ 385 - 70
internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_3.pb.go


Разлика између датотеке није приказан због своје велике величине
+ 385 - 70
internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_4.pb.go


Разлика између датотеке није приказан због своје велике величине
+ 385 - 70
internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_5.pb.go


Разлика између датотеке није приказан због своје велике величине
+ 385 - 70
internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_6.pb.go


+ 146 - 36
internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_7.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type Message11018 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *Message11018) String() string {
 func (*Message11018) ProtoMessage() {}
 
 func (x *Message11018) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[0].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message11018) XXX_Methods() *protoiface.Methods {
+func (x *Message11018) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[0].Methods()
 }
 
@@ -46,6 +55,7 @@ func (*Message11018) Descriptor() ([]byte, []int) {
 }
 
 type Message10800 struct {
+	state         protoimpl.MessageState
 	Field10808    *string  `protobuf:"bytes,1,opt,name=field10808" json:"field10808,omitempty"`
 	Field10809    *int64   `protobuf:"varint,2,opt,name=field10809" json:"field10809,omitempty"`
 	Field10810    *bool    `protobuf:"varint,3,opt,name=field10810" json:"field10810,omitempty"`
@@ -65,10 +75,18 @@ func (x *Message10800) String() string {
 func (*Message10800) ProtoMessage() {}
 
 func (x *Message10800) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[1].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message10800) XXX_Methods() *protoiface.Methods {
+func (x *Message10800) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[1].Methods()
 }
 
@@ -106,6 +124,7 @@ func (x *Message10800) GetField10811() float32 {
 }
 
 type Message10802 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -121,10 +140,18 @@ func (x *Message10802) String() string {
 func (*Message10802) ProtoMessage() {}
 
 func (x *Message10802) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[2].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message10802) XXX_Methods() *protoiface.Methods {
+func (x *Message10802) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[2].Methods()
 }
 
@@ -134,6 +161,7 @@ func (*Message10802) Descriptor() ([]byte, []int) {
 }
 
 type Message10748 struct {
+	state         protoimpl.MessageState
 	Field10750    *string `protobuf:"bytes,1,opt,name=field10750" json:"field10750,omitempty"`
 	Field10751    *int32  `protobuf:"varint,2,opt,name=field10751" json:"field10751,omitempty"`
 	Field10752    *int32  `protobuf:"varint,3,opt,name=field10752" json:"field10752,omitempty"`
@@ -153,10 +181,18 @@ func (x *Message10748) String() string {
 func (*Message10748) ProtoMessage() {}
 
 func (x *Message10748) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[3].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message10748) XXX_Methods() *protoiface.Methods {
+func (x *Message10748) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[3].Methods()
 }
 
@@ -194,6 +230,7 @@ func (x *Message10748) GetField10753() int32 {
 }
 
 type Message7966 struct {
+	state         protoimpl.MessageState
 	Field7969     *string `protobuf:"bytes,1,opt,name=field7969" json:"field7969,omitempty"`
 	Field7970     *bool   `protobuf:"varint,2,opt,name=field7970" json:"field7970,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -211,10 +248,18 @@ func (x *Message7966) String() string {
 func (*Message7966) ProtoMessage() {}
 
 func (x *Message7966) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[4].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message7966) XXX_Methods() *protoiface.Methods {
+func (x *Message7966) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[4].Methods()
 }
 
@@ -238,6 +283,7 @@ func (x *Message7966) GetField7970() bool {
 }
 
 type Message708 struct {
+	state         protoimpl.MessageState
 	Field823      *Message741 `protobuf:"bytes,1,opt,name=field823" json:"field823,omitempty"`
 	Field824      []string    `protobuf:"bytes,6,rep,name=field824" json:"field824,omitempty"`
 	Field825      *string     `protobuf:"bytes,2,opt,name=field825" json:"field825,omitempty"`
@@ -259,10 +305,18 @@ func (x *Message708) String() string {
 func (*Message708) ProtoMessage() {}
 
 func (x *Message708) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[5].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[5]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message708) XXX_Methods() *protoiface.Methods {
+func (x *Message708) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[5].Methods()
 }
 
@@ -314,6 +368,7 @@ func (x *Message708) GetField828() []string {
 }
 
 type Message8942 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -329,10 +384,18 @@ func (x *Message8942) String() string {
 func (*Message8942) ProtoMessage() {}
 
 func (x *Message8942) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[6].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[6]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message8942) XXX_Methods() *protoiface.Methods {
+func (x *Message8942) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[6].Methods()
 }
 
@@ -342,6 +405,7 @@ func (*Message8942) Descriptor() ([]byte, []int) {
 }
 
 type Message11011 struct {
+	state         protoimpl.MessageState
 	Field11752    []byte `protobuf:"bytes,1,req,name=field11752" json:"field11752,omitempty"`
 	Field11753    []byte `protobuf:"bytes,2,req,name=field11753" json:"field11753,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -359,10 +423,18 @@ func (x *Message11011) String() string {
 func (*Message11011) ProtoMessage() {}
 
 func (x *Message11011) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[7].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[7]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message11011) XXX_Methods() *protoiface.Methods {
+func (x *Message11011) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[7].Methods()
 }
 
@@ -386,6 +458,7 @@ func (x *Message11011) GetField11753() []byte {
 }
 
 type UnusedEmptyMessage struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -401,10 +474,18 @@ func (x *UnusedEmptyMessage) String() string {
 func (*UnusedEmptyMessage) ProtoMessage() {}
 
 func (x *UnusedEmptyMessage) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[8].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[8]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *UnusedEmptyMessage) XXX_Methods() *protoiface.Methods {
+func (x *UnusedEmptyMessage) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[8].Methods()
 }
 
@@ -414,6 +495,7 @@ func (*UnusedEmptyMessage) Descriptor() ([]byte, []int) {
 }
 
 type Message741 struct {
+	state         protoimpl.MessageState
 	Field936      []string `protobuf:"bytes,1,rep,name=field936" json:"field936,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -430,10 +512,18 @@ func (x *Message741) String() string {
 func (*Message741) ProtoMessage() {}
 
 func (x *Message741) ProtoReflect() protoreflect.Message {
-	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[9].MessageOf(x)
+	mi := &file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[9]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message741) XXX_Methods() *protoiface.Methods {
+func (x *Message741) XXX_Methods() *protoiface.Methods {
 	return file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[9].Methods()
 }
 
@@ -559,8 +649,10 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message11018); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -568,9 +660,11 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		}
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message10800); i {
-			case 4:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 5:
+				return &v.sizeCache
+			case 6:
 				return &v.unknownFields
 			default:
 				return nil
@@ -579,8 +673,10 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message10802); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -588,9 +684,11 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		}
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message10748); i {
-			case 4:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 5:
+				return &v.sizeCache
+			case 6:
 				return &v.unknownFields
 			default:
 				return nil
@@ -598,9 +696,11 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		}
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message7966); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -608,9 +708,11 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		}
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message708); i {
-			case 6:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 7:
+				return &v.sizeCache
+			case 8:
 				return &v.unknownFields
 			default:
 				return nil
@@ -619,8 +721,10 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message8942); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -628,9 +732,11 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		}
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message11011); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -639,8 +745,10 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*UnusedEmptyMessage); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -648,9 +756,11 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
 		}
 		file_datasets_google_message3_benchmark_message3_7_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message741); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

Разлика између датотеке није приказан због своје велике величине
+ 385 - 70
internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4.pb.go


Разлика између датотеке није приказан због своје велике величине
+ 385 - 70
internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_1.pb.go


Разлика између датотеке није приказан због своје велике величине
+ 385 - 70
internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_2.pb.go


+ 60 - 16
internal/testprotos/conformance/conformance.pb.go

@@ -131,6 +131,7 @@ func (TestCategory) EnumDescriptor() ([]byte, []int) {
 // This will be known by message_type == "conformance.FailureSet", a conformance
 // test should return a serialized FailureSet in protobuf_payload.
 type FailureSet struct {
+	state         protoimpl.MessageState
 	Failure       []string `protobuf:"bytes,1,rep,name=failure,proto3" json:"failure,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -147,10 +148,18 @@ func (x *FailureSet) String() string {
 func (*FailureSet) ProtoMessage() {}
 
 func (x *FailureSet) ProtoReflect() protoreflect.Message {
-	return file_conformance_conformance_proto_msgTypes[0].MessageOf(x)
+	mi := &file_conformance_conformance_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FailureSet) XXX_Methods() *protoiface.Methods {
+func (x *FailureSet) XXX_Methods() *protoiface.Methods {
 	return file_conformance_conformance_proto_msgTypes[0].Methods()
 }
 
@@ -172,6 +181,7 @@ func (x *FailureSet) GetFailure() []string {
 //   2. parse the protobuf or JSON payload in "payload" (which may fail)
 //   3. if the parse succeeded, serialize the message in the requested format.
 type ConformanceRequest struct {
+	state protoimpl.MessageState
 	// The payload (whether protobuf of JSON) is always for a
 	// protobuf_test_messages.proto3.TestAllTypes proto (as defined in
 	// src/google/protobuf/proto3_test_messages.proto).
@@ -214,10 +224,18 @@ func (x *ConformanceRequest) String() string {
 func (*ConformanceRequest) ProtoMessage() {}
 
 func (x *ConformanceRequest) ProtoReflect() protoreflect.Message {
-	return file_conformance_conformance_proto_msgTypes[1].MessageOf(x)
+	mi := &file_conformance_conformance_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ConformanceRequest) XXX_Methods() *protoiface.Methods {
+func (x *ConformanceRequest) XXX_Methods() *protoiface.Methods {
 	return file_conformance_conformance_proto_msgTypes[1].Methods()
 }
 
@@ -319,6 +337,7 @@ func (*ConformanceRequest_TextPayload) isConformanceRequest_Payload() {}
 
 // Represents a single test case's output.
 type ConformanceResponse struct {
+	state protoimpl.MessageState
 	// Types that are valid to be assigned to Result:
 	// This string should be set to indicate parsing failed.  The string can
 	// provide more information about the parse error if it is available.
@@ -366,10 +385,18 @@ func (x *ConformanceResponse) String() string {
 func (*ConformanceResponse) ProtoMessage() {}
 
 func (x *ConformanceResponse) ProtoReflect() protoreflect.Message {
-	return file_conformance_conformance_proto_msgTypes[2].MessageOf(x)
+	mi := &file_conformance_conformance_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ConformanceResponse) XXX_Methods() *protoiface.Methods {
+func (x *ConformanceResponse) XXX_Methods() *protoiface.Methods {
 	return file_conformance_conformance_proto_msgTypes[2].Methods()
 }
 
@@ -495,6 +522,7 @@ func (*ConformanceResponse_TextPayload) isConformanceResponse_Result() {}
 
 // Encoding options for jspb format.
 type JspbEncodingConfig struct {
+	state protoimpl.MessageState
 	// Encode the value field of Any as jspb array if ture, otherwise binary.
 	UseJspbArrayAnyFormat bool `protobuf:"varint,1,opt,name=use_jspb_array_any_format,json=useJspbArrayAnyFormat,proto3" json:"use_jspb_array_any_format,omitempty"`
 	sizeCache             protoimpl.SizeCache
@@ -512,10 +540,18 @@ func (x *JspbEncodingConfig) String() string {
 func (*JspbEncodingConfig) ProtoMessage() {}
 
 func (x *JspbEncodingConfig) ProtoReflect() protoreflect.Message {
-	return file_conformance_conformance_proto_msgTypes[3].MessageOf(x)
+	mi := &file_conformance_conformance_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *JspbEncodingConfig) XXX_Methods() *protoiface.Methods {
+func (x *JspbEncodingConfig) XXX_Methods() *protoiface.Methods {
 	return file_conformance_conformance_proto_msgTypes[3].Methods()
 }
 
@@ -658,9 +694,11 @@ func file_conformance_conformance_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_conformance_conformance_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FailureSet); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -668,9 +706,11 @@ func file_conformance_conformance_proto_init() {
 		}
 		file_conformance_conformance_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ConformanceRequest); i {
-			case 5:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 6:
+				return &v.sizeCache
+			case 7:
 				return &v.unknownFields
 			default:
 				return nil
@@ -678,9 +718,11 @@ func file_conformance_conformance_proto_init() {
 		}
 		file_conformance_conformance_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ConformanceResponse); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -688,9 +730,11 @@ func file_conformance_conformance_proto_init() {
 		}
 		file_conformance_conformance_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*JspbEncodingConfig); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 106 - 29
internal/testprotos/conformance/test_messages_proto2.pb.go

@@ -135,6 +135,7 @@ func (TestAllTypesProto2_NestedEnum) EnumDescriptor() ([]byte, []int) {
 // could trigger bugs that occur in any message type in this file.  We verify
 // this stays true in a unit test.
 type TestAllTypesProto2 struct {
+	state protoimpl.MessageState
 	// Singular
 	OptionalInt32          *int32                            `protobuf:"varint,1,opt,name=optional_int32,json=optionalInt32" json:"optional_int32,omitempty"`
 	OptionalInt64          *int64                            `protobuf:"varint,2,opt,name=optional_int64,json=optionalInt64" json:"optional_int64,omitempty"`
@@ -248,10 +249,18 @@ func (x *TestAllTypesProto2) String() string {
 func (*TestAllTypesProto2) ProtoMessage() {}
 
 func (x *TestAllTypesProto2) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto2_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto2_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypesProto2) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypesProto2) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto2_proto_msgTypes[0].Methods()
 }
 
@@ -965,6 +974,7 @@ func (*TestAllTypesProto2_OneofDouble) isTestAllTypesProto2_OneofField() {}
 func (*TestAllTypesProto2_OneofEnum) isTestAllTypesProto2_OneofField() {}
 
 type ForeignMessageProto2 struct {
+	state         protoimpl.MessageState
 	C             *int32 `protobuf:"varint,1,opt,name=c" json:"c,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -981,10 +991,18 @@ func (x *ForeignMessageProto2) String() string {
 func (*ForeignMessageProto2) ProtoMessage() {}
 
 func (x *ForeignMessageProto2) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto2_proto_msgTypes[1].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto2_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ForeignMessageProto2) XXX_Methods() *protoiface.Methods {
+func (x *ForeignMessageProto2) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto2_proto_msgTypes[1].Methods()
 }
 
@@ -1001,6 +1019,7 @@ func (x *ForeignMessageProto2) GetC() int32 {
 }
 
 type TestAllTypesProto2_NestedMessage struct {
+	state         protoimpl.MessageState
 	A             *int32              `protobuf:"varint,1,opt,name=a" json:"a,omitempty"`
 	Corecursive   *TestAllTypesProto2 `protobuf:"bytes,2,opt,name=corecursive" json:"corecursive,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -1018,10 +1037,18 @@ func (x *TestAllTypesProto2_NestedMessage) String() string {
 func (*TestAllTypesProto2_NestedMessage) ProtoMessage() {}
 
 func (x *TestAllTypesProto2_NestedMessage) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto2_proto_msgTypes[2].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto2_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypesProto2_NestedMessage) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypesProto2_NestedMessage) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto2_proto_msgTypes[2].Methods()
 }
 
@@ -1046,6 +1073,7 @@ func (x *TestAllTypesProto2_NestedMessage) GetCorecursive() *TestAllTypesProto2
 
 // groups
 type TestAllTypesProto2_Data struct {
+	state         protoimpl.MessageState
 	GroupInt32    *int32  `protobuf:"varint,202,opt,name=group_int32,json=groupInt32" json:"group_int32,omitempty"`
 	GroupUint32   *uint32 `protobuf:"varint,203,opt,name=group_uint32,json=groupUint32" json:"group_uint32,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -1063,10 +1091,18 @@ func (x *TestAllTypesProto2_Data) String() string {
 func (*TestAllTypesProto2_Data) ProtoMessage() {}
 
 func (x *TestAllTypesProto2_Data) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto2_proto_msgTypes[22].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto2_proto_msgTypes[22]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypesProto2_Data) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypesProto2_Data) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto2_proto_msgTypes[22].Methods()
 }
 
@@ -1091,6 +1127,7 @@ func (x *TestAllTypesProto2_Data) GetGroupUint32() uint32 {
 
 // message_set test case.
 type TestAllTypesProto2_MessageSetCorrect struct {
+	state           protoimpl.MessageState
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
 	extensionFields protoimpl.ExtensionFields
@@ -1107,10 +1144,18 @@ func (x *TestAllTypesProto2_MessageSetCorrect) String() string {
 func (*TestAllTypesProto2_MessageSetCorrect) ProtoMessage() {}
 
 func (x *TestAllTypesProto2_MessageSetCorrect) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto2_proto_msgTypes[23].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto2_proto_msgTypes[23]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypesProto2_MessageSetCorrect) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypesProto2_MessageSetCorrect) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto2_proto_msgTypes[23].Methods()
 }
 
@@ -1129,6 +1174,7 @@ func (*TestAllTypesProto2_MessageSetCorrect) ExtensionRangeArray() []protoiface.
 }
 
 type TestAllTypesProto2_MessageSetCorrectExtension1 struct {
+	state         protoimpl.MessageState
 	Str           *string `protobuf:"bytes,25,opt,name=str" json:"str,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1145,10 +1191,18 @@ func (x *TestAllTypesProto2_MessageSetCorrectExtension1) String() string {
 func (*TestAllTypesProto2_MessageSetCorrectExtension1) ProtoMessage() {}
 
 func (x *TestAllTypesProto2_MessageSetCorrectExtension1) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto2_proto_msgTypes[24].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto2_proto_msgTypes[24]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypesProto2_MessageSetCorrectExtension1) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypesProto2_MessageSetCorrectExtension1) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto2_proto_msgTypes[24].Methods()
 }
 
@@ -1165,6 +1219,7 @@ func (x *TestAllTypesProto2_MessageSetCorrectExtension1) GetStr() string {
 }
 
 type TestAllTypesProto2_MessageSetCorrectExtension2 struct {
+	state         protoimpl.MessageState
 	I             *int32 `protobuf:"varint,9,opt,name=i" json:"i,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1181,10 +1236,18 @@ func (x *TestAllTypesProto2_MessageSetCorrectExtension2) String() string {
 func (*TestAllTypesProto2_MessageSetCorrectExtension2) ProtoMessage() {}
 
 func (x *TestAllTypesProto2_MessageSetCorrectExtension2) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto2_proto_msgTypes[25].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto2_proto_msgTypes[25]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypesProto2_MessageSetCorrectExtension2) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypesProto2_MessageSetCorrectExtension2) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto2_proto_msgTypes[25].Methods()
 }
 
@@ -1883,11 +1946,13 @@ func file_google_protobuf_test_messages_proto2_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_test_messages_proto2_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypesProto2); i {
-			case 82:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 83:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 84:
+				return &v.unknownFields
+			case 85:
 				return &v.extensionFields
 			default:
 				return nil
@@ -1895,9 +1960,11 @@ func file_google_protobuf_test_messages_proto2_proto_init() {
 		}
 		file_google_protobuf_test_messages_proto2_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ForeignMessageProto2); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1905,9 +1972,11 @@ func file_google_protobuf_test_messages_proto2_proto_init() {
 		}
 		file_google_protobuf_test_messages_proto2_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypesProto2_NestedMessage); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1915,9 +1984,11 @@ func file_google_protobuf_test_messages_proto2_proto_init() {
 		}
 		file_google_protobuf_test_messages_proto2_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypesProto2_Data); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1926,10 +1997,12 @@ func file_google_protobuf_test_messages_proto2_proto_init() {
 		file_google_protobuf_test_messages_proto2_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypesProto2_MessageSetCorrect); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 2:
+				return &v.unknownFields
+			case 3:
 				return &v.extensionFields
 			default:
 				return nil
@@ -1937,9 +2010,11 @@ func file_google_protobuf_test_messages_proto2_proto_init() {
 		}
 		file_google_protobuf_test_messages_proto2_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypesProto2_MessageSetCorrectExtension1); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1947,9 +2022,11 @@ func file_google_protobuf_test_messages_proto2_proto_init() {
 		}
 		file_google_protobuf_test_messages_proto2_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypesProto2_MessageSetCorrectExtension2); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 45 - 12
internal/testprotos/conformance/test_messages_proto3.pb.go

@@ -173,6 +173,7 @@ func (TestAllTypesProto3_AliasedEnum) EnumDescriptor() ([]byte, []int) {
 // could trigger bugs that occur in any message type in this file.  We verify
 // this stays true in a unit test.
 type TestAllTypesProto3 struct {
+	state protoimpl.MessageState
 	// Singular
 	OptionalInt32          int32                             `protobuf:"varint,1,opt,name=optional_int32,json=optionalInt32,proto3" json:"optional_int32,omitempty"`
 	OptionalInt64          int64                             `protobuf:"varint,2,opt,name=optional_int64,json=optionalInt64,proto3" json:"optional_int64,omitempty"`
@@ -317,10 +318,18 @@ func (x *TestAllTypesProto3) String() string {
 func (*TestAllTypesProto3) ProtoMessage() {}
 
 func (x *TestAllTypesProto3) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto3_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto3_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypesProto3) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypesProto3) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto3_proto_msgTypes[0].Methods()
 }
 
@@ -1242,6 +1251,7 @@ func (*TestAllTypesProto3_OneofDouble) isTestAllTypesProto3_OneofField() {}
 func (*TestAllTypesProto3_OneofEnum) isTestAllTypesProto3_OneofField() {}
 
 type ForeignMessage struct {
+	state         protoimpl.MessageState
 	C             int32 `protobuf:"varint,1,opt,name=c,proto3" json:"c,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1258,10 +1268,18 @@ func (x *ForeignMessage) String() string {
 func (*ForeignMessage) ProtoMessage() {}
 
 func (x *ForeignMessage) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto3_proto_msgTypes[1].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto3_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ForeignMessage) XXX_Methods() *protoiface.Methods {
+func (x *ForeignMessage) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto3_proto_msgTypes[1].Methods()
 }
 
@@ -1278,6 +1296,7 @@ func (x *ForeignMessage) GetC() int32 {
 }
 
 type TestAllTypesProto3_NestedMessage struct {
+	state         protoimpl.MessageState
 	A             int32               `protobuf:"varint,1,opt,name=a,proto3" json:"a,omitempty"`
 	Corecursive   *TestAllTypesProto3 `protobuf:"bytes,2,opt,name=corecursive,proto3" json:"corecursive,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -1295,10 +1314,18 @@ func (x *TestAllTypesProto3_NestedMessage) String() string {
 func (*TestAllTypesProto3_NestedMessage) ProtoMessage() {}
 
 func (x *TestAllTypesProto3_NestedMessage) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_test_messages_proto3_proto_msgTypes[2].MessageOf(x)
+	mi := &file_google_protobuf_test_messages_proto3_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypesProto3_NestedMessage) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypesProto3_NestedMessage) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_test_messages_proto3_proto_msgTypes[2].Methods()
 }
 
@@ -2133,9 +2160,11 @@ func file_google_protobuf_test_messages_proto3_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_test_messages_proto3_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypesProto3); i {
-			case 113:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 114:
+				return &v.sizeCache
+			case 115:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2143,9 +2172,11 @@ func file_google_protobuf_test_messages_proto3_proto_init() {
 		}
 		file_google_protobuf_test_messages_proto3_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ForeignMessage); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -2153,9 +2184,11 @@ func file_google_protobuf_test_messages_proto3_proto_init() {
 		}
 		file_google_protobuf_test_messages_proto3_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypesProto3_NestedMessage); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
internal/testprotos/irregular/test.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type Message struct {
+	state           protoimpl.MessageState
 	OptionalMessage *IrregularMessage            `protobuf:"bytes,1,opt,name=optional_message,json=optionalMessage" json:"optional_message,omitempty"`
 	RepeatedMessage []*IrregularMessage          `protobuf:"bytes,2,rep,name=repeated_message,json=repeatedMessage" json:"repeated_message,omitempty"`
 	RequiredMessage *IrregularMessage            `protobuf:"bytes,3,req,name=required_message,json=requiredMessage" json:"required_message,omitempty"`
@@ -40,10 +41,18 @@ func (x *Message) String() string {
 func (*Message) ProtoMessage() {}
 
 func (x *Message) ProtoReflect() protoreflect.Message {
-	return file_irregular_test_proto_msgTypes[0].MessageOf(x)
+	mi := &file_irregular_test_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message) XXX_Methods() *protoiface.Methods {
+func (x *Message) XXX_Methods() *protoiface.Methods {
 	return file_irregular_test_proto_msgTypes[0].Methods()
 }
 
@@ -193,9 +202,11 @@ func file_irregular_test_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_irregular_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message); i {
-			case 5:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 6:
+				return &v.sizeCache
+			case 7:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
internal/testprotos/legacy/legacy.pb.go

@@ -30,6 +30,7 @@ const (
 )
 
 type Legacy struct {
+	state         protoimpl.MessageState
 	F1            *proto2_v0_0.Message  `protobuf:"bytes,1,opt,name=f1,proto3" json:"f1,omitempty"`
 	F2            *proto3_v0_0.Message  `protobuf:"bytes,2,opt,name=f2,proto3" json:"f2,omitempty"`
 	F3            *proto2_v0_01.Message `protobuf:"bytes,3,opt,name=f3,proto3" json:"f3,omitempty"`
@@ -57,10 +58,18 @@ func (x *Legacy) String() string {
 func (*Legacy) ProtoMessage() {}
 
 func (x *Legacy) ProtoReflect() protoreflect.Message {
-	return file_legacy_legacy_proto_msgTypes[0].MessageOf(x)
+	mi := &file_legacy_legacy_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Legacy) XXX_Methods() *protoiface.Methods {
+func (x *Legacy) XXX_Methods() *protoiface.Methods {
 	return file_legacy_legacy_proto_msgTypes[0].Methods()
 }
 
@@ -305,9 +314,11 @@ func file_legacy_legacy_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_legacy_legacy_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Legacy); i {
-			case 12:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 13:
+				return &v.sizeCache
+			case 14:
 				return &v.unknownFields
 			default:
 				return nil

+ 281 - 72
internal/testprotos/test/test.pb.go

@@ -222,6 +222,7 @@ func (TestDeprecatedMessage_DeprecatedEnum) EnumDescriptor() ([]byte, []int) {
 }
 
 type TestAllTypes struct {
+	state                  protoimpl.MessageState
 	OptionalInt32          *int32                                 `protobuf:"varint,1,opt,name=optional_int32,json=optionalInt32" json:"optional_int32,omitempty"`
 	OptionalInt64          *int64                                 `protobuf:"varint,2,opt,name=optional_int64,json=optionalInt64" json:"optional_int64,omitempty"`
 	OptionalUint32         *uint32                                `protobuf:"varint,3,opt,name=optional_uint32,json=optionalUint32" json:"optional_uint32,omitempty"`
@@ -327,10 +328,18 @@ func (x *TestAllTypes) String() string {
 func (*TestAllTypes) ProtoMessage() {}
 
 func (x *TestAllTypes) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[0].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypes) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypes) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[0].Methods()
 }
 
@@ -1035,6 +1044,7 @@ func (*TestAllTypes_OneofEnum) isTestAllTypes_OneofField() {}
 
 // Deprecated: Do not use.
 type TestDeprecatedMessage struct {
+	state           protoimpl.MessageState
 	DeprecatedInt32 *int32 `protobuf:"varint,1,opt,name=deprecated_int32,json=deprecatedInt32" json:"deprecated_int32,omitempty"` // Deprecated: Do not use.
 	// Types that are valid to be assigned to DeprecatedOneof:
 	//	*TestDeprecatedMessage_DeprecatedOneofField
@@ -1054,10 +1064,18 @@ func (x *TestDeprecatedMessage) String() string {
 func (*TestDeprecatedMessage) ProtoMessage() {}
 
 func (x *TestDeprecatedMessage) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[1].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestDeprecatedMessage) XXX_Methods() *protoiface.Methods {
+func (x *TestDeprecatedMessage) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[1].Methods()
 }
 
@@ -1100,6 +1118,7 @@ type TestDeprecatedMessage_DeprecatedOneofField struct {
 func (*TestDeprecatedMessage_DeprecatedOneofField) isTestDeprecatedMessage_DeprecatedOneof() {}
 
 type ForeignMessage struct {
+	state         protoimpl.MessageState
 	C             *int32 `protobuf:"varint,1,opt,name=c" json:"c,omitempty"`
 	D             *int32 `protobuf:"varint,2,opt,name=d" json:"d,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -1117,10 +1136,18 @@ func (x *ForeignMessage) String() string {
 func (*ForeignMessage) ProtoMessage() {}
 
 func (x *ForeignMessage) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[2].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ForeignMessage) XXX_Methods() *protoiface.Methods {
+func (x *ForeignMessage) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[2].Methods()
 }
 
@@ -1144,6 +1171,7 @@ func (x *ForeignMessage) GetD() int32 {
 }
 
 type TestReservedFields struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -1159,10 +1187,18 @@ func (x *TestReservedFields) String() string {
 func (*TestReservedFields) ProtoMessage() {}
 
 func (x *TestReservedFields) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[3].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestReservedFields) XXX_Methods() *protoiface.Methods {
+func (x *TestReservedFields) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[3].Methods()
 }
 
@@ -1172,6 +1208,7 @@ func (*TestReservedFields) Descriptor() ([]byte, []int) {
 }
 
 type TestAllExtensions struct {
+	state           protoimpl.MessageState
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
 	extensionFields protoimpl.ExtensionFields
@@ -1188,10 +1225,18 @@ func (x *TestAllExtensions) String() string {
 func (*TestAllExtensions) ProtoMessage() {}
 
 func (x *TestAllExtensions) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[4].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllExtensions) XXX_Methods() *protoiface.Methods {
+func (x *TestAllExtensions) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[4].Methods()
 }
 
@@ -1210,6 +1255,7 @@ func (*TestAllExtensions) ExtensionRangeArray() []protoiface.ExtensionRangeV1 {
 }
 
 type OptionalGroupExtension struct {
+	state         protoimpl.MessageState
 	A             *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1226,10 +1272,18 @@ func (x *OptionalGroupExtension) String() string {
 func (*OptionalGroupExtension) ProtoMessage() {}
 
 func (x *OptionalGroupExtension) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[5].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[5]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *OptionalGroupExtension) XXX_Methods() *protoiface.Methods {
+func (x *OptionalGroupExtension) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[5].Methods()
 }
 
@@ -1246,6 +1300,7 @@ func (x *OptionalGroupExtension) GetA() int32 {
 }
 
 type RepeatedGroupExtension struct {
+	state         protoimpl.MessageState
 	A             *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1262,10 +1317,18 @@ func (x *RepeatedGroupExtension) String() string {
 func (*RepeatedGroupExtension) ProtoMessage() {}
 
 func (x *RepeatedGroupExtension) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[6].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[6]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *RepeatedGroupExtension) XXX_Methods() *protoiface.Methods {
+func (x *RepeatedGroupExtension) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[6].Methods()
 }
 
@@ -1282,6 +1345,7 @@ func (x *RepeatedGroupExtension) GetA() int32 {
 }
 
 type TestNestedExtension struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -1297,10 +1361,18 @@ func (x *TestNestedExtension) String() string {
 func (*TestNestedExtension) ProtoMessage() {}
 
 func (x *TestNestedExtension) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[7].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[7]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestNestedExtension) XXX_Methods() *protoiface.Methods {
+func (x *TestNestedExtension) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[7].Methods()
 }
 
@@ -1310,6 +1382,7 @@ func (*TestNestedExtension) Descriptor() ([]byte, []int) {
 }
 
 type TestRequired struct {
+	state         protoimpl.MessageState
 	RequiredField *int32 `protobuf:"varint,1,req,name=required_field,json=requiredField" json:"required_field,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1326,10 +1399,18 @@ func (x *TestRequired) String() string {
 func (*TestRequired) ProtoMessage() {}
 
 func (x *TestRequired) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[8].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[8]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestRequired) XXX_Methods() *protoiface.Methods {
+func (x *TestRequired) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[8].Methods()
 }
 
@@ -1346,6 +1427,7 @@ func (x *TestRequired) GetRequiredField() int32 {
 }
 
 type TestRequiredForeign struct {
+	state           protoimpl.MessageState
 	OptionalMessage *TestRequired           `protobuf:"bytes,1,opt,name=optional_message,json=optionalMessage" json:"optional_message,omitempty"`
 	RepeatedMessage []*TestRequired         `protobuf:"bytes,2,rep,name=repeated_message,json=repeatedMessage" json:"repeated_message,omitempty"`
 	MapMessage      map[int32]*TestRequired `protobuf:"bytes,3,rep,name=map_message,json=mapMessage" json:"map_message,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
@@ -1367,10 +1449,18 @@ func (x *TestRequiredForeign) String() string {
 func (*TestRequiredForeign) ProtoMessage() {}
 
 func (x *TestRequiredForeign) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[9].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[9]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestRequiredForeign) XXX_Methods() *protoiface.Methods {
+func (x *TestRequiredForeign) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[9].Methods()
 }
 
@@ -1425,6 +1515,7 @@ type TestRequiredForeign_OneofMessage struct {
 func (*TestRequiredForeign_OneofMessage) isTestRequiredForeign_OneofField() {}
 
 type TestRequiredGroupFields struct {
+	state         protoimpl.MessageState
 	Optionalgroup *TestRequiredGroupFields_OptionalGroup   `protobuf:"group,1,opt,name=OptionalGroup,json=optionalgroup" json:"optionalgroup,omitempty"`
 	Repeatedgroup []*TestRequiredGroupFields_RepeatedGroup `protobuf:"group,3,rep,name=RepeatedGroup,json=repeatedgroup" json:"repeatedgroup,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -1442,10 +1533,18 @@ func (x *TestRequiredGroupFields) String() string {
 func (*TestRequiredGroupFields) ProtoMessage() {}
 
 func (x *TestRequiredGroupFields) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[10].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[10]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestRequiredGroupFields) XXX_Methods() *protoiface.Methods {
+func (x *TestRequiredGroupFields) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[10].Methods()
 }
 
@@ -1469,6 +1568,7 @@ func (x *TestRequiredGroupFields) GetRepeatedgroup() []*TestRequiredGroupFields_
 }
 
 type TestWeak struct {
+	state         protoimpl.MessageState
 	WeakMessage   *weak.WeakImportMessage `protobuf:"bytes,1,opt,weak=goproto.proto.test.weak.WeakImportMessage,name=weak_message,json=weakMessage" json:"weak_message,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1485,10 +1585,18 @@ func (x *TestWeak) String() string {
 func (*TestWeak) ProtoMessage() {}
 
 func (x *TestWeak) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[11].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[11]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestWeak) XXX_Methods() *protoiface.Methods {
+func (x *TestWeak) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[11].Methods()
 }
 
@@ -1506,6 +1614,7 @@ func (x *TestWeak) GetWeakMessage() *weak.WeakImportMessage {
 
 // Test that RPC services work.
 type FooRequest struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -1521,10 +1630,18 @@ func (x *FooRequest) String() string {
 func (*FooRequest) ProtoMessage() {}
 
 func (x *FooRequest) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[12].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[12]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FooRequest) XXX_Methods() *protoiface.Methods {
+func (x *FooRequest) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[12].Methods()
 }
 
@@ -1534,6 +1651,7 @@ func (*FooRequest) Descriptor() ([]byte, []int) {
 }
 
 type FooResponse struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -1549,10 +1667,18 @@ func (x *FooResponse) String() string {
 func (*FooResponse) ProtoMessage() {}
 
 func (x *FooResponse) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[13].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[13]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FooResponse) XXX_Methods() *protoiface.Methods {
+func (x *FooResponse) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[13].Methods()
 }
 
@@ -1562,6 +1688,7 @@ func (*FooResponse) Descriptor() ([]byte, []int) {
 }
 
 type TestAllTypes_NestedMessage struct {
+	state         protoimpl.MessageState
 	A             *int32        `protobuf:"varint,1,opt,name=a" json:"a,omitempty"`
 	Corecursive   *TestAllTypes `protobuf:"bytes,2,opt,name=corecursive" json:"corecursive,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -1579,10 +1706,18 @@ func (x *TestAllTypes_NestedMessage) String() string {
 func (*TestAllTypes_NestedMessage) ProtoMessage() {}
 
 func (x *TestAllTypes_NestedMessage) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[14].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[14]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypes_NestedMessage) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypes_NestedMessage) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[14].Methods()
 }
 
@@ -1606,6 +1741,7 @@ func (x *TestAllTypes_NestedMessage) GetCorecursive() *TestAllTypes {
 }
 
 type TestAllTypes_OptionalGroup struct {
+	state         protoimpl.MessageState
 	A             *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1622,10 +1758,18 @@ func (x *TestAllTypes_OptionalGroup) String() string {
 func (*TestAllTypes_OptionalGroup) ProtoMessage() {}
 
 func (x *TestAllTypes_OptionalGroup) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[15].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[15]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypes_OptionalGroup) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypes_OptionalGroup) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[15].Methods()
 }
 
@@ -1642,6 +1786,7 @@ func (x *TestAllTypes_OptionalGroup) GetA() int32 {
 }
 
 type TestAllTypes_RepeatedGroup struct {
+	state         protoimpl.MessageState
 	A             *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1658,10 +1803,18 @@ func (x *TestAllTypes_RepeatedGroup) String() string {
 func (*TestAllTypes_RepeatedGroup) ProtoMessage() {}
 
 func (x *TestAllTypes_RepeatedGroup) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[16].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[16]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypes_RepeatedGroup) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypes_RepeatedGroup) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[16].Methods()
 }
 
@@ -1678,6 +1831,7 @@ func (x *TestAllTypes_RepeatedGroup) GetA() int32 {
 }
 
 type TestRequiredGroupFields_OptionalGroup struct {
+	state         protoimpl.MessageState
 	A             *int32 `protobuf:"varint,2,req,name=a" json:"a,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1694,10 +1848,18 @@ func (x *TestRequiredGroupFields_OptionalGroup) String() string {
 func (*TestRequiredGroupFields_OptionalGroup) ProtoMessage() {}
 
 func (x *TestRequiredGroupFields_OptionalGroup) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[35].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[35]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestRequiredGroupFields_OptionalGroup) XXX_Methods() *protoiface.Methods {
+func (x *TestRequiredGroupFields_OptionalGroup) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[35].Methods()
 }
 
@@ -1714,6 +1876,7 @@ func (x *TestRequiredGroupFields_OptionalGroup) GetA() int32 {
 }
 
 type TestRequiredGroupFields_RepeatedGroup struct {
+	state         protoimpl.MessageState
 	A             *int32 `protobuf:"varint,4,req,name=a" json:"a,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -1730,10 +1893,18 @@ func (x *TestRequiredGroupFields_RepeatedGroup) String() string {
 func (*TestRequiredGroupFields_RepeatedGroup) ProtoMessage() {}
 
 func (x *TestRequiredGroupFields_RepeatedGroup) ProtoReflect() protoreflect.Message {
-	return file_test_test_proto_msgTypes[36].MessageOf(x)
+	mi := &file_test_test_proto_msgTypes[36]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestRequiredGroupFields_RepeatedGroup) XXX_Methods() *protoiface.Methods {
+func (x *TestRequiredGroupFields_RepeatedGroup) XXX_Methods() *protoiface.Methods {
 	return file_test_test_proto_msgTypes[36].Methods()
 }
 
@@ -3459,9 +3630,11 @@ func file_test_test_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_test_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypes); i {
-			case 79:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 80:
+				return &v.sizeCache
+			case 81:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3469,9 +3642,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestDeprecatedMessage); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3479,9 +3654,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ForeignMessage); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3490,8 +3667,10 @@ func file_test_test_proto_init() {
 		file_test_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestReservedFields); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3500,10 +3679,12 @@ func file_test_test_proto_init() {
 		file_test_test_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllExtensions); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 2:
+				return &v.unknownFields
+			case 3:
 				return &v.extensionFields
 			default:
 				return nil
@@ -3511,9 +3692,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*OptionalGroupExtension); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3521,9 +3704,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*RepeatedGroupExtension); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3532,8 +3717,10 @@ func file_test_test_proto_init() {
 		file_test_test_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestNestedExtension); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3541,9 +3728,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestRequired); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3551,9 +3740,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestRequiredForeign); i {
-			case 4:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 5:
+				return &v.sizeCache
+			case 6:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3561,9 +3752,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestRequiredGroupFields); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3571,9 +3764,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestWeak); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3582,8 +3777,10 @@ func file_test_test_proto_init() {
 		file_test_test_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FooRequest); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3592,8 +3789,10 @@ func file_test_test_proto_init() {
 		file_test_test_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FooResponse); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3601,9 +3800,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypes_NestedMessage); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3611,9 +3812,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypes_OptionalGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3621,9 +3824,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypes_RepeatedGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3631,9 +3836,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[35].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestRequiredGroupFields_OptionalGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -3641,9 +3848,11 @@ func file_test_test_proto_init() {
 		}
 		file_test_test_proto_msgTypes[36].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestRequiredGroupFields_RepeatedGroup); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
internal/testprotos/test/test_import.pb.go

@@ -66,6 +66,7 @@ func (ImportEnum) EnumDescriptor() ([]byte, []int) {
 }
 
 type ImportMessage struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -81,10 +82,18 @@ func (x *ImportMessage) String() string {
 func (*ImportMessage) ProtoMessage() {}
 
 func (x *ImportMessage) ProtoReflect() protoreflect.Message {
-	return file_test_test_import_proto_msgTypes[0].MessageOf(x)
+	mi := &file_test_test_import_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ImportMessage) XXX_Methods() *protoiface.Methods {
+func (x *ImportMessage) XXX_Methods() *protoiface.Methods {
 	return file_test_test_import_proto_msgTypes[0].Methods()
 }
 
@@ -143,8 +152,10 @@ func file_test_test_import_proto_init() {
 		file_test_test_import_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ImportMessage); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
internal/testprotos/test/test_public.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type PublicImportMessage struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -33,10 +34,18 @@ func (x *PublicImportMessage) String() string {
 func (*PublicImportMessage) ProtoMessage() {}
 
 func (x *PublicImportMessage) ProtoReflect() protoreflect.Message {
-	return file_test_test_public_proto_msgTypes[0].MessageOf(x)
+	mi := &file_test_test_public_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *PublicImportMessage) XXX_Methods() *protoiface.Methods {
+func (x *PublicImportMessage) XXX_Methods() *protoiface.Methods {
 	return file_test_test_public_proto_msgTypes[0].Methods()
 }
 
@@ -91,8 +100,10 @@ func file_test_test_public_proto_init() {
 		file_test_test_public_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*PublicImportMessage); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
internal/testprotos/test/weak/test_weak.pb.go

@@ -18,6 +18,7 @@ const (
 )
 
 type WeakImportMessage struct {
+	state         protoimpl.MessageState
 	A             *int32 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -34,10 +35,18 @@ func (x *WeakImportMessage) String() string {
 func (*WeakImportMessage) ProtoMessage() {}
 
 func (x *WeakImportMessage) ProtoReflect() protoreflect.Message {
-	return file_test_weak_test_weak_proto_msgTypes[0].MessageOf(x)
+	mi := &file_test_weak_test_weak_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *WeakImportMessage) XXX_Methods() *protoiface.Methods {
+func (x *WeakImportMessage) XXX_Methods() *protoiface.Methods {
 	return file_test_weak_test_weak_proto_msgTypes[0].Methods()
 }
 
@@ -100,9 +109,11 @@ func file_test_weak_test_weak_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_test_weak_test_weak_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*WeakImportMessage); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 45 - 12
internal/testprotos/test3/test.pb.go

@@ -111,6 +111,7 @@ func (TestAllTypes_NestedEnum) EnumDescriptor() ([]byte, []int) {
 }
 
 type TestAllTypes struct {
+	state                  protoimpl.MessageState
 	OptionalInt32          int32                                  `protobuf:"varint,1,opt,name=optional_int32,json=optionalInt32,proto3" json:"optional_int32,omitempty"`
 	OptionalInt64          int64                                  `protobuf:"varint,2,opt,name=optional_int64,json=optionalInt64,proto3" json:"optional_int64,omitempty"`
 	OptionalUint32         uint32                                 `protobuf:"varint,3,opt,name=optional_uint32,json=optionalUint32,proto3" json:"optional_uint32,omitempty"`
@@ -196,10 +197,18 @@ func (x *TestAllTypes) String() string {
 func (*TestAllTypes) ProtoMessage() {}
 
 func (x *TestAllTypes) ProtoReflect() protoreflect.Message {
-	return file_test3_test_proto_msgTypes[0].MessageOf(x)
+	mi := &file_test3_test_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypes) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypes) XXX_Methods() *protoiface.Methods {
 	return file_test3_test_proto_msgTypes[0].Methods()
 }
 
@@ -750,6 +759,7 @@ func (*TestAllTypes_OneofDouble) isTestAllTypes_OneofField() {}
 func (*TestAllTypes_OneofEnum) isTestAllTypes_OneofField() {}
 
 type ForeignMessage struct {
+	state         protoimpl.MessageState
 	C             int32 `protobuf:"varint,1,opt,name=c,proto3" json:"c,omitempty"`
 	D             int32 `protobuf:"varint,2,opt,name=d,proto3" json:"d,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -767,10 +777,18 @@ func (x *ForeignMessage) String() string {
 func (*ForeignMessage) ProtoMessage() {}
 
 func (x *ForeignMessage) ProtoReflect() protoreflect.Message {
-	return file_test3_test_proto_msgTypes[1].MessageOf(x)
+	mi := &file_test3_test_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ForeignMessage) XXX_Methods() *protoiface.Methods {
+func (x *ForeignMessage) XXX_Methods() *protoiface.Methods {
 	return file_test3_test_proto_msgTypes[1].Methods()
 }
 
@@ -794,6 +812,7 @@ func (x *ForeignMessage) GetD() int32 {
 }
 
 type TestAllTypes_NestedMessage struct {
+	state         protoimpl.MessageState
 	A             int32         `protobuf:"varint,1,opt,name=a,proto3" json:"a,omitempty"`
 	Corecursive   *TestAllTypes `protobuf:"bytes,2,opt,name=corecursive,proto3" json:"corecursive,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -811,10 +830,18 @@ func (x *TestAllTypes_NestedMessage) String() string {
 func (*TestAllTypes_NestedMessage) ProtoMessage() {}
 
 func (x *TestAllTypes_NestedMessage) ProtoReflect() protoreflect.Message {
-	return file_test3_test_proto_msgTypes[2].MessageOf(x)
+	mi := &file_test3_test_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *TestAllTypes_NestedMessage) XXX_Methods() *protoiface.Methods {
+func (x *TestAllTypes_NestedMessage) XXX_Methods() *protoiface.Methods {
 	return file_test3_test_proto_msgTypes[2].Methods()
 }
 
@@ -1322,9 +1349,11 @@ func file_test3_test_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_test3_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypes); i {
-			case 60:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 61:
+				return &v.sizeCache
+			case 62:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1332,9 +1361,11 @@ func file_test3_test_proto_init() {
 		}
 		file_test3_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ForeignMessage); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -1342,9 +1373,11 @@ func file_test3_test_proto_init() {
 		}
 		file_test3_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*TestAllTypes_NestedMessage); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
internal/testprotos/test3/test_import.pb.go

@@ -56,6 +56,7 @@ func (ImportEnum) EnumDescriptor() ([]byte, []int) {
 }
 
 type ImportMessage struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -71,10 +72,18 @@ func (x *ImportMessage) String() string {
 func (*ImportMessage) ProtoMessage() {}
 
 func (x *ImportMessage) ProtoReflect() protoreflect.Message {
-	return file_test3_test_import_proto_msgTypes[0].MessageOf(x)
+	mi := &file_test3_test_import_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ImportMessage) XXX_Methods() *protoiface.Methods {
+func (x *ImportMessage) XXX_Methods() *protoiface.Methods {
 	return file_test3_test_import_proto_msgTypes[0].Methods()
 }
 
@@ -133,8 +142,10 @@ func file_test3_test_import_proto_init() {
 		file_test3_test_import_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ImportMessage); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 58 - 14
reflect/protoregistry/testprotos/test.pb.go

@@ -160,6 +160,7 @@ func (Enum3) EnumDescriptor() ([]byte, []int) {
 }
 
 type Message1 struct {
+	state           protoimpl.MessageState
 	sizeCache       protoimpl.SizeCache
 	unknownFields   protoimpl.UnknownFields
 	extensionFields protoimpl.ExtensionFields
@@ -176,10 +177,18 @@ func (x *Message1) String() string {
 func (*Message1) ProtoMessage() {}
 
 func (x *Message1) ProtoReflect() protoreflect.Message {
-	return file_test_proto_msgTypes[0].MessageOf(x)
+	mi := &file_test_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message1) XXX_Methods() *protoiface.Methods {
+func (x *Message1) XXX_Methods() *protoiface.Methods {
 	return file_test_proto_msgTypes[0].Methods()
 }
 
@@ -198,6 +207,7 @@ func (*Message1) ExtensionRangeArray() []protoiface.ExtensionRangeV1 {
 }
 
 type Message2 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -213,10 +223,18 @@ func (x *Message2) String() string {
 func (*Message2) ProtoMessage() {}
 
 func (x *Message2) ProtoReflect() protoreflect.Message {
-	return file_test_proto_msgTypes[1].MessageOf(x)
+	mi := &file_test_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message2) XXX_Methods() *protoiface.Methods {
+func (x *Message2) XXX_Methods() *protoiface.Methods {
 	return file_test_proto_msgTypes[1].Methods()
 }
 
@@ -226,6 +244,7 @@ func (*Message2) Descriptor() ([]byte, []int) {
 }
 
 type Message3 struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -241,10 +260,18 @@ func (x *Message3) String() string {
 func (*Message3) ProtoMessage() {}
 
 func (x *Message3) ProtoReflect() protoreflect.Message {
-	return file_test_proto_msgTypes[2].MessageOf(x)
+	mi := &file_test_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message3) XXX_Methods() *protoiface.Methods {
+func (x *Message3) XXX_Methods() *protoiface.Methods {
 	return file_test_proto_msgTypes[2].Methods()
 }
 
@@ -254,6 +281,7 @@ func (*Message3) Descriptor() ([]byte, []int) {
 }
 
 type Message4 struct {
+	state         protoimpl.MessageState
 	BoolField     *bool `protobuf:"varint,30,opt,name=bool_field,json=boolField" json:"bool_field,omitempty"`
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
@@ -270,10 +298,18 @@ func (x *Message4) String() string {
 func (*Message4) ProtoMessage() {}
 
 func (x *Message4) ProtoReflect() protoreflect.Message {
-	return file_test_proto_msgTypes[3].MessageOf(x)
+	mi := &file_test_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Message4) XXX_Methods() *protoiface.Methods {
+func (x *Message4) XXX_Methods() *protoiface.Methods {
 	return file_test_proto_msgTypes[3].Methods()
 }
 
@@ -454,10 +490,12 @@ func file_test_proto_init() {
 		file_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message1); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
-				return &v.unknownFields
+				return &v.sizeCache
 			case 2:
+				return &v.unknownFields
+			case 3:
 				return &v.extensionFields
 			default:
 				return nil
@@ -466,8 +504,10 @@ func file_test_proto_init() {
 		file_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message2); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -476,8 +516,10 @@ func file_test_proto_init() {
 		file_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message3); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil
@@ -485,9 +527,11 @@ func file_test_proto_init() {
 		}
 		file_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Message4); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 2 - 0
runtime/protoimpl/impl.go

@@ -64,7 +64,9 @@ type (
 
 	DescBuilder      = filedesc.DescBuilder
 	TypeBuilder      = filetype.TypeBuilder
+	Pointer          = impl.Pointer
 	MessageInfo      = impl.MessageInfo
+	MessageState     = impl.MessageState
 	SizeCache        = impl.SizeCache
 	UnknownFields    = impl.UnknownFields
 	ExtensionFields  = impl.ExtensionFields

Разлика између датотеке није приказан због своје велике величине
+ 365 - 92
types/descriptorpb/descriptor.pb.go


+ 15 - 4
types/known/anypb/any.pb.go

@@ -98,6 +98,7 @@ const (
 //     }
 //
 type Any struct {
+	state protoimpl.MessageState
 	// A URL/resource name that uniquely identifies the type of the serialized
 	// protocol buffer message. This string must contain at least
 	// one "/" character. The last segment of the URL's path must represent
@@ -144,10 +145,18 @@ func (x *Any) String() string {
 func (*Any) ProtoMessage() {}
 
 func (x *Any) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_any_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_any_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Any) XXX_Methods() *protoiface.Methods {
+func (x *Any) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_any_proto_msgTypes[0].Methods()
 }
 
@@ -222,9 +231,11 @@ func file_google_protobuf_any_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_any_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Any); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 45 - 12
types/known/apipb/api.pb.go

@@ -29,6 +29,7 @@ const (
 // this message itself. See https://cloud.google.com/apis/design/glossary for
 // detailed terminology.
 type Api struct {
+	state protoimpl.MessageState
 	// The fully qualified name of this interface, including package name
 	// followed by the interface's simple name.
 	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
@@ -80,10 +81,18 @@ func (x *Api) String() string {
 func (*Api) ProtoMessage() {}
 
 func (x *Api) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_api_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_api_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Api) XXX_Methods() *protoiface.Methods {
+func (x *Api) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_api_proto_msgTypes[0].Methods()
 }
 
@@ -143,6 +152,7 @@ func (x *Api) GetSyntax() typepb.Syntax {
 
 // Method represents a method of an API interface.
 type Method struct {
+	state protoimpl.MessageState
 	// The simple name of this method.
 	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
 	// A URL of the input message type.
@@ -172,10 +182,18 @@ func (x *Method) String() string {
 func (*Method) ProtoMessage() {}
 
 func (x *Method) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_api_proto_msgTypes[1].MessageOf(x)
+	mi := &file_google_protobuf_api_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Method) XXX_Methods() *protoiface.Methods {
+func (x *Method) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_api_proto_msgTypes[1].Methods()
 }
 
@@ -312,6 +330,7 @@ func (x *Method) GetSyntax() typepb.Syntax {
 //       ...
 //     }
 type Mixin struct {
+	state protoimpl.MessageState
 	// The fully qualified name of the interface which is included.
 	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
 	// If non-empty specifies a path under which inherited HTTP paths
@@ -332,10 +351,18 @@ func (x *Mixin) String() string {
 func (*Mixin) ProtoMessage() {}
 
 func (x *Mixin) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_api_proto_msgTypes[2].MessageOf(x)
+	mi := &file_google_protobuf_api_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Mixin) XXX_Methods() *protoiface.Methods {
+func (x *Mixin) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_api_proto_msgTypes[2].Methods()
 }
 
@@ -465,9 +492,11 @@ func file_google_protobuf_api_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Api); i {
-			case 7:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 8:
+				return &v.sizeCache
+			case 9:
 				return &v.unknownFields
 			default:
 				return nil
@@ -475,9 +504,11 @@ func file_google_protobuf_api_proto_init() {
 		}
 		file_google_protobuf_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Method); i {
-			case 7:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 8:
+				return &v.sizeCache
+			case 9:
 				return &v.unknownFields
 			default:
 				return nil
@@ -485,9 +516,11 @@ func file_google_protobuf_api_proto_init() {
 		}
 		file_google_protobuf_api_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Mixin); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
types/known/durationpb/duration.pb.go

@@ -78,6 +78,7 @@ const (
 //
 //
 type Duration struct {
+	state protoimpl.MessageState
 	// Signed seconds of the span of time. Must be from -315,576,000,000
 	// to +315,576,000,000 inclusive. Note: these bounds are computed from:
 	// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
@@ -104,10 +105,18 @@ func (x *Duration) String() string {
 func (*Duration) ProtoMessage() {}
 
 func (x *Duration) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_duration_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_duration_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Duration) XXX_Methods() *protoiface.Methods {
+func (x *Duration) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_duration_proto_msgTypes[0].Methods()
 }
 
@@ -183,9 +192,11 @@ func file_google_protobuf_duration_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_duration_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Duration); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 14 - 3
types/known/emptypb/empty.pb.go

@@ -27,6 +27,7 @@ const (
 //
 // The JSON representation for `Empty` is empty JSON object `{}`.
 type Empty struct {
+	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 }
@@ -42,10 +43,18 @@ func (x *Empty) String() string {
 func (*Empty) ProtoMessage() {}
 
 func (x *Empty) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_empty_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_empty_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Empty) XXX_Methods() *protoiface.Methods {
+func (x *Empty) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_empty_proto_msgTypes[0].Methods()
 }
 
@@ -104,8 +113,10 @@ func file_google_protobuf_empty_proto_init() {
 		file_google_protobuf_empty_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Empty); i {
 			case 0:
-				return &v.sizeCache
+				return &v.state
 			case 1:
+				return &v.sizeCache
+			case 2:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
types/known/fieldmaskpb/field_mask.pb.go

@@ -217,6 +217,7 @@ const (
 // request should verify the included field paths, and return an
 // `INVALID_ARGUMENT` error if any path is duplicated or unmappable.
 type FieldMask struct {
+	state protoimpl.MessageState
 	// The set of field mask paths.
 	Paths         []string `protobuf:"bytes,1,rep,name=paths,proto3" json:"paths,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -234,10 +235,18 @@ func (x *FieldMask) String() string {
 func (*FieldMask) ProtoMessage() {}
 
 func (x *FieldMask) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_field_mask_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_field_mask_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FieldMask) XXX_Methods() *protoiface.Methods {
+func (x *FieldMask) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_field_mask_proto_msgTypes[0].Methods()
 }
 
@@ -305,9 +314,11 @@ func file_google_protobuf_field_mask_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_field_mask_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FieldMask); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
types/known/sourcecontextpb/source_context.pb.go

@@ -20,6 +20,7 @@ const (
 // `SourceContext` represents information about the source of a
 // protobuf element, like the file in which it is defined.
 type SourceContext struct {
+	state protoimpl.MessageState
 	// The path-qualified name of the .proto file that contained the associated
 	// protobuf element.  For example: `"google/protobuf/source_context.proto"`.
 	FileName      string `protobuf:"bytes,1,opt,name=file_name,json=fileName,proto3" json:"file_name,omitempty"`
@@ -38,10 +39,18 @@ func (x *SourceContext) String() string {
 func (*SourceContext) ProtoMessage() {}
 
 func (x *SourceContext) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_source_context_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_source_context_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *SourceContext) XXX_Methods() *protoiface.Methods {
+func (x *SourceContext) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_source_context_proto_msgTypes[0].Methods()
 }
 
@@ -110,9 +119,11 @@ func file_google_protobuf_source_context_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_source_context_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*SourceContext); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 45 - 12
types/known/structpb/struct.pb.go

@@ -69,6 +69,7 @@ func (NullValue) EnumDescriptor() ([]byte, []int) {
 //
 // The JSON representation for `Struct` is JSON object.
 type Struct struct {
+	state protoimpl.MessageState
 	// Unordered map of dynamically typed values.
 	Fields        map[string]*Value `protobuf:"bytes,1,rep,name=fields,proto3" json:"fields,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
 	sizeCache     protoimpl.SizeCache
@@ -86,10 +87,18 @@ func (x *Struct) String() string {
 func (*Struct) ProtoMessage() {}
 
 func (x *Struct) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_struct_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_struct_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Struct) XXX_Methods() *protoiface.Methods {
+func (x *Struct) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_struct_proto_msgTypes[0].Methods()
 }
 
@@ -112,6 +121,7 @@ func (x *Struct) GetFields() map[string]*Value {
 //
 // The JSON representation for `Value` is JSON value.
 type Value struct {
+	state protoimpl.MessageState
 	// The kind of value.
 	//
 	// Types that are valid to be assigned to Kind:
@@ -143,10 +153,18 @@ func (x *Value) String() string {
 func (*Value) ProtoMessage() {}
 
 func (x *Value) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_struct_proto_msgTypes[1].MessageOf(x)
+	mi := &file_google_protobuf_struct_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Value) XXX_Methods() *protoiface.Methods {
+func (x *Value) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_struct_proto_msgTypes[1].Methods()
 }
 
@@ -248,6 +266,7 @@ func (*Value_ListValue) isValue_Kind() {}
 //
 // The JSON representation for `ListValue` is JSON array.
 type ListValue struct {
+	state protoimpl.MessageState
 	// Repeated field of dynamically typed values.
 	Values        []*Value `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -265,10 +284,18 @@ func (x *ListValue) String() string {
 func (*ListValue) ProtoMessage() {}
 
 func (x *ListValue) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_struct_proto_msgTypes[2].MessageOf(x)
+	mi := &file_google_protobuf_struct_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *ListValue) XXX_Methods() *protoiface.Methods {
+func (x *ListValue) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_struct_proto_msgTypes[2].Methods()
 }
 
@@ -379,9 +406,11 @@ func file_google_protobuf_struct_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_struct_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Struct); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -389,9 +418,11 @@ func file_google_protobuf_struct_proto_init() {
 		}
 		file_google_protobuf_struct_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Value); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -399,9 +430,11 @@ func file_google_protobuf_struct_proto_init() {
 		}
 		file_google_protobuf_struct_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*ListValue); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 15 - 4
types/known/timestamppb/timestamp.pb.go

@@ -100,6 +100,7 @@ const (
 //
 //
 type Timestamp struct {
+	state protoimpl.MessageState
 	// Represents seconds of UTC time since Unix epoch
 	// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
 	// 9999-12-31T23:59:59Z inclusive.
@@ -124,10 +125,18 @@ func (x *Timestamp) String() string {
 func (*Timestamp) ProtoMessage() {}
 
 func (x *Timestamp) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_timestamp_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_timestamp_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Timestamp) XXX_Methods() *protoiface.Methods {
+func (x *Timestamp) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_timestamp_proto_msgTypes[0].Methods()
 }
 
@@ -203,9 +212,11 @@ func file_google_protobuf_timestamp_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_timestamp_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Timestamp); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 75 - 20
types/known/typepb/type.pb.go

@@ -227,6 +227,7 @@ func (Field_Cardinality) EnumDescriptor() ([]byte, []int) {
 
 // A protocol buffer message type.
 type Type struct {
+	state protoimpl.MessageState
 	// The fully qualified message name.
 	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
 	// The list of fields.
@@ -254,10 +255,18 @@ func (x *Type) String() string {
 func (*Type) ProtoMessage() {}
 
 func (x *Type) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_type_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_type_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Type) XXX_Methods() *protoiface.Methods {
+func (x *Type) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_type_proto_msgTypes[0].Methods()
 }
 
@@ -310,6 +319,7 @@ func (x *Type) GetSyntax() Syntax {
 
 // A single field of a message type.
 type Field struct {
+	state protoimpl.MessageState
 	// The field type.
 	Kind Field_Kind `protobuf:"varint,1,opt,name=kind,proto3,enum=google.protobuf.Field_Kind" json:"kind,omitempty"`
 	// The field cardinality.
@@ -347,10 +357,18 @@ func (x *Field) String() string {
 func (*Field) ProtoMessage() {}
 
 func (x *Field) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_type_proto_msgTypes[1].MessageOf(x)
+	mi := &file_google_protobuf_type_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Field) XXX_Methods() *protoiface.Methods {
+func (x *Field) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_type_proto_msgTypes[1].Methods()
 }
 
@@ -431,6 +449,7 @@ func (x *Field) GetDefaultValue() string {
 
 // Enum type definition.
 type Enum struct {
+	state protoimpl.MessageState
 	// Enum type name.
 	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
 	// Enum value definitions.
@@ -456,10 +475,18 @@ func (x *Enum) String() string {
 func (*Enum) ProtoMessage() {}
 
 func (x *Enum) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_type_proto_msgTypes[2].MessageOf(x)
+	mi := &file_google_protobuf_type_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Enum) XXX_Methods() *protoiface.Methods {
+func (x *Enum) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_type_proto_msgTypes[2].Methods()
 }
 
@@ -505,6 +532,7 @@ func (x *Enum) GetSyntax() Syntax {
 
 // Enum value definition.
 type EnumValue struct {
+	state protoimpl.MessageState
 	// Enum value name.
 	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
 	// Enum value number.
@@ -526,10 +554,18 @@ func (x *EnumValue) String() string {
 func (*EnumValue) ProtoMessage() {}
 
 func (x *EnumValue) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_type_proto_msgTypes[3].MessageOf(x)
+	mi := &file_google_protobuf_type_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *EnumValue) XXX_Methods() *protoiface.Methods {
+func (x *EnumValue) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_type_proto_msgTypes[3].Methods()
 }
 
@@ -562,6 +598,7 @@ func (x *EnumValue) GetOptions() []*Option {
 // A protocol buffer option, which can be attached to a message, field,
 // enumeration, etc.
 type Option struct {
+	state protoimpl.MessageState
 	// The option's name. For protobuf built-in options (options defined in
 	// descriptor.proto), this is the short name. For example, `"map_entry"`.
 	// For custom options, it should be the fully-qualified name. For example,
@@ -587,10 +624,18 @@ func (x *Option) String() string {
 func (*Option) ProtoMessage() {}
 
 func (x *Option) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_type_proto_msgTypes[4].MessageOf(x)
+	mi := &file_google_protobuf_type_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Option) XXX_Methods() *protoiface.Methods {
+func (x *Option) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_type_proto_msgTypes[4].Methods()
 }
 
@@ -788,9 +833,11 @@ func file_google_protobuf_type_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_type_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Type); i {
-			case 6:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 7:
+				return &v.sizeCache
+			case 8:
 				return &v.unknownFields
 			default:
 				return nil
@@ -798,9 +845,11 @@ func file_google_protobuf_type_proto_init() {
 		}
 		file_google_protobuf_type_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Field); i {
-			case 10:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 11:
+				return &v.sizeCache
+			case 12:
 				return &v.unknownFields
 			default:
 				return nil
@@ -808,9 +857,11 @@ func file_google_protobuf_type_proto_init() {
 		}
 		file_google_protobuf_type_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Enum); i {
-			case 5:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 6:
+				return &v.sizeCache
+			case 7:
 				return &v.unknownFields
 			default:
 				return nil
@@ -818,9 +869,11 @@ func file_google_protobuf_type_proto_init() {
 		}
 		file_google_protobuf_type_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*EnumValue); i {
-			case 3:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 4:
+				return &v.sizeCache
+			case 5:
 				return &v.unknownFields
 			default:
 				return nil
@@ -828,9 +881,11 @@ func file_google_protobuf_type_proto_init() {
 		}
 		file_google_protobuf_type_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Option); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil

+ 135 - 36
types/known/wrapperspb/wrappers.pb.go

@@ -21,6 +21,7 @@ const (
 //
 // The JSON representation for `DoubleValue` is JSON number.
 type DoubleValue struct {
+	state protoimpl.MessageState
 	// The double value.
 	Value         float64 `protobuf:"fixed64,1,opt,name=value,proto3" json:"value,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -38,10 +39,18 @@ func (x *DoubleValue) String() string {
 func (*DoubleValue) ProtoMessage() {}
 
 func (x *DoubleValue) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_wrappers_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_wrappers_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *DoubleValue) XXX_Methods() *protoiface.Methods {
+func (x *DoubleValue) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_wrappers_proto_msgTypes[0].Methods()
 }
 
@@ -61,6 +70,7 @@ func (x *DoubleValue) GetValue() float64 {
 //
 // The JSON representation for `FloatValue` is JSON number.
 type FloatValue struct {
+	state protoimpl.MessageState
 	// The float value.
 	Value         float32 `protobuf:"fixed32,1,opt,name=value,proto3" json:"value,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -78,10 +88,18 @@ func (x *FloatValue) String() string {
 func (*FloatValue) ProtoMessage() {}
 
 func (x *FloatValue) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_wrappers_proto_msgTypes[1].MessageOf(x)
+	mi := &file_google_protobuf_wrappers_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *FloatValue) XXX_Methods() *protoiface.Methods {
+func (x *FloatValue) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_wrappers_proto_msgTypes[1].Methods()
 }
 
@@ -101,6 +119,7 @@ func (x *FloatValue) GetValue() float32 {
 //
 // The JSON representation for `Int64Value` is JSON string.
 type Int64Value struct {
+	state protoimpl.MessageState
 	// The int64 value.
 	Value         int64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -118,10 +137,18 @@ func (x *Int64Value) String() string {
 func (*Int64Value) ProtoMessage() {}
 
 func (x *Int64Value) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_wrappers_proto_msgTypes[2].MessageOf(x)
+	mi := &file_google_protobuf_wrappers_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Int64Value) XXX_Methods() *protoiface.Methods {
+func (x *Int64Value) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_wrappers_proto_msgTypes[2].Methods()
 }
 
@@ -141,6 +168,7 @@ func (x *Int64Value) GetValue() int64 {
 //
 // The JSON representation for `UInt64Value` is JSON string.
 type UInt64Value struct {
+	state protoimpl.MessageState
 	// The uint64 value.
 	Value         uint64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -158,10 +186,18 @@ func (x *UInt64Value) String() string {
 func (*UInt64Value) ProtoMessage() {}
 
 func (x *UInt64Value) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_wrappers_proto_msgTypes[3].MessageOf(x)
+	mi := &file_google_protobuf_wrappers_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *UInt64Value) XXX_Methods() *protoiface.Methods {
+func (x *UInt64Value) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_wrappers_proto_msgTypes[3].Methods()
 }
 
@@ -181,6 +217,7 @@ func (x *UInt64Value) GetValue() uint64 {
 //
 // The JSON representation for `Int32Value` is JSON number.
 type Int32Value struct {
+	state protoimpl.MessageState
 	// The int32 value.
 	Value         int32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -198,10 +235,18 @@ func (x *Int32Value) String() string {
 func (*Int32Value) ProtoMessage() {}
 
 func (x *Int32Value) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_wrappers_proto_msgTypes[4].MessageOf(x)
+	mi := &file_google_protobuf_wrappers_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Int32Value) XXX_Methods() *protoiface.Methods {
+func (x *Int32Value) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_wrappers_proto_msgTypes[4].Methods()
 }
 
@@ -221,6 +266,7 @@ func (x *Int32Value) GetValue() int32 {
 //
 // The JSON representation for `UInt32Value` is JSON number.
 type UInt32Value struct {
+	state protoimpl.MessageState
 	// The uint32 value.
 	Value         uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -238,10 +284,18 @@ func (x *UInt32Value) String() string {
 func (*UInt32Value) ProtoMessage() {}
 
 func (x *UInt32Value) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_wrappers_proto_msgTypes[5].MessageOf(x)
+	mi := &file_google_protobuf_wrappers_proto_msgTypes[5]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *UInt32Value) XXX_Methods() *protoiface.Methods {
+func (x *UInt32Value) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_wrappers_proto_msgTypes[5].Methods()
 }
 
@@ -261,6 +315,7 @@ func (x *UInt32Value) GetValue() uint32 {
 //
 // The JSON representation for `BoolValue` is JSON `true` and `false`.
 type BoolValue struct {
+	state protoimpl.MessageState
 	// The bool value.
 	Value         bool `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -278,10 +333,18 @@ func (x *BoolValue) String() string {
 func (*BoolValue) ProtoMessage() {}
 
 func (x *BoolValue) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_wrappers_proto_msgTypes[6].MessageOf(x)
+	mi := &file_google_protobuf_wrappers_proto_msgTypes[6]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *BoolValue) XXX_Methods() *protoiface.Methods {
+func (x *BoolValue) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_wrappers_proto_msgTypes[6].Methods()
 }
 
@@ -301,6 +364,7 @@ func (x *BoolValue) GetValue() bool {
 //
 // The JSON representation for `StringValue` is JSON string.
 type StringValue struct {
+	state protoimpl.MessageState
 	// The string value.
 	Value         string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -318,10 +382,18 @@ func (x *StringValue) String() string {
 func (*StringValue) ProtoMessage() {}
 
 func (x *StringValue) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_wrappers_proto_msgTypes[7].MessageOf(x)
+	mi := &file_google_protobuf_wrappers_proto_msgTypes[7]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *StringValue) XXX_Methods() *protoiface.Methods {
+func (x *StringValue) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_wrappers_proto_msgTypes[7].Methods()
 }
 
@@ -341,6 +413,7 @@ func (x *StringValue) GetValue() string {
 //
 // The JSON representation for `BytesValue` is JSON string.
 type BytesValue struct {
+	state protoimpl.MessageState
 	// The bytes value.
 	Value         []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
 	sizeCache     protoimpl.SizeCache
@@ -358,10 +431,18 @@ func (x *BytesValue) String() string {
 func (*BytesValue) ProtoMessage() {}
 
 func (x *BytesValue) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_wrappers_proto_msgTypes[8].MessageOf(x)
+	mi := &file_google_protobuf_wrappers_proto_msgTypes[8]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *BytesValue) XXX_Methods() *protoiface.Methods {
+func (x *BytesValue) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_wrappers_proto_msgTypes[8].Methods()
 }
 
@@ -455,9 +536,11 @@ func file_google_protobuf_wrappers_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_wrappers_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*DoubleValue); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -465,9 +548,11 @@ func file_google_protobuf_wrappers_proto_init() {
 		}
 		file_google_protobuf_wrappers_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*FloatValue); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -475,9 +560,11 @@ func file_google_protobuf_wrappers_proto_init() {
 		}
 		file_google_protobuf_wrappers_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Int64Value); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -485,9 +572,11 @@ func file_google_protobuf_wrappers_proto_init() {
 		}
 		file_google_protobuf_wrappers_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*UInt64Value); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -495,9 +584,11 @@ func file_google_protobuf_wrappers_proto_init() {
 		}
 		file_google_protobuf_wrappers_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Int32Value); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -505,9 +596,11 @@ func file_google_protobuf_wrappers_proto_init() {
 		}
 		file_google_protobuf_wrappers_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*UInt32Value); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -515,9 +608,11 @@ func file_google_protobuf_wrappers_proto_init() {
 		}
 		file_google_protobuf_wrappers_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*BoolValue); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -525,9 +620,11 @@ func file_google_protobuf_wrappers_proto_init() {
 		}
 		file_google_protobuf_wrappers_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*StringValue); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil
@@ -535,9 +632,11 @@ func file_google_protobuf_wrappers_proto_init() {
 		}
 		file_google_protobuf_wrappers_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*BytesValue); i {
-			case 1:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 2:
+				return &v.sizeCache
+			case 3:
 				return &v.unknownFields
 			default:
 				return nil

+ 60 - 16
types/pluginpb/plugin.pb.go

@@ -20,6 +20,7 @@ const (
 
 // The version number of protocol compiler.
 type Version struct {
+	state protoimpl.MessageState
 	Major *int32 `protobuf:"varint,1,opt,name=major" json:"major,omitempty"`
 	Minor *int32 `protobuf:"varint,2,opt,name=minor" json:"minor,omitempty"`
 	Patch *int32 `protobuf:"varint,3,opt,name=patch" json:"patch,omitempty"`
@@ -41,10 +42,18 @@ func (x *Version) String() string {
 func (*Version) ProtoMessage() {}
 
 func (x *Version) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_compiler_plugin_proto_msgTypes[0].MessageOf(x)
+	mi := &file_google_protobuf_compiler_plugin_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *Version) XXX_Methods() *protoiface.Methods {
+func (x *Version) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_compiler_plugin_proto_msgTypes[0].Methods()
 }
 
@@ -83,6 +92,7 @@ func (x *Version) GetSuffix() string {
 
 // An encoded CodeGeneratorRequest is written to the plugin's stdin.
 type CodeGeneratorRequest struct {
+	state protoimpl.MessageState
 	// The .proto files that were explicitly listed on the command-line.  The
 	// code generator should generate code only for these files.  Each file's
 	// descriptor will be included in proto_file, below.
@@ -121,10 +131,18 @@ func (x *CodeGeneratorRequest) String() string {
 func (*CodeGeneratorRequest) ProtoMessage() {}
 
 func (x *CodeGeneratorRequest) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_compiler_plugin_proto_msgTypes[1].MessageOf(x)
+	mi := &file_google_protobuf_compiler_plugin_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *CodeGeneratorRequest) XXX_Methods() *protoiface.Methods {
+func (x *CodeGeneratorRequest) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_compiler_plugin_proto_msgTypes[1].Methods()
 }
 
@@ -163,6 +181,7 @@ func (x *CodeGeneratorRequest) GetCompilerVersion() *Version {
 
 // The plugin writes an encoded CodeGeneratorResponse to stdout.
 type CodeGeneratorResponse struct {
+	state protoimpl.MessageState
 	// Error message.  If non-empty, code generation failed.  The plugin process
 	// should exit with status code zero even if it reports an error in this way.
 	//
@@ -188,10 +207,18 @@ func (x *CodeGeneratorResponse) String() string {
 func (*CodeGeneratorResponse) ProtoMessage() {}
 
 func (x *CodeGeneratorResponse) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_compiler_plugin_proto_msgTypes[2].MessageOf(x)
+	mi := &file_google_protobuf_compiler_plugin_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *CodeGeneratorResponse) XXX_Methods() *protoiface.Methods {
+func (x *CodeGeneratorResponse) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_compiler_plugin_proto_msgTypes[2].Methods()
 }
 
@@ -216,6 +243,7 @@ func (x *CodeGeneratorResponse) GetFile() []*CodeGeneratorResponse_File {
 
 // Represents a single generated file.
 type CodeGeneratorResponse_File struct {
+	state protoimpl.MessageState
 	// The file name, relative to the output directory.  The name must not
 	// contain "." or ".." components and must be relative, not be absolute (so,
 	// the file cannot lie outside the output directory).  "/" must be used as
@@ -283,10 +311,18 @@ func (x *CodeGeneratorResponse_File) String() string {
 func (*CodeGeneratorResponse_File) ProtoMessage() {}
 
 func (x *CodeGeneratorResponse_File) ProtoReflect() protoreflect.Message {
-	return file_google_protobuf_compiler_plugin_proto_msgTypes[3].MessageOf(x)
+	mi := &file_google_protobuf_compiler_plugin_proto_msgTypes[3]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
 }
 
-func (m *CodeGeneratorResponse_File) XXX_Methods() *protoiface.Methods {
+func (x *CodeGeneratorResponse_File) XXX_Methods() *protoiface.Methods {
 	return file_google_protobuf_compiler_plugin_proto_msgTypes[3].Methods()
 }
 
@@ -407,9 +443,11 @@ func file_google_protobuf_compiler_plugin_proto_init() {
 	if !protoimpl.UnsafeEnabled {
 		file_google_protobuf_compiler_plugin_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Version); i {
-			case 4:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 5:
+				return &v.sizeCache
+			case 6:
 				return &v.unknownFields
 			default:
 				return nil
@@ -417,9 +455,11 @@ func file_google_protobuf_compiler_plugin_proto_init() {
 		}
 		file_google_protobuf_compiler_plugin_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*CodeGeneratorRequest); i {
-			case 4:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 5:
+				return &v.sizeCache
+			case 6:
 				return &v.unknownFields
 			default:
 				return nil
@@ -427,9 +467,11 @@ func file_google_protobuf_compiler_plugin_proto_init() {
 		}
 		file_google_protobuf_compiler_plugin_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*CodeGeneratorResponse); i {
-			case 2:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 3:
+				return &v.sizeCache
+			case 4:
 				return &v.unknownFields
 			default:
 				return nil
@@ -437,9 +479,11 @@ func file_google_protobuf_compiler_plugin_proto_init() {
 		}
 		file_google_protobuf_compiler_plugin_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*CodeGeneratorResponse_File); i {
-			case 3:
-				return &v.sizeCache
+			case 0:
+				return &v.state
 			case 4:
+				return &v.sizeCache
+			case 5:
 				return &v.unknownFields
 			default:
 				return nil

Неке датотеке нису приказане због велике количине промена