mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/types2: use self_test.go from go/types
This CL replaces self_test.go with the (improved) version from go/types, modified for types2. To see the differences between go/types/self_test.go and this version, compare against patch set 1. Change-Id: I7ae830a17f7a0de40cc1f5063166a7247f78ec27 Reviewed-on: https://go-review.googlesource.com/c/go/+/300997 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
16ad1ea841
commit
7588ef0d90
1 changed files with 53 additions and 33 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
// UNREVIEWED
|
|
||||||
// Copyright 2013 The Go Authors. All rights reserved.
|
// Copyright 2013 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
@ -7,17 +6,15 @@ package types2_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmd/compile/internal/syntax"
|
"cmd/compile/internal/syntax"
|
||||||
"flag"
|
"path"
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "cmd/compile/internal/types2"
|
. "cmd/compile/internal/types2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var benchmark = flag.Bool("b", false, "run benchmarks")
|
|
||||||
|
|
||||||
func TestSelf(t *testing.T) {
|
func TestSelf(t *testing.T) {
|
||||||
files, err := pkgFiles(".")
|
files, err := pkgFiles(".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -25,7 +22,7 @@ func TestSelf(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
conf := Config{Importer: defaultImporter()}
|
conf := Config{Importer: defaultImporter()}
|
||||||
_, err = conf.Check("go/types", files, nil)
|
_, err = conf.Check("cmd/compile/internal/types2", files, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Importing go/constant doesn't work in the
|
// Importing go/constant doesn't work in the
|
||||||
// build dashboard environment. Don't report an error
|
// build dashboard environment. Don't report an error
|
||||||
|
|
@ -36,46 +33,69 @@ func TestSelf(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBenchmark(t *testing.T) {
|
func BenchmarkCheck(b *testing.B) {
|
||||||
if !*benchmark {
|
for _, p := range []string{
|
||||||
return
|
filepath.Join("src", "net", "http"),
|
||||||
}
|
filepath.Join("src", "go", "parser"),
|
||||||
|
filepath.Join("src", "go", "constant"),
|
||||||
// We're not using testing's benchmarking mechanism directly
|
filepath.Join("src", "go", "internal", "gcimporter"),
|
||||||
// because we want custom output.
|
} {
|
||||||
|
b.Run(path.Base(p), func(b *testing.B) {
|
||||||
for _, p := range []string{"types", "constant", filepath.Join("internal", "gcimporter")} {
|
path := filepath.Join(runtime.GOROOT(), p)
|
||||||
path := filepath.Join("..", p)
|
for _, ignoreFuncBodies := range []bool{false, true} {
|
||||||
runbench(t, path, false)
|
name := "funcbodies"
|
||||||
runbench(t, path, true)
|
if ignoreFuncBodies {
|
||||||
fmt.Println()
|
name = "nofuncbodies"
|
||||||
|
}
|
||||||
|
b.Run(name, func(b *testing.B) {
|
||||||
|
b.Run("info", func(b *testing.B) {
|
||||||
|
runbench(b, path, ignoreFuncBodies, true)
|
||||||
|
})
|
||||||
|
b.Run("noinfo", func(b *testing.B) {
|
||||||
|
runbench(b, path, ignoreFuncBodies, false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runbench(t *testing.T, path string, ignoreFuncBodies bool) {
|
func runbench(b *testing.B, path string, ignoreFuncBodies, writeInfo bool) {
|
||||||
files, err := pkgFiles(path)
|
files, err := pkgFiles(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
b := testing.Benchmark(func(b *testing.B) {
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
conf := Config{IgnoreFuncBodies: ignoreFuncBodies}
|
|
||||||
conf.Check(path, files, nil)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// determine line count
|
// determine line count
|
||||||
var lines uint
|
var lines uint
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
lines += f.EOF.Line()
|
lines += f.EOF.Line()
|
||||||
}
|
}
|
||||||
|
|
||||||
d := time.Duration(b.NsPerOp())
|
b.ResetTimer()
|
||||||
fmt.Printf(
|
start := time.Now()
|
||||||
"%s: %s for %d lines (%d lines/s), ignoreFuncBodies = %v\n",
|
for i := 0; i < b.N; i++ {
|
||||||
filepath.Base(path), d, lines, int64(float64(lines)/d.Seconds()), ignoreFuncBodies,
|
conf := Config{
|
||||||
)
|
IgnoreFuncBodies: ignoreFuncBodies,
|
||||||
|
Importer: defaultImporter(),
|
||||||
|
}
|
||||||
|
var info *Info
|
||||||
|
if writeInfo {
|
||||||
|
info = &Info{
|
||||||
|
Types: make(map[syntax.Expr]TypeAndValue),
|
||||||
|
Defs: make(map[*syntax.Name]Object),
|
||||||
|
Uses: make(map[*syntax.Name]Object),
|
||||||
|
Implicits: make(map[syntax.Node]Object),
|
||||||
|
Selections: make(map[*syntax.SelectorExpr]*Selection),
|
||||||
|
Scopes: make(map[syntax.Node]*Scope),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := conf.Check(path, files, info); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.StopTimer()
|
||||||
|
b.ReportMetric(float64(lines)*float64(b.N)/time.Since(start).Seconds(), "lines/s")
|
||||||
}
|
}
|
||||||
|
|
||||||
func pkgFiles(path string) ([]*syntax.File, error) {
|
func pkgFiles(path string) ([]*syntax.File, error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue