Skip to content

Commit 42563f8

Browse files
committed
cmd/compile: remove 'ext' fields from unified IR reader/writer types
This is a vestigial artifact of how I initially split apart the public and private data for objects. But now objects are split into more parts, and it's proven easier to just keep them as separate variables. So it's time to cleanup the initial public/private code to follow the same approach. Change-Id: I3976b19fb433cbe21d299d3799ec616f9e59561e Reviewed-on: https://go-review.googlesource.com/c/go/+/348412 Trust: Matthew Dempsky <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]>
1 parent 4c52eac commit 42563f8

File tree

3 files changed

+20
-32
lines changed

3 files changed

+20
-32
lines changed

src/cmd/compile/internal/noder/reader.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ type reader struct {
7979

8080
p *pkgReader
8181

82-
ext *reader
83-
8482
dict *readerDict
8583

8684
// TODO(mdempsky): The state below is all specific to reading
@@ -586,10 +584,10 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
586584
dict := pr.objDictIdx(sym, idx, implicits, explicits)
587585

588586
r := pr.newReader(relocObj, idx, syncObject1)
589-
r.ext = pr.newReader(relocObjExt, idx, syncObject1)
587+
rext := pr.newReader(relocObjExt, idx, syncObject1)
590588

591589
r.dict = dict
592-
r.ext.dict = dict
590+
rext.dict = dict
593591

594592
sym = r.mangle(sym)
595593
if !sym.IsBlank() && sym.Def != nil {
@@ -642,7 +640,7 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
642640
name.Func = ir.NewFunc(r.pos())
643641
name.Func.Nname = name
644642

645-
r.ext.funcExt(name)
643+
rext.funcExt(name)
646644
return name
647645

648646
case objType:
@@ -651,7 +649,7 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
651649
setType(name, typ)
652650

653651
// Important: We need to do this before SetUnderlying.
654-
r.ext.typeExt(name)
652+
rext.typeExt(name)
655653

656654
// We need to defer CheckSize until we've called SetUnderlying to
657655
// handle recursive types.
@@ -661,7 +659,7 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
661659

662660
methods := make([]*types.Field, r.len())
663661
for i := range methods {
664-
methods[i] = r.method()
662+
methods[i] = r.method(rext)
665663
}
666664
if len(methods) != 0 {
667665
typ.Methods().Set(methods)
@@ -674,7 +672,7 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
674672
case objVar:
675673
name := do(ir.ONAME, false)
676674
setType(name, r.typ())
677-
r.ext.varExt(name)
675+
rext.varExt(name)
678676
return name
679677
}
680678
}
@@ -756,7 +754,7 @@ func (r *reader) typeParamNames() {
756754
}
757755
}
758756

759-
func (r *reader) method() *types.Field {
757+
func (r *reader) method(rext *reader) *types.Field {
760758
r.sync(syncMethod)
761759
pos := r.pos()
762760
pkg, sym := r.selector()
@@ -772,7 +770,7 @@ func (r *reader) method() *types.Field {
772770
name.Func = ir.NewFunc(r.pos())
773771
name.Func.Nname = name
774772

775-
r.ext.funcExt(name)
773+
rext.funcExt(name)
776774

777775
meth := types.NewField(name.Func.Pos(), sym, typ)
778776
meth.Nname = name

src/cmd/compile/internal/noder/unified.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func unified(noders []*noder) {
106106
readPackage(localPkgReader, types.LocalPkg)
107107

108108
r := localPkgReader.newReader(relocMeta, privateRootIdx, syncPrivate)
109-
r.ext = r
110109
r.pkgInit(types.LocalPkg, target)
111110

112111
// Type-check any top-level assignments. We ignore non-assignments
@@ -190,7 +189,6 @@ func writePkgStub(noders []*noder) string {
190189

191190
{
192191
w := privateRootWriter
193-
w.ext = w
194192
w.pkgInit(noders)
195193
w.flush()
196194
}

src/cmd/compile/internal/noder/writer.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ type writer struct {
7575

7676
encoder
7777

78-
// For writing out object descriptions, ext points to the extension
79-
// writer for where we can write the compiler's private extension
80-
// details for the object.
81-
//
82-
// TODO(mdempsky): This is a little hacky, but works easiest with
83-
// the way things are currently.
84-
ext *writer
85-
8678
// TODO(mdempsky): We should be able to prune localsIdx whenever a
8779
// scope closes, and then maybe we can just use the same map for
8880
// storing the TypeParams too (as their TypeName instead).
@@ -504,21 +496,21 @@ func (pw *pkgWriter) objIdx(obj types2.Object) int {
504496
}
505497

506498
w := pw.newWriter(relocObj, syncObject1)
507-
w.ext = pw.newWriter(relocObjExt, syncObject1)
499+
wext := pw.newWriter(relocObjExt, syncObject1)
508500
wname := pw.newWriter(relocName, syncObject1)
509501
wdict := pw.newWriter(relocObjDict, syncObject1)
510502

511503
pw.globalsIdx[obj] = w.idx // break cycles
512-
assert(w.ext.idx == w.idx)
504+
assert(wext.idx == w.idx)
513505
assert(wname.idx == w.idx)
514506
assert(wdict.idx == w.idx)
515507

516508
w.dict = dict
517-
w.ext.dict = dict
509+
wext.dict = dict
518510

519-
code := w.doObj(obj)
511+
code := w.doObj(wext, obj)
520512
w.flush()
521-
w.ext.flush()
513+
wext.flush()
522514

523515
wname.qualifiedIdent(obj)
524516
wname.code(code)
@@ -530,7 +522,7 @@ func (pw *pkgWriter) objIdx(obj types2.Object) int {
530522
return w.idx
531523
}
532524

533-
func (w *writer) doObj(obj types2.Object) codeObj {
525+
func (w *writer) doObj(wext *writer, obj types2.Object) codeObj {
534526
if obj.Pkg() != w.p.curpkg {
535527
return objStub
536528
}
@@ -555,7 +547,7 @@ func (w *writer) doObj(obj types2.Object) codeObj {
555547
w.typeParamNames(sig.TypeParams())
556548
w.signature(sig)
557549
w.pos(decl)
558-
w.ext.funcExt(obj)
550+
wext.funcExt(obj)
559551
return objFunc
560552

561553
case *types2.TypeName:
@@ -573,20 +565,20 @@ func (w *writer) doObj(obj types2.Object) codeObj {
573565

574566
w.pos(obj)
575567
w.typeParamNames(named.TypeParams())
576-
w.ext.typeExt(obj)
568+
wext.typeExt(obj)
577569
w.typExpr(decl.Type)
578570

579571
w.len(named.NumMethods())
580572
for i := 0; i < named.NumMethods(); i++ {
581-
w.method(named.Method(i))
573+
w.method(wext, named.Method(i))
582574
}
583575

584576
return objType
585577

586578
case *types2.Var:
587579
w.pos(obj)
588580
w.typ(obj.Type())
589-
w.ext.varExt(obj)
581+
wext.varExt(obj)
590582
return objVar
591583
}
592584
}
@@ -648,7 +640,7 @@ func (w *writer) typeParamNames(tparams *types2.TypeParamList) {
648640
}
649641
}
650642

651-
func (w *writer) method(meth *types2.Func) {
643+
func (w *writer) method(wext *writer, meth *types2.Func) {
652644
decl, ok := w.p.funDecls[meth]
653645
assert(ok)
654646
sig := meth.Type().(*types2.Signature)
@@ -661,7 +653,7 @@ func (w *writer) method(meth *types2.Func) {
661653
w.signature(sig)
662654

663655
w.pos(decl) // XXX: Hack to workaround linker limitations.
664-
w.ext.funcExt(meth)
656+
wext.funcExt(meth)
665657
}
666658

667659
// qualifiedIdent writes out the name of an object declared at package

0 commit comments

Comments
 (0)