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 (
|
2016-12-06 17:08:06 -08:00
|
|
|
"cmd/internal/src"
|
2015-02-13 14:40:36 -05:00
|
|
|
"fmt"
|
2016-03-10 23:59:59 -08:00
|
|
|
"sort"
|
2015-02-13 14:40:36 -05:00
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2016-04-05 12:48:49 -07:00
|
|
|
// Declaration stack & operations
|
|
|
|
|
|
2016-04-05 14:20:04 -07:00
|
|
|
var externdcl []*Node
|
|
|
|
|
|
|
|
|
|
var blockgen int32 // max block number
|
|
|
|
|
|
|
|
|
|
var block int32 // current block number
|
|
|
|
|
|
2016-04-05 12:48:49 -07:00
|
|
|
// dclstack maintains a stack of shadowed symbol declarations so that
|
|
|
|
|
// popdcl can restore their declarations when a block scope ends.
|
|
|
|
|
// The stack is maintained as a linked list, using Sym's Link field.
|
|
|
|
|
//
|
|
|
|
|
// In practice, the "stack" actually ends up forming a tree: goto and label
|
|
|
|
|
// statements record the current state of dclstack so that checkgoto can
|
|
|
|
|
// validate that a goto statement does not jump over any declarations or
|
|
|
|
|
// into a new block scope.
|
|
|
|
|
//
|
|
|
|
|
// Finally, the Syms in this list are not "real" Syms as they don't actually
|
|
|
|
|
// represent object names. Sym is just a convenient type for saving shadowed
|
|
|
|
|
// Sym definitions, and only a subset of its fields are actually used.
|
|
|
|
|
var dclstack *Sym
|
|
|
|
|
|
|
|
|
|
func dcopy(a, b *Sym) {
|
2015-02-13 14:40:36 -05:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 12:48:49 -07:00
|
|
|
// pushdcl pushes the current declaration for symbol s (if any) so that
|
|
|
|
|
// it can be shadowed by a new declaration within a nested block scope.
|
2015-02-13 14:40:36 -05:00
|
|
|
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)
|
|
|
|
|
return d
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 12:48:49 -07:00
|
|
|
// popdcl pops the innermost block scope and restores all symbol declarations
|
|
|
|
|
// to their previous state.
|
2015-02-13 14:40:36 -05:00
|
|
|
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-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
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 12:48:49 -07:00
|
|
|
// markdcl records the start of a new block scope for declarations.
|
2015-02-13 14:40:36 -05:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// keep around for debugging
|
|
|
|
|
func dumpdclstack() {
|
2015-02-23 16:07:24 -05:00
|
|
|
i := 0
|
|
|
|
|
for d := dclstack; d != nil; d = d.Link {
|
2016-03-18 17:21:32 -07:00
|
|
|
fmt.Printf("%6d %p", i, d)
|
|
|
|
|
if d.Name != "" {
|
|
|
|
|
fmt.Printf(" '%s' %v\n", d.Name, Pkglookup(d.Name, d.Pkg))
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Printf(" ---\n")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
i++
|
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()
|
|
|
|
|
}
|
2017-03-14 09:46:45 -07:00
|
|
|
Fatalf("mark left on the stack")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 12:48:49 -07:00
|
|
|
// redeclare emits a diagnostic about symbol s being redeclared somewhere.
|
2015-02-13 14:40:36 -05:00
|
|
|
func redeclare(s *Sym, where string) {
|
2016-12-07 16:02:42 -08:00
|
|
|
if !s.Lastlineno.IsKnown() {
|
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
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("%v redeclared %s\n"+
|
2016-09-09 21:08:46 -07:00
|
|
|
"\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-09-09 21:08:46 -07: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
|
|
|
|
|
|
2016-04-05 12:48:49 -07:00
|
|
|
// declare records that Node n declares symbol n.Sym in the specified
|
|
|
|
|
// declaration context.
|
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-12-07 17:40:46 -08:00
|
|
|
n.Pos = 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 {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("cannot declare name %v", s)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ctxt == PEXTERN && s.Name == "init" {
|
2016-09-15 15:45:10 +10: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-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)
|
2016-09-16 00:33:29 +10: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]
|
2016-09-16 11:00:54 +10: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
|
2016-09-16 00:33:29 +10:00
|
|
|
if funcdepth > 0 {
|
2016-09-16 11:00:54 +10: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 {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("missing expression in var declaration")
|
2015-02-13 14:40:36 -05:00
|
|
|
break
|
|
|
|
|
}
|
2016-03-09 20:29:21 -08:00
|
|
|
e = el[0]
|
|
|
|
|
el = el[1:]
|
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-02-13 14:40:36 -05:00
|
|
|
|
2016-09-16 00:33:29 +10:00
|
|
|
if e != nil || funcdepth > 0 || isblank(v) {
|
|
|
|
|
if funcdepth > 0 {
|
2016-09-16 11:00:54 +10:00
|
|
|
init = append(init, nod(ODCL, v, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-09-16 11:00:54 +10: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 {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("extra expression in var declaration")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
return init
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 12:48:49 -07:00
|
|
|
// newname returns a new ONAME Node associated with symbol s.
|
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
|
|
|
}
|
2016-09-16 11:00:54 +10:00
|
|
|
n := nod(ONAME, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Sym = s
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetAddable(true)
|
2016-10-27 20:15:29 -07:00
|
|
|
n.Xoffset = 0
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// newnoname returns a new ONONAME Node associated with symbol s.
|
|
|
|
|
func newnoname(s *Sym) *Node {
|
|
|
|
|
if s == nil {
|
|
|
|
|
Fatalf("newnoname nil")
|
|
|
|
|
}
|
|
|
|
|
n := nod(ONONAME, nil, nil)
|
|
|
|
|
n.Sym = s
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetAddable(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
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)
|
2017-02-27 19:56:38 +02:00
|
|
|
n.Func.SetIsHiddenClosure(Curfn != nil)
|
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
|
2016-09-16 11:00:54 +10:00
|
|
|
if t.nod == nil || t.nod.Type != t {
|
|
|
|
|
t.nod = nod(OTYPE, nil, nil)
|
|
|
|
|
t.nod.Type = t
|
|
|
|
|
t.nod.Sym = t.Sym
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-16 11:00:54 +10:00
|
|
|
return t.nod
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-18 16:11:50 -07:00
|
|
|
func anonfield(typ *Type) *Node {
|
|
|
|
|
return nod(ODCLFIELD, nil, typenod(typ))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func namedfield(s string, typ *Type) *Node {
|
|
|
|
|
return nod(ODCLFIELD, newname(lookup(s)), typenod(typ))
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 12:48:49 -07:00
|
|
|
// oldname returns the Node that declares symbol s in the current scope.
|
|
|
|
|
// If no such Node currently exists, an ONONAME Node is returned instead.
|
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 {
|
2016-04-05 12:48:49 -07:00
|
|
|
// Maybe a top-level declaration will come along later to
|
|
|
|
|
// define s. resolve will check s.Def again once all input
|
|
|
|
|
// source has been processed.
|
2016-10-31 16:20:42 -07:00
|
|
|
return newnoname(s)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-16 00:33:29 +10:00
|
|
|
if Curfn != nil && n.Op == ONAME && n.Name.Funcdepth > 0 && n.Name.Funcdepth != funcdepth {
|
2016-05-27 00:56:19 -04:00
|
|
|
// Inner func is referring to var in outer func.
|
2015-02-13 14:40:36 -05:00
|
|
|
//
|
|
|
|
|
// 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.
|
2016-05-27 00:56:19 -04:00
|
|
|
c := n.Name.Param.Innermost
|
2016-09-16 00:33:29 +10:00
|
|
|
if c == nil || c.Name.Funcdepth != funcdepth {
|
2016-05-27 00:56:19 -04:00
|
|
|
// Do not have a closure var for the active closure yet; make one.
|
2016-09-16 11:00:54 +10:00
|
|
|
c = nod(ONAME, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
c.Sym = s
|
2016-05-25 10:29:50 -04:00
|
|
|
c.Class = PAUTOHEAP
|
2017-02-27 19:56:38 +02:00
|
|
|
c.SetIsClosureVar(true)
|
|
|
|
|
c.SetIsddd(n.Isddd())
|
2015-05-26 22:19:27 -04:00
|
|
|
c.Name.Defn = n
|
2017-02-27 19:56:38 +02:00
|
|
|
c.SetAddable(false)
|
2016-09-16 00:33:29 +10:00
|
|
|
c.Name.Funcdepth = funcdepth
|
2016-05-27 14:24:26 -04:00
|
|
|
|
2016-05-27 00:56:19 -04:00
|
|
|
// Link into list of active closure variables.
|
|
|
|
|
// Popped from list in func closurebody.
|
|
|
|
|
c.Name.Param.Outer = n.Name.Param.Innermost
|
|
|
|
|
n.Name.Param.Innermost = c
|
|
|
|
|
|
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
|
2016-05-27 00:56:19 -04:00
|
|
|
return c
|
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 {
|
2017-03-06 20:00:54 +02:00
|
|
|
n.Sym.SetUniq(true)
|
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-12-07 17:40:46 -08:00
|
|
|
yyerrorl(defn.Pos, "non-name %v on left side of :=", n)
|
2015-02-13 14:40:36 -05:00
|
|
|
nerr++
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 20:00:54 +02:00
|
|
|
if !n.Sym.Uniq() {
|
2016-12-07 17:40:46 -08:00
|
|
|
yyerrorl(defn.Pos, "%v repeated on left side of :=", n.Sym)
|
2017-02-27 19:56:38 +02:00
|
|
|
n.SetDiag(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
nerr++
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 20:00:54 +02:00
|
|
|
n.Sym.SetUniq(false)
|
2015-02-13 14:40:36 -05:00
|
|
|
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-09-16 11:00:54 +10: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-12-07 17:40:46 -08:00
|
|
|
yyerrorl(defn.Pos, "no new variables on left side of :=")
|
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) {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("methods must have a unique non-blank name")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2016-09-16 00:33:29 +10:00
|
|
|
if funcdepth == 0 && dclcontext != PEXTERN {
|
2016-03-18 17:21:32 -07:00
|
|
|
Fatalf("funchdr: dclcontext = %d", dclcontext)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dclcontext = PAUTO
|
2016-05-26 23:43:19 -04:00
|
|
|
funcstart(n)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
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-04-27 15:10:10 +10:00
|
|
|
Fatalf("funcargs %v", nt.Op)
|
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-04-27 15:10:10 +10:00
|
|
|
Fatalf("funcargs receiver %v", n.Op)
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-31 11:58:19 +11:00
|
|
|
for _, n := range nt.List.Slice() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Op != ODCLFIELD {
|
2016-04-27 15:10:10 +10:00
|
|
|
Fatalf("funcargs in %v", n.Op)
|
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-31 11:58:19 +11:00
|
|
|
for _, n := range nt.Rlist.Slice() {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Op != ODCLFIELD {
|
2016-04-27 15:10:10 +10:00
|
|
|
Fatalf("funcargs out %v", n.Op)
|
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-09-15 15:45:10 +10: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-09-15 15:45:10 +10: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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-26 23:43:19 -04:00
|
|
|
var funcstack []*Node // stack of previous values of Curfn
|
2016-09-16 00:33:29 +10:00
|
|
|
var funcdepth int32 // len(funcstack) during parsing, but then forced to be the same later during compilation
|
2016-05-26 23:43:19 -04:00
|
|
|
|
|
|
|
|
// start the function.
|
|
|
|
|
// called before funcargs; undone at end of funcbody.
|
|
|
|
|
func funcstart(n *Node) {
|
|
|
|
|
markdcl()
|
|
|
|
|
funcstack = append(funcstack, Curfn)
|
2016-09-16 00:33:29 +10:00
|
|
|
funcdepth++
|
2016-05-26 23:43:19 -04:00
|
|
|
Curfn = n
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
2016-03-18 17:21:32 -07:00
|
|
|
Fatalf("funcbody: unexpected dclcontext %d", dclcontext)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
popdcl()
|
2016-05-26 23:43:19 -04:00
|
|
|
funcstack, Curfn = funcstack[:len(funcstack)-1], funcstack[len(funcstack)-1]
|
2016-09-16 00:33:29 +10:00
|
|
|
funcdepth--
|
|
|
|
|
if funcdepth == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
dclcontext = PEXTERN
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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() {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("embedded type cannot be a pointer to interface")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 14:05:48 -07:00
|
|
|
if t.IsPtr() || t.IsUnsafePtr() {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("embedded type cannot be a pointer")
|
2016-12-07 16:02:42 -08:00
|
|
|
} else if t.Etype == TFORW && !t.ForwardType().Embedlineno.IsKnown() {
|
2016-04-01 20:11:30 -07:00
|
|
|
t.ForwardType().Embedlineno = lineno
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
func structfield(n *Node) *Field {
|
2016-03-02 17:34:42 -08:00
|
|
|
lno := lineno
|
2016-12-07 17:40:46 -08:00
|
|
|
lineno = n.Pos
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
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()
|
2017-02-27 19:56:38 +02:00
|
|
|
f.SetIsddd(n.Isddd())
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
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 {
|
2017-02-27 19:56:38 +02:00
|
|
|
f.SetBroke(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-04-22 12:27:29 -07:00
|
|
|
switch u := n.Val().U.(type) {
|
|
|
|
|
case string:
|
2016-04-25 13:24:48 -07:00
|
|
|
f.Note = u
|
2015-02-13 14:40:36 -05:00
|
|
|
default:
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("field annotation must be string")
|
2016-04-22 12:27:29 -07:00
|
|
|
case nil:
|
|
|
|
|
// noop
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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] {
|
2016-12-07 17:40:46 -08:00
|
|
|
lineno = f.Nname.Pos
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("duplicate %s %s", what, f.Sym.Name)
|
2016-03-10 15:50:49 -08:00
|
|
|
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-31 11:58:19 +11:00
|
|
|
fields := make([]*Field, len(l))
|
|
|
|
|
for i, n := range l {
|
2016-03-31 10:30:04 +11:00
|
|
|
f := structfield(n)
|
2017-02-27 19:56:38 +02:00
|
|
|
if f.Broke() {
|
|
|
|
|
t.SetBroke(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-31 11:58:19 +11:00
|
|
|
fields[i] = 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
|
|
|
|
2017-02-27 19:56:38 +02:00
|
|
|
if !t.Broke() {
|
2015-02-13 14:40:36 -05:00
|
|
|
checkwidth(t)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-25 10:01:58 -04:00
|
|
|
func tofunargs(l []*Node, funarg Funarg) *Type {
|
2015-02-23 16:07:24 -05:00
|
|
|
t := typ(TSTRUCT)
|
2016-05-25 10:01:58 -04:00
|
|
|
t.StructType().Funarg = funarg
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-31 11:58:19 +11:00
|
|
|
fields := make([]*Field, len(l))
|
|
|
|
|
for i, n := range l {
|
2016-03-10 05:22:14 -08:00
|
|
|
f := structfield(n)
|
2016-05-25 10:01:58 -04:00
|
|
|
f.Funarg = funarg
|
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
|
|
|
}
|
2017-02-27 19:56:38 +02:00
|
|
|
if f.Broke() {
|
|
|
|
|
t.SetBroke(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-31 11:58:19 +11:00
|
|
|
fields[i] = 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-10-20 17:33:45 -07:00
|
|
|
func tofunargsfield(fields []*Field, funarg Funarg) *Type {
|
|
|
|
|
t := typ(TSTRUCT)
|
|
|
|
|
t.StructType().Funarg = funarg
|
|
|
|
|
|
|
|
|
|
for _, f := range fields {
|
|
|
|
|
f.Funarg = funarg
|
|
|
|
|
|
|
|
|
|
// esc.go needs to find f given a PPARAM to add the tag.
|
|
|
|
|
if f.Nname != nil && f.Nname.Class == PPARAM {
|
|
|
|
|
f.Nname.Name.Param.Field = f
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
t.SetFields(fields)
|
|
|
|
|
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
|
2016-12-07 17:40:46 -08:00
|
|
|
lineno = n.Pos
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
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 {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("interface method cannot have annotation")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 01:20:49 -07:00
|
|
|
f := newField()
|
2017-02-27 19:56:38 +02:00
|
|
|
f.SetIsddd(n.Isddd())
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
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)
|
2016-03-30 16:59:53 -07:00
|
|
|
n.Type.SetNname(n.Right)
|
2015-02-13 14:40:36 -05:00
|
|
|
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:
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("interface type loop involving %v", n.Type)
|
2017-02-27 19:56:38 +02:00
|
|
|
f.SetBroke(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
default:
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("interface contains embedded non-interface %v", n.Type)
|
2017-02-27 19:56:38 +02:00
|
|
|
f.SetBroke(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Right = nil
|
|
|
|
|
|
|
|
|
|
f.Type = n.Type
|
|
|
|
|
if f.Type == nil {
|
2017-02-27 19:56:38 +02:00
|
|
|
f.SetBroke(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 {
|
2017-03-18 14:39:48 -07:00
|
|
|
if len(l) == 0 {
|
|
|
|
|
return Types[TINTER]
|
|
|
|
|
}
|
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
|
2017-02-27 19:56:38 +02:00
|
|
|
f.SetBroke(t1.Broke())
|
2015-02-13 14:40:36 -05:00
|
|
|
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
|
|
|
}
|
2017-02-27 19:56:38 +02:00
|
|
|
if f.Broke() {
|
|
|
|
|
t.SetBroke(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-31 11:58:19 +11:00
|
|
|
sort.Sort(methcmp(fields))
|
|
|
|
|
t.SetFields(fields)
|
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) {
|
2016-09-15 15:45:10 +10:00
|
|
|
n = newname(lookup(name))
|
2015-02-13 14:40:36 -05:00
|
|
|
} 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))
|
|
|
|
|
}
|
2016-09-16 11:00:54 +10:00
|
|
|
n = nod(ODCLFIELD, n, oldname(s))
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Embedded = 1
|
|
|
|
|
return n
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-25 16:25:57 -07:00
|
|
|
// thisT is the singleton type used for interface method receivers.
|
|
|
|
|
var thisT *Type
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func fakethis() *Node {
|
2016-10-25 16:25:57 -07:00
|
|
|
if thisT == nil {
|
2017-03-19 09:51:22 +01:00
|
|
|
thisT = typPtr(typ(TSTRUCT))
|
2016-10-25 16:25:57 -07:00
|
|
|
}
|
|
|
|
|
return nod(ODCLFIELD, nil, typenod(thisT))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 17:33:45 -07:00
|
|
|
func fakethisfield() *Field {
|
2016-10-25 16:25:57 -07:00
|
|
|
if thisT == nil {
|
2017-03-19 09:51:22 +01:00
|
|
|
thisT = typPtr(typ(TSTRUCT))
|
2016-10-25 16:25:57 -07:00
|
|
|
}
|
2016-10-20 17:33:45 -07:00
|
|
|
f := newField()
|
2016-10-25 16:25:57 -07:00
|
|
|
f.Type = thisT
|
2016-10-20 17:33:45 -07:00
|
|
|
return f
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// Is this field a method on an interface?
|
2016-10-25 16:25:57 -07:00
|
|
|
// Those methods have thisT as the receiver.
|
2015-10-22 09:51:12 +09:00
|
|
|
// (See fakethis above.)
|
2015-02-17 22:13:49 -05:00
|
|
|
func isifacemethod(f *Type) bool {
|
2016-10-25 16:25:57 -07:00
|
|
|
return f.Recv().Type == thisT
|
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-08-30 11:15:38 -07:00
|
|
|
t.FuncType().Receiver = tofunargs(rcvr, FunargRcvr)
|
|
|
|
|
t.FuncType().Results = tofunargs(out, FunargResults)
|
|
|
|
|
t.FuncType().Params = tofunargs(in, FunargParams)
|
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
|
|
|
|
2017-02-27 19:56:38 +02:00
|
|
|
if t.Recvs().Broke() || t.Results().Broke() || t.Params().Broke() {
|
|
|
|
|
t.SetBroke(true)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-04-01 20:11:30 -07:00
|
|
|
t.FuncType().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
|
2016-04-01 20:11:30 -07:00
|
|
|
t.FuncType().Outnamed = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 17:33:45 -07:00
|
|
|
func functypefield(this *Field, in, out []*Field) *Type {
|
|
|
|
|
t := typ(TFUNC)
|
|
|
|
|
functypefield0(t, this, in, out)
|
|
|
|
|
return t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func functypefield0(t *Type, this *Field, in, out []*Field) {
|
|
|
|
|
var rcvr []*Field
|
|
|
|
|
if this != nil {
|
|
|
|
|
rcvr = []*Field{this}
|
|
|
|
|
}
|
|
|
|
|
t.FuncType().Receiver = tofunargsfield(rcvr, FunargRcvr)
|
|
|
|
|
t.FuncType().Results = tofunargsfield(out, FunargRcvr)
|
|
|
|
|
t.FuncType().Params = tofunargsfield(in, FunargRcvr)
|
|
|
|
|
|
|
|
|
|
t.FuncType().Outnamed = false
|
|
|
|
|
if len(out) > 0 && out[0].Nname != nil && out[0].Nname.Orig != nil {
|
|
|
|
|
s := out[0].Nname.Orig.Sym
|
|
|
|
|
if s != nil && (s.Name[0] != '~' || s.Name[1] != 'r') { // ~r%d is the name invented for an unnamed result
|
|
|
|
|
t.FuncType().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 {
|
2017-03-19 09:51:22 +01:00
|
|
|
t0 = typPtr(t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-09-09 21:08:46 -07:00
|
|
|
p = fmt.Sprintf("(%-S).%s.%s%s", t0, nsym.Pkg.Prefix, nsym.Name, suffix)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2016-09-09 21:08:46 -07:00
|
|
|
p = fmt.Sprintf("%-S.%s.%s%s", t0, 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-09-09 21:08:46 -07:00
|
|
|
p = fmt.Sprintf("(%-S).%s%s", t0, nsym.Name, suffix)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2016-09-09 21:08:46 -07:00
|
|
|
p = fmt.Sprintf("%-S.%s%s", t0, 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:
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("illegal receiver type: %v", t0)
|
2015-02-13 14:40:36 -05:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 14:24:24 -08:00
|
|
|
// methodname is a misnomer because this now returns a Sym, rather
|
|
|
|
|
// than an ONAME.
|
|
|
|
|
// TODO(mdempsky): Reconcile with methodsym.
|
|
|
|
|
func methodname(s *Sym, recv *Type) *Sym {
|
2016-10-20 17:33:45 -07:00
|
|
|
star := false
|
2017-01-23 14:24:24 -08:00
|
|
|
if recv.IsPtr() {
|
2016-10-20 17:33:45 -07:00
|
|
|
star = true
|
2017-01-23 14:24:24 -08:00
|
|
|
recv = recv.Elem()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-01-23 14:24:24 -08:00
|
|
|
tsym := recv.Sym
|
2016-10-20 17:33:45 -07:00
|
|
|
if tsym == nil || isblanksym(s) {
|
2017-01-23 14:24:24 -08:00
|
|
|
return s
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
var p string
|
2016-10-20 17:33:45 -07:00
|
|
|
if star {
|
|
|
|
|
p = fmt.Sprintf("(*%v).%v", tsym, s)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2016-10-20 17:33:45 -07:00
|
|
|
p = fmt.Sprintf("%v.%v", tsym, s)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 17:33:45 -07:00
|
|
|
if exportname(tsym.Name) {
|
|
|
|
|
s = lookup(p)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2016-10-20 17:33:45 -07:00
|
|
|
s = Pkglookup(p, tsym.Pkg)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-01-23 14:24:24 -08:00
|
|
|
return s
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
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)
|
2016-08-30 14:21:06 -07:00
|
|
|
func addmethod(msym *Sym, t *Type, local, nointerface bool) {
|
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 {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("missing receiver")
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-30 13:50:03 -07:00
|
|
|
mt := methtype(rf.Type)
|
2016-08-30 13:43:37 -07:00
|
|
|
if mt == nil || mt.Sym == nil {
|
2016-08-30 13:50:03 -07:00
|
|
|
pa := rf.Type
|
|
|
|
|
t := pa
|
|
|
|
|
if t != nil && t.IsPtr() {
|
|
|
|
|
if t.Sym != nil {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("invalid receiver type %v (%v is a pointer type)", pa, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
2016-08-30 13:50:03 -07:00
|
|
|
t = t.Elem()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-08-30 13:50:03 -07:00
|
|
|
switch {
|
2017-02-27 19:56:38 +02:00
|
|
|
case t == nil || t.Broke():
|
2016-08-30 13:50:03 -07:00
|
|
|
// rely on typecheck having complained before
|
|
|
|
|
case t.Sym == nil:
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("invalid receiver type %v (%v is an unnamed type)", pa, t)
|
2016-08-30 13:50:03 -07:00
|
|
|
case t.IsPtr():
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("invalid receiver type %v (%v is a pointer type)", pa, t)
|
2016-08-30 13:50:03 -07:00
|
|
|
case t.IsInterface():
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("invalid receiver type %v (%v is an interface type)", pa, t)
|
2016-08-30 13:50:03 -07:00
|
|
|
default:
|
|
|
|
|
// Should have picked off all the reasons above,
|
|
|
|
|
// but just in case, fall back to generic error.
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("invalid receiver type %v (%L / %L)", pa, pa, t)
|
2016-08-30 13:50:03 -07:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 19:56:38 +02:00
|
|
|
if local && !mt.Local() {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("cannot define new methods on non-local type %v", mt)
|
2015-11-15 23:32:30 +01:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-11 17:12:31 -08:00
|
|
|
if isblanksym(msym) {
|
2015-11-15 23:32:30 +01:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-30 13:50:03 -07:00
|
|
|
if mt.IsStruct() {
|
|
|
|
|
for _, f := range mt.Fields().Slice() {
|
2016-03-11 17:12:31 -08:00
|
|
|
if f.Sym == msym {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("type %v has both field and method named %v", mt, msym)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-30 13:50:03 -07:00
|
|
|
for _, f := range mt.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
|
|
|
|
|
}
|
2016-09-15 14:34:20 +10:00
|
|
|
// eqtype only checks that incoming and result parameters match,
|
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
|
|
|
// so explicitly check that the receiver parameters match too.
|
2016-09-15 14:34:20 +10:00
|
|
|
if !eqtype(t, f.Type) || !eqtype(t.Recv().Type, f.Type.Recv().Type) {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("method redeclared: %v.%v\n\t%v\n\t%v", mt, msym, f.Type, t)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 17:33:45 -07:00
|
|
|
f := newField()
|
|
|
|
|
f.Sym = msym
|
|
|
|
|
f.Nname = newname(msym)
|
|
|
|
|
f.Type = t
|
2017-02-27 19:56:38 +02:00
|
|
|
f.SetNointerface(nointerface)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-08-30 13:50:03 -07:00
|
|
|
mt.Methods().Append(f)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func funccompile(n *Node) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dclcontext = PAUTO
|
2016-09-16 00:33:29 +10:00
|
|
|
funcdepth = n.Func.Depth + 1
|
2015-02-13 14:40:36 -05:00
|
|
|
compile(n)
|
|
|
|
|
Curfn = nil
|
2016-10-07 02:06:33 +09:00
|
|
|
pc = nil
|
2016-09-16 00:33:29 +10:00
|
|
|
funcdepth = 0
|
2015-02-13 14:40:36 -05:00
|
|
|
dclcontext = PEXTERN
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
2016-10-13 22:56:38 +03:00
|
|
|
if !Ctxt.Flag_dynlink && s1.Def == nil {
|
|
|
|
|
s1.Def = newfuncname(s1)
|
2017-01-23 13:40:25 -08:00
|
|
|
s1.Def.Func.Shortname = s
|
2016-10-13 22:56:38 +03:00
|
|
|
funcsyms = append(funcsyms, s1.Def)
|
|
|
|
|
}
|
2015-03-12 18:45:30 -04:00
|
|
|
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
|
|
|
|
|
}
|
2016-04-13 18:37:18 -07:00
|
|
|
if compiling_runtime && s.Name == "getg" {
|
2015-07-15 11:31:30 +12:00
|
|
|
// runtime.getg() is not a real function and so does
|
|
|
|
|
// not get a funcsym.
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
s1 := funcsym(s)
|
2017-01-23 14:24:24 -08:00
|
|
|
if s1.Def != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2015-07-15 11:31:30 +12:00
|
|
|
s1.Def = newfuncname(s1)
|
2017-01-23 13:40:25 -08:00
|
|
|
s1.Def.Func.Shortname = 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
|
2016-12-15 17:17:01 -08:00
|
|
|
lineno src.XPos
|
2015-11-02 16:45:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 {
|
2016-12-07 17:40:46 -08:00
|
|
|
if n.Func.WBPos.IsKnown() && n.Func.Pragma&Yeswritebarrierrec == 0 {
|
|
|
|
|
c.best[n] = nowritebarrierrecCall{target: nil, depth: 0, lineno: n.Func.WBPos}
|
2015-11-02 16:45:07 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 {
|
2016-10-10 16:46:28 -04:00
|
|
|
if n.Func.Pragma&Yeswritebarrierrec != 0 {
|
|
|
|
|
// Don't propagate write
|
|
|
|
|
// barrier up to a
|
|
|
|
|
// yeswritebarrierrec function.
|
|
|
|
|
continue
|
|
|
|
|
}
|
2016-12-07 17:40:46 -08:00
|
|
|
if !n.Func.WBPos.IsKnown() {
|
2015-11-02 16:45:07 -05:00
|
|
|
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-12-07 17:40:46 -08:00
|
|
|
yyerrorl(n.Func.WBPos, 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
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
2016-12-07 17:40:46 -08:00
|
|
|
c.best[c.curfn] = nowritebarrierrecCall{target: defn, depth: fnbest.depth + 1, lineno: n.Pos}
|
2015-11-02 16:45:07 -05:00
|
|
|
c.stable = false
|
|
|
|
|
}
|