Commit f351dbfa authored by Daniel Martí's avatar Daniel Martí

cmd/compile: expand inlining test to multiple pkgs

Rework the test to work with any number of std packages. This was done
to include a few funcs from unicode/utf8. Adding more will be much
simpler too.

While at it, add more runtime funcs by searching for "inlined" or
"inlining" in the git log of its directory. These are: addb, subtractb,
fastrand and noescape.

Updates #21851.

Change-Id: I4fb2bd8aa6a5054218f9b36cb19d897ac533710e
Reviewed-on: https://go-review.googlesource.com/63611
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 99414a5b
......@@ -21,28 +21,60 @@ func TestIntendedInlining(t *testing.T) {
testenv.MustHaveGoRun(t)
t.Parallel()
// want is the list of function names that should be inlined.
want := []string{"tophash", "add", "(*bmap).keys", "bucketShift", "bucketMask"}
// want is the list of function names (by package) that should
// be inlined.
want := map[string][]string{
"runtime": {
"tophash",
"add",
"addb",
"subtractb",
"(*bmap).keys",
"bucketShift",
"bucketMask",
"fastrand",
"noescape",
m := make(map[string]bool, len(want))
for _, s := range want {
m[s] = true
// TODO: These were modified at some point to be
// made inlineable, but have since been broken.
// "nextFreeFast",
},
"unicode/utf8": {
"FullRune",
"FullRuneInString",
"RuneLen",
"ValidRune",
},
}
cmd := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "build", "-a", "-gcflags=-m", "runtime"))
m := make(map[string]bool)
pkgs := make([]string, 0, len(want))
for pname, fnames := range want {
pkgs = append(pkgs, pname)
for _, fname := range fnames {
m[pname+"."+fname] = true
}
}
args := append([]string{"build", "-a", "-gcflags=-m"}, pkgs...)
cmd := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), args...))
out, err := cmd.CombinedOutput()
if err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
lines := bytes.Split(out, []byte{'\n'})
for _, x := range lines {
f := bytes.Split(x, []byte(": can inline "))
curPkg := ""
for _, l := range lines {
if bytes.HasPrefix(l, []byte("# ")) {
curPkg = string(l[2:])
}
f := bytes.Split(l, []byte(": can inline "))
if len(f) < 2 {
continue
}
fn := bytes.TrimSpace(f[1])
delete(m, string(fn))
delete(m, curPkg+"."+string(fn))
}
for s := range m {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment