2016-05-06 23:17:29 -07:00
|
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2016-11-08 16:01:56 -08:00
|
|
|
"os"
|
2018-02-01 14:07:21 -05:00
|
|
|
"path/filepath"
|
2017-08-22 10:33:10 +08:00
|
|
|
"runtime"
|
2016-05-06 23:17:29 -07:00
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"unicode/utf8"
|
|
|
|
|
|
|
|
|
|
"cmd/compile/internal/syntax"
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
"cmd/compile/internal/types"
|
2017-04-18 12:53:25 -07:00
|
|
|
"cmd/internal/objabi"
|
2016-12-09 17:15:05 -08:00
|
|
|
"cmd/internal/src"
|
2016-05-06 23:17:29 -07:00
|
|
|
)
|
|
|
|
|
|
2018-06-10 10:26:40 +03:00
|
|
|
// parseFiles concurrently parses files into *syntax.File structures.
|
|
|
|
|
// Each declaration in every *syntax.File is converted to a syntax tree
|
|
|
|
|
// and its root represented by *Node is appended to xtop.
|
|
|
|
|
// Returns the total count of parsed lines.
|
2017-01-11 15:31:48 -08:00
|
|
|
func parseFiles(filenames []string) uint {
|
2017-01-11 15:48:30 -08:00
|
|
|
var noders []*noder
|
2017-08-22 10:33:10 +08:00
|
|
|
// Limit the number of simultaneously open files.
|
|
|
|
|
sem := make(chan struct{}, runtime.GOMAXPROCS(0)+10)
|
2016-11-08 16:01:56 -08:00
|
|
|
|
2017-01-11 15:31:48 -08:00
|
|
|
for _, filename := range filenames {
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
p := &noder{
|
|
|
|
|
basemap: make(map[*syntax.PosBase]*src.PosBase),
|
|
|
|
|
err: make(chan syntax.Error),
|
|
|
|
|
}
|
2017-01-11 15:48:30 -08:00
|
|
|
noders = append(noders, p)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
go func(filename string) {
|
2017-08-22 10:33:10 +08:00
|
|
|
sem <- struct{}{}
|
|
|
|
|
defer func() { <-sem }()
|
2017-01-11 15:48:30 -08:00
|
|
|
defer close(p.err)
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
base := syntax.NewFileBase(filename)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
f, err := os.Open(filename)
|
|
|
|
|
if err != nil {
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
p.error(syntax.Error{Pos: syntax.MakePos(base, 0, 0), Msg: err.Error()})
|
2017-01-11 15:48:30 -08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
2017-01-11 15:31:48 -08:00
|
|
|
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
p.file, _ = syntax.Parse(base, f, p.error, p.pragma, syntax.CheckBranches) // errors are tracked via p.error
|
2017-01-11 15:48:30 -08:00
|
|
|
}(filename)
|
2016-08-30 16:31:53 -07:00
|
|
|
}
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-10-11 10:14:31 +01:00
|
|
|
var lines uint
|
2017-01-11 15:48:30 -08:00
|
|
|
for _, p := range noders {
|
|
|
|
|
for e := range p.err {
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
p.yyerrorpos(e.Pos, "%s", e.Msg)
|
2017-01-11 15:48:30 -08:00
|
|
|
}
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
p.node()
|
|
|
|
|
lines += p.file.Lines
|
|
|
|
|
p.file = nil // release memory
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
if nsyntaxerrors != 0 {
|
|
|
|
|
errorexit()
|
|
|
|
|
}
|
2017-01-11 13:53:34 -08:00
|
|
|
// Always run testdclstack here, even when debug_dclstack is not set, as a sanity measure.
|
2016-05-06 23:17:29 -07:00
|
|
|
testdclstack()
|
|
|
|
|
}
|
2016-12-09 17:15:05 -08:00
|
|
|
|
2018-04-05 14:29:32 -07:00
|
|
|
localpkg.Height = myheight
|
|
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
return lines
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
// makeSrcPosBase translates from a *syntax.PosBase to a *src.PosBase.
|
|
|
|
|
func (p *noder) makeSrcPosBase(b0 *syntax.PosBase) *src.PosBase {
|
|
|
|
|
// fast path: most likely PosBase hasn't changed
|
|
|
|
|
if p.basecache.last == b0 {
|
|
|
|
|
return p.basecache.base
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b1, ok := p.basemap[b0]
|
|
|
|
|
if !ok {
|
|
|
|
|
fn := b0.Filename()
|
cmd/compile, cmd/compile/internal/syntax: print relative column info
This change enables printing of relative column information if a
prior line directive specified a valid column. If there was no
line directive, or the line directive didn't specify a column
(or the -C flag is specified), no column information is shown in
file positions.
Implementation: Column values (and line values, for that matter)
that are zero are interpreted as "unknown". A line directive that
doesn't specify a column records that as a zero column in the
respective PosBase data structure. When computing relative columns,
a relative value is zero of the base's column value is zero.
When formatting a position, a zero column value is not printed.
To make this work without special cases, the PosBase for a file
is given a concrete (non-0:0) position 1:1 with the PosBase's
line and column also being 1:1. In other words, at the position
1:1 of a file, it's relative positions are starting with 1:1 as
one would expect.
In the package syntax, this requires self-recursive PosBases for
file bases, matching what cmd/internal/src.PosBase was already
doing. In src.PosBase, file and inlining bases also need to be
based at 1:1 to indicate "known" positions.
This change completes the cmd/compiler part of the issue below.
Fixes #22662.
Change-Id: I6c3d2dee26709581fba0d0261b1d12e93f1cba1a
Reviewed-on: https://go-review.googlesource.com/97375
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-26 17:35:29 -08:00
|
|
|
if b0.IsFileBase() {
|
|
|
|
|
b1 = src.NewFileBase(fn, absFilename(fn))
|
|
|
|
|
} else {
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
// line directive base
|
cmd/compile, cmd/compile/internal/syntax: print relative column info
This change enables printing of relative column information if a
prior line directive specified a valid column. If there was no
line directive, or the line directive didn't specify a column
(or the -C flag is specified), no column information is shown in
file positions.
Implementation: Column values (and line values, for that matter)
that are zero are interpreted as "unknown". A line directive that
doesn't specify a column records that as a zero column in the
respective PosBase data structure. When computing relative columns,
a relative value is zero of the base's column value is zero.
When formatting a position, a zero column value is not printed.
To make this work without special cases, the PosBase for a file
is given a concrete (non-0:0) position 1:1 with the PosBase's
line and column also being 1:1. In other words, at the position
1:1 of a file, it's relative positions are starting with 1:1 as
one would expect.
In the package syntax, this requires self-recursive PosBases for
file bases, matching what cmd/internal/src.PosBase was already
doing. In src.PosBase, file and inlining bases also need to be
based at 1:1 to indicate "known" positions.
This change completes the cmd/compiler part of the issue below.
Fixes #22662.
Change-Id: I6c3d2dee26709581fba0d0261b1d12e93f1cba1a
Reviewed-on: https://go-review.googlesource.com/97375
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-02-26 17:35:29 -08:00
|
|
|
p0 := b0.Pos()
|
2018-02-22 17:24:19 -08:00
|
|
|
p1 := src.MakePos(p.makeSrcPosBase(p0.Base()), p0.Line(), p0.Col())
|
|
|
|
|
b1 = src.NewLinePragmaBase(p1, fn, fileh(fn), b0.Line(), b0.Col())
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
}
|
|
|
|
|
p.basemap[b0] = b1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update cache
|
|
|
|
|
p.basecache.last = b0
|
|
|
|
|
p.basecache.base = b1
|
|
|
|
|
|
|
|
|
|
return b1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) makeXPos(pos syntax.Pos) (_ src.XPos) {
|
|
|
|
|
return Ctxt.PosTable.XPos(src.MakePos(p.makeSrcPosBase(pos.Base()), pos.Line(), pos.Col()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) yyerrorpos(pos syntax.Pos, format string, args ...interface{}) {
|
|
|
|
|
yyerrorl(p.makeXPos(pos), format, args...)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
2016-12-09 17:15:05 -08:00
|
|
|
var pathPrefix string
|
|
|
|
|
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
// TODO(gri) Can we eliminate fileh in favor of absFilename?
|
2017-09-13 19:04:25 -04:00
|
|
|
func fileh(name string) string {
|
|
|
|
|
return objabi.AbsFile("", name, pathPrefix)
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 17:15:05 -08:00
|
|
|
func absFilename(name string) string {
|
2017-04-18 12:53:25 -07:00
|
|
|
return objabi.AbsFile(Ctxt.Pathname, name, pathPrefix)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
// noder transforms package syntax's AST into a Node tree.
|
2016-05-06 23:17:29 -07:00
|
|
|
type noder struct {
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
basemap map[*syntax.PosBase]*src.PosBase
|
|
|
|
|
basecache struct {
|
|
|
|
|
last *syntax.PosBase
|
|
|
|
|
base *src.PosBase
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
file *syntax.File
|
|
|
|
|
linknames []linkname
|
2018-04-11 15:37:16 -07:00
|
|
|
pragcgobuf [][]string
|
2017-01-11 15:48:30 -08:00
|
|
|
err chan syntax.Error
|
2017-05-02 16:46:01 +02:00
|
|
|
scope ScopeID
|
2018-02-15 07:40:44 +01:00
|
|
|
|
|
|
|
|
// scopeVars is a stack tracking the number of variables declared in the
|
|
|
|
|
// current function at the moment each open scope was opened.
|
|
|
|
|
scopeVars []int
|
|
|
|
|
|
|
|
|
|
lastCloseScopePos syntax.Pos
|
2017-05-02 16:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 16:53:30 -07:00
|
|
|
func (p *noder) funcBody(fn *Node, block *syntax.BlockStmt) {
|
|
|
|
|
oldScope := p.scope
|
2017-05-02 16:46:01 +02:00
|
|
|
p.scope = 0
|
2018-03-14 16:53:30 -07:00
|
|
|
funchdr(fn)
|
|
|
|
|
|
|
|
|
|
if block != nil {
|
|
|
|
|
body := p.stmts(block.List)
|
|
|
|
|
if body == nil {
|
|
|
|
|
body = []*Node{nod(OEMPTY, nil, nil)}
|
|
|
|
|
}
|
|
|
|
|
fn.Nbody.Set(body)
|
|
|
|
|
|
|
|
|
|
lineno = p.makeXPos(block.Rbrace)
|
|
|
|
|
fn.Func.Endlineno = lineno
|
|
|
|
|
}
|
2017-05-02 16:46:01 +02:00
|
|
|
|
2017-08-09 16:13:09 +09:00
|
|
|
funcbody()
|
2018-03-14 16:53:30 -07:00
|
|
|
p.scope = oldScope
|
2017-05-02 16:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
func (p *noder) openScope(pos syntax.Pos) {
|
2017-05-02 16:46:01 +02:00
|
|
|
types.Markdcl()
|
|
|
|
|
|
|
|
|
|
if trackScopes {
|
|
|
|
|
Curfn.Func.Parents = append(Curfn.Func.Parents, p.scope)
|
2018-02-15 07:40:44 +01:00
|
|
|
p.scopeVars = append(p.scopeVars, len(Curfn.Func.Dcl))
|
2017-05-02 16:46:01 +02:00
|
|
|
p.scope = ScopeID(len(Curfn.Func.Parents))
|
|
|
|
|
|
|
|
|
|
p.markScope(pos)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
func (p *noder) closeScope(pos syntax.Pos) {
|
2018-02-15 07:40:44 +01:00
|
|
|
p.lastCloseScopePos = pos
|
2017-05-02 16:46:01 +02:00
|
|
|
types.Popdcl()
|
|
|
|
|
|
|
|
|
|
if trackScopes {
|
2018-02-15 07:40:44 +01:00
|
|
|
scopeVars := p.scopeVars[len(p.scopeVars)-1]
|
|
|
|
|
p.scopeVars = p.scopeVars[:len(p.scopeVars)-1]
|
|
|
|
|
if scopeVars == len(Curfn.Func.Dcl) {
|
|
|
|
|
// no variables were declared in this scope, so we can retract it.
|
|
|
|
|
|
|
|
|
|
if int(p.scope) != len(Curfn.Func.Parents) {
|
|
|
|
|
Fatalf("scope tracking inconsistency, no variables declared but scopes were not retracted")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.scope = Curfn.Func.Parents[p.scope-1]
|
|
|
|
|
Curfn.Func.Parents = Curfn.Func.Parents[:len(Curfn.Func.Parents)-1]
|
|
|
|
|
|
|
|
|
|
nmarks := len(Curfn.Func.Marks)
|
|
|
|
|
Curfn.Func.Marks[nmarks-1].Scope = p.scope
|
|
|
|
|
prevScope := ScopeID(0)
|
|
|
|
|
if nmarks >= 2 {
|
|
|
|
|
prevScope = Curfn.Func.Marks[nmarks-2].Scope
|
|
|
|
|
}
|
|
|
|
|
if Curfn.Func.Marks[nmarks-1].Scope == prevScope {
|
|
|
|
|
Curfn.Func.Marks = Curfn.Func.Marks[:nmarks-1]
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-02 16:46:01 +02:00
|
|
|
p.scope = Curfn.Func.Parents[p.scope-1]
|
|
|
|
|
|
|
|
|
|
p.markScope(pos)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
func (p *noder) markScope(pos syntax.Pos) {
|
|
|
|
|
xpos := p.makeXPos(pos)
|
2017-05-02 16:46:01 +02:00
|
|
|
if i := len(Curfn.Func.Marks); i > 0 && Curfn.Func.Marks[i-1].Pos == xpos {
|
|
|
|
|
Curfn.Func.Marks[i-1].Scope = p.scope
|
|
|
|
|
} else {
|
|
|
|
|
Curfn.Func.Marks = append(Curfn.Func.Marks, Mark{xpos, p.scope})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// closeAnotherScope is like closeScope, but it reuses the same mark
|
|
|
|
|
// position as the last closeScope call. This is useful for "for" and
|
|
|
|
|
// "if" statements, as their implicit blocks always end at the same
|
|
|
|
|
// position as an explicit block.
|
|
|
|
|
func (p *noder) closeAnotherScope() {
|
2018-02-15 07:40:44 +01:00
|
|
|
p.closeScope(p.lastCloseScopePos)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
// linkname records a //go:linkname directive.
|
|
|
|
|
type linkname struct {
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
pos syntax.Pos
|
2017-01-11 15:48:30 -08:00
|
|
|
local string
|
|
|
|
|
remote string
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
func (p *noder) node() {
|
2017-04-06 20:57:46 -07:00
|
|
|
types.Block = 1
|
2017-01-11 15:31:48 -08:00
|
|
|
imported_unsafe = false
|
|
|
|
|
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(p.file.PkgName)
|
2017-01-11 15:48:30 -08:00
|
|
|
mkpackage(p.file.PkgName.Value)
|
2016-08-30 16:31:53 -07:00
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
xtop = append(xtop, p.decls(p.file.DeclList)...)
|
2016-08-30 16:31:53 -07:00
|
|
|
|
2017-01-11 15:48:30 -08:00
|
|
|
for _, n := range p.linknames {
|
|
|
|
|
if imported_unsafe {
|
|
|
|
|
lookup(n.local).Linkname = n.remote
|
|
|
|
|
} else {
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
p.yyerrorpos(n.pos, "//go:linkname only allowed in Go files that import \"unsafe\"")
|
2017-01-11 15:31:48 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-11 15:37:16 -07:00
|
|
|
pragcgobuf = append(pragcgobuf, p.pragcgobuf...)
|
2017-03-20 15:32:00 -07:00
|
|
|
lineno = src.NoXPos
|
2017-01-11 15:20:38 -08:00
|
|
|
clearImports()
|
2016-08-30 16:31:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) decls(decls []syntax.Decl) (l []*Node) {
|
2017-01-31 16:31:11 -08:00
|
|
|
var cs constState
|
2016-05-06 23:17:29 -07:00
|
|
|
|
|
|
|
|
for _, decl := range decls {
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(decl)
|
2016-05-06 23:17:29 -07:00
|
|
|
switch decl := decl.(type) {
|
|
|
|
|
case *syntax.ImportDecl:
|
|
|
|
|
p.importDecl(decl)
|
|
|
|
|
|
|
|
|
|
case *syntax.VarDecl:
|
|
|
|
|
l = append(l, p.varDecl(decl)...)
|
2016-08-30 16:31:53 -07:00
|
|
|
|
2016-05-06 23:17:29 -07:00
|
|
|
case *syntax.ConstDecl:
|
2017-01-31 16:31:11 -08:00
|
|
|
l = append(l, p.constDecl(decl, &cs)...)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
|
|
|
|
case *syntax.TypeDecl:
|
|
|
|
|
l = append(l, p.typeDecl(decl))
|
|
|
|
|
|
|
|
|
|
case *syntax.FuncDecl:
|
|
|
|
|
l = append(l, p.funcDecl(decl))
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
panic("unhandled Decl")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) importDecl(imp *syntax.ImportDecl) {
|
|
|
|
|
val := p.basicLit(imp.Path)
|
2017-03-24 13:10:24 -07:00
|
|
|
ipkg := importfile(&val)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
|
|
|
|
if ipkg == nil {
|
|
|
|
|
if nerrors == 0 {
|
|
|
|
|
Fatalf("phase error in import")
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ipkg.Direct = true
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
var my *types.Sym
|
2016-05-06 23:17:29 -07:00
|
|
|
if imp.LocalPkgName != nil {
|
|
|
|
|
my = p.name(imp.LocalPkgName)
|
|
|
|
|
} else {
|
2016-09-15 15:45:10 +10:00
|
|
|
my = lookup(ipkg.Name)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pack := p.nod(imp, OPACK, nil, nil)
|
|
|
|
|
pack.Sym = my
|
|
|
|
|
pack.Name.Pkg = ipkg
|
|
|
|
|
|
2017-10-15 22:49:52 +01:00
|
|
|
switch my.Name {
|
|
|
|
|
case ".":
|
2016-05-06 23:17:29 -07:00
|
|
|
importdot(ipkg, pack)
|
|
|
|
|
return
|
2017-10-15 22:49:52 +01:00
|
|
|
case "init":
|
2016-12-07 17:40:46 -08:00
|
|
|
yyerrorl(pack.Pos, "cannot import package as init - init must be a func")
|
2016-05-06 23:17:29 -07:00
|
|
|
return
|
2017-10-15 22:49:52 +01:00
|
|
|
case "_":
|
2016-05-06 23:17:29 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if my.Def != nil {
|
2018-04-02 17:33:38 -07:00
|
|
|
redeclare(pack.Pos, my, "as imported package name")
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
my.Def = asTypesNode(pack)
|
2016-12-07 17:40:46 -08:00
|
|
|
my.Lastlineno = pack.Pos
|
2016-05-06 23:17:29 -07:00
|
|
|
my.Block = 1 // at top level
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) varDecl(decl *syntax.VarDecl) []*Node {
|
|
|
|
|
names := p.declNames(decl.NameList)
|
2016-12-29 15:49:01 -08:00
|
|
|
typ := p.typeExprOrNil(decl.Type)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
|
|
|
|
var exprs []*Node
|
|
|
|
|
if decl.Values != nil {
|
|
|
|
|
exprs = p.exprList(decl.Values)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(decl)
|
2016-05-06 23:17:29 -07:00
|
|
|
return variter(names, typ, exprs)
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 15:13:48 -08:00
|
|
|
// constState tracks state between constant specifiers within a
|
|
|
|
|
// declaration group. This state is kept separate from noder so nested
|
|
|
|
|
// constant declarations are handled correctly (e.g., issue 15550).
|
2017-01-31 16:31:11 -08:00
|
|
|
type constState struct {
|
|
|
|
|
group *syntax.Group
|
|
|
|
|
typ *Node
|
|
|
|
|
values []*Node
|
|
|
|
|
iota int64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) constDecl(decl *syntax.ConstDecl, cs *constState) []*Node {
|
|
|
|
|
if decl.Group == nil || decl.Group != cs.group {
|
|
|
|
|
*cs = constState{
|
|
|
|
|
group: decl.Group,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-06 23:17:29 -07:00
|
|
|
names := p.declNames(decl.NameList)
|
2016-12-29 15:49:01 -08:00
|
|
|
typ := p.typeExprOrNil(decl.Type)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-01-31 16:31:11 -08:00
|
|
|
var values []*Node
|
2016-05-06 23:17:29 -07:00
|
|
|
if decl.Values != nil {
|
2017-01-31 16:31:11 -08:00
|
|
|
values = p.exprList(decl.Values)
|
|
|
|
|
cs.typ, cs.values = typ, values
|
|
|
|
|
} else {
|
|
|
|
|
if typ != nil {
|
|
|
|
|
yyerror("const declaration cannot have type without expression")
|
|
|
|
|
}
|
|
|
|
|
typ, values = cs.typ, cs.values
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-31 16:31:11 -08:00
|
|
|
var nn []*Node
|
|
|
|
|
for i, n := range names {
|
|
|
|
|
if i >= len(values) {
|
|
|
|
|
yyerror("missing value in const declaration")
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
v := values[i]
|
|
|
|
|
if decl.Values == nil {
|
|
|
|
|
v = treecopy(v, n.Pos)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Op = OLITERAL
|
|
|
|
|
declare(n, dclcontext)
|
|
|
|
|
|
|
|
|
|
n.Name.Param.Ntype = typ
|
|
|
|
|
n.Name.Defn = v
|
|
|
|
|
n.SetIota(cs.iota)
|
|
|
|
|
|
|
|
|
|
nn = append(nn, p.nod(decl, ODCLCONST, n, nil))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(values) > len(names) {
|
|
|
|
|
yyerror("extra expression in const declaration")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cs.iota++
|
|
|
|
|
|
|
|
|
|
return nn
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) typeDecl(decl *syntax.TypeDecl) *Node {
|
2017-02-01 12:35:53 -08:00
|
|
|
n := p.declName(decl.Name)
|
|
|
|
|
n.Op = OTYPE
|
|
|
|
|
declare(n, dclcontext)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-01-11 11:24:35 -08:00
|
|
|
// decl.Type may be nil but in that case we got a syntax error during parsing
|
2016-12-29 15:49:01 -08:00
|
|
|
typ := p.typeExprOrNil(decl.Type)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-02-01 12:35:53 -08:00
|
|
|
param := n.Name.Param
|
|
|
|
|
param.Ntype = typ
|
|
|
|
|
param.Pragma = decl.Pragma
|
|
|
|
|
param.Alias = decl.Alias
|
|
|
|
|
if param.Alias && param.Pragma != 0 {
|
|
|
|
|
yyerror("cannot specify directive with type alias")
|
|
|
|
|
param.Pragma = 0
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-24 15:49:32 -07:00
|
|
|
nod := p.nod(decl, ODCLTYPE, n, nil)
|
|
|
|
|
if param.Alias && !langSupported(1, 9) {
|
|
|
|
|
yyerrorl(nod.Pos, "type aliases only supported as of -lang=go1.9")
|
|
|
|
|
}
|
|
|
|
|
return nod
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) declNames(names []*syntax.Name) []*Node {
|
|
|
|
|
var nodes []*Node
|
|
|
|
|
for _, name := range names {
|
|
|
|
|
nodes = append(nodes, p.declName(name))
|
|
|
|
|
}
|
|
|
|
|
return nodes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) declName(name *syntax.Name) *Node {
|
2018-10-31 11:38:37 -07:00
|
|
|
n := dclname(p.name(name))
|
|
|
|
|
n.Pos = p.pos(name)
|
|
|
|
|
return n
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node {
|
|
|
|
|
name := p.name(fun.Name)
|
|
|
|
|
t := p.signature(fun.Recv, fun.Type)
|
|
|
|
|
f := p.nod(fun, ODCLFUNC, nil, nil)
|
|
|
|
|
|
|
|
|
|
if fun.Recv == nil {
|
|
|
|
|
if name.Name == "init" {
|
|
|
|
|
name = renameinit()
|
|
|
|
|
if t.List.Len() > 0 || t.Rlist.Len() > 0 {
|
2017-03-23 13:38:15 -07:00
|
|
|
yyerrorl(f.Pos, "func init must have no arguments and no return values")
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if localpkg.Name == "main" && name.Name == "main" {
|
|
|
|
|
if t.List.Len() > 0 || t.Rlist.Len() > 0 {
|
2017-03-23 13:38:15 -07:00
|
|
|
yyerrorl(f.Pos, "func main must have no arguments and no return values")
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-01-23 13:40:25 -08:00
|
|
|
f.Func.Shortname = name
|
2017-01-23 14:24:24 -08:00
|
|
|
name = nblank.Sym // filled in by typecheckfunc
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
2018-10-31 11:38:37 -07:00
|
|
|
f.Func.Nname = newfuncnamel(p.pos(fun.Name), name)
|
2016-05-06 23:17:29 -07:00
|
|
|
f.Func.Nname.Name.Defn = f
|
2017-03-23 13:38:15 -07:00
|
|
|
f.Func.Nname.Name.Param.Ntype = t
|
|
|
|
|
|
|
|
|
|
pragma := fun.Pragma
|
|
|
|
|
f.Func.Pragma = fun.Pragma
|
|
|
|
|
f.SetNoescape(pragma&Noescape != 0)
|
|
|
|
|
if pragma&Systemstack != 0 && pragma&Nosplit != 0 {
|
|
|
|
|
yyerrorl(f.Pos, "go:nosplit and go:systemstack cannot be combined")
|
|
|
|
|
}
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-01-23 14:24:24 -08:00
|
|
|
if fun.Recv == nil {
|
|
|
|
|
declare(f.Func.Nname, PFUNC)
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 16:53:30 -07:00
|
|
|
p.funcBody(f, fun.Body)
|
2017-03-23 13:38:15 -07:00
|
|
|
|
|
|
|
|
if fun.Body != nil {
|
|
|
|
|
if f.Noescape() {
|
|
|
|
|
yyerrorl(f.Pos, "can only use //go:noescape with external func implementations")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-04-23 05:10:21 -07:00
|
|
|
if pure_go || strings.HasPrefix(f.funcname(), "init.") {
|
2017-09-03 12:31:14 -07:00
|
|
|
yyerrorl(f.Pos, "missing function body")
|
2017-03-23 13:38:15 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-06 23:17:29 -07:00
|
|
|
return f
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) signature(recv *syntax.Field, typ *syntax.FuncType) *Node {
|
|
|
|
|
n := p.nod(typ, OTFUNC, nil, nil)
|
|
|
|
|
if recv != nil {
|
|
|
|
|
n.Left = p.param(recv, false, false)
|
|
|
|
|
}
|
|
|
|
|
n.List.Set(p.params(typ.ParamList, true))
|
|
|
|
|
n.Rlist.Set(p.params(typ.ResultList, false))
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) params(params []*syntax.Field, dddOk bool) []*Node {
|
|
|
|
|
var nodes []*Node
|
|
|
|
|
for i, param := range params {
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(param)
|
2016-05-06 23:17:29 -07:00
|
|
|
nodes = append(nodes, p.param(param, dddOk, i+1 == len(params)))
|
|
|
|
|
}
|
|
|
|
|
return nodes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) param(param *syntax.Field, dddOk, final bool) *Node {
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
var name *types.Sym
|
2016-05-06 23:17:29 -07:00
|
|
|
if param.Name != nil {
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
name = p.name(param.Name)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typ := p.typeExpr(param.Type)
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
n := p.nodSym(param, ODCLFIELD, typ, name)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
|
|
|
|
// rewrite ...T parameter
|
|
|
|
|
if typ.Op == ODDD {
|
|
|
|
|
if !dddOk {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("cannot use ... in receiver or result parameter list")
|
2016-05-06 23:17:29 -07:00
|
|
|
} else if !final {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("can only use ... with final parameter in list")
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
typ.Op = OTARRAY
|
|
|
|
|
typ.Right = typ.Left
|
|
|
|
|
typ.Left = nil
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetIsddd(true)
|
2016-05-06 23:17:29 -07:00
|
|
|
if n.Left != nil {
|
2017-02-27 19:56:38 +02:00
|
|
|
n.Left.SetIsddd(true)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) exprList(expr syntax.Expr) []*Node {
|
|
|
|
|
if list, ok := expr.(*syntax.ListExpr); ok {
|
|
|
|
|
return p.exprs(list.ElemList)
|
|
|
|
|
}
|
|
|
|
|
return []*Node{p.expr(expr)}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) exprs(exprs []syntax.Expr) []*Node {
|
|
|
|
|
var nodes []*Node
|
|
|
|
|
for _, expr := range exprs {
|
|
|
|
|
nodes = append(nodes, p.expr(expr))
|
|
|
|
|
}
|
|
|
|
|
return nodes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) expr(expr syntax.Expr) *Node {
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(expr)
|
2016-05-06 23:17:29 -07:00
|
|
|
switch expr := expr.(type) {
|
2017-03-24 16:23:21 -07:00
|
|
|
case nil, *syntax.BadExpr:
|
2016-05-06 23:17:29 -07:00
|
|
|
return nil
|
|
|
|
|
case *syntax.Name:
|
|
|
|
|
return p.mkname(expr)
|
|
|
|
|
case *syntax.BasicLit:
|
2018-10-31 11:38:37 -07:00
|
|
|
return nodlit(p.basicLit(expr))
|
2016-05-06 23:17:29 -07:00
|
|
|
case *syntax.CompositeLit:
|
|
|
|
|
n := p.nod(expr, OCOMPLIT, nil, nil)
|
|
|
|
|
if expr.Type != nil {
|
|
|
|
|
n.Right = p.expr(expr.Type)
|
|
|
|
|
}
|
2016-08-30 16:31:53 -07:00
|
|
|
l := p.exprs(expr.ElemList)
|
|
|
|
|
for i, e := range l {
|
|
|
|
|
l[i] = p.wrapname(expr.ElemList[i], e)
|
|
|
|
|
}
|
|
|
|
|
n.List.Set(l)
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
lineno = p.makeXPos(expr.Rbrace)
|
2016-05-06 23:17:29 -07:00
|
|
|
return n
|
|
|
|
|
case *syntax.KeyValueExpr:
|
2018-03-13 13:11:09 -07:00
|
|
|
// use position of expr.Key rather than of expr (which has position of ':')
|
|
|
|
|
return p.nod(expr.Key, OKEY, p.expr(expr.Key), p.wrapname(expr.Value, p.expr(expr.Value)))
|
2016-05-06 23:17:29 -07:00
|
|
|
case *syntax.FuncLit:
|
2017-05-02 16:46:01 +02:00
|
|
|
return p.funcLit(expr)
|
2016-05-06 23:17:29 -07:00
|
|
|
case *syntax.ParenExpr:
|
|
|
|
|
return p.nod(expr, OPAREN, p.expr(expr.X), nil)
|
|
|
|
|
case *syntax.SelectorExpr:
|
|
|
|
|
// parser.new_dotname
|
|
|
|
|
obj := p.expr(expr.X)
|
|
|
|
|
if obj.Op == OPACK {
|
2017-04-27 15:17:57 -07:00
|
|
|
obj.Name.SetUsed(true)
|
2016-10-21 16:07:47 -07:00
|
|
|
return oldname(restrictlookup(expr.Sel.Value, obj.Name.Pkg))
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
2018-10-31 11:38:37 -07:00
|
|
|
n := nodSym(OXDOT, obj, p.name(expr.Sel))
|
|
|
|
|
n.Pos = p.pos(expr) // lineno may have been changed by p.expr(expr.X)
|
|
|
|
|
return n
|
2016-05-06 23:17:29 -07:00
|
|
|
case *syntax.IndexExpr:
|
|
|
|
|
return p.nod(expr, OINDEX, p.expr(expr.X), p.expr(expr.Index))
|
|
|
|
|
case *syntax.SliceExpr:
|
|
|
|
|
op := OSLICE
|
|
|
|
|
if expr.Full {
|
|
|
|
|
op = OSLICE3
|
|
|
|
|
}
|
|
|
|
|
n := p.nod(expr, op, p.expr(expr.X), nil)
|
|
|
|
|
var index [3]*Node
|
|
|
|
|
for i, x := range expr.Index {
|
|
|
|
|
if x != nil {
|
|
|
|
|
index[i] = p.expr(x)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
n.SetSliceBounds(index[0], index[1], index[2])
|
|
|
|
|
return n
|
|
|
|
|
case *syntax.AssertExpr:
|
2018-03-29 18:22:23 -07:00
|
|
|
return p.nod(expr, ODOTTYPE, p.expr(expr.X), p.typeExpr(expr.Type))
|
2016-05-06 23:17:29 -07:00
|
|
|
case *syntax.Operation:
|
2017-11-07 15:55:26 -08:00
|
|
|
if expr.Op == syntax.Add && expr.Y != nil {
|
|
|
|
|
return p.sum(expr)
|
|
|
|
|
}
|
2016-05-06 23:17:29 -07:00
|
|
|
x := p.expr(expr.X)
|
|
|
|
|
if expr.Y == nil {
|
|
|
|
|
if expr.Op == syntax.And {
|
|
|
|
|
x = unparen(x) // TODO(mdempsky): Needed?
|
|
|
|
|
if x.Op == OCOMPLIT {
|
|
|
|
|
// Special case for &T{...}: turn into (*T){...}.
|
2018-04-24 23:40:08 +09:00
|
|
|
x.Right = p.nod(expr, OIND, x.Right, nil)
|
2017-02-27 19:56:38 +02:00
|
|
|
x.Right.SetImplicit(true)
|
2016-05-06 23:17:29 -07:00
|
|
|
return x
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return p.nod(expr, p.unOp(expr.Op), x, nil)
|
|
|
|
|
}
|
|
|
|
|
return p.nod(expr, p.binOp(expr.Op), x, p.expr(expr.Y))
|
|
|
|
|
case *syntax.CallExpr:
|
|
|
|
|
n := p.nod(expr, OCALL, p.expr(expr.Fun), nil)
|
|
|
|
|
n.List.Set(p.exprs(expr.ArgList))
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetIsddd(expr.HasDots)
|
2016-05-06 23:17:29 -07:00
|
|
|
return n
|
|
|
|
|
|
|
|
|
|
case *syntax.ArrayType:
|
|
|
|
|
var len *Node
|
|
|
|
|
if expr.Len != nil {
|
|
|
|
|
len = p.expr(expr.Len)
|
|
|
|
|
} else {
|
|
|
|
|
len = p.nod(expr, ODDD, nil, nil)
|
|
|
|
|
}
|
|
|
|
|
return p.nod(expr, OTARRAY, len, p.typeExpr(expr.Elem))
|
|
|
|
|
case *syntax.SliceType:
|
|
|
|
|
return p.nod(expr, OTARRAY, nil, p.typeExpr(expr.Elem))
|
|
|
|
|
case *syntax.DotsType:
|
|
|
|
|
return p.nod(expr, ODDD, p.typeExpr(expr.Elem), nil)
|
|
|
|
|
case *syntax.StructType:
|
|
|
|
|
return p.structType(expr)
|
|
|
|
|
case *syntax.InterfaceType:
|
|
|
|
|
return p.interfaceType(expr)
|
|
|
|
|
case *syntax.FuncType:
|
|
|
|
|
return p.signature(nil, expr)
|
|
|
|
|
case *syntax.MapType:
|
|
|
|
|
return p.nod(expr, OTMAP, p.typeExpr(expr.Key), p.typeExpr(expr.Value))
|
|
|
|
|
case *syntax.ChanType:
|
|
|
|
|
n := p.nod(expr, OTCHAN, p.typeExpr(expr.Elem), nil)
|
2018-03-08 04:18:18 -08:00
|
|
|
n.SetTChanDir(p.chanDir(expr.Dir))
|
2016-05-06 23:17:29 -07:00
|
|
|
return n
|
|
|
|
|
|
|
|
|
|
case *syntax.TypeSwitchGuard:
|
|
|
|
|
n := p.nod(expr, OTYPESW, nil, p.expr(expr.X))
|
|
|
|
|
if expr.Lhs != nil {
|
|
|
|
|
n.Left = p.declName(expr.Lhs)
|
2018-04-08 13:39:10 +01:00
|
|
|
if n.Left.isBlank() {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("invalid variable name %v in type switch", n.Left)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
panic("unhandled Expr")
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 15:55:26 -08:00
|
|
|
// sum efficiently handles very large summation expressions (such as
|
|
|
|
|
// in issue #16394). In particular, it avoids left recursion and
|
|
|
|
|
// collapses string literals.
|
|
|
|
|
func (p *noder) sum(x syntax.Expr) *Node {
|
|
|
|
|
// While we need to handle long sums with asymptotic
|
|
|
|
|
// efficiency, the vast majority of sums are very small: ~95%
|
|
|
|
|
// have only 2 or 3 operands, and ~99% of string literals are
|
|
|
|
|
// never concatenated.
|
|
|
|
|
|
|
|
|
|
adds := make([]*syntax.Operation, 0, 2)
|
|
|
|
|
for {
|
|
|
|
|
add, ok := x.(*syntax.Operation)
|
|
|
|
|
if !ok || add.Op != syntax.Add || add.Y == nil {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
adds = append(adds, add)
|
|
|
|
|
x = add.X
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// nstr is the current rightmost string literal in the
|
|
|
|
|
// summation (if any), and chunks holds its accumulated
|
|
|
|
|
// substrings.
|
|
|
|
|
//
|
|
|
|
|
// Consider the expression x + "a" + "b" + "c" + y. When we
|
|
|
|
|
// reach the string literal "a", we assign nstr to point to
|
|
|
|
|
// its corresponding Node and initialize chunks to {"a"}.
|
|
|
|
|
// Visiting the subsequent string literals "b" and "c", we
|
|
|
|
|
// simply append their values to chunks. Finally, when we
|
|
|
|
|
// reach the non-constant operand y, we'll join chunks to form
|
|
|
|
|
// "abc" and reassign the "a" string literal's value.
|
|
|
|
|
//
|
|
|
|
|
// N.B., we need to be careful about named string constants
|
|
|
|
|
// (indicated by Sym != nil) because 1) we can't modify their
|
|
|
|
|
// value, as doing so would affect other uses of the string
|
|
|
|
|
// constant, and 2) they may have types, which we need to
|
|
|
|
|
// handle correctly. For now, we avoid these problems by
|
|
|
|
|
// treating named string constants the same as non-constant
|
|
|
|
|
// operands.
|
|
|
|
|
var nstr *Node
|
|
|
|
|
chunks := make([]string, 0, 1)
|
|
|
|
|
|
|
|
|
|
n := p.expr(x)
|
|
|
|
|
if Isconst(n, CTSTR) && n.Sym == nil {
|
|
|
|
|
nstr = n
|
|
|
|
|
chunks = append(chunks, nstr.Val().U.(string))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := len(adds) - 1; i >= 0; i-- {
|
|
|
|
|
add := adds[i]
|
|
|
|
|
|
|
|
|
|
r := p.expr(add.Y)
|
|
|
|
|
if Isconst(r, CTSTR) && r.Sym == nil {
|
|
|
|
|
if nstr != nil {
|
|
|
|
|
// Collapse r into nstr instead of adding to n.
|
|
|
|
|
chunks = append(chunks, r.Val().U.(string))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nstr = r
|
|
|
|
|
chunks = append(chunks, nstr.Val().U.(string))
|
|
|
|
|
} else {
|
|
|
|
|
if len(chunks) > 1 {
|
|
|
|
|
nstr.SetVal(Val{U: strings.Join(chunks, "")})
|
|
|
|
|
}
|
|
|
|
|
nstr = nil
|
|
|
|
|
chunks = chunks[:0]
|
|
|
|
|
}
|
|
|
|
|
n = p.nod(add, OADD, n, r)
|
|
|
|
|
}
|
|
|
|
|
if len(chunks) > 1 {
|
|
|
|
|
nstr.SetVal(Val{U: strings.Join(chunks, "")})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-06 23:17:29 -07:00
|
|
|
func (p *noder) typeExpr(typ syntax.Expr) *Node {
|
|
|
|
|
// TODO(mdempsky): Be stricter? typecheck should handle errors anyway.
|
|
|
|
|
return p.expr(typ)
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-29 15:49:01 -08:00
|
|
|
func (p *noder) typeExprOrNil(typ syntax.Expr) *Node {
|
|
|
|
|
if typ != nil {
|
|
|
|
|
return p.expr(typ)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *noder) chanDir(dir syntax.ChanDir) types.ChanDir {
|
2016-05-06 23:17:29 -07:00
|
|
|
switch dir {
|
|
|
|
|
case 0:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Cboth
|
2016-05-06 23:17:29 -07:00
|
|
|
case syntax.SendOnly:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Csend
|
2016-05-06 23:17:29 -07:00
|
|
|
case syntax.RecvOnly:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Crecv
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
panic("unhandled ChanDir")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) structType(expr *syntax.StructType) *Node {
|
|
|
|
|
var l []*Node
|
|
|
|
|
for i, field := range expr.FieldList {
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(field)
|
2016-05-06 23:17:29 -07:00
|
|
|
var n *Node
|
|
|
|
|
if field.Name == nil {
|
|
|
|
|
n = p.embedded(field.Type)
|
|
|
|
|
} else {
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
n = p.nodSym(field, ODCLFIELD, p.typeExpr(field.Type), p.name(field.Name))
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
if i < len(expr.TagList) && expr.TagList[i] != nil {
|
|
|
|
|
n.SetVal(p.basicLit(expr.TagList[i]))
|
|
|
|
|
}
|
|
|
|
|
l = append(l, n)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(expr)
|
2016-05-06 23:17:29 -07:00
|
|
|
n := p.nod(expr, OTSTRUCT, nil, nil)
|
|
|
|
|
n.List.Set(l)
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) interfaceType(expr *syntax.InterfaceType) *Node {
|
|
|
|
|
var l []*Node
|
|
|
|
|
for _, method := range expr.MethodList {
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(method)
|
2016-05-06 23:17:29 -07:00
|
|
|
var n *Node
|
|
|
|
|
if method.Name == nil {
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
n = p.nodSym(method, ODCLFIELD, oldname(p.packname(method.Type)), nil)
|
2016-05-06 23:17:29 -07:00
|
|
|
} else {
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
mname := p.name(method.Name)
|
2016-05-06 23:17:29 -07:00
|
|
|
sig := p.typeExpr(method.Type)
|
2017-04-24 22:17:03 -07:00
|
|
|
sig.Left = fakeRecv()
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
n = p.nodSym(method, ODCLFIELD, sig, mname)
|
2016-05-06 23:17:29 -07:00
|
|
|
ifacedcl(n)
|
|
|
|
|
}
|
|
|
|
|
l = append(l, n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n := p.nod(expr, OTINTER, nil, nil)
|
|
|
|
|
n.List.Set(l)
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *noder) packname(expr syntax.Expr) *types.Sym {
|
2016-05-06 23:17:29 -07:00
|
|
|
switch expr := expr.(type) {
|
|
|
|
|
case *syntax.Name:
|
|
|
|
|
name := p.name(expr)
|
|
|
|
|
if n := oldname(name); n.Name != nil && n.Name.Pack != nil {
|
2017-04-27 15:17:57 -07:00
|
|
|
n.Name.Pack.Name.SetUsed(true)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
return name
|
|
|
|
|
case *syntax.SelectorExpr:
|
|
|
|
|
name := p.name(expr.X.(*syntax.Name))
|
2018-10-23 16:01:43 -07:00
|
|
|
def := asNode(name.Def)
|
|
|
|
|
if def == nil {
|
|
|
|
|
yyerror("undefined: %v", name)
|
|
|
|
|
return name
|
|
|
|
|
}
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
var pkg *types.Pkg
|
2018-10-23 16:01:43 -07:00
|
|
|
if def.Op != OPACK {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("%v is not a package", name)
|
2016-05-06 23:17:29 -07:00
|
|
|
pkg = localpkg
|
|
|
|
|
} else {
|
2018-10-23 16:01:43 -07:00
|
|
|
def.Name.SetUsed(true)
|
|
|
|
|
pkg = def.Name.Pkg
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
2016-10-21 16:07:47 -07:00
|
|
|
return restrictlookup(expr.Sel.Value, pkg)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
panic(fmt.Sprintf("unexpected packname: %#v", expr))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) embedded(typ syntax.Expr) *Node {
|
|
|
|
|
op, isStar := typ.(*syntax.Operation)
|
|
|
|
|
if isStar {
|
|
|
|
|
if op.Op != syntax.Mul || op.Y != nil {
|
|
|
|
|
panic("unexpected Operation")
|
|
|
|
|
}
|
|
|
|
|
typ = op.X
|
|
|
|
|
}
|
2017-08-24 15:36:47 -07:00
|
|
|
|
|
|
|
|
sym := p.packname(typ)
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
n := p.nodSym(typ, ODCLFIELD, oldname(sym), lookup(sym.Name))
|
2017-08-24 15:36:47 -07:00
|
|
|
n.SetEmbedded(true)
|
|
|
|
|
|
2016-05-06 23:17:29 -07:00
|
|
|
if isStar {
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
n.Left = p.nod(op, OIND, n.Left, nil)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) stmts(stmts []syntax.Stmt) []*Node {
|
2017-09-01 14:55:15 -07:00
|
|
|
return p.stmtsFall(stmts, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) stmtsFall(stmts []syntax.Stmt, fallOK bool) []*Node {
|
2016-05-06 23:17:29 -07:00
|
|
|
var nodes []*Node
|
2017-09-01 14:55:15 -07:00
|
|
|
for i, stmt := range stmts {
|
|
|
|
|
s := p.stmtFall(stmt, fallOK && i+1 == len(stmts))
|
2016-05-06 23:17:29 -07:00
|
|
|
if s == nil {
|
|
|
|
|
} else if s.Op == OBLOCK && s.Ninit.Len() == 0 {
|
|
|
|
|
nodes = append(nodes, s.List.Slice()...)
|
|
|
|
|
} else {
|
|
|
|
|
nodes = append(nodes, s)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nodes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) stmt(stmt syntax.Stmt) *Node {
|
2017-09-01 14:55:15 -07:00
|
|
|
return p.stmtFall(stmt, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) stmtFall(stmt syntax.Stmt, fallOK bool) *Node {
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(stmt)
|
2016-05-06 23:17:29 -07:00
|
|
|
switch stmt := stmt.(type) {
|
|
|
|
|
case *syntax.EmptyStmt:
|
|
|
|
|
return nil
|
|
|
|
|
case *syntax.LabeledStmt:
|
2017-09-01 14:55:15 -07:00
|
|
|
return p.labeledStmt(stmt, fallOK)
|
2016-05-06 23:17:29 -07:00
|
|
|
case *syntax.BlockStmt:
|
2017-03-21 22:23:15 -07:00
|
|
|
l := p.blockStmt(stmt)
|
|
|
|
|
if len(l) == 0 {
|
|
|
|
|
// TODO(mdempsky): Line number?
|
|
|
|
|
return nod(OEMPTY, nil, nil)
|
|
|
|
|
}
|
|
|
|
|
return liststmt(l)
|
2016-05-06 23:17:29 -07:00
|
|
|
case *syntax.ExprStmt:
|
|
|
|
|
return p.wrapname(stmt, p.expr(stmt.X))
|
|
|
|
|
case *syntax.SendStmt:
|
|
|
|
|
return p.nod(stmt, OSEND, p.expr(stmt.Chan), p.expr(stmt.Value))
|
|
|
|
|
case *syntax.DeclStmt:
|
2016-08-30 16:31:53 -07:00
|
|
|
return liststmt(p.decls(stmt.DeclList))
|
2016-05-06 23:17:29 -07:00
|
|
|
case *syntax.AssignStmt:
|
|
|
|
|
if stmt.Op != 0 && stmt.Op != syntax.Def {
|
|
|
|
|
n := p.nod(stmt, OASOP, p.expr(stmt.Lhs), p.expr(stmt.Rhs))
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetImplicit(stmt.Rhs == syntax.ImplicitOne)
|
2018-03-08 04:18:18 -08:00
|
|
|
n.SetSubOp(p.binOp(stmt.Op))
|
2016-05-06 23:17:29 -07:00
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n := p.nod(stmt, OAS, nil, nil) // assume common case
|
|
|
|
|
|
2017-09-27 23:52:04 -07:00
|
|
|
rhs := p.exprList(stmt.Rhs)
|
|
|
|
|
lhs := p.assignList(stmt.Lhs, n, stmt.Op == syntax.Def)
|
2016-05-06 23:17:29 -07:00
|
|
|
|
|
|
|
|
if len(lhs) == 1 && len(rhs) == 1 {
|
|
|
|
|
// common case
|
|
|
|
|
n.Left = lhs[0]
|
|
|
|
|
n.Right = rhs[0]
|
|
|
|
|
} else {
|
|
|
|
|
n.Op = OAS2
|
|
|
|
|
n.List.Set(lhs)
|
|
|
|
|
n.Rlist.Set(rhs)
|
|
|
|
|
}
|
|
|
|
|
return n
|
|
|
|
|
|
|
|
|
|
case *syntax.BranchStmt:
|
|
|
|
|
var op Op
|
|
|
|
|
switch stmt.Tok {
|
|
|
|
|
case syntax.Break:
|
|
|
|
|
op = OBREAK
|
|
|
|
|
case syntax.Continue:
|
|
|
|
|
op = OCONTINUE
|
|
|
|
|
case syntax.Fallthrough:
|
2017-09-01 14:55:15 -07:00
|
|
|
if !fallOK {
|
|
|
|
|
yyerror("fallthrough statement out of place")
|
|
|
|
|
}
|
|
|
|
|
op = OFALL
|
2016-05-06 23:17:29 -07:00
|
|
|
case syntax.Goto:
|
|
|
|
|
op = OGOTO
|
|
|
|
|
default:
|
|
|
|
|
panic("unhandled BranchStmt")
|
|
|
|
|
}
|
|
|
|
|
n := p.nod(stmt, op, nil, nil)
|
|
|
|
|
if stmt.Label != nil {
|
2018-10-26 20:10:23 -07:00
|
|
|
n.Sym = p.name(stmt.Label)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
return n
|
|
|
|
|
case *syntax.CallStmt:
|
|
|
|
|
var op Op
|
|
|
|
|
switch stmt.Tok {
|
|
|
|
|
case syntax.Defer:
|
|
|
|
|
op = ODEFER
|
|
|
|
|
case syntax.Go:
|
|
|
|
|
op = OPROC
|
|
|
|
|
default:
|
|
|
|
|
panic("unhandled CallStmt")
|
|
|
|
|
}
|
|
|
|
|
return p.nod(stmt, op, p.expr(stmt.Call), nil)
|
|
|
|
|
case *syntax.ReturnStmt:
|
|
|
|
|
var results []*Node
|
|
|
|
|
if stmt.Results != nil {
|
|
|
|
|
results = p.exprList(stmt.Results)
|
|
|
|
|
}
|
|
|
|
|
n := p.nod(stmt, ORETURN, nil, nil)
|
|
|
|
|
n.List.Set(results)
|
|
|
|
|
if n.List.Len() == 0 && Curfn != nil {
|
|
|
|
|
for _, ln := range Curfn.Func.Dcl {
|
2017-04-25 18:14:12 -07:00
|
|
|
if ln.Class() == PPARAM {
|
2016-05-06 23:17:29 -07:00
|
|
|
continue
|
|
|
|
|
}
|
2017-04-25 18:14:12 -07:00
|
|
|
if ln.Class() != PPARAMOUT {
|
2016-05-06 23:17:29 -07:00
|
|
|
break
|
|
|
|
|
}
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if asNode(ln.Sym.Def) != ln {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("%s is shadowed during return", ln.Sym.Name)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return n
|
|
|
|
|
case *syntax.IfStmt:
|
|
|
|
|
return p.ifStmt(stmt)
|
|
|
|
|
case *syntax.ForStmt:
|
|
|
|
|
return p.forStmt(stmt)
|
|
|
|
|
case *syntax.SwitchStmt:
|
|
|
|
|
return p.switchStmt(stmt)
|
|
|
|
|
case *syntax.SelectStmt:
|
|
|
|
|
return p.selectStmt(stmt)
|
|
|
|
|
}
|
|
|
|
|
panic("unhandled Stmt")
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 23:52:04 -07:00
|
|
|
func (p *noder) assignList(expr syntax.Expr, defn *Node, colas bool) []*Node {
|
|
|
|
|
if !colas {
|
|
|
|
|
return p.exprList(expr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defn.SetColas(true)
|
|
|
|
|
|
|
|
|
|
var exprs []syntax.Expr
|
|
|
|
|
if list, ok := expr.(*syntax.ListExpr); ok {
|
|
|
|
|
exprs = list.ElemList
|
|
|
|
|
} else {
|
|
|
|
|
exprs = []syntax.Expr{expr}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res := make([]*Node, len(exprs))
|
|
|
|
|
seen := make(map[*types.Sym]bool, len(exprs))
|
|
|
|
|
|
|
|
|
|
newOrErr := false
|
|
|
|
|
for i, expr := range exprs {
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(expr)
|
2017-09-27 23:52:04 -07:00
|
|
|
res[i] = nblank
|
|
|
|
|
|
|
|
|
|
name, ok := expr.(*syntax.Name)
|
|
|
|
|
if !ok {
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
p.yyerrorpos(expr.Pos(), "non-name %v on left side of :=", p.expr(expr))
|
2017-09-27 23:52:04 -07:00
|
|
|
newOrErr = true
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sym := p.name(name)
|
|
|
|
|
if sym.IsBlank() {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if seen[sym] {
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
p.yyerrorpos(expr.Pos(), "%v repeated on left side of :=", sym)
|
2017-09-27 23:52:04 -07:00
|
|
|
newOrErr = true
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
seen[sym] = true
|
|
|
|
|
|
|
|
|
|
if sym.Block == types.Block {
|
|
|
|
|
res[i] = oldname(sym)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newOrErr = true
|
|
|
|
|
n := newname(sym)
|
|
|
|
|
declare(n, dclcontext)
|
|
|
|
|
n.Name.Defn = defn
|
|
|
|
|
defn.Ninit.Append(nod(ODCL, n, nil))
|
|
|
|
|
res[i] = n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !newOrErr {
|
|
|
|
|
yyerrorl(defn.Pos, "no new variables on left side of :=")
|
|
|
|
|
}
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-21 22:23:15 -07:00
|
|
|
func (p *noder) blockStmt(stmt *syntax.BlockStmt) []*Node {
|
2017-05-02 16:46:01 +02:00
|
|
|
p.openScope(stmt.Pos())
|
2017-03-21 22:23:15 -07:00
|
|
|
nodes := p.stmts(stmt.List)
|
2017-05-02 16:46:01 +02:00
|
|
|
p.closeScope(stmt.Rbrace)
|
2016-05-06 23:17:29 -07:00
|
|
|
return nodes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) ifStmt(stmt *syntax.IfStmt) *Node {
|
2017-05-02 16:46:01 +02:00
|
|
|
p.openScope(stmt.Pos())
|
2016-05-06 23:17:29 -07:00
|
|
|
n := p.nod(stmt, OIF, nil, nil)
|
|
|
|
|
if stmt.Init != nil {
|
|
|
|
|
n.Ninit.Set1(p.stmt(stmt.Init))
|
|
|
|
|
}
|
|
|
|
|
if stmt.Cond != nil {
|
|
|
|
|
n.Left = p.expr(stmt.Cond)
|
|
|
|
|
}
|
2017-03-21 22:23:15 -07:00
|
|
|
n.Nbody.Set(p.blockStmt(stmt.Then))
|
2016-05-06 23:17:29 -07:00
|
|
|
if stmt.Else != nil {
|
|
|
|
|
e := p.stmt(stmt.Else)
|
|
|
|
|
if e.Op == OBLOCK && e.Ninit.Len() == 0 {
|
|
|
|
|
n.Rlist.Set(e.List.Slice())
|
|
|
|
|
} else {
|
|
|
|
|
n.Rlist.Set1(e)
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-02 16:46:01 +02:00
|
|
|
p.closeAnotherScope()
|
2016-05-06 23:17:29 -07:00
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) forStmt(stmt *syntax.ForStmt) *Node {
|
2017-05-02 16:46:01 +02:00
|
|
|
p.openScope(stmt.Pos())
|
2016-05-06 23:17:29 -07:00
|
|
|
var n *Node
|
|
|
|
|
if r, ok := stmt.Init.(*syntax.RangeClause); ok {
|
|
|
|
|
if stmt.Cond != nil || stmt.Post != nil {
|
|
|
|
|
panic("unexpected RangeClause")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n = p.nod(r, ORANGE, nil, p.expr(r.X))
|
|
|
|
|
if r.Lhs != nil {
|
2017-09-27 23:52:04 -07:00
|
|
|
n.List.Set(p.assignList(r.Lhs, n, r.Def))
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
n = p.nod(stmt, OFOR, nil, nil)
|
|
|
|
|
if stmt.Init != nil {
|
|
|
|
|
n.Ninit.Set1(p.stmt(stmt.Init))
|
|
|
|
|
}
|
|
|
|
|
if stmt.Cond != nil {
|
|
|
|
|
n.Left = p.expr(stmt.Cond)
|
|
|
|
|
}
|
|
|
|
|
if stmt.Post != nil {
|
|
|
|
|
n.Right = p.stmt(stmt.Post)
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-21 22:23:15 -07:00
|
|
|
n.Nbody.Set(p.blockStmt(stmt.Body))
|
2017-05-02 16:46:01 +02:00
|
|
|
p.closeAnotherScope()
|
2016-05-06 23:17:29 -07:00
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) switchStmt(stmt *syntax.SwitchStmt) *Node {
|
2017-05-02 16:46:01 +02:00
|
|
|
p.openScope(stmt.Pos())
|
2016-05-06 23:17:29 -07:00
|
|
|
n := p.nod(stmt, OSWITCH, nil, nil)
|
|
|
|
|
if stmt.Init != nil {
|
|
|
|
|
n.Ninit.Set1(p.stmt(stmt.Init))
|
|
|
|
|
}
|
|
|
|
|
if stmt.Tag != nil {
|
|
|
|
|
n.Left = p.expr(stmt.Tag)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tswitch := n.Left
|
2017-09-01 14:55:15 -07:00
|
|
|
if tswitch != nil && tswitch.Op != OTYPESW {
|
2016-05-06 23:17:29 -07:00
|
|
|
tswitch = nil
|
|
|
|
|
}
|
2017-05-02 16:46:01 +02:00
|
|
|
n.List.Set(p.caseClauses(stmt.Body, tswitch, stmt.Rbrace))
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-05-02 16:46:01 +02:00
|
|
|
p.closeScope(stmt.Rbrace)
|
2016-05-06 23:17:29 -07:00
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
func (p *noder) caseClauses(clauses []*syntax.CaseClause, tswitch *Node, rbrace syntax.Pos) []*Node {
|
2016-05-06 23:17:29 -07:00
|
|
|
var nodes []*Node
|
2017-05-02 16:46:01 +02:00
|
|
|
for i, clause := range clauses {
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(clause)
|
2017-05-02 16:46:01 +02:00
|
|
|
if i > 0 {
|
|
|
|
|
p.closeScope(clause.Pos())
|
|
|
|
|
}
|
|
|
|
|
p.openScope(clause.Pos())
|
|
|
|
|
|
2016-05-06 23:17:29 -07:00
|
|
|
n := p.nod(clause, OXCASE, nil, nil)
|
|
|
|
|
if clause.Cases != nil {
|
|
|
|
|
n.List.Set(p.exprList(clause.Cases))
|
|
|
|
|
}
|
2017-09-01 14:55:15 -07:00
|
|
|
if tswitch != nil && tswitch.Left != nil {
|
2016-05-06 23:17:29 -07:00
|
|
|
nn := newname(tswitch.Left.Sym)
|
|
|
|
|
declare(nn, dclcontext)
|
|
|
|
|
n.Rlist.Set1(nn)
|
|
|
|
|
// keep track of the instances for reporting unused
|
|
|
|
|
nn.Name.Defn = tswitch
|
|
|
|
|
}
|
2017-09-01 14:55:15 -07:00
|
|
|
|
|
|
|
|
// Trim trailing empty statements. We omit them from
|
|
|
|
|
// the Node AST anyway, and it's easier to identify
|
|
|
|
|
// out-of-place fallthrough statements without them.
|
|
|
|
|
body := clause.Body
|
|
|
|
|
for len(body) > 0 {
|
|
|
|
|
if _, ok := body[len(body)-1].(*syntax.EmptyStmt); !ok {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
body = body[:len(body)-1]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Nbody.Set(p.stmtsFall(body, true))
|
|
|
|
|
if l := n.Nbody.Len(); l > 0 && n.Nbody.Index(l-1).Op == OFALL {
|
|
|
|
|
if tswitch != nil {
|
|
|
|
|
yyerror("cannot fallthrough in type switch")
|
|
|
|
|
}
|
|
|
|
|
if i+1 == len(clauses) {
|
|
|
|
|
yyerror("cannot fallthrough final case in switch")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-06 23:17:29 -07:00
|
|
|
nodes = append(nodes, n)
|
|
|
|
|
}
|
2017-05-02 16:46:01 +02:00
|
|
|
if len(clauses) > 0 {
|
|
|
|
|
p.closeScope(rbrace)
|
|
|
|
|
}
|
2016-05-06 23:17:29 -07:00
|
|
|
return nodes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) selectStmt(stmt *syntax.SelectStmt) *Node {
|
|
|
|
|
n := p.nod(stmt, OSELECT, nil, nil)
|
2017-05-02 16:46:01 +02:00
|
|
|
n.List.Set(p.commClauses(stmt.Body, stmt.Rbrace))
|
2016-05-06 23:17:29 -07:00
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
func (p *noder) commClauses(clauses []*syntax.CommClause, rbrace syntax.Pos) []*Node {
|
2016-05-06 23:17:29 -07:00
|
|
|
var nodes []*Node
|
2017-05-02 16:46:01 +02:00
|
|
|
for i, clause := range clauses {
|
2018-10-31 11:38:37 -07:00
|
|
|
p.setlineno(clause)
|
2017-05-02 16:46:01 +02:00
|
|
|
if i > 0 {
|
|
|
|
|
p.closeScope(clause.Pos())
|
|
|
|
|
}
|
|
|
|
|
p.openScope(clause.Pos())
|
|
|
|
|
|
2016-05-06 23:17:29 -07:00
|
|
|
n := p.nod(clause, OXCASE, nil, nil)
|
|
|
|
|
if clause.Comm != nil {
|
|
|
|
|
n.List.Set1(p.stmt(clause.Comm))
|
|
|
|
|
}
|
|
|
|
|
n.Nbody.Set(p.stmts(clause.Body))
|
|
|
|
|
nodes = append(nodes, n)
|
|
|
|
|
}
|
2017-05-02 16:46:01 +02:00
|
|
|
if len(clauses) > 0 {
|
|
|
|
|
p.closeScope(rbrace)
|
|
|
|
|
}
|
2016-05-06 23:17:29 -07:00
|
|
|
return nodes
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-01 14:55:15 -07:00
|
|
|
func (p *noder) labeledStmt(label *syntax.LabeledStmt, fallOK bool) *Node {
|
2018-10-26 20:10:23 -07:00
|
|
|
lhs := p.nodSym(label, OLABEL, nil, p.name(label.Label))
|
2016-05-06 23:17:29 -07:00
|
|
|
|
|
|
|
|
var ls *Node
|
|
|
|
|
if label.Stmt != nil { // TODO(mdempsky): Should always be present.
|
2017-09-01 14:55:15 -07:00
|
|
|
ls = p.stmtFall(label.Stmt, fallOK)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lhs.Name.Defn = ls
|
|
|
|
|
l := []*Node{lhs}
|
|
|
|
|
if ls != nil {
|
|
|
|
|
if ls.Op == OBLOCK && ls.Ninit.Len() == 0 {
|
|
|
|
|
l = append(l, ls.List.Slice()...)
|
|
|
|
|
} else {
|
|
|
|
|
l = append(l, ls)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return liststmt(l)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var unOps = [...]Op{
|
|
|
|
|
syntax.Recv: ORECV,
|
|
|
|
|
syntax.Mul: OIND,
|
|
|
|
|
syntax.And: OADDR,
|
|
|
|
|
|
|
|
|
|
syntax.Not: ONOT,
|
|
|
|
|
syntax.Xor: OCOM,
|
|
|
|
|
syntax.Add: OPLUS,
|
|
|
|
|
syntax.Sub: OMINUS,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) unOp(op syntax.Operator) Op {
|
|
|
|
|
if uint64(op) >= uint64(len(unOps)) || unOps[op] == 0 {
|
|
|
|
|
panic("invalid Operator")
|
|
|
|
|
}
|
|
|
|
|
return unOps[op]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var binOps = [...]Op{
|
|
|
|
|
syntax.OrOr: OOROR,
|
|
|
|
|
syntax.AndAnd: OANDAND,
|
|
|
|
|
|
|
|
|
|
syntax.Eql: OEQ,
|
|
|
|
|
syntax.Neq: ONE,
|
|
|
|
|
syntax.Lss: OLT,
|
|
|
|
|
syntax.Leq: OLE,
|
|
|
|
|
syntax.Gtr: OGT,
|
|
|
|
|
syntax.Geq: OGE,
|
|
|
|
|
|
|
|
|
|
syntax.Add: OADD,
|
|
|
|
|
syntax.Sub: OSUB,
|
|
|
|
|
syntax.Or: OOR,
|
|
|
|
|
syntax.Xor: OXOR,
|
|
|
|
|
|
|
|
|
|
syntax.Mul: OMUL,
|
|
|
|
|
syntax.Div: ODIV,
|
|
|
|
|
syntax.Rem: OMOD,
|
|
|
|
|
syntax.And: OAND,
|
|
|
|
|
syntax.AndNot: OANDNOT,
|
|
|
|
|
syntax.Shl: OLSH,
|
|
|
|
|
syntax.Shr: ORSH,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) binOp(op syntax.Operator) Op {
|
|
|
|
|
if uint64(op) >= uint64(len(binOps)) || binOps[op] == 0 {
|
|
|
|
|
panic("invalid Operator")
|
|
|
|
|
}
|
|
|
|
|
return binOps[op]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) basicLit(lit *syntax.BasicLit) Val {
|
|
|
|
|
// TODO: Don't try to convert if we had syntax errors (conversions may fail).
|
|
|
|
|
// Use dummy values so we can continue to compile. Eventually, use a
|
|
|
|
|
// form of "unknown" literals that are ignored during type-checking so
|
|
|
|
|
// we can continue type-checking w/o spurious follow-up errors.
|
|
|
|
|
switch s := lit.Value; lit.Kind {
|
|
|
|
|
case syntax.IntLit:
|
|
|
|
|
x := new(Mpint)
|
|
|
|
|
x.SetString(s)
|
|
|
|
|
return Val{U: x}
|
|
|
|
|
|
|
|
|
|
case syntax.FloatLit:
|
|
|
|
|
x := newMpflt()
|
|
|
|
|
x.SetString(s)
|
|
|
|
|
return Val{U: x}
|
|
|
|
|
|
|
|
|
|
case syntax.ImagLit:
|
|
|
|
|
x := new(Mpcplx)
|
|
|
|
|
x.Imag.SetString(strings.TrimSuffix(s, "i"))
|
|
|
|
|
return Val{U: x}
|
|
|
|
|
|
|
|
|
|
case syntax.RuneLit:
|
|
|
|
|
var r rune
|
|
|
|
|
if u, err := strconv.Unquote(s); err == nil && len(u) > 0 {
|
|
|
|
|
// Package syntax already reported any errors.
|
|
|
|
|
// Check for them again though because 0 is a
|
|
|
|
|
// better fallback value for invalid rune
|
|
|
|
|
// literals than 0xFFFD.
|
|
|
|
|
if len(u) == 1 {
|
|
|
|
|
r = rune(u[0])
|
|
|
|
|
} else {
|
|
|
|
|
r, _ = utf8.DecodeRuneInString(u)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
x := new(Mpint)
|
|
|
|
|
x.SetInt64(int64(r))
|
|
|
|
|
x.Rune = true
|
|
|
|
|
return Val{U: x}
|
|
|
|
|
|
|
|
|
|
case syntax.StringLit:
|
|
|
|
|
if len(s) > 0 && s[0] == '`' {
|
|
|
|
|
// strip carriage returns from raw string
|
|
|
|
|
s = strings.Replace(s, "\r", "", -1)
|
|
|
|
|
}
|
|
|
|
|
// Ignore errors because package syntax already reported them.
|
|
|
|
|
u, _ := strconv.Unquote(s)
|
|
|
|
|
return Val{U: u}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
panic("unhandled BasicLit kind")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *noder) name(name *syntax.Name) *types.Sym {
|
2016-09-15 15:45:10 +10:00
|
|
|
return lookup(name.Value)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) mkname(name *syntax.Name) *Node {
|
|
|
|
|
// TODO(mdempsky): Set line number?
|
|
|
|
|
return mkname(p.name(name))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) newname(name *syntax.Name) *Node {
|
|
|
|
|
// TODO(mdempsky): Set line number?
|
|
|
|
|
return newname(p.name(name))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) wrapname(n syntax.Node, x *Node) *Node {
|
|
|
|
|
// These nodes do not carry line numbers.
|
|
|
|
|
// Introduce a wrapper node to give them the correct line.
|
|
|
|
|
switch x.Op {
|
2016-10-25 15:43:05 -07:00
|
|
|
case OTYPE, OLITERAL:
|
|
|
|
|
if x.Sym == nil {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
fallthrough
|
|
|
|
|
case ONAME, ONONAME, OPACK:
|
2016-05-06 23:17:29 -07:00
|
|
|
x = p.nod(n, OPAREN, x, nil)
|
2017-02-27 19:56:38 +02:00
|
|
|
x.SetImplicit(true)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
return x
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *noder) nod(orig syntax.Node, op Op, left, right *Node) *Node {
|
2018-10-31 11:38:37 -07:00
|
|
|
return nodl(p.pos(orig), op, left, right)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
func (p *noder) nodSym(orig syntax.Node, op Op, left *Node, sym *types.Sym) *Node {
|
2018-10-31 11:38:37 -07:00
|
|
|
n := nodSym(op, left, sym)
|
|
|
|
|
n.Pos = p.pos(orig)
|
|
|
|
|
return n
|
cmd/compile: replace Field.Nname.Pos with Field.Pos
For struct fields and methods, Field.Nname was only used to store
position information, which means we're allocating an entire ONAME
Node+Name+Param structure just for one field. We can optimize away
these ONAME allocations by instead adding a Field.Pos field.
Unfortunately, we can't get rid of Field.Nname, because it's needed
for function parameters, so Field grows a little bit and now has more
redundant information in those cases. However, that was already the
case (e.g., Field.Sym and Field.Nname.Sym), and it's still a net win
for allocations as demonstrated by the benchmarks below.
Additionally, by moving the ONAME allocation for function parameters
to funcargs, we can avoid allocating them for function parameters that
aren't used in corresponding function bodies (e.g., interface methods,
function-typed variables, and imported functions/methods without
inline bodies).
name old time/op new time/op delta
Template 254ms ± 6% 251ms ± 6% -1.04% (p=0.000 n=487+488)
Unicode 128ms ± 7% 128ms ± 7% ~ (p=0.294 n=482+467)
GoTypes 862ms ± 5% 860ms ± 4% ~ (p=0.075 n=488+471)
Compiler 3.91s ± 4% 3.90s ± 4% -0.39% (p=0.000 n=468+473)
name old user-time/op new user-time/op delta
Template 339ms ±14% 336ms ±14% -1.02% (p=0.001 n=498+494)
Unicode 176ms ±18% 176ms ±25% ~ (p=0.940 n=491+499)
GoTypes 1.13s ± 8% 1.13s ± 9% ~ (p=0.157 n=496+493)
Compiler 5.24s ± 6% 5.21s ± 6% -0.57% (p=0.000 n=485+489)
name old alloc/op new alloc/op delta
Template 38.3MB ± 0% 37.3MB ± 0% -2.58% (p=0.000 n=499+497)
Unicode 29.1MB ± 0% 29.1MB ± 0% -0.03% (p=0.000 n=500+493)
GoTypes 116MB ± 0% 115MB ± 0% -0.65% (p=0.000 n=498+499)
Compiler 492MB ± 0% 487MB ± 0% -1.00% (p=0.000 n=497+498)
name old allocs/op new allocs/op delta
Template 364k ± 0% 360k ± 0% -1.15% (p=0.000 n=499+499)
Unicode 336k ± 0% 336k ± 0% -0.01% (p=0.000 n=500+493)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.30% (p=0.000 n=499+499)
Compiler 4.54M ± 0% 4.51M ± 0% -0.58% (p=0.000 n=494+495)
Passes toolstash-check -gcflags=-dwarf=false. Changes DWARF output
because position information is now tracked more precisely for
function parameters.
Change-Id: Ib8077d70d564cc448c5e4290baceab3a4396d712
Reviewed-on: https://go-review.googlesource.com/108217
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-18 22:57:10 -07:00
|
|
|
}
|
|
|
|
|
|
2018-10-31 11:38:37 -07:00
|
|
|
func (p *noder) pos(n syntax.Node) src.XPos {
|
|
|
|
|
// TODO(gri): orig.Pos() should always be known - fix package syntax
|
|
|
|
|
xpos := lineno
|
|
|
|
|
if pos := n.Pos(); pos.IsKnown() {
|
|
|
|
|
xpos = p.makeXPos(pos)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
2018-10-31 11:38:37 -07:00
|
|
|
return xpos
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
2018-10-31 11:38:37 -07:00
|
|
|
func (p *noder) setlineno(n syntax.Node) {
|
|
|
|
|
if n != nil {
|
|
|
|
|
lineno = p.pos(n)
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 15:17:32 -08:00
|
|
|
// error is called concurrently if files are parsed concurrently.
|
2016-11-08 16:01:56 -08:00
|
|
|
func (p *noder) error(err error) {
|
2017-01-11 15:48:30 -08:00
|
|
|
p.err <- err.(syntax.Error)
|
2016-08-30 16:31:53 -07:00
|
|
|
}
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2017-06-06 13:23:59 -07:00
|
|
|
// pragmas that are allowed in the std lib, but don't have
|
|
|
|
|
// a syntax.Pragma value (see lex.go) associated with them.
|
|
|
|
|
var allowedStdPragmas = map[string]bool{
|
|
|
|
|
"go:cgo_export_static": true,
|
|
|
|
|
"go:cgo_export_dynamic": true,
|
|
|
|
|
"go:cgo_import_static": true,
|
|
|
|
|
"go:cgo_import_dynamic": true,
|
|
|
|
|
"go:cgo_ldflag": true,
|
|
|
|
|
"go:cgo_dynamic_linker": true,
|
|
|
|
|
"go:generate": true,
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 15:17:32 -08:00
|
|
|
// pragma is called concurrently if files are parsed concurrently.
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
func (p *noder) pragma(pos syntax.Pos, text string) syntax.Pragma {
|
2016-08-30 16:31:53 -07:00
|
|
|
switch {
|
|
|
|
|
case strings.HasPrefix(text, "line "):
|
2016-12-09 17:15:05 -08:00
|
|
|
// line directives are handled by syntax package
|
|
|
|
|
panic("unreachable")
|
2016-08-30 16:31:53 -07:00
|
|
|
|
|
|
|
|
case strings.HasPrefix(text, "go:linkname "):
|
|
|
|
|
f := strings.Fields(text)
|
|
|
|
|
if len(f) != 3 {
|
2016-12-02 10:44:34 -08:00
|
|
|
p.error(syntax.Error{Pos: pos, Msg: "usage: //go:linkname localname linkname"})
|
2016-08-30 16:31:53 -07:00
|
|
|
break
|
|
|
|
|
}
|
2017-01-11 15:48:30 -08:00
|
|
|
p.linknames = append(p.linknames, linkname{pos, f[1], f[2]})
|
2016-05-06 23:17:29 -07:00
|
|
|
|
2018-02-14 07:42:40 -08:00
|
|
|
case strings.HasPrefix(text, "go:cgo_import_dynamic "):
|
|
|
|
|
// This is permitted for general use because Solaris
|
|
|
|
|
// code relies on it in golang.org/x/sys/unix and others.
|
|
|
|
|
fields := pragmaFields(text)
|
|
|
|
|
if len(fields) >= 4 {
|
|
|
|
|
lib := strings.Trim(fields[3], `"`)
|
|
|
|
|
if lib != "" && !safeArg(lib) && !isCgoGeneratedFile(pos) {
|
|
|
|
|
p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("invalid library name %q in cgo_import_dynamic directive", lib)})
|
|
|
|
|
}
|
2018-04-11 15:37:16 -07:00
|
|
|
p.pragcgo(pos, text)
|
2018-02-14 07:42:40 -08:00
|
|
|
return pragmaValue("go:cgo_import_dynamic")
|
|
|
|
|
}
|
|
|
|
|
fallthrough
|
2016-08-30 16:31:53 -07:00
|
|
|
case strings.HasPrefix(text, "go:cgo_"):
|
2018-02-14 07:42:40 -08:00
|
|
|
// For security, we disallow //go:cgo_* directives other
|
|
|
|
|
// than cgo_import_dynamic outside cgo-generated files.
|
2018-02-01 14:07:21 -05:00
|
|
|
// Exception: they are allowed in the standard library, for runtime and syscall.
|
|
|
|
|
if !isCgoGeneratedFile(pos) && !compiling_std {
|
|
|
|
|
p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("//%s only allowed in cgo-generated code", text)})
|
|
|
|
|
}
|
2018-04-11 15:37:16 -07:00
|
|
|
p.pragcgo(pos, text)
|
2016-08-30 16:31:53 -07:00
|
|
|
fallthrough // because of //go:cgo_unsafe_args
|
|
|
|
|
default:
|
2016-05-06 23:17:29 -07:00
|
|
|
verb := text
|
2017-10-05 15:49:32 +02:00
|
|
|
if i := strings.Index(text, " "); i >= 0 {
|
2016-05-06 23:17:29 -07:00
|
|
|
verb = verb[:i]
|
|
|
|
|
}
|
2017-01-11 15:48:30 -08:00
|
|
|
prag := pragmaValue(verb)
|
|
|
|
|
const runtimePragmas = Systemstack | Nowritebarrier | Nowritebarrierrec | Yeswritebarrierrec
|
|
|
|
|
if !compiling_runtime && prag&runtimePragmas != 0 {
|
2017-02-01 15:17:32 -08:00
|
|
|
p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("//%s only allowed in runtime", verb)})
|
2017-01-11 15:48:30 -08:00
|
|
|
}
|
2017-06-06 13:23:59 -07:00
|
|
|
if prag == 0 && !allowedStdPragmas[verb] && compiling_std {
|
|
|
|
|
p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("//%s is not allowed in the standard library", verb)})
|
|
|
|
|
}
|
2017-01-11 15:48:30 -08:00
|
|
|
return prag
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-30 16:31:53 -07:00
|
|
|
return 0
|
2016-05-06 23:17:29 -07:00
|
|
|
}
|
2016-10-31 16:42:30 -07:00
|
|
|
|
2018-02-01 14:07:21 -05:00
|
|
|
// isCgoGeneratedFile reports whether pos is in a file
|
|
|
|
|
// generated by cgo, which is to say a file with name
|
|
|
|
|
// beginning with "_cgo_". Such files are allowed to
|
|
|
|
|
// contain cgo directives, and for security reasons
|
|
|
|
|
// (primarily misuse of linker flags), other files are not.
|
|
|
|
|
// See golang.org/issue/23672.
|
cmd/compile/internal/syntax: remove dependency on cmd/internal/src
For dependency reasons, the data structure implementing source
positions in the compiler is in cmd/internal/src. It contains
highly compiler specific details (e.g. inlining index).
This change introduces a parallel but simpler position
representation, defined in the syntax package, which removes
that package's dependency on cmd/internal/src, and also removes
the need to deal with certain filename-specific operations
(defined by the needs of the compiler) in the syntax package.
As a result, the syntax package becomes again a compiler-
independent, stand-alone package that at some point might
replace (or augment) the existing top-level go/* syntax-related
packages.
Additionally, line directives that update column numbers
are now correctly tracked through the syntax package, with
additional tests added. (The respective changes also need to
be made in cmd/internal/src; i.e., the compiler accepts but
still ignores column numbers in line directives.)
This change comes at the cost of a new position translation
step, but that step is cheap because it only needs to do real
work if the position base changed (i.e., if there is a new file,
or new line directive).
There is no noticeable impact on overall compiler performance
measured with `compilebench -count 5 -alloc`:
name old time/op new time/op delta
Template 220ms ± 8% 228ms ±18% ~ (p=0.548 n=5+5)
Unicode 119ms ±11% 113ms ± 5% ~ (p=0.056 n=5+5)
GoTypes 684ms ± 6% 677ms ± 3% ~ (p=0.841 n=5+5)
Compiler 3.19s ± 7% 3.01s ± 1% ~ (p=0.095 n=5+5)
SSA 7.92s ± 8% 7.79s ± 1% ~ (p=0.690 n=5+5)
Flate 141ms ± 7% 139ms ± 4% ~ (p=0.548 n=5+5)
GoParser 173ms ±12% 171ms ± 4% ~ (p=1.000 n=5+5)
Reflect 417ms ± 5% 411ms ± 3% ~ (p=0.548 n=5+5)
Tar 205ms ± 5% 198ms ± 2% ~ (p=0.690 n=5+5)
XML 232ms ± 4% 229ms ± 4% ~ (p=0.690 n=5+5)
StdCmd 28.7s ± 5% 28.2s ± 2% ~ (p=0.421 n=5+5)
name old user-time/op new user-time/op delta
Template 269ms ± 4% 265ms ± 5% ~ (p=0.421 n=5+5)
Unicode 153ms ± 7% 149ms ± 3% ~ (p=0.841 n=5+5)
GoTypes 850ms ± 7% 862ms ± 4% ~ (p=0.841 n=5+5)
Compiler 4.01s ± 5% 3.86s ± 0% ~ (p=0.190 n=5+4)
SSA 10.9s ± 4% 10.8s ± 2% ~ (p=0.548 n=5+5)
Flate 166ms ± 7% 167ms ± 6% ~ (p=1.000 n=5+5)
GoParser 204ms ± 8% 206ms ± 7% ~ (p=0.841 n=5+5)
Reflect 514ms ± 5% 508ms ± 4% ~ (p=0.548 n=5+5)
Tar 245ms ± 6% 244ms ± 3% ~ (p=0.690 n=5+5)
XML 280ms ± 4% 278ms ± 4% ~ (p=0.841 n=5+5)
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.9MB ± 0% ~ (p=0.841 n=5+5)
Unicode 28.8MB ± 0% 28.8MB ± 0% ~ (p=0.841 n=5+5)
GoTypes 113MB ± 0% 113MB ± 0% ~ (p=0.151 n=5+5)
Compiler 468MB ± 0% 468MB ± 0% -0.01% (p=0.032 n=5+5)
SSA 1.50GB ± 0% 1.50GB ± 0% ~ (p=0.548 n=5+5)
Flate 24.4MB ± 0% 24.4MB ± 0% ~ (p=1.000 n=5+5)
GoParser 30.7MB ± 0% 30.7MB ± 0% ~ (p=1.000 n=5+5)
Reflect 76.5MB ± 0% 76.5MB ± 0% ~ (p=0.548 n=5+5)
Tar 38.9MB ± 0% 38.9MB ± 0% ~ (p=0.222 n=5+5)
XML 41.6MB ± 0% 41.6MB ± 0% ~ (p=0.548 n=5+5)
name old allocs/op new allocs/op delta
Template 382k ± 0% 382k ± 0% +0.01% (p=0.008 n=5+5)
Unicode 343k ± 0% 343k ± 0% ~ (p=0.841 n=5+5)
GoTypes 1.19M ± 0% 1.19M ± 0% +0.01% (p=0.008 n=5+5)
Compiler 4.53M ± 0% 4.53M ± 0% +0.03% (p=0.008 n=5+5)
SSA 12.4M ± 0% 12.4M ± 0% +0.00% (p=0.008 n=5+5)
Flate 235k ± 0% 235k ± 0% ~ (p=0.079 n=5+5)
GoParser 318k ± 0% 318k ± 0% ~ (p=0.730 n=5+5)
Reflect 978k ± 0% 978k ± 0% ~ (p=1.000 n=5+5)
Tar 393k ± 0% 393k ± 0% ~ (p=0.056 n=5+5)
XML 405k ± 0% 405k ± 0% ~ (p=0.548 n=5+5)
name old text-bytes new text-bytes delta
HelloSize 672kB ± 0% 672kB ± 0% ~ (all equal)
CmdGoSize 7.12MB ± 0% 7.12MB ± 0% ~ (all equal)
name old data-bytes new data-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
CmdGoSize 390kB ± 0% 390kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.07MB ± 0% 1.07MB ± 0% ~ (all equal)
CmdGoSize 11.2MB ± 0% 11.2MB ± 0% ~ (all equal)
Passes toolstash compare.
For #22662.
Change-Id: I19edb53dd9675af57f7122cb7dba2a6d8bdcc3da
Reviewed-on: https://go-review.googlesource.com/94515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-02 16:58:37 -08:00
|
|
|
func isCgoGeneratedFile(pos syntax.Pos) bool {
|
|
|
|
|
return strings.HasPrefix(filepath.Base(filepath.Clean(fileh(pos.Base().Filename()))), "_cgo_")
|
2018-02-01 14:07:21 -05:00
|
|
|
}
|
|
|
|
|
|
2018-02-14 07:42:40 -08:00
|
|
|
// safeArg reports whether arg is a "safe" command-line argument,
|
|
|
|
|
// meaning that when it appears in a command-line, it probably
|
|
|
|
|
// doesn't have some special meaning other than its own name.
|
|
|
|
|
// This is copied from SafeArg in cmd/go/internal/load/pkg.go.
|
|
|
|
|
func safeArg(name string) bool {
|
|
|
|
|
if name == "" {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
c := name[0]
|
|
|
|
|
return '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '.' || c == '_' || c == '/' || c >= utf8.RuneSelf
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func mkname(sym *types.Sym) *Node {
|
2016-10-31 16:42:30 -07:00
|
|
|
n := oldname(sym)
|
|
|
|
|
if n.Name != nil && n.Name.Pack != nil {
|
2017-04-27 15:17:57 -07:00
|
|
|
n.Name.Pack.Name.SetUsed(true)
|
2016-10-31 16:42:30 -07:00
|
|
|
}
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func unparen(x *Node) *Node {
|
|
|
|
|
for x.Op == OPAREN {
|
|
|
|
|
x = x.Left
|
|
|
|
|
}
|
|
|
|
|
return x
|
|
|
|
|
}
|