]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: cleaner solution for importing init functions
authorMatthew Dempsky <mdempsky@google.com>
Thu, 26 Apr 2018 22:25:36 +0000 (15:25 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 26 Apr 2018 23:21:28 +0000 (23:21 +0000)
Using oldname+resolve is how typecheck handles this anyway.

Passes toolstash -cmp, with both -iexport enabled and disabled.

Change-Id: I12b0f0333d6b86ce6bfc4d416c461b5f15c1110d
Reviewed-on: https://go-review.googlesource.com/109715
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/init.go
src/cmd/compile/internal/gc/noder.go

index 98ea289548733449074690ca664be5f0b9ab25f4..bb2bc4b844e65e10f40c2cff70284c5c35e393e2 100644 (file)
@@ -115,12 +115,18 @@ func fninit(n []*Node) {
 
        // (6)
        for _, s := range types.InitSyms {
-               if s.Def != nil && s != initsym {
-                       n := asNode(s.Def)
-                       n.checkInitFuncSignature()
-                       a = nod(OCALL, n, nil)
-                       r = append(r, a)
+               if s == initsym {
+                       continue
+               }
+               n := resolve(oldname(s))
+               if n.Op == ONONAME {
+                       // No package-scope init function; just a
+                       // local variable, field name, or something.
+                       continue
                }
+               n.checkInitFuncSignature()
+               a = nod(OCALL, n, nil)
+               r = append(r, a)
        }
 
        // (7)
index 98ac9b36b83d90e9d70c3f81cbd2bb0d7c8249f1..ecd039ae78db6dc617ee7042fdf52f6e186ff740 100644 (file)
@@ -67,17 +67,6 @@ func parseFiles(filenames []string) uint {
 
        localpkg.Height = myheight
 
-       if flagiexport {
-               // init.go requires all imported init functions to be
-               // fully resolved.
-               // TODO(mdempsky): Can this be done elsewhere more cleanly?
-               for _, s := range types.InitSyms {
-                       if n := asNode(s.Def); n != nil && s.Pkg != localpkg {
-                               resolve(n)
-                       }
-               }
-       }
-
        return lines
 }