proto: use UnmarshalState

The UnmarshalState method provides information about whether the
message was initialized or not. Checking that bit saves performance
needing to verify again.

Generated files change because of newer versions of dependencies.

Change-Id: I1c1e99b7e28da5959d083ea8652b5fdc8e6c3124
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/220500
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/go.mod b/go.mod
index 269f7ab..4872926 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,6 @@
 go 1.9
 
 require (
-	github.com/google/go-cmp v0.3.1
-	google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd
+	github.com/google/go-cmp v0.4.0
+	google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64
 )
diff --git a/go.sum b/go.sum
index 6cbf9e7..e5a2e4e 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,10 @@
+github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
 github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
-github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
 github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
-google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd h1:zSMqFwpTkfj+1nNFgmgu4B+Qv5Kpf4jpd11lCmHKuwQ=
+github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
+github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64 h1:BhpvsYSxWvxATQJYrD9UKX1U3jo+Bxq195IzJGtyh40=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
diff --git a/proto/wire.go b/proto/wire.go
index 53196ab..5e8b7ac 100644
--- a/proto/wire.go
+++ b/proto/wire.go
@@ -6,6 +6,7 @@
 
 import (
 	protoV2 "google.golang.org/protobuf/proto"
+	"google.golang.org/protobuf/runtime/protoiface"
 	"google.golang.org/protobuf/runtime/protoimpl"
 )
 
@@ -61,12 +62,17 @@
 // UnmarshalMerge parses a wire-format message in b and places the decoded results in m.
 func UnmarshalMerge(b []byte, m Message) error {
 	mi := protoimpl.X.ProtoMessageV2Of(m)
-	err := protoV2.UnmarshalOptions{
+	out, err := protoV2.UnmarshalOptions{
 		AllowPartial: true,
 		Merge:        true,
-	}.Unmarshal(b, mi)
+	}.UnmarshalState(mi, protoiface.UnmarshalInput{
+		Buf: b,
+	})
 	if err != nil {
 		return err
 	}
+	if out.Flags&protoiface.UnmarshalInitialized > 0 {
+		return nil
+	}
 	return checkRequiredNotSet(mi)
 }
diff --git a/protoc-gen-go/descriptor/descriptor.pb.go b/protoc-gen-go/descriptor/descriptor.pb.go
index a6d156a..63dc057 100644
--- a/protoc-gen-go/descriptor/descriptor.pb.go
+++ b/protoc-gen-go/descriptor/descriptor.pb.go
@@ -8,7 +8,6 @@
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	descriptorpb "google.golang.org/protobuf/types/descriptorpb"
 	reflect "reflect"
-	sync "sync"
 )
 
 // Symbols defined in public import of google/protobuf/descriptor.proto.
@@ -167,18 +166,6 @@
 	0x6f, 0x74, 0x6f, 0x32,
 }
 
-var (
-	file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDescOnce sync.Once
-	file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDescData = file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDesc
-)
-
-func file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDescGZIP() []byte {
-	file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDescOnce.Do(func() {
-		file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDescData)
-	})
-	return file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDescData
-}
-
 var file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_goTypes = []interface{}{}
 var file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_depIdxs = []int32{
 	0, // [0:0] is the sub-list for method output_type
diff --git a/protoc-gen-go/plugin/plugin.pb.go b/protoc-gen-go/plugin/plugin.pb.go
index df86663..2704536 100644
--- a/protoc-gen-go/plugin/plugin.pb.go
+++ b/protoc-gen-go/plugin/plugin.pb.go
@@ -8,7 +8,6 @@
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	pluginpb "google.golang.org/protobuf/types/pluginpb"
 	reflect "reflect"
-	sync "sync"
 )
 
 // Symbols defined in public import of google/protobuf/compiler/plugin.proto.
@@ -34,18 +33,6 @@
 	0x67, 0x6f, 0x50, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32,
 }
 
-var (
-	file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_rawDescOnce sync.Once
-	file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_rawDescData = file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_rawDesc
-)
-
-func file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_rawDescGZIP() []byte {
-	file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_rawDescOnce.Do(func() {
-		file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_rawDescData)
-	})
-	return file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_rawDescData
-}
-
 var file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_goTypes = []interface{}{}
 var file_github_com_golang_protobuf_protoc_gen_go_plugin_plugin_proto_depIdxs = []int32{
 	0, // [0:0] is the sub-list for method output_type
diff --git a/ptypes/any/any.pb.go b/ptypes/any/any.pb.go
index a12e7d5..0ef27d3 100644
--- a/ptypes/any/any.pb.go
+++ b/ptypes/any/any.pb.go
@@ -8,7 +8,6 @@
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	anypb "google.golang.org/protobuf/types/known/anypb"
 	reflect "reflect"
-	sync "sync"
 )
 
 // Symbols defined in public import of google/protobuf/any.proto.
@@ -29,18 +28,6 @@
 	0x74, 0x6f, 0x33,
 }
 
-var (
-	file_github_com_golang_protobuf_ptypes_any_any_proto_rawDescOnce sync.Once
-	file_github_com_golang_protobuf_ptypes_any_any_proto_rawDescData = file_github_com_golang_protobuf_ptypes_any_any_proto_rawDesc
-)
-
-func file_github_com_golang_protobuf_ptypes_any_any_proto_rawDescGZIP() []byte {
-	file_github_com_golang_protobuf_ptypes_any_any_proto_rawDescOnce.Do(func() {
-		file_github_com_golang_protobuf_ptypes_any_any_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_golang_protobuf_ptypes_any_any_proto_rawDescData)
-	})
-	return file_github_com_golang_protobuf_ptypes_any_any_proto_rawDescData
-}
-
 var file_github_com_golang_protobuf_ptypes_any_any_proto_goTypes = []interface{}{}
 var file_github_com_golang_protobuf_ptypes_any_any_proto_depIdxs = []int32{
 	0, // [0:0] is the sub-list for method output_type
diff --git a/ptypes/duration/duration.pb.go b/ptypes/duration/duration.pb.go
index 6bb3b2a..d0079ee 100644
--- a/ptypes/duration/duration.pb.go
+++ b/ptypes/duration/duration.pb.go
@@ -8,7 +8,6 @@
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	durationpb "google.golang.org/protobuf/types/known/durationpb"
 	reflect "reflect"
-	sync "sync"
 )
 
 // Symbols defined in public import of google/protobuf/duration.proto.
@@ -30,18 +29,6 @@
 	0x6f, 0x6e, 0x50, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
-var (
-	file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDescOnce sync.Once
-	file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDescData = file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDesc
-)
-
-func file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDescGZIP() []byte {
-	file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDescOnce.Do(func() {
-		file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDescData)
-	})
-	return file_github_com_golang_protobuf_ptypes_duration_duration_proto_rawDescData
-}
-
 var file_github_com_golang_protobuf_ptypes_duration_duration_proto_goTypes = []interface{}{}
 var file_github_com_golang_protobuf_ptypes_duration_duration_proto_depIdxs = []int32{
 	0, // [0:0] is the sub-list for method output_type
diff --git a/ptypes/empty/empty.pb.go b/ptypes/empty/empty.pb.go
index 5cab9ad..16686a6 100644
--- a/ptypes/empty/empty.pb.go
+++ b/ptypes/empty/empty.pb.go
@@ -8,7 +8,6 @@
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	emptypb "google.golang.org/protobuf/types/known/emptypb"
 	reflect "reflect"
-	sync "sync"
 )
 
 // Symbols defined in public import of google/protobuf/empty.proto.
@@ -29,18 +28,6 @@
 	0x70, 0x74, 0x79, 0x50, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
-var (
-	file_github_com_golang_protobuf_ptypes_empty_empty_proto_rawDescOnce sync.Once
-	file_github_com_golang_protobuf_ptypes_empty_empty_proto_rawDescData = file_github_com_golang_protobuf_ptypes_empty_empty_proto_rawDesc
-)
-
-func file_github_com_golang_protobuf_ptypes_empty_empty_proto_rawDescGZIP() []byte {
-	file_github_com_golang_protobuf_ptypes_empty_empty_proto_rawDescOnce.Do(func() {
-		file_github_com_golang_protobuf_ptypes_empty_empty_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_golang_protobuf_ptypes_empty_empty_proto_rawDescData)
-	})
-	return file_github_com_golang_protobuf_ptypes_empty_empty_proto_rawDescData
-}
-
 var file_github_com_golang_protobuf_ptypes_empty_empty_proto_goTypes = []interface{}{}
 var file_github_com_golang_protobuf_ptypes_empty_empty_proto_depIdxs = []int32{
 	0, // [0:0] is the sub-list for method output_type
diff --git a/ptypes/struct/struct.pb.go b/ptypes/struct/struct.pb.go
index 66298b5..8d82abe 100644
--- a/ptypes/struct/struct.pb.go
+++ b/ptypes/struct/struct.pb.go
@@ -8,7 +8,6 @@
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	structpb "google.golang.org/protobuf/types/known/structpb"
 	reflect "reflect"
-	sync "sync"
 )
 
 // Symbols defined in public import of google/protobuf/struct.proto.
@@ -45,18 +44,6 @@
 	0x6f, 0x74, 0x6f, 0x33,
 }
 
-var (
-	file_github_com_golang_protobuf_ptypes_struct_struct_proto_rawDescOnce sync.Once
-	file_github_com_golang_protobuf_ptypes_struct_struct_proto_rawDescData = file_github_com_golang_protobuf_ptypes_struct_struct_proto_rawDesc
-)
-
-func file_github_com_golang_protobuf_ptypes_struct_struct_proto_rawDescGZIP() []byte {
-	file_github_com_golang_protobuf_ptypes_struct_struct_proto_rawDescOnce.Do(func() {
-		file_github_com_golang_protobuf_ptypes_struct_struct_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_golang_protobuf_ptypes_struct_struct_proto_rawDescData)
-	})
-	return file_github_com_golang_protobuf_ptypes_struct_struct_proto_rawDescData
-}
-
 var file_github_com_golang_protobuf_ptypes_struct_struct_proto_goTypes = []interface{}{}
 var file_github_com_golang_protobuf_ptypes_struct_struct_proto_depIdxs = []int32{
 	0, // [0:0] is the sub-list for method output_type
diff --git a/ptypes/timestamp/timestamp.pb.go b/ptypes/timestamp/timestamp.pb.go
index 5c10e7e..a76f807 100644
--- a/ptypes/timestamp/timestamp.pb.go
+++ b/ptypes/timestamp/timestamp.pb.go
@@ -8,7 +8,6 @@
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	timestamppb "google.golang.org/protobuf/types/known/timestamppb"
 	reflect "reflect"
-	sync "sync"
 )
 
 // Symbols defined in public import of google/protobuf/timestamp.proto.
@@ -31,18 +30,6 @@
 	0x33,
 }
 
-var (
-	file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDescOnce sync.Once
-	file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDescData = file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDesc
-)
-
-func file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDescGZIP() []byte {
-	file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDescOnce.Do(func() {
-		file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDescData)
-	})
-	return file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_rawDescData
-}
-
 var file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_goTypes = []interface{}{}
 var file_github_com_golang_protobuf_ptypes_timestamp_timestamp_proto_depIdxs = []int32{
 	0, // [0:0] is the sub-list for method output_type
diff --git a/ptypes/wrappers/wrappers.pb.go b/ptypes/wrappers/wrappers.pb.go
index c0cbd2f..cc40f27 100644
--- a/ptypes/wrappers/wrappers.pb.go
+++ b/ptypes/wrappers/wrappers.pb.go
@@ -8,7 +8,6 @@
 	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
 	wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
 	reflect "reflect"
-	sync "sync"
 )
 
 // Symbols defined in public import of google/protobuf/wrappers.proto.
@@ -38,18 +37,6 @@
 	0x72, 0x73, 0x50, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
-var (
-	file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_rawDescOnce sync.Once
-	file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_rawDescData = file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_rawDesc
-)
-
-func file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_rawDescGZIP() []byte {
-	file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_rawDescOnce.Do(func() {
-		file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_rawDescData)
-	})
-	return file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_rawDescData
-}
-
 var file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_goTypes = []interface{}{}
 var file_github_com_golang_protobuf_ptypes_wrappers_wrappers_proto_depIdxs = []int32{
 	0, // [0:0] is the sub-list for method output_type