2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2009 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 (
|
|
|
|
|
"cmd/internal/obj"
|
|
|
|
|
"fmt"
|
2016-03-10 23:59:59 -08:00
|
|
|
"sort"
|
2015-02-13 14:40:36 -05:00
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
func dflag() bool {
|
|
|
|
|
if Debug['d'] == 0 {
|
|
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if Debug['y'] != 0 {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if incannedimport != 0 {
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// declaration stack & operations
|
2015-02-13 14:40:36 -05:00
|
|
|
func dcopy(a *Sym, b *Sym) {
|
|
|
|
|
a.Pkg = b.Pkg
|
|
|
|
|
a.Name = b.Name
|
|
|
|
|
a.Def = b.Def
|
|
|
|
|
a.Block = b.Block
|
|
|
|
|
a.Lastlineno = b.Lastlineno
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func push() *Sym {
|
2015-02-23 16:07:24 -05:00
|
|
|
d := new(Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
d.Lastlineno = lineno
|
|
|
|
|
d.Link = dclstack
|
|
|
|
|
dclstack = d
|
|
|
|
|
return d
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func pushdcl(s *Sym) *Sym {
|
2015-02-23 16:07:24 -05:00
|
|
|
d := push()
|
2015-02-13 14:40:36 -05:00
|
|
|
dcopy(d, s)
|
2015-02-17 22:13:49 -05:00
|
|
|
if dflag() {
|
2016-03-02 11:30:29 -08:00
|
|
|
fmt.Printf("\t%v push %v %p\n", linestr(lineno), s, s.Def)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
return d
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func popdcl() {
|
2016-03-02 11:01:25 -08:00
|
|
|
d := dclstack
|
|
|
|
|
for ; d != nil && d.Name != ""; d = d.Link {
|
|
|
|
|
s := Pkglookup(d.Name, d.Pkg)
|
|
|
|
|
lno := s.Lastlineno
|
2015-02-13 14:40:36 -05:00
|
|
|
dcopy(s, d)
|
2016-03-02 11:01:25 -08:00
|
|
|
d.Lastlineno = lno
|
2015-02-17 22:13:49 -05:00
|
|
|
if dflag() {
|
2016-03-02 11:30:29 -08:00
|
|
|
fmt.Printf("\t%v pop %v %p\n", linestr(lineno), s, s.Def)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d == nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("popdcl: no mark")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-02 11:01:25 -08:00
|
|
|
|
|
|
|
|
dclstack = d.Link // pop mark
|
2015-02-13 14:40:36 -05:00
|
|
|
block = d.Block
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func markdcl() {
|
2015-02-23 16:07:24 -05:00
|
|
|
d := push()
|
2015-02-13 14:40:36 -05:00
|
|
|
d.Name = "" // used as a mark in fifo
|
|
|
|
|
d.Block = block
|
|
|
|
|
|
|
|
|
|
blockgen++
|
|
|
|
|
block = blockgen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func dumpdcl(st string) {
|
2015-02-23 16:07:24 -05:00
|
|
|
i := 0
|
|
|
|
|
for d := dclstack; d != nil; d = d.Link {
|
2015-02-13 14:40:36 -05:00
|
|
|
i++
|
|
|
|
|
fmt.Printf(" %.2d %p", i, d)
|
|
|
|
|
if d.Name == "" {
|
|
|
|
|
fmt.Printf("\n")
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf(" '%s'", d.Name)
|
2016-03-02 11:01:25 -08:00
|
|
|
fmt.Printf(" %v\n", Pkglookup(d.Name, d.Pkg))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testdclstack() {
|
2015-02-23 16:07:24 -05:00
|
|
|
for d := dclstack; d != nil; d = d.Link {
|
2015-02-13 14:40:36 -05:00
|
|
|
if d.Name == "" {
|
|
|
|
|
if nerrors != 0 {
|
|
|
|
|
errorexit()
|
|
|
|
|
}
|
|
|
|
|
Yyerror("mark left on the stack")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func redeclare(s *Sym, where string) {
|
|
|
|
|
if s.Lastlineno == 0 {
|
2015-03-02 16:03:26 -05:00
|
|
|
var tmp string
|
2015-02-13 14:40:36 -05:00
|
|
|
if s.Origpkg != nil {
|
|
|
|
|
tmp = s.Origpkg.Path
|
|
|
|
|
} else {
|
|
|
|
|
tmp = s.Pkg.Path
|
|
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
pkgstr := tmp
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("%v redeclared %s\n"+"\tprevious declaration during import %q", s, where, pkgstr)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2016-03-02 11:01:25 -08:00
|
|
|
line1 := lineno
|
|
|
|
|
line2 := s.Lastlineno
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// When an import and a declaration collide in separate files,
|
|
|
|
|
// present the import as the "redeclared", because the declaration
|
|
|
|
|
// is visible where the import is, but not vice versa.
|
|
|
|
|
// See issue 4510.
|
|
|
|
|
if s.Def == nil {
|
|
|
|
|
line2 = line1
|
2016-03-02 11:01:25 -08:00
|
|
|
line1 = s.Lastlineno
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 11:30:29 -08:00
|
|
|
yyerrorl(line1, "%v redeclared %s\n"+"\tprevious declaration at %v", s, where, linestr(line2))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var vargen int
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// declare individual names - var, typ, const
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
var declare_typegen int
|
|
|
|
|
|
2015-10-26 14:57:36 -07:00
|
|
|
func declare(n *Node, ctxt Class) {
|
2015-02-13 14:40:36 -05:00
|
|
|
if ctxt == PDISCARD {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if isblank(n) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 23:08:39 -04:00
|
|
|
if n.Name == nil {
|
|
|
|
|
// named OLITERAL needs Name; most OLITERALs don't.
|
|
|
|
|
n.Name = new(Name)
|
|
|
|
|
}
|
2016-03-02 11:01:25 -08:00
|
|
|
n.Lineno = lineno
|
2015-02-23 16:07:24 -05:00
|
|
|
s := n.Sym
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-01 23:21:55 +00:00
|
|
|
// kludgy: typecheckok means we're past parsing. Eg genwrapper may declare out of package names later.
|
2015-08-30 23:56:40 +02:00
|
|
|
if importpkg == nil && !typecheckok && s.Pkg != localpkg {
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("cannot declare name %v", s)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ctxt == PEXTERN && s.Name == "init" {
|
2015-05-13 19:05:50 -04:00
|
|
|
Yyerror("cannot declare init - must be func")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
gen := 0
|
2015-02-13 14:40:36 -05:00
|
|
|
if ctxt == PEXTERN {
|
2015-09-10 15:57:39 +10:00
|
|
|
externdcl = append(externdcl, n)
|
2015-02-17 22:13:49 -05:00
|
|
|
if dflag() {
|
2016-03-02 11:30:29 -08:00
|
|
|
fmt.Printf("\t%v global decl %v %p\n", linestr(lineno), s, n)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if Curfn == nil && ctxt == PAUTO {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("automatic outside function")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if Curfn != nil {
|
2016-02-25 10:35:19 -08:00
|
|
|
Curfn.Func.Dcl = append(Curfn.Func.Dcl, n)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if n.Op == OTYPE {
|
|
|
|
|
declare_typegen++
|
|
|
|
|
gen = declare_typegen
|
|
|
|
|
} else if n.Op == ONAME && ctxt == PAUTO && !strings.Contains(s.Name, "·") {
|
|
|
|
|
vargen++
|
|
|
|
|
gen = vargen
|
|
|
|
|
}
|
|
|
|
|
pushdcl(s)
|
2015-05-27 07:31:56 -04:00
|
|
|
n.Name.Curfn = Curfn
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ctxt == PAUTO {
|
|
|
|
|
n.Xoffset = 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if s.Block == block {
|
|
|
|
|
// functype will print errors about duplicate function arguments.
|
|
|
|
|
// Don't repeat the error here.
|
|
|
|
|
if ctxt != PPARAM && ctxt != PPARAMOUT {
|
|
|
|
|
redeclare(s, "in this block")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.Block = block
|
2016-03-02 11:01:25 -08:00
|
|
|
s.Lastlineno = lineno
|
2015-02-13 14:40:36 -05:00
|
|
|
s.Def = n
|
2015-05-26 23:56:14 -04:00
|
|
|
n.Name.Vargen = int32(gen)
|
2015-05-27 00:44:05 -04:00
|
|
|
n.Name.Funcdepth = Funcdepth
|
2015-10-26 14:57:36 -07:00
|
|
|
n.Class = ctxt
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
autoexport(n, ctxt)
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 14:57:36 -07:00
|
|
|
func addvar(n *Node, t *Type, ctxt Class) {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n == nil || n.Sym == nil || (n.Op != ONAME && n.Op != ONONAME) || t == nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("addvar: n=%v t=%v nil", n, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Op = ONAME
|
|
|
|
|
declare(n, ctxt)
|
|
|
|
|
n.Type = t
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// declare variables from grammar
|
|
|
|
|
// new_name_list (type | [type] = expr_list)
|
2016-03-09 20:29:21 -08:00
|
|
|
func variter(vl []*Node, t *Node, el []*Node) []*Node {
|
|
|
|
|
var init []*Node
|
|
|
|
|
doexpr := len(el) > 0
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-09 20:29:21 -08:00
|
|
|
if len(el) == 1 && len(vl) > 1 {
|
|
|
|
|
e := el[0]
|
2015-02-23 16:07:24 -05:00
|
|
|
as2 := Nod(OAS2, nil, nil)
|
2016-03-09 20:29:21 -08:00
|
|
|
as2.List.Set(vl)
|
2016-03-10 10:13:42 -08:00
|
|
|
as2.Rlist.Set1(e)
|
2016-03-09 20:29:21 -08:00
|
|
|
for _, v := range vl {
|
2015-02-13 14:40:36 -05:00
|
|
|
v.Op = ONAME
|
|
|
|
|
declare(v, dclcontext)
|
2015-05-27 00:44:05 -04:00
|
|
|
v.Name.Param.Ntype = t
|
2015-05-26 22:19:27 -04:00
|
|
|
v.Name.Defn = as2
|
2015-02-13 14:40:36 -05:00
|
|
|
if Funcdepth > 0 {
|
2016-03-09 20:29:21 -08:00
|
|
|
init = append(init, Nod(ODCL, v, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 20:29:21 -08:00
|
|
|
return append(init, as2)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-09 20:29:21 -08:00
|
|
|
for _, v := range vl {
|
|
|
|
|
var e *Node
|
2015-02-17 22:13:49 -05:00
|
|
|
if doexpr {
|
2016-03-09 20:29:21 -08:00
|
|
|
if len(el) == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("missing expression in var declaration")
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 20:29:21 -08:00
|
|
|
e = el[0]
|
|
|
|
|
el = el[1:]
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
|
|
|
|
e = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v.Op = ONAME
|
|
|
|
|
declare(v, dclcontext)
|
2015-05-27 00:44:05 -04:00
|
|
|
v.Name.Param.Ntype = t
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
if e != nil || Funcdepth > 0 || isblank(v) {
|
|
|
|
|
if Funcdepth > 0 {
|
2016-03-09 20:29:21 -08:00
|
|
|
init = append(init, Nod(ODCL, v, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
e = Nod(OAS, v, e)
|
2016-03-09 20:29:21 -08:00
|
|
|
init = append(init, e)
|
2015-02-13 14:40:36 -05:00
|
|
|
if e.Right != nil {
|
2015-05-26 22:19:27 -04:00
|
|
|
v.Name.Defn = e
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 20:29:21 -08:00
|
|
|
if len(el) != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("extra expression in var declaration")
|
|
|
|
|
}
|
|
|
|
|
return init
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// declare constants from grammar
|
|
|
|
|
// new_name_list [[type] = expr_list]
|
2016-03-09 20:29:21 -08:00
|
|
|
func constiter(vl []*Node, t *Node, cl []*Node) []*Node {
|
2015-05-22 22:01:01 -04:00
|
|
|
lno := int32(0) // default is to leave line number alone in listtreecopy
|
2016-03-09 20:29:21 -08:00
|
|
|
if len(cl) == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
if t != nil {
|
|
|
|
|
Yyerror("const declaration cannot have type without expression")
|
|
|
|
|
}
|
|
|
|
|
cl = lastconst
|
|
|
|
|
t = lasttype
|
2016-03-09 20:29:21 -08:00
|
|
|
lno = vl[0].Lineno
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
|
|
|
|
lastconst = cl
|
|
|
|
|
lasttype = t
|
|
|
|
|
}
|
2016-03-09 20:29:21 -08:00
|
|
|
clcopy := listtreecopy(cl, lno)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
var c *Node
|
2016-03-09 20:29:21 -08:00
|
|
|
var vv []*Node
|
|
|
|
|
for _, v := range vl {
|
2016-03-04 17:28:07 -08:00
|
|
|
if len(clcopy) == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("missing value in const declaration")
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 17:28:07 -08:00
|
|
|
c = clcopy[0]
|
|
|
|
|
clcopy = clcopy[1:]
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
v.Op = OLITERAL
|
|
|
|
|
declare(v, dclcontext)
|
|
|
|
|
|
2015-05-27 00:44:05 -04:00
|
|
|
v.Name.Param.Ntype = t
|
2015-05-26 22:19:27 -04:00
|
|
|
v.Name.Defn = c
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-09 20:29:21 -08:00
|
|
|
vv = append(vv, Nod(ODCLCONST, v, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-04 17:28:07 -08:00
|
|
|
if len(clcopy) != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("extra expression in const declaration")
|
|
|
|
|
}
|
|
|
|
|
iota_ += 1
|
|
|
|
|
return vv
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// this generates a new name node,
|
|
|
|
|
// typically for labels or other one-off names.
|
2015-02-13 14:40:36 -05:00
|
|
|
func newname(s *Sym) *Node {
|
|
|
|
|
if s == nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("newname nil")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
n := Nod(ONAME, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Sym = s
|
|
|
|
|
n.Type = nil
|
2015-04-02 19:58:37 -07:00
|
|
|
n.Addable = true
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Ullman = 1
|
|
|
|
|
n.Xoffset = 0
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 21:37:13 -07:00
|
|
|
// newfuncname generates a new name node for a function or method.
|
|
|
|
|
// TODO(rsc): Use an ODCLFUNC node instead. See comment in CL 7360.
|
|
|
|
|
func newfuncname(s *Sym) *Node {
|
|
|
|
|
n := newname(s)
|
|
|
|
|
n.Func = new(Func)
|
2015-05-27 07:31:56 -04:00
|
|
|
n.Func.FCurfn = Curfn
|
2015-03-10 21:37:13 -07:00
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// this generates a new name node for a name
|
|
|
|
|
// being declared.
|
2015-02-13 14:40:36 -05:00
|
|
|
func dclname(s *Sym) *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := newname(s)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Op = ONONAME // caller will correct it
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func typenod(t *Type) *Node {
|
|
|
|
|
// if we copied another type with *t = *u
|
|
|
|
|
// then t->nod might be out of date, so
|
|
|
|
|
// check t->nod->type too
|
|
|
|
|
if t.Nod == nil || t.Nod.Type != t {
|
|
|
|
|
t.Nod = Nod(OTYPE, nil, nil)
|
|
|
|
|
t.Nod.Type = t
|
|
|
|
|
t.Nod.Sym = t.Sym
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return t.Nod
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// this will return an old name
|
|
|
|
|
// that has already been pushed on the
|
|
|
|
|
// declaration list. a diagnostic is
|
|
|
|
|
// generated if no name has been defined.
|
2015-02-13 14:40:36 -05:00
|
|
|
func oldname(s *Sym) *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := s.Def
|
2015-02-13 14:40:36 -05:00
|
|
|
if n == nil {
|
|
|
|
|
// maybe a top-level name will come along
|
|
|
|
|
// to give this a definition later.
|
|
|
|
|
// walkdef will check s->def again once
|
|
|
|
|
// all the input source has been processed.
|
|
|
|
|
n = newname(s)
|
|
|
|
|
n.Op = ONONAME
|
2015-05-26 23:56:14 -04:00
|
|
|
n.Name.Iota = iota_ // save current iota value in const declarations
|
2016-03-02 17:40:18 -08:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 00:44:05 -04:00
|
|
|
if Curfn != nil && n.Op == ONAME && n.Name.Funcdepth > 0 && n.Name.Funcdepth != Funcdepth {
|
2015-02-13 14:40:36 -05:00
|
|
|
// inner func is referring to var in outer func.
|
|
|
|
|
//
|
|
|
|
|
// TODO(rsc): If there is an outer variable x and we
|
|
|
|
|
// are parsing x := 5 inside the closure, until we get to
|
|
|
|
|
// the := it looks like a reference to the outer x so we'll
|
|
|
|
|
// make x a closure variable unnecessarily.
|
2015-05-27 00:44:05 -04:00
|
|
|
if n.Name.Param.Closure == nil || n.Name.Param.Closure.Name.Funcdepth != Funcdepth {
|
2015-02-13 14:40:36 -05:00
|
|
|
// create new closure var.
|
2015-02-23 16:07:24 -05:00
|
|
|
c := Nod(ONAME, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
c.Sym = s
|
|
|
|
|
c.Class = PPARAMREF
|
|
|
|
|
c.Isddd = n.Isddd
|
2015-05-26 22:19:27 -04:00
|
|
|
c.Name.Defn = n
|
2015-04-02 19:58:37 -07:00
|
|
|
c.Addable = false
|
2015-02-13 14:40:36 -05:00
|
|
|
c.Ullman = 2
|
2015-05-27 00:44:05 -04:00
|
|
|
c.Name.Funcdepth = Funcdepth
|
|
|
|
|
c.Name.Param.Outer = n.Name.Param.Closure
|
|
|
|
|
n.Name.Param.Closure = c
|
|
|
|
|
c.Name.Param.Closure = n
|
2015-02-13 14:40:36 -05:00
|
|
|
c.Xoffset = 0
|
2016-02-26 17:03:58 -08:00
|
|
|
Curfn.Func.Cvars.Append(c)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return ref to closure var, not original
|
2015-05-27 00:44:05 -04:00
|
|
|
return n.Name.Param.Closure
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// := declarations
|
2015-02-17 22:13:49 -05:00
|
|
|
func colasname(n *Node) bool {
|
2015-02-13 14:40:36 -05:00
|
|
|
switch n.Op {
|
|
|
|
|
case ONAME,
|
|
|
|
|
ONONAME,
|
|
|
|
|
OPACK,
|
|
|
|
|
OTYPE,
|
|
|
|
|
OLITERAL:
|
2015-02-17 22:13:49 -05:00
|
|
|
return n.Sym != nil
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-25 15:34:55 -07:00
|
|
|
func colasdefn(left []*Node, defn *Node) {
|
|
|
|
|
for _, n := range left {
|
|
|
|
|
if n.Sym != nil {
|
|
|
|
|
n.Sym.Flags |= SymUniq
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-25 15:34:55 -07:00
|
|
|
var nnew, nerr int
|
|
|
|
|
for i, n := range left {
|
2015-02-13 14:40:36 -05:00
|
|
|
if isblank(n) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2015-02-17 22:13:49 -05:00
|
|
|
if !colasname(n) {
|
2016-03-02 11:01:25 -08:00
|
|
|
yyerrorl(defn.Lineno, "non-name %v on left side of :=", n)
|
2015-02-13 14:40:36 -05:00
|
|
|
nerr++
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if n.Sym.Flags&SymUniq == 0 {
|
2016-03-02 11:01:25 -08:00
|
|
|
yyerrorl(defn.Lineno, "%v repeated on left side of :=", n.Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Diag++
|
|
|
|
|
nerr++
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Sym.Flags &^= SymUniq
|
|
|
|
|
if n.Sym.Block == block {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nnew++
|
|
|
|
|
n = newname(n.Sym)
|
|
|
|
|
declare(n, dclcontext)
|
2015-05-26 22:19:27 -04:00
|
|
|
n.Name.Defn = defn
|
2016-03-08 15:10:26 -08:00
|
|
|
defn.Ninit.Append(Nod(ODCL, n, nil))
|
2016-03-25 15:34:55 -07:00
|
|
|
left[i] = n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if nnew == 0 && nerr == 0 {
|
2016-03-02 11:01:25 -08:00
|
|
|
yyerrorl(defn.Lineno, "no new variables on left side of :=")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-25 15:34:55 -07:00
|
|
|
func colas(left, right []*Node, lno int32) *Node {
|
|
|
|
|
n := Nod(OAS, nil, nil) // assume common case
|
|
|
|
|
n.Colas = true
|
|
|
|
|
n.Lineno = lno // set before calling colasdefn for correct error line
|
|
|
|
|
colasdefn(left, n) // modifies left, call before using left[0] in common case
|
|
|
|
|
if len(left) == 1 && len(right) == 1 {
|
|
|
|
|
// common case
|
|
|
|
|
n.Left = left[0]
|
|
|
|
|
n.Right = right[0]
|
|
|
|
|
} else {
|
|
|
|
|
n.Op = OAS2
|
|
|
|
|
n.List.Set(left)
|
|
|
|
|
n.Rlist.Set(right)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-25 15:34:55 -07:00
|
|
|
return n
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// declare the arguments in an
|
|
|
|
|
// interface field declaration.
|
2015-02-13 14:40:36 -05:00
|
|
|
func ifacedcl(n *Node) {
|
|
|
|
|
if n.Op != ODCLFIELD || n.Right == nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("ifacedcl")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if isblank(n.Left) {
|
|
|
|
|
Yyerror("methods must have a unique non-blank name")
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 21:37:13 -07:00
|
|
|
n.Func = new(Func)
|
2015-05-27 07:31:56 -04:00
|
|
|
n.Func.FCurfn = Curfn
|
2015-02-13 14:40:36 -05:00
|
|
|
dclcontext = PPARAM
|
|
|
|
|
markdcl()
|
|
|
|
|
Funcdepth++
|
2015-05-27 00:44:05 -04:00
|
|
|
n.Func.Outer = Curfn
|
2015-02-13 14:40:36 -05:00
|
|
|
Curfn = n
|
|
|
|
|
funcargs(n.Right)
|
|
|
|
|
|
|
|
|
|
// funcbody is normally called after the parser has
|
|
|
|
|
// seen the body of a function but since an interface
|
|
|
|
|
// field declaration does not have a body, we must
|
|
|
|
|
// call it now to pop the current declaration context.
|
|
|
|
|
dclcontext = PAUTO
|
|
|
|
|
|
|
|
|
|
funcbody(n)
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// declare the function proper
|
|
|
|
|
// and declare the arguments.
|
|
|
|
|
// called in extern-declaration context
|
|
|
|
|
// returns in auto-declaration context.
|
2015-02-13 14:40:36 -05:00
|
|
|
func funchdr(n *Node) {
|
|
|
|
|
// change the declaration context from extern to auto
|
|
|
|
|
if Funcdepth == 0 && dclcontext != PEXTERN {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("funchdr: dclcontext")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-07-15 11:31:30 +12:00
|
|
|
if importpkg == nil && n.Func.Nname != nil {
|
|
|
|
|
makefuncsym(n.Func.Nname.Sym)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
dclcontext = PAUTO
|
|
|
|
|
markdcl()
|
|
|
|
|
Funcdepth++
|
|
|
|
|
|
2015-05-27 00:44:05 -04:00
|
|
|
n.Func.Outer = Curfn
|
2015-02-13 14:40:36 -05:00
|
|
|
Curfn = n
|
|
|
|
|
|
2015-05-27 10:42:55 -04:00
|
|
|
if n.Func.Nname != nil {
|
|
|
|
|
funcargs(n.Func.Nname.Name.Param.Ntype)
|
2015-05-27 00:44:05 -04:00
|
|
|
} else if n.Func.Ntype != nil {
|
|
|
|
|
funcargs(n.Func.Ntype)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
|
|
|
|
funcargs2(n.Type)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func funcargs(nt *Node) {
|
|
|
|
|
if nt.Op != OTFUNC {
|
2016-03-07 08:23:55 -08:00
|
|
|
Fatalf("funcargs %v", Oconv(nt.Op, 0))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// re-start the variable generation number
|
|
|
|
|
// we want to use small numbers for the return variables,
|
|
|
|
|
// so let them have the chunk starting at 1.
|
2016-03-08 15:10:26 -08:00
|
|
|
vargen = nt.Rlist.Len()
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// declare the receiver and in arguments.
|
|
|
|
|
// no n->defn because type checking of func header
|
|
|
|
|
// will not fill in the types until later
|
|
|
|
|
if nt.Left != nil {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := nt.Left
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Op != ODCLFIELD {
|
2016-03-07 08:23:55 -08:00
|
|
|
Fatalf("funcargs receiver %v", Oconv(n.Op, 0))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if n.Left != nil {
|
|
|
|
|
n.Left.Op = ONAME
|
2015-05-27 00:44:05 -04:00
|
|
|
n.Left.Name.Param.Ntype = n.Right
|
2015-02-13 14:40:36 -05:00
|
|
|
declare(n.Left, PPARAM)
|
|
|
|
|
if dclcontext == PAUTO {
|
|
|
|
|
vargen++
|
2015-05-26 23:56:14 -04:00
|
|
|
n.Left.Name.Vargen = int32(vargen)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
var n *Node
|
2016-03-08 15:10:26 -08:00
|
|
|
for _, n = range nt.List.Slice() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Op != ODCLFIELD {
|
2016-03-07 08:23:55 -08:00
|
|
|
Fatalf("funcargs in %v", Oconv(n.Op, 0))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if n.Left != nil {
|
|
|
|
|
n.Left.Op = ONAME
|
2015-05-27 00:44:05 -04:00
|
|
|
n.Left.Name.Param.Ntype = n.Right
|
2015-02-13 14:40:36 -05:00
|
|
|
declare(n.Left, PPARAM)
|
|
|
|
|
if dclcontext == PAUTO {
|
|
|
|
|
vargen++
|
2015-05-26 23:56:14 -04:00
|
|
|
n.Left.Name.Vargen = int32(vargen)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// declare the out arguments.
|
2016-03-08 15:10:26 -08:00
|
|
|
gen := nt.List.Len()
|
2015-02-13 14:40:36 -05:00
|
|
|
var i int = 0
|
2016-03-08 15:10:26 -08:00
|
|
|
for _, n = range nt.Rlist.Slice() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Op != ODCLFIELD {
|
2016-03-07 08:23:55 -08:00
|
|
|
Fatalf("funcargs out %v", Oconv(n.Op, 0))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if n.Left == nil {
|
|
|
|
|
// Name so that escape analysis can track it. ~r stands for 'result'.
|
2016-03-19 18:17:58 -07:00
|
|
|
n.Left = newname(LookupN("~r", gen))
|
2015-02-13 14:40:36 -05:00
|
|
|
gen++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: n->left->missing = 1;
|
|
|
|
|
n.Left.Op = ONAME
|
|
|
|
|
|
|
|
|
|
if isblank(n.Left) {
|
|
|
|
|
// Give it a name so we can assign to it during return. ~b stands for 'blank'.
|
|
|
|
|
// The name must be different from ~r above because if you have
|
|
|
|
|
// func f() (_ int)
|
|
|
|
|
// func g() int
|
|
|
|
|
// f is allowed to use a plain 'return' with no arguments, while g is not.
|
|
|
|
|
// So the two cases must be distinguished.
|
|
|
|
|
// We do not record a pointer to the original node (n->orig).
|
|
|
|
|
// Having multiple names causes too much confusion in later passes.
|
2016-03-23 16:01:15 +11:00
|
|
|
nn := *n.Left
|
|
|
|
|
nn.Orig = &nn
|
2016-03-19 18:17:58 -07:00
|
|
|
nn.Sym = LookupN("~b", gen)
|
2015-02-13 14:40:36 -05:00
|
|
|
gen++
|
2016-03-23 16:01:15 +11:00
|
|
|
n.Left = &nn
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 00:44:05 -04:00
|
|
|
n.Left.Name.Param.Ntype = n.Right
|
2015-02-13 14:40:36 -05:00
|
|
|
declare(n.Left, PPARAMOUT)
|
|
|
|
|
if dclcontext == PAUTO {
|
|
|
|
|
i++
|
2015-05-26 23:56:14 -04:00
|
|
|
n.Left.Name.Vargen = int32(i)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// Same as funcargs, except run over an already constructed TFUNC.
|
|
|
|
|
// This happens during import, where the hidden_fndcl rule has
|
|
|
|
|
// used functype directly to parse the function's type.
|
2015-02-13 14:40:36 -05:00
|
|
|
func funcargs2(t *Type) {
|
|
|
|
|
if t.Etype != TFUNC {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("funcargs2 %v", t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 01:47:16 -07:00
|
|
|
for _, ft := range t.Recvs().Fields().Slice() {
|
|
|
|
|
if ft.Nname == nil || ft.Nname.Sym == nil {
|
|
|
|
|
continue
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-17 01:47:16 -07:00
|
|
|
n := ft.Nname // no need for newname(ft->nname->sym)
|
|
|
|
|
n.Type = ft.Type
|
|
|
|
|
declare(n, PPARAM)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 01:47:16 -07:00
|
|
|
for _, ft := range t.Params().Fields().Slice() {
|
|
|
|
|
if ft.Nname == nil || ft.Nname.Sym == nil {
|
|
|
|
|
continue
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-17 01:47:16 -07:00
|
|
|
n := ft.Nname
|
|
|
|
|
n.Type = ft.Type
|
|
|
|
|
declare(n, PPARAM)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 01:47:16 -07:00
|
|
|
for _, ft := range t.Results().Fields().Slice() {
|
|
|
|
|
if ft.Nname == nil || ft.Nname.Sym == nil {
|
|
|
|
|
continue
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-17 01:47:16 -07:00
|
|
|
n := ft.Nname
|
|
|
|
|
n.Type = ft.Type
|
|
|
|
|
declare(n, PPARAMOUT)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// finish the body.
|
|
|
|
|
// called in auto-declaration context.
|
|
|
|
|
// returns in extern-declaration context.
|
2015-02-13 14:40:36 -05:00
|
|
|
func funcbody(n *Node) {
|
|
|
|
|
// change the declaration context from auto to extern
|
|
|
|
|
if dclcontext != PAUTO {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("funcbody: dclcontext")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
popdcl()
|
|
|
|
|
Funcdepth--
|
2015-05-27 00:44:05 -04:00
|
|
|
Curfn = n.Func.Outer
|
|
|
|
|
n.Func.Outer = nil
|
2015-02-13 14:40:36 -05:00
|
|
|
if Funcdepth == 0 {
|
|
|
|
|
dclcontext = PEXTERN
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// new type being defined with name s.
|
2015-02-13 14:40:36 -05:00
|
|
|
func typedcl0(s *Sym) *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := newname(s)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Op = OTYPE
|
|
|
|
|
declare(n, dclcontext)
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// node n, which was returned by typedcl0
|
|
|
|
|
// is being declared to have uncompiled type t.
|
|
|
|
|
// return the ODCLTYPE node to use.
|
2015-03-10 09:58:01 +11:00
|
|
|
func typedcl1(n *Node, t *Node, local bool) *Node {
|
2015-05-27 00:44:05 -04:00
|
|
|
n.Name.Param.Ntype = t
|
2015-03-10 09:58:01 +11:00
|
|
|
n.Local = local
|
2015-02-13 14:40:36 -05:00
|
|
|
return Nod(ODCLTYPE, n, nil)
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// structs, functions, and methods.
|
|
|
|
|
// they don't belong here, but where do they belong?
|
2015-02-13 14:40:36 -05:00
|
|
|
func checkembeddedtype(t *Type) {
|
|
|
|
|
if t == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 15:09:25 -07:00
|
|
|
if t.Sym == nil && t.IsPtr() {
|
2016-03-30 10:57:47 -07:00
|
|
|
t = t.Elem()
|
2016-03-30 14:56:08 -07:00
|
|
|
if t.IsInterface() {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("embedded type cannot be a pointer to interface")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 15:09:25 -07:00
|
|
|
if t.IsPtr() {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("embedded type cannot be a pointer")
|
|
|
|
|
} else if t.Etype == TFORW && t.Embedlineno == 0 {
|
|
|
|
|
t.Embedlineno = lineno
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
func structfield(n *Node) *Field {
|
2016-03-02 17:34:42 -08:00
|
|
|
lno := lineno
|
2015-02-13 14:40:36 -05:00
|
|
|
lineno = n.Lineno
|
|
|
|
|
|
|
|
|
|
if n.Op != ODCLFIELD {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("structfield: oops %v\n", n)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
f := newField()
|
2015-02-13 14:40:36 -05:00
|
|
|
f.Isddd = n.Isddd
|
|
|
|
|
|
|
|
|
|
if n.Right != nil {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
n.Right = typecheck(n.Right, Etype)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Type = n.Right.Type
|
|
|
|
|
if n.Left != nil {
|
|
|
|
|
n.Left.Type = n.Type
|
|
|
|
|
}
|
|
|
|
|
if n.Embedded != 0 {
|
|
|
|
|
checkembeddedtype(n.Type)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Right = nil
|
|
|
|
|
|
|
|
|
|
f.Type = n.Type
|
|
|
|
|
if f.Type == nil {
|
2015-09-07 10:37:26 +10:00
|
|
|
f.Broke = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 00:47:05 -04:00
|
|
|
switch n.Val().Ctype() {
|
2015-02-13 14:40:36 -05:00
|
|
|
case CTSTR:
|
2015-03-02 16:03:26 -05:00
|
|
|
f.Note = new(string)
|
2015-05-27 00:47:05 -04:00
|
|
|
*f.Note = n.Val().U.(string)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Yyerror("field annotation must be string")
|
|
|
|
|
fallthrough
|
|
|
|
|
|
|
|
|
|
case CTxxx:
|
|
|
|
|
f.Note = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if n.Left != nil && n.Left.Op == ONAME {
|
|
|
|
|
f.Nname = n.Left
|
|
|
|
|
f.Embedded = n.Embedded
|
|
|
|
|
f.Sym = f.Nname.Sym
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
2015-02-13 14:40:36 -05:00
|
|
|
return f
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-10 15:50:49 -08:00
|
|
|
// checkdupfields emits errors for duplicately named fields or methods in
|
|
|
|
|
// a list of struct or interface types.
|
|
|
|
|
func checkdupfields(what string, ts ...*Type) {
|
2016-03-02 17:34:42 -08:00
|
|
|
lno := lineno
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-10 15:50:49 -08:00
|
|
|
seen := make(map[*Sym]bool)
|
|
|
|
|
for _, t := range ts {
|
2016-03-17 01:32:18 -07:00
|
|
|
for _, f := range t.Fields().Slice() {
|
2016-03-10 15:50:49 -08:00
|
|
|
if f.Sym == nil || f.Nname == nil || isblank(f.Nname) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if seen[f.Sym] {
|
|
|
|
|
lineno = f.Nname.Lineno
|
|
|
|
|
Yyerror("duplicate %s %s", what, f.Sym.Name)
|
|
|
|
|
continue
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-10 15:50:49 -08:00
|
|
|
seen[f.Sym] = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// convert a parsed id/type list into
|
|
|
|
|
// a type for struct/interface/arglist
|
2016-03-08 10:26:20 -08:00
|
|
|
func tostruct(l []*Node) *Type {
|
2015-02-23 16:07:24 -05:00
|
|
|
t := typ(TSTRUCT)
|
2015-08-13 19:05:37 -07:00
|
|
|
tostruct0(t, l)
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
func tostruct0(t *Type, l []*Node) {
|
2016-03-30 14:56:08 -07:00
|
|
|
if t == nil || !t.IsStruct() {
|
2015-08-13 19:05:37 -07:00
|
|
|
Fatalf("struct expected")
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
var fields []*Field
|
2016-03-09 12:39:36 -08:00
|
|
|
for _, n := range l {
|
2016-03-31 10:30:04 +11:00
|
|
|
f := structfield(n)
|
2015-09-07 10:37:26 +10:00
|
|
|
if f.Broke {
|
|
|
|
|
t.Broke = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-31 10:30:04 +11:00
|
|
|
fields = append(fields, f)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-31 10:30:04 +11:00
|
|
|
t.SetFields(fields)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-10 15:50:49 -08:00
|
|
|
checkdupfields("field", t)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-09-07 10:37:26 +10:00
|
|
|
if !t.Broke {
|
2015-02-13 14:40:36 -05:00
|
|
|
checkwidth(t)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
func tofunargs(l []*Node) *Type {
|
2015-02-23 16:07:24 -05:00
|
|
|
t := typ(TSTRUCT)
|
2015-09-08 03:51:30 +02:00
|
|
|
t.Funarg = true
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
var fields []*Field
|
2016-03-09 12:39:36 -08:00
|
|
|
for _, n := range l {
|
2016-03-10 05:22:14 -08:00
|
|
|
f := structfield(n)
|
2015-09-08 03:51:30 +02:00
|
|
|
f.Funarg = true
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// esc.go needs to find f given a PPARAM to add the tag.
|
2016-03-09 12:39:36 -08:00
|
|
|
if n.Left != nil && n.Left.Class == PPARAM {
|
|
|
|
|
n.Left.Name.Param.Field = f
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-09-07 10:37:26 +10:00
|
|
|
if f.Broke {
|
|
|
|
|
t.Broke = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-31 10:30:04 +11:00
|
|
|
fields = append(fields, f)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-31 10:30:04 +11:00
|
|
|
t.SetFields(fields)
|
2015-02-13 14:40:36 -05:00
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
func interfacefield(n *Node) *Field {
|
2016-03-02 17:34:42 -08:00
|
|
|
lno := lineno
|
2015-02-13 14:40:36 -05:00
|
|
|
lineno = n.Lineno
|
|
|
|
|
|
|
|
|
|
if n.Op != ODCLFIELD {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("interfacefield: oops %v\n", n)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 00:47:05 -04:00
|
|
|
if n.Val().Ctype() != CTxxx {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("interface method cannot have annotation")
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
f := newField()
|
2015-02-13 14:40:36 -05:00
|
|
|
f.Isddd = n.Isddd
|
|
|
|
|
|
|
|
|
|
if n.Right != nil {
|
|
|
|
|
if n.Left != nil {
|
|
|
|
|
// queue resolution of method type for later.
|
|
|
|
|
// right now all we need is the name list.
|
|
|
|
|
// avoids cycles for recursive interface types.
|
|
|
|
|
n.Type = typ(TINTERMETH)
|
|
|
|
|
|
|
|
|
|
n.Type.Nname = n.Right
|
|
|
|
|
n.Left.Type = n.Type
|
|
|
|
|
queuemethod(n)
|
|
|
|
|
|
|
|
|
|
if n.Left.Op == ONAME {
|
|
|
|
|
f.Nname = n.Left
|
|
|
|
|
f.Embedded = n.Embedded
|
|
|
|
|
f.Sym = f.Nname.Sym
|
|
|
|
|
}
|
|
|
|
|
} else {
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
n.Right = typecheck(n.Right, Etype)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Type = n.Right.Type
|
|
|
|
|
|
|
|
|
|
if n.Embedded != 0 {
|
|
|
|
|
checkembeddedtype(n.Type)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if n.Type != nil {
|
|
|
|
|
switch n.Type.Etype {
|
|
|
|
|
case TINTER:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case TFORW:
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("interface type loop involving %v", n.Type)
|
2015-09-07 10:37:26 +10:00
|
|
|
f.Broke = true
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
default:
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("interface contains embedded non-interface %v", n.Type)
|
2015-09-07 10:37:26 +10:00
|
|
|
f.Broke = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Right = nil
|
|
|
|
|
|
|
|
|
|
f.Type = n.Type
|
|
|
|
|
if f.Type == nil {
|
2015-09-07 10:37:26 +10:00
|
|
|
f.Broke = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
2015-02-13 14:40:36 -05:00
|
|
|
return f
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
func tointerface(l []*Node) *Type {
|
2015-02-23 16:07:24 -05:00
|
|
|
t := typ(TINTER)
|
2015-08-13 19:05:37 -07:00
|
|
|
tointerface0(t, l)
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
func tointerface0(t *Type, l []*Node) *Type {
|
2016-03-30 14:56:08 -07:00
|
|
|
if t == nil || !t.IsInterface() {
|
2015-08-13 19:05:37 -07:00
|
|
|
Fatalf("interface expected")
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
var fields []*Field
|
2016-03-08 15:10:26 -08:00
|
|
|
for _, n := range l {
|
|
|
|
|
f := interfacefield(n)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-30 14:56:08 -07:00
|
|
|
if n.Left == nil && f.Type.IsInterface() {
|
2015-02-13 14:40:36 -05:00
|
|
|
// embedded interface, inline methods
|
2016-03-17 01:32:18 -07:00
|
|
|
for _, t1 := range f.Type.Fields().Slice() {
|
2016-03-14 01:20:49 -07:00
|
|
|
f = newField()
|
2015-02-13 14:40:36 -05:00
|
|
|
f.Type = t1.Type
|
|
|
|
|
f.Broke = t1.Broke
|
|
|
|
|
f.Sym = t1.Sym
|
|
|
|
|
if f.Sym != nil {
|
|
|
|
|
f.Nname = newname(f.Sym)
|
|
|
|
|
}
|
2016-03-10 05:22:14 -08:00
|
|
|
fields = append(fields, f)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
2016-03-10 05:22:14 -08:00
|
|
|
fields = append(fields, f)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-10 23:59:59 -08:00
|
|
|
sort.Sort(methcmp(fields))
|
2016-03-10 05:22:14 -08:00
|
|
|
t.SetFields(fields)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-10 01:50:58 -08:00
|
|
|
for f, it := IterFields(t); f != nil && !t.Broke; f = it.Next() {
|
2015-09-07 10:37:26 +10:00
|
|
|
if f.Broke {
|
|
|
|
|
t.Broke = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-10 15:50:49 -08:00
|
|
|
checkdupfields("method", t)
|
2015-02-13 14:40:36 -05:00
|
|
|
checkwidth(t)
|
|
|
|
|
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func embedded(s *Sym, pkg *Pkg) *Node {
|
|
|
|
|
const (
|
|
|
|
|
CenterDot = 0xB7
|
|
|
|
|
)
|
|
|
|
|
// Names sometimes have disambiguation junk
|
2016-03-01 23:21:55 +00:00
|
|
|
// appended after a center dot. Discard it when
|
2015-02-13 14:40:36 -05:00
|
|
|
// making the name for the embedded struct field.
|
2015-02-23 16:07:24 -05:00
|
|
|
name := s.Name
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
if i := strings.Index(s.Name, string(CenterDot)); i >= 0 {
|
|
|
|
|
name = s.Name[:i]
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
var n *Node
|
2015-02-13 14:40:36 -05:00
|
|
|
if exportname(name) {
|
|
|
|
|
n = newname(Lookup(name))
|
|
|
|
|
} else if s.Pkg == builtinpkg {
|
|
|
|
|
// The name of embedded builtins belongs to pkg.
|
|
|
|
|
n = newname(Pkglookup(name, pkg))
|
|
|
|
|
} else {
|
|
|
|
|
n = newname(Pkglookup(name, s.Pkg))
|
|
|
|
|
}
|
|
|
|
|
n = Nod(ODCLFIELD, n, oldname(s))
|
|
|
|
|
n.Embedded = 1
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func fakethis() *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := Nod(ODCLFIELD, nil, typenod(Ptrto(typ(TSTRUCT))))
|
2015-02-13 14:40:36 -05:00
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// Is this field a method on an interface?
|
|
|
|
|
// Those methods have an anonymous *struct{} as the receiver.
|
|
|
|
|
// (See fakethis above.)
|
2015-02-17 22:13:49 -05:00
|
|
|
func isifacemethod(f *Type) bool {
|
2016-03-09 20:54:59 -08:00
|
|
|
rcvr := f.Recv()
|
2015-02-13 14:40:36 -05:00
|
|
|
if rcvr.Sym != nil {
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
t := rcvr.Type
|
2016-03-30 15:09:25 -07:00
|
|
|
if !t.IsPtr() {
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-30 10:57:47 -07:00
|
|
|
t = t.Elem()
|
2016-03-30 14:56:08 -07:00
|
|
|
if t.Sym != nil || !t.IsStruct() || t.NumFields() != 0 {
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// turn a parsed function declaration into a type
|
2016-03-08 10:26:20 -08:00
|
|
|
func functype(this *Node, in, out []*Node) *Type {
|
2015-02-23 16:07:24 -05:00
|
|
|
t := typ(TFUNC)
|
2015-08-13 19:05:37 -07:00
|
|
|
functype0(t, this, in, out)
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
func functype0(t *Type, this *Node, in, out []*Node) {
|
2015-08-13 19:05:37 -07:00
|
|
|
if t == nil || t.Etype != TFUNC {
|
|
|
|
|
Fatalf("function type expected")
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
var rcvr []*Node
|
2015-02-13 14:40:36 -05:00
|
|
|
if this != nil {
|
2016-03-08 10:26:20 -08:00
|
|
|
rcvr = []*Node{this}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-09 20:54:59 -08:00
|
|
|
*t.RecvsP() = tofunargs(rcvr)
|
2016-03-08 16:31:28 -08:00
|
|
|
*t.ResultsP() = tofunargs(out)
|
|
|
|
|
*t.ParamsP() = tofunargs(in)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-10 15:50:49 -08:00
|
|
|
checkdupfields("argument", t.Recvs(), t.Results(), t.Params())
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-09 20:54:59 -08:00
|
|
|
if t.Recvs().Broke || t.Results().Broke || t.Params().Broke {
|
2015-09-07 10:37:26 +10:00
|
|
|
t.Broke = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-08 03:51:30 +02:00
|
|
|
t.Outnamed = false
|
2016-03-17 01:47:16 -07:00
|
|
|
if len(out) > 0 && out[0].Left != nil && out[0].Left.Orig != nil {
|
2016-03-09 20:29:21 -08:00
|
|
|
s := out[0].Left.Orig.Sym
|
2015-02-13 14:40:36 -05:00
|
|
|
if s != nil && (s.Name[0] != '~' || s.Name[1] != 'r') { // ~r%d is the name invented for an unnamed result
|
2015-09-08 03:51:30 +02:00
|
|
|
t.Outnamed = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var methodsym_toppkg *Pkg
|
|
|
|
|
|
|
|
|
|
func methodsym(nsym *Sym, t0 *Type, iface int) *Sym {
|
|
|
|
|
var s *Sym
|
|
|
|
|
var p string
|
|
|
|
|
var suffix string
|
|
|
|
|
var spkg *Pkg
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
t := t0
|
2015-02-13 14:40:36 -05:00
|
|
|
if t == nil {
|
|
|
|
|
goto bad
|
|
|
|
|
}
|
|
|
|
|
s = t.Sym
|
2016-03-30 15:09:25 -07:00
|
|
|
if s == nil && t.IsPtr() {
|
2016-03-30 10:57:47 -07:00
|
|
|
t = t.Elem()
|
2015-02-13 14:40:36 -05:00
|
|
|
if t == nil {
|
|
|
|
|
goto bad
|
|
|
|
|
}
|
|
|
|
|
s = t.Sym
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spkg = nil
|
|
|
|
|
if s != nil {
|
|
|
|
|
spkg = s.Pkg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if t0 == *t and t0 has a sym,
|
|
|
|
|
// we want to see *t, not t0, in the method name.
|
|
|
|
|
if t != t0 && t0.Sym != nil {
|
|
|
|
|
t0 = Ptrto(t)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suffix = ""
|
|
|
|
|
if iface != 0 {
|
|
|
|
|
dowidth(t0)
|
|
|
|
|
if t0.Width < Types[Tptr].Width {
|
|
|
|
|
suffix = "·i"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (spkg == nil || nsym.Pkg != spkg) && !exportname(nsym.Name) {
|
2016-03-30 15:09:25 -07:00
|
|
|
if t0.Sym == nil && t0.IsPtr() {
|
2016-03-15 13:06:58 -07:00
|
|
|
p = fmt.Sprintf("(%v).%s.%s%s", Tconv(t0, FmtLeft|FmtShort), nsym.Pkg.Prefix, nsym.Name, suffix)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2016-03-15 13:06:58 -07:00
|
|
|
p = fmt.Sprintf("%v.%s.%s%s", Tconv(t0, FmtLeft|FmtShort), nsym.Pkg.Prefix, nsym.Name, suffix)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
} else {
|
2016-03-30 15:09:25 -07:00
|
|
|
if t0.Sym == nil && t0.IsPtr() {
|
2016-03-15 13:06:58 -07:00
|
|
|
p = fmt.Sprintf("(%v).%s%s", Tconv(t0, FmtLeft|FmtShort), nsym.Name, suffix)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2016-03-15 13:06:58 -07:00
|
|
|
p = fmt.Sprintf("%v.%s%s", Tconv(t0, FmtLeft|FmtShort), nsym.Name, suffix)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if spkg == nil {
|
|
|
|
|
if methodsym_toppkg == nil {
|
2015-03-02 16:03:26 -05:00
|
|
|
methodsym_toppkg = mkpkg("go")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
spkg = methodsym_toppkg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s = Pkglookup(p, spkg)
|
|
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
bad:
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("illegal receiver type: %v", t0)
|
2015-02-13 14:40:36 -05:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func methodname(n *Node, t *Type) *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
s := methodsym(n.Sym, t, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
if s == nil {
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
return newname(s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func methodname1(n *Node, t *Node) *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
star := ""
|
2015-02-13 14:40:36 -05:00
|
|
|
if t.Op == OIND {
|
|
|
|
|
star = "*"
|
|
|
|
|
t = t.Left
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if t.Sym == nil || isblank(n) {
|
2015-03-10 21:37:13 -07:00
|
|
|
return newfuncname(n.Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
var p string
|
2015-02-13 14:40:36 -05:00
|
|
|
if star != "" {
|
2015-04-17 12:03:22 -04:00
|
|
|
p = fmt.Sprintf("(%s%v).%v", star, t.Sym, n.Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2015-04-17 12:03:22 -04:00
|
|
|
p = fmt.Sprintf("%v.%v", t.Sym, n.Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if exportname(t.Sym.Name) {
|
2015-03-10 21:37:13 -07:00
|
|
|
n = newfuncname(Lookup(p))
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2015-03-10 21:37:13 -07:00
|
|
|
n = newfuncname(Pkglookup(p, t.Sym.Pkg))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 17:12:31 -08:00
|
|
|
// Add a method, declared as a function.
|
|
|
|
|
// - msym is the method symbol
|
|
|
|
|
// - t is function type (with receiver)
|
|
|
|
|
// - tpkg is the package of the type declaring the method during import, or nil (ignored) --- for verification only
|
|
|
|
|
func addmethod(msym *Sym, t *Type, tpkg *Pkg, local, nointerface bool) {
|
2015-02-13 14:40:36 -05:00
|
|
|
// get field sym
|
2016-03-11 17:12:31 -08:00
|
|
|
if msym == nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("no method symbol")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get parent type sym
|
2016-03-14 01:20:49 -07:00
|
|
|
rf := t.Recv() // ptr to this structure
|
|
|
|
|
if rf == nil {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("missing receiver")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
pa := rf.Type // base type
|
|
|
|
|
mt := methtype(pa, 1)
|
|
|
|
|
if mt == nil {
|
2015-02-13 14:40:36 -05:00
|
|
|
t = pa
|
|
|
|
|
if t == nil { // rely on typecheck having complained before
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if t != nil {
|
2016-03-30 15:09:25 -07:00
|
|
|
if t.IsPtr() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if t.Sym != nil {
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("invalid receiver type %v (%v is a pointer type)", pa, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 10:57:47 -07:00
|
|
|
t = t.Elem()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-07 10:37:26 +10:00
|
|
|
if t.Broke { // rely on typecheck having complained before
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if t.Sym == nil {
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("invalid receiver type %v (%v is an unnamed type)", pa, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 15:09:25 -07:00
|
|
|
if t.IsPtr() {
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("invalid receiver type %v (%v is a pointer type)", pa, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 14:56:08 -07:00
|
|
|
if t.IsInterface() {
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("invalid receiver type %v (%v is an interface type)", pa, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Should have picked off all the reasons above,
|
|
|
|
|
// but just in case, fall back to generic error.
|
2016-03-15 13:06:58 -07:00
|
|
|
Yyerror("invalid receiver type %v (%v / %v)", pa, Tconv(pa, FmtLong), Tconv(t, FmtLong))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
pa = mt
|
2015-11-15 23:32:30 +01:00
|
|
|
if local && !pa.Local {
|
|
|
|
|
Yyerror("cannot define new methods on non-local type %v", pa)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 17:12:31 -08:00
|
|
|
if isblanksym(msym) {
|
2015-11-15 23:32:30 +01:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 14:56:08 -07:00
|
|
|
if pa.IsStruct() {
|
2016-03-17 01:32:18 -07:00
|
|
|
for _, f := range pa.Fields().Slice() {
|
2016-03-11 17:12:31 -08:00
|
|
|
if f.Sym == msym {
|
|
|
|
|
Yyerror("type %v has both field and method named %v", pa, msym)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 17:12:31 -08:00
|
|
|
n := Nod(ODCLFIELD, newname(msym), nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Type = t
|
|
|
|
|
|
2016-03-17 01:32:18 -07:00
|
|
|
for _, f := range pa.Methods().Slice() {
|
2016-03-11 17:12:31 -08:00
|
|
|
if msym.Name != f.Sym.Name {
|
2015-02-13 14:40:36 -05:00
|
|
|
continue
|
|
|
|
|
}
|
cmd/compile: ignore receiver parameters in Eqtype
Receiver parameters generally aren't relevant to the function
signature type. In particular:
1. When checking whether a type's method implements an interface's
method, we specifically want to ignore the receiver parameters,
because they'll be different.
2. When checking interface type equality, interface methods always
use the same "fakethis" *struct{} type as their receiver.
3. Finally, method expressions and method values degenerate into
receiver-less function types.
The only case where we care about receiver types matching is in
addmethod, which is easily handled by adding an extra Eqtype check of
the receiver parameters. Also, added a test for this, since
(surprisingly) there weren't any.
As precedence, go/types.Identical ignores receiver parameters when
comparing go/types.Signature values.
Notably, this allows us to slightly simplify the "implements"
function, which is used for checking whether type/interface t
implements interface iface. Currently, cmd/compile actually works
around Eqtype's receiver parameter checking by creating new throwaway
TFUNC Types without the receiver parameter.
(Worse, the compiler currently only provides APIs to build TFUNC Types
from Nod syntax trees, so building those throwaway types also involves
first building throwaway syntax trees.)
Passes toolstash -cmp.
Change-Id: Ib07289c66feacee284e016bc312e8c5ff674714f
Reviewed-on: https://go-review.googlesource.com/20602
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-03-11 14:38:16 -08:00
|
|
|
// Eqtype only checks that incoming and result parameters match,
|
|
|
|
|
// so explicitly check that the receiver parameters match too.
|
2016-03-19 17:51:17 -07:00
|
|
|
if !Eqtype(t, f.Type) || !Eqtype(t.Recv().Type, f.Type.Recv().Type) {
|
2016-03-11 17:12:31 -08:00
|
|
|
Yyerror("method redeclared: %v.%v\n\t%v\n\t%v", pa, msym, f.Type, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
f := structfield(n)
|
2015-02-17 22:13:49 -05:00
|
|
|
f.Nointerface = nointerface
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// during import unexported method names should be in the type's package
|
2016-03-11 17:12:31 -08:00
|
|
|
if tpkg != nil && f.Sym != nil && !exportname(f.Sym.Name) && f.Sym.Pkg != tpkg {
|
2016-03-15 13:06:58 -07:00
|
|
|
Fatalf("imported method name %v in wrong package %s\n", Sconv(f.Sym, FmtSign), tpkg.Name)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 00:44:07 -07:00
|
|
|
pa.Methods().Append(f)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func funccompile(n *Node) {
|
|
|
|
|
Stksize = BADWIDTH
|
|
|
|
|
Maxarg = 0
|
|
|
|
|
|
|
|
|
|
if n.Type == nil {
|
|
|
|
|
if nerrors == 0 {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("funccompile missing type")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// assign parameter offsets
|
|
|
|
|
checkwidth(n.Type)
|
|
|
|
|
|
|
|
|
|
if Curfn != nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("funccompile %v inside %v", n.Func.Nname.Sym, Curfn.Func.Nname.Sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Stksize = 0
|
|
|
|
|
dclcontext = PAUTO
|
2015-05-27 00:44:05 -04:00
|
|
|
Funcdepth = n.Func.Depth + 1
|
2015-02-13 14:40:36 -05:00
|
|
|
compile(n)
|
|
|
|
|
Curfn = nil
|
2016-02-24 09:12:51 -08:00
|
|
|
Pc = nil
|
|
|
|
|
continpc = nil
|
|
|
|
|
breakpc = nil
|
2015-02-13 14:40:36 -05:00
|
|
|
Funcdepth = 0
|
|
|
|
|
dclcontext = PEXTERN
|
2016-03-18 10:45:30 -07:00
|
|
|
if nerrors != 0 {
|
|
|
|
|
// If we have compile errors, ignore any assembler/linker errors.
|
|
|
|
|
Ctxt.DiagFunc = func(string, ...interface{}) {}
|
|
|
|
|
}
|
2016-02-24 09:12:51 -08:00
|
|
|
flushdata()
|
|
|
|
|
obj.Flushplist(Ctxt) // convert from Prog list to machine code
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func funcsym(s *Sym) *Sym {
|
2015-03-12 18:45:30 -04:00
|
|
|
if s.Fsym != nil {
|
|
|
|
|
return s.Fsym
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-03-12 18:45:30 -04:00
|
|
|
s1 := Pkglookup(s.Name+"·f", s.Pkg)
|
|
|
|
|
s.Fsym = s1
|
2015-07-15 04:11:26 +00:00
|
|
|
return s1
|
2015-07-13 20:50:51 -04:00
|
|
|
}
|
2015-07-15 11:31:30 +12:00
|
|
|
|
|
|
|
|
func makefuncsym(s *Sym) {
|
|
|
|
|
if isblanksym(s) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if compiling_runtime != 0 && s.Name == "getg" {
|
|
|
|
|
// runtime.getg() is not a real function and so does
|
|
|
|
|
// not get a funcsym.
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
s1 := funcsym(s)
|
|
|
|
|
s1.Def = newfuncname(s1)
|
|
|
|
|
s1.Def.Func.Shortname = newname(s)
|
2015-10-05 16:33:53 -07:00
|
|
|
funcsyms = append(funcsyms, s1.Def)
|
2015-07-15 11:31:30 +12:00
|
|
|
}
|
2015-11-02 16:45:07 -05:00
|
|
|
|
|
|
|
|
type nowritebarrierrecChecker struct {
|
|
|
|
|
curfn *Node
|
|
|
|
|
stable bool
|
|
|
|
|
|
|
|
|
|
// best maps from the ODCLFUNC of each visited function that
|
|
|
|
|
// recursively invokes a write barrier to the called function
|
|
|
|
|
// on the shortest path to a write barrier.
|
|
|
|
|
best map[*Node]nowritebarrierrecCall
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type nowritebarrierrecCall struct {
|
|
|
|
|
target *Node
|
|
|
|
|
depth int
|
|
|
|
|
lineno int32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func checknowritebarrierrec() {
|
|
|
|
|
c := nowritebarrierrecChecker{
|
|
|
|
|
best: make(map[*Node]nowritebarrierrecCall),
|
|
|
|
|
}
|
|
|
|
|
visitBottomUp(xtop, func(list []*Node, recursive bool) {
|
|
|
|
|
// Functions with write barriers have depth 0.
|
|
|
|
|
for _, n := range list {
|
|
|
|
|
if n.Func.WBLineno != 0 {
|
|
|
|
|
c.best[n] = nowritebarrierrecCall{target: nil, depth: 0, lineno: n.Func.WBLineno}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Propagate write barrier depth up from callees. In
|
|
|
|
|
// the recursive case, we have to update this at most
|
|
|
|
|
// len(list) times and can stop when we an iteration
|
|
|
|
|
// that doesn't change anything.
|
|
|
|
|
for _ = range list {
|
|
|
|
|
c.stable = false
|
|
|
|
|
for _, n := range list {
|
|
|
|
|
if n.Func.WBLineno == 0 {
|
|
|
|
|
c.curfn = n
|
2016-03-03 16:27:05 -08:00
|
|
|
c.visitcodelist(n.Nbody)
|
2015-11-02 16:45:07 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if c.stable {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check nowritebarrierrec functions.
|
|
|
|
|
for _, n := range list {
|
2016-02-26 13:32:28 -08:00
|
|
|
if n.Func.Pragma&Nowritebarrierrec == 0 {
|
2015-11-02 16:45:07 -05:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
call, hasWB := c.best[n]
|
|
|
|
|
if !hasWB {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build the error message in reverse.
|
|
|
|
|
err := ""
|
|
|
|
|
for call.target != nil {
|
2016-03-02 11:30:29 -08:00
|
|
|
err = fmt.Sprintf("\n\t%v: called by %v%s", linestr(call.lineno), n.Func.Nname, err)
|
2015-11-02 16:45:07 -05:00
|
|
|
n = call.target
|
|
|
|
|
call = c.best[n]
|
|
|
|
|
}
|
|
|
|
|
err = fmt.Sprintf("write barrier prohibited by caller; %v%s", n.Func.Nname, err)
|
2016-03-02 11:01:25 -08:00
|
|
|
yyerrorl(n.Func.WBLineno, err)
|
2015-11-02 16:45:07 -05:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
func (c *nowritebarrierrecChecker) visitcodelist(l Nodes) {
|
2016-03-08 15:10:26 -08:00
|
|
|
for _, n := range l.Slice() {
|
|
|
|
|
c.visitcode(n)
|
2016-02-27 14:31:33 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-02 16:45:07 -05:00
|
|
|
func (c *nowritebarrierrecChecker) visitcode(n *Node) {
|
|
|
|
|
if n == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if n.Op == OCALLFUNC || n.Op == OCALLMETH {
|
|
|
|
|
c.visitcall(n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.visitcodelist(n.Ninit)
|
|
|
|
|
c.visitcode(n.Left)
|
|
|
|
|
c.visitcode(n.Right)
|
|
|
|
|
c.visitcodelist(n.List)
|
2016-03-03 16:27:05 -08:00
|
|
|
c.visitcodelist(n.Nbody)
|
2015-11-02 16:45:07 -05:00
|
|
|
c.visitcodelist(n.Rlist)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *nowritebarrierrecChecker) visitcall(n *Node) {
|
|
|
|
|
fn := n.Left
|
|
|
|
|
if n.Op == OCALLMETH {
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
fn = n.Left.Sym.Def
|
2015-11-02 16:45:07 -05:00
|
|
|
}
|
|
|
|
|
if fn == nil || fn.Op != ONAME || fn.Class != PFUNC || fn.Name.Defn == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2015-11-17 17:28:35 -05:00
|
|
|
if (compiling_runtime != 0 || fn.Sym.Pkg == Runtimepkg) && fn.Sym.Name == "allocm" {
|
|
|
|
|
return
|
|
|
|
|
}
|
2015-11-02 16:45:07 -05:00
|
|
|
defn := fn.Name.Defn
|
|
|
|
|
|
|
|
|
|
fnbest, ok := c.best[defn]
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
best, ok := c.best[c.curfn]
|
|
|
|
|
if ok && fnbest.depth+1 >= best.depth {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
c.best[c.curfn] = nowritebarrierrecCall{target: defn, depth: fnbest.depth + 1, lineno: n.Lineno}
|
|
|
|
|
c.stable = false
|
|
|
|
|
}
|