[Vendor] blevesearch v0.8.1 -> v1.0.7 (#11360)

* Update blevesearch v0.8.1 -> v1.0.7

* make vendor

Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
6543 2020-05-10 07:40:54 +02:00 committed by GitHub
parent a44854c287
commit fdf750e4d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
255 changed files with 9786 additions and 974 deletions

View file

@ -5078,6 +5078,46 @@ var coderStringPtr = pointerCoderFuncs{
merge: mergeStringPtr,
}
// appendStringPtrValidateUTF8 wire encodes a *string pointer as a String.
// It panics if the pointer is nil.
func appendStringPtrValidateUTF8(b []byte, p pointer, f *coderFieldInfo, _ marshalOptions) ([]byte, error) {
v := **p.StringPtr()
b = protowire.AppendVarint(b, f.wiretag)
b = protowire.AppendString(b, v)
if !utf8.ValidString(v) {
return b, errInvalidUTF8{}
}
return b, nil
}
// consumeStringPtrValidateUTF8 wire decodes a *string pointer as a String.
func consumeStringPtrValidateUTF8(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, _ unmarshalOptions) (out unmarshalOutput, err error) {
if wtyp != protowire.BytesType {
return out, errUnknown
}
v, n := protowire.ConsumeString(b)
if n < 0 {
return out, protowire.ParseError(n)
}
if !utf8.ValidString(v) {
return out, errInvalidUTF8{}
}
vp := p.StringPtr()
if *vp == nil {
*vp = new(string)
}
**vp = v
out.n = n
return out, nil
}
var coderStringPtrValidateUTF8 = pointerCoderFuncs{
size: sizeStringPtr,
marshal: appendStringPtrValidateUTF8,
unmarshal: consumeStringPtrValidateUTF8,
merge: mergeStringPtr,
}
// sizeStringSlice returns the size of wire encoding a []string pointer as a repeated String.
func sizeStringSlice(p pointer, f *coderFieldInfo, _ marshalOptions) (size int) {
s := *p.StringSlice()

View file

@ -31,6 +31,11 @@ type coderMessageInfo struct {
needsInitCheck bool
isMessageSet bool
numRequiredFields uint8
// Include space for a number of coderFieldInfos to improve cache locality.
// The number of entries is chosen through a combination of guesswork and
// empirical testing.
coderFieldBuf [32]coderFieldInfo
}
type coderFieldInfo struct {
@ -53,11 +58,13 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
mi.coderFields = make(map[protowire.Number]*coderFieldInfo)
fields := mi.Desc.Fields()
preallocFields := mi.coderFieldBuf[:]
for i := 0; i < fields.Len(); i++ {
fd := fields.Get(i)
fs := si.fieldsByNumber[fd.Number()]
if fd.ContainingOneof() != nil {
isOneof := fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic()
if isOneof {
fs = si.oneofsByName[fd.ContainingOneof().Name()]
}
ft := fs.Type
@ -71,7 +78,7 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
var funcs pointerCoderFuncs
var childMessage *MessageInfo
switch {
case fd.ContainingOneof() != nil:
case isOneof:
fieldOffset = offsetOf(fs, mi.Exporter)
case fd.IsWeak():
fieldOffset = si.weakOffset
@ -80,7 +87,14 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
fieldOffset = offsetOf(fs, mi.Exporter)
childMessage, funcs = fieldCoder(fd, ft)
}
cf := &coderFieldInfo{
var cf *coderFieldInfo
if len(preallocFields) > 0 {
cf = &preallocFields[0]
preallocFields = preallocFields[1:]
} else {
cf = new(coderFieldInfo)
}
*cf = coderFieldInfo{
num: fd.Number(),
offset: fieldOffset,
wiretag: wiretag,
@ -89,17 +103,16 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
funcs: funcs,
mi: childMessage,
validation: newFieldValidationInfo(mi, si, fd, ft),
isPointer: (fd.Cardinality() == pref.Repeated ||
fd.Kind() == pref.MessageKind ||
fd.Kind() == pref.GroupKind ||
fd.Syntax() != pref.Proto3),
isPointer: fd.Cardinality() == pref.Repeated || fd.HasPresence(),
isRequired: fd.Cardinality() == pref.Required,
}
mi.orderedCoderFields = append(mi.orderedCoderFields, cf)
mi.coderFields[cf.num] = cf
}
for i, oneofs := 0, mi.Desc.Oneofs(); i < oneofs.Len(); i++ {
mi.initOneofFieldCoders(oneofs.Get(i), si)
if od := oneofs.Get(i); !od.IsSynthetic() {
mi.initOneofFieldCoders(od, si)
}
}
if messageset.IsMessageSet(mi.Desc) {
if !mi.extensionOffset.IsValid() {
@ -123,7 +136,7 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
}
mi.denseCoderFields = make([]*coderFieldInfo, maxDense+1)
for _, cf := range mi.orderedCoderFields {
if int(cf.num) > len(mi.denseCoderFields) {
if int(cf.num) >= len(mi.denseCoderFields) {
break
}
mi.denseCoderFields[cf.num] = cf

View file

@ -338,6 +338,9 @@ func fieldCoder(fd pref.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointer
return nil, coderDoublePtr
}
case pref.StringKind:
if ft.Kind() == reflect.String && strs.EnforceUTF8(fd) {
return nil, coderStringPtrValidateUTF8
}
if ft.Kind() == reflect.String {
return nil, coderStringPtr
}

View file

@ -162,7 +162,7 @@ func (c *boolConverter) IsValidPB(v pref.Value) bool {
return ok
}
func (c *boolConverter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *boolConverter) New() pref.Value { return c.def }
func (c *boolConverter) Zero() pref.Value { return c.def }
@ -186,7 +186,7 @@ func (c *int32Converter) IsValidPB(v pref.Value) bool {
return ok
}
func (c *int32Converter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *int32Converter) New() pref.Value { return c.def }
func (c *int32Converter) Zero() pref.Value { return c.def }
@ -210,7 +210,7 @@ func (c *int64Converter) IsValidPB(v pref.Value) bool {
return ok
}
func (c *int64Converter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *int64Converter) New() pref.Value { return c.def }
func (c *int64Converter) Zero() pref.Value { return c.def }
@ -234,7 +234,7 @@ func (c *uint32Converter) IsValidPB(v pref.Value) bool {
return ok
}
func (c *uint32Converter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *uint32Converter) New() pref.Value { return c.def }
func (c *uint32Converter) Zero() pref.Value { return c.def }
@ -258,7 +258,7 @@ func (c *uint64Converter) IsValidPB(v pref.Value) bool {
return ok
}
func (c *uint64Converter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *uint64Converter) New() pref.Value { return c.def }
func (c *uint64Converter) Zero() pref.Value { return c.def }
@ -282,7 +282,7 @@ func (c *float32Converter) IsValidPB(v pref.Value) bool {
return ok
}
func (c *float32Converter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *float32Converter) New() pref.Value { return c.def }
func (c *float32Converter) Zero() pref.Value { return c.def }
@ -306,7 +306,7 @@ func (c *float64Converter) IsValidPB(v pref.Value) bool {
return ok
}
func (c *float64Converter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *float64Converter) New() pref.Value { return c.def }
func (c *float64Converter) Zero() pref.Value { return c.def }
@ -336,7 +336,7 @@ func (c *stringConverter) IsValidPB(v pref.Value) bool {
return ok
}
func (c *stringConverter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *stringConverter) New() pref.Value { return c.def }
func (c *stringConverter) Zero() pref.Value { return c.def }
@ -363,7 +363,7 @@ func (c *bytesConverter) IsValidPB(v pref.Value) bool {
return ok
}
func (c *bytesConverter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *bytesConverter) New() pref.Value { return c.def }
func (c *bytesConverter) Zero() pref.Value { return c.def }
@ -400,7 +400,7 @@ func (c *enumConverter) IsValidPB(v pref.Value) bool {
}
func (c *enumConverter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *enumConverter) New() pref.Value {
@ -455,7 +455,7 @@ func (c *messageConverter) IsValidPB(v pref.Value) bool {
}
func (c *messageConverter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *messageConverter) New() pref.Value {

View file

@ -22,7 +22,7 @@ func newListConverter(t reflect.Type, fd pref.FieldDescriptor) Converter {
}
type listConverter struct {
goType reflect.Type
goType reflect.Type // []T
c Converter
}
@ -48,11 +48,11 @@ func (c *listConverter) IsValidPB(v pref.Value) bool {
if !ok {
return false
}
return list.v.Type().Elem() == c.goType && list.IsValid()
return list.v.Type().Elem() == c.goType
}
func (c *listConverter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *listConverter) New() pref.Value {
@ -64,7 +64,7 @@ func (c *listConverter) Zero() pref.Value {
}
type listPtrConverter struct {
goType reflect.Type
goType reflect.Type // *[]T
c Converter
}
@ -88,7 +88,7 @@ func (c *listPtrConverter) IsValidPB(v pref.Value) bool {
}
func (c *listPtrConverter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *listPtrConverter) New() pref.Value {

View file

@ -12,7 +12,7 @@ import (
)
type mapConverter struct {
goType reflect.Type
goType reflect.Type // map[K]V
keyConv, valConv Converter
}
@ -43,11 +43,11 @@ func (c *mapConverter) IsValidPB(v pref.Value) bool {
if !ok {
return false
}
return mapv.v.Type() == c.goType && mapv.IsValid()
return mapv.v.Type() == c.goType
}
func (c *mapConverter) IsValidGo(v reflect.Value) bool {
return v.Type() == c.goType
return v.IsValid() && v.Type() == c.goType
}
func (c *mapConverter) New() pref.Value {

View file

@ -7,14 +7,12 @@ package impl
import (
"encoding/binary"
"encoding/json"
"fmt"
"hash/crc32"
"math"
"reflect"
"google.golang.org/protobuf/internal/errors"
pref "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
piface "google.golang.org/protobuf/runtime/protoiface"
)
@ -92,13 +90,3 @@ func (Export) CompressGZIP(in []byte) (out []byte) {
out = append(out, gzipFooter[:]...)
return out
}
// WeakNil returns a typed nil pointer to a concrete message.
// It panics if the message is not linked into the binary.
func (Export) WeakNil(s pref.FullName) piface.MessageV1 {
mt, err := protoregistry.GlobalTypes.FindMessageByName(s)
if err != nil {
panic(fmt.Sprintf("weak message %v is not linked in", s))
}
return mt.Zero().Interface().(piface.MessageV1)
}

View file

@ -155,6 +155,8 @@ func (x placeholderExtension) Cardinality() pref.Cardinality { retu
func (x placeholderExtension) Kind() pref.Kind { return 0 }
func (x placeholderExtension) HasJSONName() bool { return false }
func (x placeholderExtension) JSONName() string { return "" }
func (x placeholderExtension) HasPresence() bool { return false }
func (x placeholderExtension) HasOptionalKeyword() bool { return false }
func (x placeholderExtension) IsExtension() bool { return true }
func (x placeholderExtension) IsWeak() bool { return false }
func (x placeholderExtension) IsPacked() bool { return false }

View file

@ -15,7 +15,6 @@ import (
"google.golang.org/protobuf/internal/genname"
"google.golang.org/protobuf/reflect/protoreflect"
pref "google.golang.org/protobuf/reflect/protoreflect"
piface "google.golang.org/protobuf/runtime/protoiface"
)
// MessageInfo provides protobuf related functionality for a given Go type
@ -109,7 +108,7 @@ func (mi *MessageInfo) getPointer(m pref.Message) (p pointer, ok bool) {
type (
SizeCache = int32
WeakFields = map[int32]piface.MessageV1
WeakFields = map[int32]protoreflect.ProtoMessage
UnknownFields = []byte
ExtensionFields = map[int32]ExtensionField
)

View file

@ -53,7 +53,7 @@ func (mi *MessageInfo) makeKnownFieldsFunc(si structInfo) {
fs := si.fieldsByNumber[fd.Number()]
var fi fieldInfo
switch {
case fd.ContainingOneof() != nil:
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
fi = fieldInfoForOneof(fd, si.oneofsByName[fd.ContainingOneof().Name()], mi.Exporter, si.oneofWrappersByNumber[fd.Number()])
case fd.IsMap():
fi = fieldInfoForMap(fd, fs, mi.Exporter)
@ -72,7 +72,7 @@ func (mi *MessageInfo) makeKnownFieldsFunc(si structInfo) {
mi.oneofs = map[pref.Name]*oneofInfo{}
for i := 0; i < md.Oneofs().Len(); i++ {
od := md.Oneofs().Get(i)
mi.oneofs[od.Name()] = makeOneofInfo(od, si.oneofsByName[od.Name()], mi.Exporter, si.oneofWrappersByType)
mi.oneofs[od.Name()] = makeOneofInfo(od, si, mi.Exporter)
}
mi.denseFields = make([]*fieldInfo, fds.Len()*2)
@ -84,7 +84,7 @@ func (mi *MessageInfo) makeKnownFieldsFunc(si structInfo) {
for i := 0; i < fds.Len(); {
fd := fds.Get(i)
if od := fd.ContainingOneof(); od != nil {
if od := fd.ContainingOneof(); od != nil && !od.IsSynthetic() {
mi.rangeInfos = append(mi.rangeInfos, mi.oneofs[od.Name()])
i += od.Fields().Len()
} else {
@ -170,6 +170,8 @@ func (m *extensionMap) Has(xt pref.ExtensionType) (ok bool) {
return x.Value().List().Len() > 0
case xd.IsMap():
return x.Value().Map().Len() > 0
case xd.Message() != nil:
return x.Value().Message().IsValid()
}
return true
}
@ -186,15 +188,28 @@ func (m *extensionMap) Get(xt pref.ExtensionType) pref.Value {
return xt.Zero()
}
func (m *extensionMap) Set(xt pref.ExtensionType, v pref.Value) {
if !xt.IsValidValue(v) {
xd := xt.TypeDescriptor()
isValid := true
switch {
case !xt.IsValidValue(v):
isValid = false
case xd.IsList():
isValid = v.List().IsValid()
case xd.IsMap():
isValid = v.Map().IsValid()
case xd.Message() != nil:
isValid = v.Message().IsValid()
}
if !isValid {
panic(fmt.Sprintf("%v: assigning invalid value", xt.TypeDescriptor().FullName()))
}
if *m == nil {
*m = make(map[int32]ExtensionField)
}
var x ExtensionField
x.Set(xt, v)
(*m)[int32(xt.TypeDescriptor().Number())] = x
(*m)[int32(xd.Number())] = x
}
func (m *extensionMap) Mutable(xt pref.ExtensionType) pref.Value {
xd := xt.TypeDescriptor()

View file

@ -221,7 +221,7 @@ var (
func fieldInfoForScalar(fd pref.FieldDescriptor, fs reflect.StructField, x exporter) fieldInfo {
ft := fs.Type
nullable := fd.Syntax() == pref.Proto2
nullable := fd.HasPresence()
isBytes := ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8
if nullable {
if ft.Kind() != reflect.Ptr && ft.Kind() != reflect.Slice {
@ -290,9 +290,9 @@ func fieldInfoForScalar(fd pref.FieldDescriptor, fs reflect.StructField, x expor
rv.Set(conv.GoValueOf(v))
if isBytes && rv.Len() == 0 {
if nullable {
rv.Set(emptyBytes) // preserve presence in proto2
rv.Set(emptyBytes) // preserve presence
} else {
rv.Set(nilBytes) // do not preserve presence in proto3
rv.Set(nilBytes) // do not preserve presence
}
}
},
@ -426,11 +426,25 @@ type oneofInfo struct {
which func(pointer) pref.FieldNumber
}
func makeOneofInfo(od pref.OneofDescriptor, fs reflect.StructField, x exporter, wrappersByType map[reflect.Type]pref.FieldNumber) *oneofInfo {
fieldOffset := offsetOf(fs, x)
return &oneofInfo{
oneofDesc: od,
which: func(p pointer) pref.FieldNumber {
func makeOneofInfo(od pref.OneofDescriptor, si structInfo, x exporter) *oneofInfo {
oi := &oneofInfo{oneofDesc: od}
if od.IsSynthetic() {
fs := si.fieldsByNumber[od.Fields().Get(0).Number()]
fieldOffset := offsetOf(fs, x)
oi.which = func(p pointer) pref.FieldNumber {
if p.IsNil() {
return 0
}
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
if rv.IsNil() { // valid on either *T or []byte
return 0
}
return od.Fields().Get(0).Number()
}
} else {
fs := si.oneofsByName[od.Name()]
fieldOffset := offsetOf(fs, x)
oi.which = func(p pointer) pref.FieldNumber {
if p.IsNil() {
return 0
}
@ -442,7 +456,8 @@ func makeOneofInfo(od pref.OneofDescriptor, fs reflect.StructField, x exporter,
if rv.IsNil() {
return 0
}
return wrappersByType[rv.Type().Elem()]
},
return si.oneofWrappersByType[rv.Type().Elem()]
}
}
return oi
}

View file

@ -108,7 +108,7 @@ const (
func newFieldValidationInfo(mi *MessageInfo, si structInfo, fd pref.FieldDescriptor, ft reflect.Type) validationInfo {
var vi validationInfo
switch {
case fd.ContainingOneof() != nil:
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
switch fd.Kind() {
case pref.MessageKind:
vi.typ = validationTypeMessage

View file

@ -5,9 +5,10 @@
package impl
import (
"reflect"
"fmt"
pref "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
)
// weakFields adds methods to the exported WeakFields type for internal use.
@ -16,31 +17,58 @@ import (
// defined directly on it.
type weakFields WeakFields
func (w *weakFields) get(num pref.FieldNumber) (_ pref.ProtoMessage, ok bool) {
if *w == nil {
return nil, false
}
m, ok := (*w)[int32(num)]
if !ok {
return nil, false
}
// As a legacy quirk, consider a typed nil to be unset.
//
// TODO: Consider fixing the generated set methods to clear the field
// when provided with a typed nil.
if v := reflect.ValueOf(m); v.Kind() == reflect.Ptr && v.IsNil() {
return nil, false
}
return Export{}.ProtoMessageV2Of(m), true
func (w weakFields) get(num pref.FieldNumber) (pref.ProtoMessage, bool) {
m, ok := w[int32(num)]
return m, ok
}
func (w *weakFields) set(num pref.FieldNumber, m pref.ProtoMessage) {
if *w == nil {
*w = make(weakFields)
}
(*w)[int32(num)] = Export{}.ProtoMessageV1Of(m)
(*w)[int32(num)] = m
}
func (w *weakFields) clear(num pref.FieldNumber) {
delete(*w, int32(num))
}
func (Export) HasWeak(w WeakFields, num pref.FieldNumber) bool {
_, ok := w[int32(num)]
return ok
}
func (Export) ClearWeak(w *WeakFields, num pref.FieldNumber) {
delete(*w, int32(num))
}
func (Export) GetWeak(w WeakFields, num pref.FieldNumber, name pref.FullName) pref.ProtoMessage {
if m, ok := w[int32(num)]; ok {
return m
}
mt, _ := protoregistry.GlobalTypes.FindMessageByName(name)
if mt == nil {
panic(fmt.Sprintf("message %v for weak field is not linked in", name))
}
return mt.Zero().Interface()
}
func (Export) SetWeak(w *WeakFields, num pref.FieldNumber, name pref.FullName, m pref.ProtoMessage) {
if m != nil {
mt, _ := protoregistry.GlobalTypes.FindMessageByName(name)
if mt == nil {
panic(fmt.Sprintf("message %v for weak field is not linked in", name))
}
if mt != m.ProtoReflect().Type() {
panic(fmt.Sprintf("invalid message type for weak field: got %T, want %T", m, mt.Zero().Interface()))
}
}
if m == nil || !m.ProtoReflect().IsValid() {
delete(*w, int32(num))
return
}
if *w == nil {
*w = make(weakFields)
}
(*w)[int32(num)] = m
}