]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: do not declare func nodes
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 19 Aug 2020 09:05:02 +0000 (16:05 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 3 Sep 2020 02:48:11 +0000 (02:48 +0000)
The primary responsibility of declare() to associate a symbol (Sym) with
a declaration (Node), so "oldname" will work. Function literals are
anonymous, so their symbols does not need to be declared.

Passes toolstash-check.

Change-Id: I739b1054e3953e85fbd74a99148b9cfd7e5a57eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/249078
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/alg.go
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/init.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/walk.go

index 2b63700569e453be6646ad81cc3ccf2de3da474c..c9d71ea00b44f68524d0102c26cf420f8488e9b5 100644 (file)
@@ -429,8 +429,7 @@ func hashfor(t *types.Type) *Node {
        }
 
        n := newname(sym)
-       n.SetClass(PFUNC)
-       n.Sym.SetFunc(true)
+       setNodeNameFunc(n)
        n.Type = functype(nil, []*Node{
                anonfield(types.NewPtr(t)),
                anonfield(types.Types[TUINTPTR]),
index 23e48939b46b96f39f77280c605f0e583d71780a..250be38e5bf9f470fcf698a840d297fdb939ce31 100644 (file)
@@ -107,18 +107,7 @@ func typecheckclosure(clo *Node, top int) {
        }
 
        xfunc.Func.Nname.Sym = closurename(Curfn)
-       disableExport(xfunc.Func.Nname.Sym)
-       if xfunc.Func.Nname.Sym.Def != nil {
-               // The only case we can reach here is when the outer function was redeclared.
-               // In that case, don't bother to redeclare the closure. Otherwise, we will get
-               // a spurious error message, see #17758. While we are here, double check that
-               // we already reported other error.
-               if nsavederrors+nerrors == 0 {
-                       Fatalf("unexpected symbol collision %v", xfunc.Func.Nname.Sym)
-               }
-       } else {
-               declare(xfunc.Func.Nname, PFUNC)
-       }
+       setNodeNameFunc(xfunc.Func.Nname)
        xfunc = typecheck(xfunc, ctxStmt)
 
        // Type check the body now, but only if we're inside a function.
@@ -473,7 +462,6 @@ func makepartialcall(fn *Node, t0 *types.Type, meth *types.Sym) *Node {
        tfn.List.Set(structargs(t0.Params(), true))
        tfn.Rlist.Set(structargs(t0.Results(), false))
 
-       disableExport(sym)
        xfunc := dclfunc(sym, tfn)
        xfunc.Func.SetDupok(true)
        xfunc.Func.SetNeedctxt(true)
index 6dc6f4db7026d33046e1b8eaf00ff76e8b9a14bd..69eb13f60764992acd56101b35d7b03d5b3f47d8 100644 (file)
@@ -985,10 +985,14 @@ func makefuncsym(s *types.Sym) {
        }
 }
 
-// disableExport prevents sym from being included in package export
-// data. To be effectual, it must be called before declare.
-func disableExport(sym *types.Sym) {
-       sym.SetOnExportList(true)
+// setNodeNameFunc marks a node as a function.
+func setNodeNameFunc(n *Node) {
+       if n.Op != ONAME || n.Class() != Pxxx {
+               Fatalf("expected ONAME/Pxxx node, got %v", n)
+       }
+
+       n.SetClass(PFUNC)
+       n.Sym.SetFunc(true)
 }
 
 func dclfunc(sym *types.Sym, tfn *Node) *Node {
@@ -1000,7 +1004,7 @@ func dclfunc(sym *types.Sym, tfn *Node) *Node {
        fn.Func.Nname = newfuncnamel(lineno, sym)
        fn.Func.Nname.Name.Defn = fn
        fn.Func.Nname.Name.Param.Ntype = tfn
-       declare(fn.Func.Nname, PFUNC)
+       setNodeNameFunc(fn.Func.Nname)
        funchdr(fn)
        fn.Func.Nname.Name.Param.Ntype = typecheck(fn.Func.Nname.Name.Param.Ntype, ctxType)
        return fn
index 03e475e85a0c1b652ac4562f34d62e0f7dea35c7..94cbcf98467254dec26d8d8efcd63ced6efe354c 100644 (file)
@@ -45,7 +45,6 @@ func fninit(n []*Node) {
        if len(nf) > 0 {
                lineno = nf[0].Pos // prolog/epilog gets line number of first init stmt
                initializers := lookup("init")
-               disableExport(initializers)
                fn := dclfunc(initializers, nod(OTFUNC, nil, nil))
                for _, dcl := range dummyInitFn.Func.Dcl {
                        dcl.Name.Curfn = fn
index 9c6cd24eb78b88b64a8a0a84b53782c285e85fe4..8fa3fca50f5dd32cda675721969d118c8dfa1d06 100644 (file)
@@ -1543,7 +1543,6 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym) {
        tfn.List.Set(structargs(method.Type.Params(), true))
        tfn.Rlist.Set(structargs(method.Type.Results(), false))
 
-       disableExport(newnam)
        fn := dclfunc(newnam, tfn)
        fn.Func.SetDupok(true)
 
@@ -1631,8 +1630,7 @@ func hashmem(t *types.Type) *Node {
        sym := Runtimepkg.Lookup("memhash")
 
        n := newname(sym)
-       n.SetClass(PFUNC)
-       n.Sym.SetFunc(true)
+       setNodeNameFunc(n)
        n.Type = functype(nil, []*Node{
                anonfield(types.NewPtr(t)),
                anonfield(types.Types[TUINTPTR]),
index 90ecb50d6a48971077c482ef554d639dc6379794..0158af8700f1d8ba49e539b90fc93bb1ef3949bd 100644 (file)
@@ -3166,8 +3166,7 @@ func eqfor(t *types.Type) (n *Node, needsize bool) {
        case ASPECIAL:
                sym := typesymprefix(".eq", t)
                n := newname(sym)
-               n.SetClass(PFUNC)
-               n.Sym.SetFunc(true)
+               setNodeNameFunc(n)
                n.Type = functype(nil, []*Node{
                        anonfield(types.NewPtr(t)),
                        anonfield(types.NewPtr(t)),