cmd/protoc-gen-go: correlate v1 ExtensionDesc with v2 ExtensionType

Unfortunately a good amount of code uses pointer comparisons on the
v1 ExtensionDesc to determine exactly which extension field is set,
rather than checking whether the extension descriptor semantically
describes the field that they are interested in.

To preserve this behavior in v1, we need a 1:1 mapping between
a v2 ExtensionType and a specific v1 ExtensionDesc.

Change-Id: I852b3cefb4585bd656e48e5adad6cc28795d02df
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167759
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/testprotos/test/ext.pb.go b/internal/testprotos/test/ext.pb.go
index 0ceed42..a1fce7e 100644
--- a/internal/testprotos/test/ext.pb.go
+++ b/internal/testprotos/test/ext.pb.go
@@ -16,14 +16,20 @@
 // proto package needs to be updated.
 const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
 
-var E_ForeignInt32Extension = &proto.ExtensionDesc{
-	ExtendedType:  (*TestAllExtensions)(nil),
-	ExtensionType: (*int32)(nil),
-	Field:         2000,
-	Name:          "goproto.proto.test.foreign_int32_extension",
-	Tag:           "varint,2000,opt,name=foreign_int32_extension",
-	Filename:      "test/ext.proto",
+var xxx_File_test_ext_proto_extDescs = []proto.ExtensionDesc{
+	{
+		ExtendedType:  (*TestAllExtensions)(nil),
+		ExtensionType: (*int32)(nil),
+		Field:         2000,
+		Name:          "goproto.proto.test.foreign_int32_extension",
+		Tag:           "varint,2000,opt,name=foreign_int32_extension",
+		Filename:      "test/ext.proto",
+	},
 }
+var (
+	// extend goproto.proto.test.TestAllExtensions { optional int32 foreign_int32_extension = 2000; }
+	E_ForeignInt32Extension = &xxx_File_test_ext_proto_extDescs[0]
+)
 
 func init() {
 	proto.RegisterFile("test/ext.proto", xxx_File_test_ext_proto_rawdesc_gzipped)
@@ -71,9 +77,9 @@
 		RawDescriptor:        xxx_File_test_ext_proto_rawdesc,
 		GoTypes:              xxx_File_test_ext_proto_goTypes,
 		DependencyIndexes:    xxx_File_test_ext_proto_depIdxs,
+		LegacyExtensions:     xxx_File_test_ext_proto_extDescs,
 		ExtensionOutputTypes: extensionTypes,
 	}.Init()
-	E_ForeignInt32Extension.Type = extensionTypes[0]
 	xxx_File_test_ext_proto_goTypes = nil
 	xxx_File_test_ext_proto_depIdxs = nil
 }