mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.inline] cmd/internal/src: replace src.Pos with syntax.Pos
This replaces the src.Pos LineHist-based position tracking with the syntax.Pos implementation and updates all uses. The LineHist table is not used anymore - the respective code is still there but should be removed eventually. CL forthcoming. Passes toolstash -cmp when comparing to the master repo (with the exception of a couple of swapped assembly instructions, likely due to different instruction scheduling because the line-based sorting has changed; though this is won't affect correctness). The sizes of various important compiler data structures have increased significantly (see the various sizes_test.go files); this is probably the reason for an increase of compilation times (to be addressed). Here are the results of compilebench -count 5, run on a "quiet" machine (no apps running besides a terminal): name old time/op new time/op delta Template 256ms ± 1% 280ms ±15% +9.54% (p=0.008 n=5+5) Unicode 132ms ± 1% 132ms ± 1% ~ (p=0.690 n=5+5) GoTypes 891ms ± 1% 917ms ± 2% +2.88% (p=0.008 n=5+5) Compiler 3.84s ± 2% 3.99s ± 2% +3.95% (p=0.016 n=5+5) MakeBash 47.1s ± 1% 47.2s ± 2% ~ (p=0.841 n=5+5) name old user-ns/op new user-ns/op delta Template 309M ± 1% 326M ± 2% +5.18% (p=0.008 n=5+5) Unicode 165M ± 1% 168M ± 4% ~ (p=0.421 n=5+5) GoTypes 1.14G ± 2% 1.18G ± 1% +3.47% (p=0.008 n=5+5) Compiler 5.00G ± 1% 5.16G ± 1% +3.12% (p=0.008 n=5+5) Change-Id: I241c4246cdff627d7ecb95cac23060b38f9775ec Reviewed-on: https://go-review.googlesource.com/34273 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
2d429f01bd
commit
4808fc4443
38 changed files with 376 additions and 394 deletions
|
|
@ -6,6 +6,7 @@ package syntax
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"cmd/internal/src"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
|
@ -18,11 +19,11 @@ import (
|
|||
)
|
||||
|
||||
var fast = flag.Bool("fast", false, "parse package files in parallel")
|
||||
var src = flag.String("src", "parser.go", "source file to parse")
|
||||
var src_ = flag.String("src", "parser.go", "source file to parse")
|
||||
var verify = flag.Bool("verify", false, "verify idempotent printing")
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
_, err := ParseFile(*src, nil, nil, 0)
|
||||
_, err := ParseFile(*src_, nil, nil, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -133,7 +134,7 @@ func verifyPrint(filename string, ast1 *File) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
ast2, err := ParseBytes(filename, buf1.Bytes(), nil, nil, 0)
|
||||
ast2, err := ParseBytes(src.NewFileBase(filename, filename), buf1.Bytes(), nil, nil, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -157,7 +158,7 @@ func verifyPrint(filename string, ast1 *File) {
|
|||
}
|
||||
|
||||
func TestIssue17697(t *testing.T) {
|
||||
_, err := ParseBytes("", nil, nil, nil, 0) // return with parser error, don't panic
|
||||
_, err := ParseBytes(nil, nil, nil, nil, 0) // return with parser error, don't panic
|
||||
if err == nil {
|
||||
t.Errorf("no error reported")
|
||||
}
|
||||
|
|
@ -202,7 +203,7 @@ func TestLineDirectives(t *testing.T) {
|
|||
{"//line foo:123\n foo", "syntax error: package statement must be first", "foo", 123, 3},
|
||||
{"//line foo:123\n//line bar:345\nfoo", "syntax error: package statement must be first", "bar", 345, 0},
|
||||
} {
|
||||
_, err := ParseBytes("", []byte(test.src), nil, nil, 0)
|
||||
_, err := ParseBytes(nil, []byte(test.src), nil, nil, 0)
|
||||
if err == nil {
|
||||
t.Errorf("%s: no error reported", test.src)
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue