@@ -149,7 +149,7 @@ type readerDict struct {
149149 funcsObj []ir.Node
150150}
151151
152- func ( r * reader ) setType (n ir.Node , typ * types.Type ) {
152+ func setType (n ir.Node , typ * types.Type ) {
153153 n .SetType (typ )
154154 n .SetTypecheck (1 )
155155
@@ -159,7 +159,7 @@ func (r *reader) setType(n ir.Node, typ *types.Type) {
159159 }
160160}
161161
162- func ( r * reader ) setValue (name * ir.Name , val constant.Value ) {
162+ func setValue (name * ir.Name , val constant.Value ) {
163163 name .SetVal (val )
164164 name .Defn = nil
165165}
@@ -602,23 +602,23 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
602602
603603 case objAlias :
604604 name := do (ir .OTYPE , false )
605- r . setType (name , r .typ ())
605+ setType (name , r .typ ())
606606 name .SetAlias (true )
607607 return name
608608
609609 case objConst :
610610 name := do (ir .OLITERAL , false )
611611 typ , val := r .value ()
612- r . setType (name , typ )
613- r . setValue (name , val )
612+ setType (name , typ )
613+ setValue (name , val )
614614 return name
615615
616616 case objFunc :
617617 if sym .Name == "init" {
618618 sym = renameinit ()
619619 }
620620 name := do (ir .ONAME , true )
621- r . setType (name , r .signature (sym .Pkg , nil ))
621+ setType (name , r .signature (sym .Pkg , nil ))
622622
623623 name .Func = ir .NewFunc (r .pos ())
624624 name .Func .Nname = name
@@ -629,7 +629,7 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
629629 case objType :
630630 name := do (ir .OTYPE , true )
631631 typ := types .NewNamed (name )
632- r . setType (name , typ )
632+ setType (name , typ )
633633
634634 // Important: We need to do this before SetUnderlying.
635635 r .ext .typeExt (name )
@@ -654,7 +654,7 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
654654
655655 case objVar :
656656 name := do (ir .ONAME , false )
657- r . setType (name , r .typ ())
657+ setType (name , r .typ ())
658658 r .ext .varExt (name )
659659 return name
660660 }
@@ -754,7 +754,7 @@ func (r *reader) method() *types.Field {
754754 fnsym := sym
755755 fnsym = ir .MethodSym (recv .Type , fnsym )
756756 name := ir .NewNameAt (pos , fnsym )
757- r . setType (name , typ )
757+ setType (name , typ )
758758
759759 name .Func = ir .NewFunc (r .pos ())
760760 name .Func .Nname = name
@@ -996,7 +996,7 @@ func (r *reader) funcarg(param *types.Field, sym *types.Sym, ctxt ir.Class) {
996996 }
997997
998998 name := ir .NewNameAt (r .updatePos (param .Pos ), sym )
999- r . setType (name , param .Type )
999+ setType (name , param .Type )
10001000 r .addLocal (name , ctxt )
10011001
10021002 if r .inlCall == nil {
@@ -1276,7 +1276,7 @@ func (r *reader) stmt1(tag codeStmt, out *ir.Nodes) ir.Node {
12761276
12771277 name := ir .NewDeclNameAt (src .NoXPos , ir .OTYPE , ir .BlankNode .Sym ())
12781278 name .SetAlias (true )
1279- r . setType (name , types .Types [types .TINT ])
1279+ setType (name , types .Types [types .TINT ])
12801280
12811281 n := ir .NewDecl (src .NoXPos , ir .ODCLTYPE , name )
12821282 n .SetTypecheck (1 )
@@ -1297,7 +1297,7 @@ func (r *reader) assignList() ([]*ir.Name, []ir.Node) {
12971297 name := ir .NewNameAt (pos , sym )
12981298 lhs [i ] = name
12991299 names = append (names , name )
1300- r . setType (name , typ )
1300+ setType (name , typ )
13011301 r .addLocal (name , ir .PAUTO )
13021302 continue
13031303 }
@@ -1438,7 +1438,7 @@ func (r *reader) switchStmt(label *types.Sym) ir.Node {
14381438 typ := r .typ ()
14391439
14401440 name := ir .NewNameAt (pos , tswitch .Tag .Sym ())
1441- r . setType (name , typ )
1441+ setType (name , typ )
14421442 r .addLocal (name , ir .PAUTO )
14431443 clause .Var = name
14441444 name .Defn = tswitch
@@ -1701,12 +1701,12 @@ func (r *reader) funcLit() ir.Node {
17011701 clo := fn .OClosure
17021702 ir .NameClosure (clo , r .curfn )
17031703
1704- r . setType (fn .Nname , xtype2 )
1704+ setType (fn .Nname , xtype2 )
17051705 if quirksMode () {
17061706 fn .Nname .Ntype = ir .TypeNodeAt (typPos , xtype2 )
17071707 }
17081708 typecheck .Func (fn )
1709- r . setType (clo , fn .Type ())
1709+ setType (clo , fn .Type ())
17101710
17111711 fn .ClosureVars = make ([]* ir.Name , 0 , r .len ())
17121712 for len (fn .ClosureVars ) < cap (fn .ClosureVars ) {
@@ -1910,7 +1910,7 @@ func InlineCall(call *ir.CallExpr, fn *ir.Func, inlIndex int) *ir.InlinedCallExp
19101910 tmpfn .Closgen = callerfn .Closgen
19111911 defer func () { callerfn .Closgen = tmpfn .Closgen }()
19121912
1913- r . setType (tmpfn .Nname , fn .Type ())
1913+ setType (tmpfn .Nname , fn .Type ())
19141914 r .curfn = tmpfn
19151915
19161916 r .inlCaller = callerfn
@@ -2098,7 +2098,7 @@ func expandInline(fn *ir.Func, pri pkgReaderIndex) {
20982098
20992099 {
21002100 r := pri .asReader (relocBody , syncFuncBody )
2101- r . setType (tmpfn .Nname , fn .Type ())
2101+ setType (tmpfn .Nname , fn .Type ())
21022102
21032103 // Don't change parameter's Sym/Nname fields.
21042104 r .funarghack = true
@@ -2194,34 +2194,39 @@ func (r *reader) importedDef() bool {
21942194 return r .p != localPkgReader && ! r .hasTypeParams ()
21952195}
21962196
2197- func (r * reader ) wrapTypes (target * ir.Package ) {
2197+ func MakeWrappers (target * ir.Package ) {
2198+ // Only unified IR in non-quirks mode emits its own wrappers.
2199+ if base .Debug .Unified == 0 || quirksMode () {
2200+ return
2201+ }
2202+
21982203 // always generate a wrapper for error.Error (#29304)
2199- r . needWrapper ( types .ErrorType )
2204+ needWrapperTypes = append ( needWrapperTypes , types .ErrorType )
22002205
22012206 seen := make (map [string ]* types.Type )
22022207
22032208 for _ , typ := range haveWrapperTypes {
2204- r . wrapType (typ , target , seen , false )
2209+ wrapType (typ , target , seen , false )
22052210 }
22062211 haveWrapperTypes = nil
22072212
22082213 for _ , typ := range needWrapperTypes {
2209- r . wrapType (typ , target , seen , true )
2214+ wrapType (typ , target , seen , true )
22102215 }
22112216 needWrapperTypes = nil
22122217
22132218 for _ , wrapper := range haveMethodValueWrappers {
2214- r . methodValueWrapper (wrapper .rcvr , wrapper .method , target , false )
2219+ wrapMethodValue (wrapper .rcvr , wrapper .method , target , false )
22152220 }
22162221 haveMethodValueWrappers = nil
22172222
22182223 for _ , wrapper := range needMethodValueWrappers {
2219- r . methodValueWrapper (wrapper .rcvr , wrapper .method , target , true )
2224+ wrapMethodValue (wrapper .rcvr , wrapper .method , target , true )
22202225 }
22212226 needMethodValueWrappers = nil
22222227}
22232228
2224- func ( r * reader ) wrapType (typ * types.Type , target * ir.Package , seen map [string ]* types.Type , needed bool ) {
2229+ func wrapType (typ * types.Type , target * ir.Package , seen map [string ]* types.Type , needed bool ) {
22252230 key := typ .LinkString ()
22262231 if prev := seen [key ]; prev != nil {
22272232 if ! types .Identical (typ , prev ) {
@@ -2244,22 +2249,22 @@ func (r *reader) wrapType(typ *types.Type, target *ir.Package, seen map[string]*
22442249 base .FatalfAt (meth .Pos , "invalid method: %v" , meth )
22452250 }
22462251
2247- r . methodWrapper (0 , typ , meth , target )
2252+ methodWrapper (0 , typ , meth , target )
22482253
22492254 // For non-interface types, we also want *T wrappers.
22502255 if ! typ .IsInterface () {
2251- r . methodWrapper (1 , typ , meth , target )
2256+ methodWrapper (1 , typ , meth , target )
22522257
22532258 // For not-in-heap types, *T is a scalar, not pointer shaped,
22542259 // so the interface wrappers use **T.
22552260 if typ .NotInHeap () {
2256- r . methodWrapper (2 , typ , meth , target )
2261+ methodWrapper (2 , typ , meth , target )
22572262 }
22582263 }
22592264 }
22602265}
22612266
2262- func ( r * reader ) methodWrapper (derefs int , tbase * types.Type , method * types.Field , target * ir.Package ) {
2267+ func methodWrapper (derefs int , tbase * types.Type , method * types.Field , target * ir.Package ) {
22632268 wrapper := tbase
22642269 for i := 0 ; i < derefs ; i ++ {
22652270 wrapper = types .NewPtr (wrapper )
@@ -2279,7 +2284,7 @@ func (r *reader) methodWrapper(derefs int, tbase *types.Type, method *types.Fiel
22792284 // TODO(mdempsky): Use method.Pos instead?
22802285 pos := base .AutogeneratedPos
22812286
2282- fn := r . newWrapperFunc (pos , sym , wrapper , method )
2287+ fn := newWrapperFunc (pos , sym , wrapper , method )
22832288
22842289 var recv ir.Node = fn .Nname .Type ().Recv ().Nname .(* ir.Name )
22852290
@@ -2299,10 +2304,10 @@ func (r *reader) methodWrapper(derefs int, tbase *types.Type, method *types.Fiel
22992304
23002305 addTailCall (pos , fn , recv , method )
23012306
2302- r . finishWrapperFunc (fn , target )
2307+ finishWrapperFunc (fn , target )
23032308}
23042309
2305- func ( r * reader ) methodValueWrapper (recvType * types.Type , method * types.Field , target * ir.Package , needed bool ) {
2310+ func wrapMethodValue (recvType * types.Type , method * types.Field , target * ir.Package , needed bool ) {
23062311 sym := ir .MethodSymSuffix (recvType , method .Sym , "-fm" )
23072312 if sym .Uniq () {
23082313 return
@@ -2312,7 +2317,7 @@ func (r *reader) methodValueWrapper(recvType *types.Type, method *types.Field, t
23122317 // TODO(mdempsky): Use method.Pos instead?
23132318 pos := base .AutogeneratedPos
23142319
2315- fn := r . newWrapperFunc (pos , sym , nil , method )
2320+ fn := newWrapperFunc (pos , sym , nil , method )
23162321 sym .Def = fn .Nname
23172322
23182323 // Declare and initialize variable holding receiver.
@@ -2325,10 +2330,10 @@ func (r *reader) methodValueWrapper(recvType *types.Type, method *types.Field, t
23252330
23262331 addTailCall (pos , fn , recv , method )
23272332
2328- r . finishWrapperFunc (fn , target )
2333+ finishWrapperFunc (fn , target )
23292334}
23302335
2331- func ( r * reader ) newWrapperFunc (pos src.XPos , sym * types.Sym , wrapper * types.Type , method * types.Field ) * ir.Func {
2336+ func newWrapperFunc (pos src.XPos , sym * types.Sym , wrapper * types.Type , method * types.Field ) * ir.Func {
23322337 fn := ir .NewFunc (pos )
23332338 fn .SetDupok (true ) // TODO(mdempsky): Leave unset for local, non-generic wrappers?
23342339
@@ -2339,14 +2344,14 @@ func (r *reader) newWrapperFunc(pos src.XPos, sym *types.Sym, wrapper *types.Typ
23392344 fn .Nname = name
23402345
23412346 sig := newWrapperType (wrapper , method )
2342- r . setType (name , sig )
2347+ setType (name , sig )
23432348
23442349 // TODO(mdempsky): De-duplicate with similar logic in funcargs.
23452350 defParams := func (class ir.Class , params * types.Type ) {
23462351 for _ , param := range params .FieldSlice () {
23472352 name := ir .NewNameAt (param .Pos , param .Sym )
23482353 name .Class = class
2349- r . setType (name , param .Type )
2354+ setType (name , param .Type )
23502355
23512356 name .Curfn = fn
23522357 fn .Dcl = append (fn .Dcl , name )
@@ -2362,13 +2367,17 @@ func (r *reader) newWrapperFunc(pos src.XPos, sym *types.Sym, wrapper *types.Typ
23622367 return fn
23632368}
23642369
2365- func ( r * reader ) finishWrapperFunc (fn * ir.Func , target * ir.Package ) {
2370+ func finishWrapperFunc (fn * ir.Func , target * ir.Package ) {
23662371 typecheck .Func (fn )
23672372
23682373 ir .WithFunc (fn , func () {
23692374 typecheck .Stmts (fn .Body )
23702375 })
23712376
2377+ // We generate wrappers after the global inlining pass,
2378+ // so we're responsible for applying inlining ourselves here.
2379+ inline .InlineCalls (fn )
2380+
23722381 target .Decls = append (target .Decls , fn )
23732382}
23742383
0 commit comments