cmd/protoc-gen-go: generate descriptor proto using v2 textpb

Changes:
* Modify protoc-gen-go to use a helper from internal/impl
to print the message as text.
* Add a helper function to internal/impl that calls v2 textpb.
* Modify encoding/textpb to avoid depending on descriptor proto,
which would cause an import cycle.
* Modify internal/fileinit to populate a pseudo-internal
method on MessageDescriptor to check whether the message should
use the message set wire format. We avoid adding this to the
main MessageDescriptor interface since message sets are a
deprecated proto1 feature that we should avoid promoting.

Change-Id: Ibaf79a563af695756f11ddc4db69b38e25a8f1a7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168439
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/encoding/textpb/encode.go b/encoding/textpb/encode.go
index 9f1da09..ebc33b7 100644
--- a/encoding/textpb/encode.go
+++ b/encoding/textpb/encode.go
@@ -15,8 +15,6 @@
 	"github.com/golang/protobuf/v2/proto"
 	pref "github.com/golang/protobuf/v2/reflect/protoreflect"
 	"github.com/golang/protobuf/v2/reflect/protoregistry"
-
-	descpb "github.com/golang/protobuf/v2/types/descriptor"
 )
 
 // Marshal writes the given proto.Message in textproto format using default options.
@@ -342,15 +340,8 @@
 	if xt.FullName().Parent() != mt.FullName() {
 		return false
 	}
-	xmt := xt.ExtendedType()
-	if xmt.Fields().Len() != 0 {
-		return false
-	}
-	opt := xmt.Options().(*descpb.MessageOptions)
-	if opt == nil {
-		return false
-	}
-	return opt.GetMessageSetWireFormat()
+	xmt, ok := xt.ExtendedType().(interface{ IsMessageSet() bool })
+	return ok && xmt.IsMessageSet()
 }
 
 // appendUnknown parses the given []byte and appends field(s) into the given fields slice.