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/encoding/textpb/encode_test.go b/encoding/textpb/encode_test.go
index f119ce9..3430fc5 100644
--- a/encoding/textpb/encode_test.go
+++ b/encoding/textpb/encode_test.go
@@ -17,7 +17,6 @@
 	"github.com/golang/protobuf/v2/internal/encoding/pack"
 	"github.com/golang/protobuf/v2/internal/encoding/wire"
 	"github.com/golang/protobuf/v2/internal/impl"
-	"github.com/golang/protobuf/v2/internal/legacy"
 	"github.com/golang/protobuf/v2/internal/scalar"
 	"github.com/golang/protobuf/v2/proto"
 	preg "github.com/golang/protobuf/v2/reflect/protoregistry"
@@ -52,14 +51,13 @@
 }
 
 func setExtension(m proto.Message, xd *protoapi.ExtensionDesc, val interface{}) {
-	xt := legacy.Export{}.ExtensionTypeFromDesc(xd)
 	knownFields := m.ProtoReflect().KnownFields()
 	extTypes := knownFields.ExtensionTypes()
-	extTypes.Register(xt)
+	extTypes.Register(xd.Type)
 	if val == nil {
 		return
 	}
-	pval := xt.ValueOf(val)
+	pval := xd.Type.ValueOf(val)
 	knownFields.Set(wire.Number(xd.Field), pval)
 }