fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Fix compilation on 32 bit architectures (#936)

This PR fixes a bug where Zoekt would not compile on 32-bit architectures. It
also takes the opportunity to start using the `math` library everywhere instead
of our own constants like `maxUInt32` to help prevent this sort of issue in the
future by encouraging devs to select the most accurate "max" type for their
specific situation.

Closes https://github.com/sourcegraph/zoekt/issues/935

+38 -34
+1 -1
cmd/zoekt-sourcegraph-indexserver/index.go
··· 115 115 // nothing needs to be done. 116 116 RepositoryDescription: zoekt.Repository{ 117 117 TenantID: o.TenantID, 118 - ID: uint32(o.IndexOptions.RepoID), 118 + ID: o.IndexOptions.RepoID, 119 119 Name: o.Name, 120 120 Branches: o.Branches, 121 121 RawConfig: map[string]string{
+4 -4
index/bits_test.go
··· 17 17 import ( 18 18 "encoding/binary" 19 19 "log" 20 + "math" 20 21 "math/rand" 21 22 "reflect" 23 + "slices" 22 24 "strconv" 23 25 "testing" 24 26 "testing/quick" 25 - 26 - "slices" 27 27 28 28 "github.com/google/go-cmp/cmp" 29 29 ) ··· 99 99 ends []uint32 100 100 want uint32 101 101 }{ 102 - {maxUInt32, 0, []uint32{34}, 1}, 102 + {math.MaxUint32, 0, []uint32{34}, 1}, 103 103 {9, 0, []uint32{34}, 0}, 104 104 {450, 0, []uint32{100, 200, 300, 400, 500, 600}, 4}, 105 105 } { ··· 150 150 151 151 var nums []uint32 152 152 i := newCompressedPostingIterator(data, stringToNGram("abc")) 153 - for i.first() != maxUInt32 { 153 + for i.first() != math.MaxUint32 { 154 154 nums = append(nums, i.first()) 155 155 i.next(i.first()) 156 156 }
+13 -12
index/hititer.go
··· 17 17 import ( 18 18 "encoding/binary" 19 19 "fmt" 20 + "math" 20 21 21 22 "github.com/sourcegraph/zoekt" 22 23 ) ··· 24 25 // hitIterator finds potential search matches, measured in offsets of 25 26 // the concatenation of all documents. 26 27 type hitIterator interface { 27 - // Return the first hit, or maxUInt32 if none. 28 + // Return the first hit, or math.MaxUint32 if none. 28 29 first() uint32 29 30 30 - // Skip until past limit. The argument maxUInt32 should be 31 + // Skip until past limit. The argument math.MaxUint32 should be 31 32 // treated specially. 32 33 next(limit uint32) 33 34 ··· 52 53 var p1, p2 uint32 53 54 p1 = i.i1.first() 54 55 p2 = i.i2.first() 55 - if p1 == maxUInt32 || p2 == maxUInt32 { 56 - i.i1.next(maxUInt32) 56 + if p1 == math.MaxUint32 || p2 == math.MaxUint32 { 57 + i.i1.next(math.MaxUint32) 57 58 break 58 59 } 59 60 ··· 85 86 l2 := limit + i.distance 86 87 87 88 if l2 < limit { // overflow. 88 - l2 = maxUInt32 89 + l2 = math.MaxUint32 89 90 } 90 91 i.i2.next(l2) 91 92 i.findNext() ··· 158 159 if len(i.postings) > 0 { 159 160 return i.postings[0] 160 161 } 161 - return maxUInt32 162 + return math.MaxUint32 162 163 } 163 164 164 - func (i *inMemoryIterator) updateStats(s *zoekt.Stats) { 165 + func (i *inMemoryIterator) updateStats(_ *zoekt.Stats) { 165 166 } 166 167 167 168 func (i *inMemoryIterator) next(limit uint32) { 168 - if limit == maxUInt32 { 169 + if limit == math.MaxUint32 { 169 170 i.postings = nil 170 171 } 171 172 ··· 203 204 } 204 205 205 206 func (i *compressedPostingIterator) next(limit uint32) { 206 - if limit == maxUInt32 { 207 + if limit == math.MaxUint32 { 207 208 i.blob = nil 208 - i._first = maxUInt32 209 + i._first = math.MaxUint32 209 210 return 210 211 } 211 212 ··· 217 218 } 218 219 219 220 if i._first <= limit && len(i.blob) == 0 { 220 - i._first = maxUInt32 221 + i._first = math.MaxUint32 221 222 } 222 223 } 223 224 ··· 248 249 } 249 250 250 251 func (i *mergingIterator) first() uint32 { 251 - r := uint32(maxUInt32) 252 + r := uint32(math.MaxUint32) 252 253 for _, j := range i.iters { 253 254 f := j.first() 254 255 if f < r {
+2 -3
index/indexdata.go
··· 20 20 "fmt" 21 21 "hash/crc64" 22 22 "log" 23 + "math" 23 24 "math/bits" 24 25 "slices" 25 26 "unicode/utf8" ··· 354 355 return 355 356 } 356 357 357 - const maxUInt32 = 0xffffffff 358 - 359 358 func minFrequencyNgramOffsets(ngramOffs []runeNgramOff, frequencies []uint32) (first, last runeNgramOff) { 360 359 // Find the two lowest frequency ngrams. 361 360 idx0, idx1 := 0, 0 362 - min0, min1 := uint32(maxUInt32), uint32(maxUInt32) 361 + min0, min1 := uint32(math.MaxUint32), uint32(math.MaxUint32) 363 362 for i, x := range frequencies { 364 363 if x <= min0 { 365 364 idx0, idx1 = i, idx0
+2 -1
index/indexfile.go
··· 19 19 import ( 20 20 "fmt" 21 21 "log" 22 + "math" 22 23 "os" 23 24 24 25 "golang.org/x/sys/unix" ··· 62 63 } 63 64 64 65 sz := fi.Size() 65 - if sz >= maxUInt32 { 66 + if sz >= math.MaxUint32 { 66 67 return nil, fmt.Errorf("file %s too large: %d", f.Name(), sz) 67 68 } 68 69 r := &mmapedIndexFile{
+4 -3
index/matchiter.go
··· 17 17 import ( 18 18 "bytes" 19 19 "fmt" 20 + "math" 20 21 21 22 "github.com/sourcegraph/zoekt" 22 23 ) ··· 95 96 } 96 97 97 98 func (t *noMatchTree) nextDoc() uint32 { 98 - return maxUInt32 99 + return math.MaxUint32 99 100 } 100 101 101 102 func (t *noMatchTree) prepare(uint32) {} ··· 148 149 func (i *ngramDocIterator) nextDoc() uint32 { 149 150 i.fileIdx = nextFileIndex(i.iter.first(), i.fileIdx, i.ends) 150 151 if i.fileIdx >= uint32(len(i.ends)) { 151 - return maxUInt32 152 + return math.MaxUint32 152 153 } 153 154 return i.fileIdx 154 155 } ··· 190 191 var candidates []*candidateMatch 191 192 for { 192 193 p1 := i.iter.first() 193 - if p1 == maxUInt32 || p1 >= i.ends[i.fileIdx] { 194 + if p1 == math.MaxUint32 || p1 >= i.ends[i.fileIdx] { 194 195 break 195 196 } 196 197 i.iter.next(p1)
+7 -6
index/matchtree.go
··· 18 18 "bytes" 19 19 "fmt" 20 20 "log" 21 + "math" 21 22 "regexp/syntax" 22 23 "strings" 23 24 "unicode/utf8" ··· 442 443 return i 443 444 } 444 445 } 445 - return maxUInt32 446 + return math.MaxUint32 446 447 } 447 448 448 449 func (t *bruteForceMatchTree) nextDoc() uint32 { ··· 464 465 } 465 466 466 467 func (t *orMatchTree) nextDoc() uint32 { 467 - min := uint32(maxUInt32) 468 + min := uint32(math.MaxUint32) 468 469 for _, c := range t.children { 469 470 m := c.nextDoc() 470 471 if m < min { ··· 497 498 return i 498 499 } 499 500 } 500 - return maxUInt32 501 + return math.MaxUint32 501 502 } 502 503 503 504 // all String methods ··· 672 673 // can return MatchesFound. 673 674 674 675 // find child with fewest candidates 675 - min := maxUInt32 676 + minCount := math.MaxInt 676 677 fewestChildren := 0 677 678 for ix, child := range t.children { 678 679 v, ok := child.(*substrMatchTree) ··· 681 682 if !ok || v.fileName { 682 683 return matchesFound 683 684 } 684 - if len(v.current) < min { 685 - min = len(v.current) 685 + if len(v.current) < minCount { 686 + minCount = len(v.current) 686 687 fewestChildren = ix 687 688 } 688 689 }
+5 -4
index/matchtree_test.go
··· 15 15 package index 16 16 17 17 import ( 18 + "math" 18 19 "reflect" 19 20 "regexp/syntax" 20 21 "testing" ··· 304 305 } 305 306 mt.prepare(nextDoc) 306 307 } 307 - if mt.nextDoc() != maxUInt32 { 308 + if mt.nextDoc() != math.MaxUint32 { 308 309 t.Fatalf("expected %d document, but got at least 1 more", len(want)) 309 310 } 310 311 } ··· 327 328 } 328 329 mt.prepare(nextDoc) 329 330 } 330 - if mt.nextDoc() != maxUInt32 { 331 + if mt.nextDoc() != math.MaxUint32 { 331 332 t.Fatalf("expect %d documents, but got at least 1 more", len(want)) 332 333 } 333 334 } ··· 360 361 mt.prepare(nextDoc) 361 362 } 362 363 363 - if mt.nextDoc() != maxUInt32 { 364 + if mt.nextDoc() != math.MaxUint32 { 364 365 t.Fatalf("expect %d documents, but got at least 1 more", len(want)) 365 366 } 366 367 } ··· 383 384 } 384 385 mt.prepare(nextDoc) 385 386 } 386 - if mt.nextDoc() != maxUInt32 { 387 + if mt.nextDoc() != math.MaxUint32 { 387 388 t.Fatalf("expected %d document, but got at least 1 more", len(want)) 388 389 } 389 390 }