From: Cuong Manh Le Date: Sun, 20 Jun 2021 15:17:19 +0000 (+0700) Subject: [dev.typeparams] cmd/compile: explain why reader.funcExt need to set n.Defn X-Git-Tag: go1.18beta1~1818^2^2~307 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e57da8e53c;p=gostls13.git [dev.typeparams] cmd/compile: explain why reader.funcExt need to set n.Defn Change-Id: I1a7d669879af57a1c1f48ce63ff0d214b694e680 Reviewed-on: https://go-review.googlesource.com/c/go/+/329572 Trust: Cuong Manh Le Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index ad3cc25fd0..4fc9e7a777 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -741,8 +741,13 @@ func (r *reader) funcExt(name *ir.Name) { fn.SetPos(name.Pos()) } - // TODO(mdempsky): Remember why I wrote this code. I think it has to - // do with how ir.VisitFuncsBottomUp works? + // Normally, we only compile local functions, which saves redundant compilation work. + // n.Defn is not nil for local functions, and is nil for imported function. But for + // generic functions, we might have an instantiation that no other package has seen before. + // So we need to be conservative and compile it again. + // + // That's why name.Defn is set here, so ir.VisitFuncsBottomUp can analyze function. + // TODO(mdempsky,cuonglm): find a cleaner way to handle this. if name.Sym().Pkg == types.LocalPkg || r.hasTypeParams() { name.Defn = fn }