From f351dbfa4de7ee38b3d9b50413fbc432b4531412 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Wed, 13 Sep 2017 21:03:20 +0200 Subject: [PATCH] cmd/compile: expand inlining test to multiple pkgs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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í TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/compile/internal/gc/inl_test.go | 50 ++++++++++++++++++++----- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/gc/inl_test.go b/src/cmd/compile/internal/gc/inl_test.go index 77fc04dbf4..07e8eea1b8 100644 --- a/src/cmd/compile/internal/gc/inl_test.go +++ b/src/cmd/compile/internal/gc/inl_test.go @@ -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 { -- 2.48.1