]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/compile/internal/test/pgo_devirtualize_test.go
cmd/compile: initial function value devirtualization
[gostls13.git] / src / cmd / compile / internal / test / pgo_devirtualize_test.go
index fbee8dedfdbe345d786d2d3f425a651951b86c8d..3e264a3f41cb6752d9b363ed27f7b5ac2e943d26 100644 (file)
@@ -29,11 +29,21 @@ go 1.19
                t.Fatalf("error writing go.mod: %v", err)
        }
 
+       // Run the test without PGO to ensure that the test assertions are
+       // correct even in the non-optimized version.
+       cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.GoToolPath(t), "test", "."))
+       cmd.Dir = dir
+       b, err := cmd.CombinedOutput()
+       t.Logf("Test without PGO:\n%s", b)
+       if err != nil {
+               t.Fatalf("Test failed without PGO: %v", err)
+       }
+
        // Build the test with the profile.
        pprof := filepath.Join(dir, "devirt.pprof")
        gcflag := fmt.Sprintf("-gcflags=-m=2 -pgoprofile=%s -d=pgodebug=3", pprof)
        out := filepath.Join(dir, "test.exe")
-       cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.GoToolPath(t), "build", "-o", out, gcflag, "."))
+       cmd = testenv.CleanCmdEnv(testenv.Command(t, testenv.GoToolPath(t), "test", "-o", out, gcflag, "."))
        cmd.Dir = dir
 
        pr, pw, err := os.Pipe()
@@ -56,19 +66,50 @@ go 1.19
        }
 
        want := []devirtualization{
+               // ExerciseIface
                {
-                       pos:    "./devirt.go:66:21",
+                       pos:    "./devirt.go:101:20",
                        callee: "mult.Mult.Multiply",
                },
                {
-                       pos:    "./devirt.go:66:31",
+                       pos:    "./devirt.go:101:39",
                        callee: "Add.Add",
                },
+               // ExerciseFuncConcrete
+               {
+                       pos:    "./devirt.go:178:18",
+                       callee: "AddFn",
+               },
+               // TODO(prattmic): Export data lookup for function value callees not implemented.
+               //{
+               //      pos:    "./devirt.go:179:15",
+               //      callee: "mult.MultFn",
+               //},
+               // ExerciseFuncField
+               {
+                       pos:    "./devirt.go:218:13",
+                       callee: "AddFn",
+               },
+               // TODO(prattmic): Export data lookup for function value callees not implemented.
+               //{
+               //      pos:    "./devirt.go:219:19",
+               //      callee: "mult.MultFn",
+               //},
+               // ExerciseFuncClosure
+               // TODO(prattmic): Closure callees not implemented.
+               //{
+               //      pos:    "./devirt.go:266:9",
+               //      callee: "AddClosure.func1",
+               //},
+               //{
+               //      pos:    "./devirt.go:267:15",
+               //      callee: "mult.MultClosure.func1",
+               //},
        }
 
        got := make(map[devirtualization]struct{})
 
-       devirtualizedLine := regexp.MustCompile(`(.*): PGO devirtualizing .* to (.*)`)
+       devirtualizedLine := regexp.MustCompile(`(.*): PGO devirtualizing \w+ call .* to (.*)`)
 
        scanner := bufio.NewScanner(pr)
        for scanner.Scan() {
@@ -102,6 +143,15 @@ go 1.19
                }
                t.Errorf("devirtualization %v missing; got %v", w, got)
        }
+
+       // Run test with PGO to ensure the assertions are still true.
+       cmd = testenv.CleanCmdEnv(testenv.Command(t, out))
+       cmd.Dir = dir
+       b, err = cmd.CombinedOutput()
+       t.Logf("Test with PGO:\n%s", b)
+       if err != nil {
+               t.Fatalf("Test failed without PGO: %v", err)
+       }
 }
 
 // TestPGODevirtualize tests that specific functions are devirtualized when PGO