Skip to content

Commit 134c9b2

Browse files
committed
cmd/compile: remove FS debug hash form
The FS form was only necessary for reliable hashes in tests, and for that we can use -trimpath. Another potential concern would be temporary work directory names leaking into the names of files generated by cgo and the like, but we already make sure to avoid those to ensure reproducible builds: the compiler never sees those paths. So the FS form is not necessary for that either. Change-Id: Idae2c6acb22ab64dfb33bb053244d23fbe153830 Reviewed-on: https://go-review.googlesource.com/c/go/+/493737 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent da5a314 commit 134c9b2

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

src/cmd/compile/internal/base/flag.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,7 @@ func ParseFlags() {
213213

214214
if Debug.LoopVarHash != "" {
215215
// This first little bit controls the inputs for debug-hash-matching.
216-
basenameOnly := false
217216
mostInlineOnly := true
218-
if strings.HasPrefix(Debug.LoopVarHash, "FS") {
219-
// Magic handshake for testing, use file suffixes only when hashing on a position.
220-
// i.e., rather than /tmp/asdfasdfasdf/go-test-whatever/foo_test.go,
221-
// hash only on "foo_test.go", so that it will be the same hash across all runs.
222-
Debug.LoopVarHash = Debug.LoopVarHash[2:]
223-
basenameOnly = true
224-
}
225217
if strings.HasPrefix(Debug.LoopVarHash, "IL") {
226218
// When hash-searching on a position that is an inline site, default is to use the
227219
// most-inlined position only. This makes the hash faster, plus there's no point
@@ -237,7 +229,6 @@ func ParseFlags() {
237229
Debug.LoopVar = 1 // 1 means those loops that syntactically escape their dcl vars are eligible.
238230
}
239231
LoopVarHash.SetInlineSuffixOnly(mostInlineOnly)
240-
LoopVarHash.SetFileSuffixOnly(basenameOnly)
241232
} else if buildcfg.Experiment.LoopVar && Debug.LoopVar == 0 {
242233
Debug.LoopVar = 1
243234
}

src/cmd/compile/internal/base/hashdebug.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ type HashDebug struct {
4040
inlineSuffixOnly bool // for Pos hashes, remove all but the most inline position.
4141
}
4242

43-
// SetFileSuffixOnly controls whether hashing and reporting use the entire
44-
// file path name, just the basename. This makes hashing more consistent,
45-
// at the expense of being able to certainly locate the file.
46-
func (d *HashDebug) SetFileSuffixOnly(b bool) *HashDebug {
47-
d.fileSuffixOnly = b
48-
return d
49-
}
50-
5143
// SetInlineSuffixOnly controls whether hashing and reporting use the entire
5244
// inline position, or just the most-inline suffix. Compiler debugging tends
5345
// to want the whole inlining, debugging user problems (loopvarhash, e.g.)

src/cmd/compile/internal/loopvar/loopvar_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,29 +178,40 @@ func TestLoopVarHashes(t *testing.T) {
178178
root := "cmd/compile/internal/loopvar/testdata/inlines"
179179

180180
f := func(hash string) string {
181-
// This disables the loopvar change, except for the specified package.
182-
// The effect should follow the package, even though everything (except "c")
183-
// is inlined.
184-
cmd := testenv.Command(t, gocmd, "run", root)
185-
cmd.Env = append(cmd.Env, "GOCOMPILEDEBUG=loopvarhash=FS"+hash, "HOME="+tmpdir)
181+
// This disables the loopvar change, except for the specified hash pattern.
182+
// -trimpath is necessary so we get the same answer no matter where the
183+
// Go repository is checked out. This is not normally a concern since people
184+
// do not rely on the meaning of specific hashes.
185+
cmd := testenv.Command(t, gocmd, "run", "-trimpath", root)
186+
cmd.Env = append(cmd.Env, "GOCOMPILEDEBUG=loopvarhash="+hash, "HOME="+tmpdir)
186187
cmd.Dir = filepath.Join("testdata", "inlines")
187188

188189
b, _ := cmd.CombinedOutput()
189190
// Ignore the error, sometimes it's supposed to fail, the output test will catch it.
190191
return string(b)
191192
}
192193

193-
m := f("011011011110011110111101")
194+
m := f("001100110110110010100100")
194195
t.Logf(m)
195196

196-
mCount := strings.Count(m, "loopvarhash triggered main.go:27:6")
197+
mCount := strings.Count(m, "loopvarhash triggered cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 001100110110110010100100")
197198
otherCount := strings.Count(m, "loopvarhash")
198199
if mCount < 1 {
199-
t.Errorf("Did not see expected value of m compile")
200+
t.Errorf("did not see triggered main.go:27:6")
200201
}
201202
if mCount != otherCount {
202-
t.Errorf("Saw extraneous hash matches")
203+
t.Errorf("too many matches")
203204
}
205+
206+
mCount = strings.Count(m, "cmd/compile/internal/loopvar/testdata/inlines/main.go:27:6 [bisect-match 0x7802e115b9336ca4]")
207+
otherCount = strings.Count(m, "[bisect-match ")
208+
if mCount < 1 {
209+
t.Errorf("did not see bisect-match for main.go:27:6")
210+
}
211+
if mCount != otherCount {
212+
t.Errorf("too many matches")
213+
}
214+
204215
// This next test carefully dodges a bug-to-be-fixed with inlined locations for ir.Names.
205216
if !strings.Contains(m, ", 100, 100, 100, 100") {
206217
t.Errorf("Did not see expected value of m run")

0 commit comments

Comments
 (0)