@@ -333,8 +333,6 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
333333 fn .Inline (llssa .NoInline )
334334 }
335335 }
336- // set compiled to check generic function global instantiation
337- pkg .Prog .SetFuncCompiled (name )
338336 isCgo := isCgoExternSymbol (f )
339337 if nblk := len (f .Blocks ); nblk > 0 {
340338 p .cgoCalled = false
@@ -1139,7 +1137,7 @@ func NewPackageEx(prog llssa.Program, patches Patches, rewrites map[string]strin
11391137 ctx .initPyModule ()
11401138 ctx .initFiles (pkgPath , files , pkgName == "C" )
11411139 ctx .prog .SetPatch (ctx .patchType )
1142- ctx .prog .SetCheckRuntimeNamed (ctx .checkRuntimeNamed )
1140+ ctx .prog .SetCompileMethods (ctx .checkCompileMethods )
11431141 ret .SetResolveLinkname (ctx .resolveLinkname )
11441142
11451143 if hasPatch {
@@ -1352,15 +1350,26 @@ func (p *context) resolveLinkname(name string) string {
13521350 return name
13531351}
13541352
1355- // checkRuntimeNamed compiles methods for generic type instantiations.
1356- // Only types with type arguments (instantiated generics) need method compilation
1357- // here, as non-generic types have their methods compiled elsewhere.
1358- func (p * context ) checkRuntimeNamed (pkg llssa.Package , typ * types.Named ) {
1359- if typ .TypeArgs () == nil {
1360- return
1353+ // checkCompileMethods ensures that all methods attached to the given type
1354+ // (and to the types it refers to) are compiled and emitted into the
1355+ // current SSA package. Generic named types and struct types are the
1356+ // primary targets; pointer types are followed until a non-pointer is
1357+ // reached. non-generic named have their methods compiled elsewhere.
1358+ func (p * context ) checkCompileMethods (pkg llssa.Package , typ types.Type ) {
1359+ nt := typ
1360+ retry:
1361+ switch t := nt .(type ) {
1362+ case * types.Named :
1363+ if t .TypeArgs () == nil {
1364+ return
1365+ }
1366+ p .compileMethods (pkg , typ )
1367+ case * types.Struct :
1368+ p .compileMethods (pkg , typ )
1369+ case * types.Pointer :
1370+ nt = t .Elem ()
1371+ goto retry
13611372 }
1362- p .compileMethods (pkg , typ )
1363- p .compileMethods (pkg , types .NewPointer (typ ))
13641373}
13651374
13661375// -----------------------------------------------------------------------------
0 commit comments