]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: expand inlining test to multiple pkgs
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 13 Sep 2017 19:03:20 +0000 (21:03 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Thu, 14 Sep 2017 04:49:58 +0000 (04:49 +0000)
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: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/inl_test.go

index 77fc04dbf488d5f7f5b203a50388bd16ea41e081..07e8eea1b882755061672aef7ae0fb2890382976 100644 (file)
@@ -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 {