Skip to content

Commit

Permalink
internal/bisect: copy parser changes from CL 494177
Browse files Browse the repository at this point in the history
x/tools/cmd/bisect is changing to emit hex skips for robustness.
Update this copy of internal/bisect to understand them.

Change-Id: Ie9445714e8e9fb594e656db2f94dcde9b6ce82d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/494178
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
rsc authored and pull[bot] committed Jul 20, 2023
1 parent ca3c53b commit 1834491
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
46 changes: 24 additions & 22 deletions src/cmd/compile/internal/loopvar/loopvar_test.go
Expand Up @@ -191,30 +191,32 @@ func TestLoopVarHashes(t *testing.T) {
return string(b)
}

m := f("v001100110110110010100100")
t.Logf(m)

mCount := strings.Count(m, "loopvarhash triggered cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 001100110110110010100100")
otherCount := strings.Count(m, "loopvarhash")
if mCount < 1 {
t.Errorf("did not see triggered main.go:27:6")
}
if mCount != otherCount {
t.Errorf("too many matches")
}
for _, arg := range []string{"v001100110110110010100100", "vx336ca4"} {
m := f(arg)
t.Logf(m)

mCount := strings.Count(m, "loopvarhash triggered cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 001100110110110010100100")
otherCount := strings.Count(m, "loopvarhash")
if mCount < 1 {
t.Errorf("%s: did not see triggered main.go:27:6", arg)
}
if mCount != otherCount {
t.Errorf("%s: too many matches", arg)
}

mCount = strings.Count(m, "cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 [bisect-match 0x7802e115b9336ca4]")
otherCount = strings.Count(m, "[bisect-match ")
if mCount < 1 {
t.Errorf("did not see bisect-match for main.go:27:6")
}
if mCount != otherCount {
t.Errorf("too many matches")
}
mCount = strings.Count(m, "cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 [bisect-match 0x7802e115b9336ca4]")
otherCount = strings.Count(m, "[bisect-match ")
if mCount < 1 {
t.Errorf("%s: did not see bisect-match for main.go:27:6", arg)
}
if mCount != otherCount {
t.Errorf("%s: too many matches", arg)
}

// This next test carefully dodges a bug-to-be-fixed with inlined locations for ir.Names.
if !strings.Contains(m, ", 100, 100, 100, 100") {
t.Errorf("Did not see expected value of m run")
// This next test carefully dodges a bug-to-be-fixed with inlined locations for ir.Names.
if !strings.Contains(m, ", 100, 100, 100, 100") {
t.Errorf("%s: did not see expected value of m run", arg)
}
}
}

Expand Down
23 changes: 21 additions & 2 deletions src/internal/bisect/bisect.go
Expand Up @@ -229,17 +229,35 @@ func New(pattern string) (*Matcher, error) {
result := true
bits := uint64(0)
start := 0
wid := 1 // 1-bit (binary); sometimes 4-bit (hex)
for i := 0; i <= len(p); i++ {
// Imagine a trailing - at the end of the pattern to flush final suffix
c := byte('-')
if i < len(p) {
c = p[i]
}
if i == start && wid == 1 && c == 'x' { // leading x for hex
start = i + 1
wid = 4
continue
}
switch c {
default:
return nil, &parseError{"invalid pattern syntax: " + pattern}
case '2', '3', '4', '5', '6', '7', '8', '9':
if wid != 4 {
return nil, &parseError{"invalid pattern syntax: " + pattern}
}
fallthrough
case '0', '1':
bits = bits<<1 | uint64(c-'0')
bits <<= wid
bits |= uint64(c - '0')
case 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F':
if wid != 4 {
return nil, &parseError{"invalid pattern syntax: " + pattern}
}
bits <<= 4
bits |= uint64(c&^0x20 - 'A' + 10)
case 'y':
if i+1 < len(p) && (p[i+1] == '0' || p[i+1] == '1') {
return nil, &parseError{"invalid pattern syntax: " + pattern}
Expand All @@ -251,7 +269,7 @@ func New(pattern string) (*Matcher, error) {
return nil, &parseError{"invalid pattern syntax (+ after -): " + pattern}
}
if i > 0 {
n := i - start
n := (i - start) * wid
if n > 64 {
return nil, &parseError{"pattern bits too long: " + pattern}
}
Expand All @@ -270,6 +288,7 @@ func New(pattern string) (*Matcher, error) {
bits = 0
result = c == '+'
start = i + 1
wid = 1
}
}
return m, nil
Expand Down

0 comments on commit 1834491

Please sign in to comment.