cmd/protoc-gen-go: use Merge instead of Marshal/Unmarshal

Change-Id: I689dee8417944bb0fbe19c75b7ca1accb49afb33
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/185144
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/cmd/protoc-gen-go/internal_gengo/reflect.go b/cmd/protoc-gen-go/internal_gengo/reflect.go
index 42e2a3a..862a464 100644
--- a/cmd/protoc-gen-go/internal_gengo/reflect.go
+++ b/cmd/protoc-gen-go/internal_gengo/reflect.go
@@ -183,21 +183,11 @@
 }
 
 func genFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo) {
-	// TODO: Replace this with v2 Clone.
 	descProto := new(descriptorpb.FileDescriptorProto)
-	b, err := proto.Marshal(f.Proto)
-	if err != nil {
-		gen.Error(err)
-		return
-	}
-	if err := proto.Unmarshal(b, descProto); err != nil {
-		gen.Error(err)
-		return
-	}
+	proto.Merge(descProto, f.Proto)
+	descProto.SourceCodeInfo = nil // drop source code information
 
-	// Trim the source_code_info from the descriptor.
-	descProto.SourceCodeInfo = nil
-	b, err = proto.MarshalOptions{Deterministic: true}.Marshal(descProto)
+	b, err := proto.MarshalOptions{AllowPartial: true, Deterministic: true}.Marshal(descProto)
 	if err != nil {
 		gen.Error(err)
 		return