aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/reader.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-07-20 16:52:37 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-07-21 01:29:21 +0000
commit897970688b326f7baa8ad8e3330fb552d94b0014 (patch)
treeb5d15c69d32ea4e5ae110b812fa3f44363fcfd7a /src/cmd/compile/internal/noder/reader.go
parentd5f6ba943c4e8f39d1bd20c79f4e9274ad10c103 (diff)
downloadgo-897970688b326f7baa8ad8e3330fb552d94b0014.tar.gz
go-897970688b326f7baa8ad8e3330fb552d94b0014.zip
[dev.typeparams] cmd/compile: cleanup unified IR file format a little
This CL makes two changes: 1. It moves object symbols and code tags into a new "relocName" relocation, which should eventually allow getting rid of objStub. 2. It moves the type parameter data into the relocObjDict relocation, so everything related to writing out dictionaries is contained there. Change-Id: If0f7ff7d9384e8664957c3180bf6f20e97bcff6e Reviewed-on: https://go-review.googlesource.com/c/go/+/336051 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/reader.go')
-rw-r--r--src/cmd/compile/internal/noder/reader.go79
1 files changed, 42 insertions, 37 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go
index de708769ba..44d1c4f28b 100644
--- a/src/cmd/compile/internal/noder/reader.go
+++ b/src/cmd/compile/internal/noder/reader.go
@@ -534,18 +534,10 @@ func (r *reader) obj() ir.Node {
}
func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node {
- r := pr.newReader(relocObj, idx, syncObject1)
- r.ext = pr.newReader(relocObjExt, idx, syncObject1)
-
- _, sym := r.qualifiedIdent()
-
- dict := &readerDict{}
- r.dict = dict
- r.ext.dict = dict
-
- r.typeParamBounds(sym, implicits, explicits)
+ rname := pr.newReader(relocName, idx, syncObject1)
+ _, sym := rname.qualifiedIdent()
+ tag := codeObj(rname.code(syncCodeObj))
- tag := codeObj(r.code(syncCodeObj))
if tag == objStub {
assert(!sym.IsBlank())
switch sym.Pkg {
@@ -556,30 +548,19 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node
return pri.pr.objIdx(pri.idx, nil, explicits)
}
if haveLegacyImports {
- assert(!r.hasTypeParams())
+ assert(len(explicits) == 0)
return typecheck.Resolve(ir.NewIdent(src.NoXPos, sym))
}
base.Fatalf("unresolved stub: %v", sym)
}
- {
- rdict := pr.newReader(relocObjDict, idx, syncObject1)
- r.dict.derived = make([]derivedInfo, rdict.len())
- r.dict.derivedTypes = make([]*types.Type, len(r.dict.derived))
- for i := range r.dict.derived {
- r.dict.derived[i] = derivedInfo{rdict.reloc(relocType), rdict.bool()}
- }
- r.dict.funcs = make([]objInfo, rdict.len())
- r.dict.funcsObj = make([]ir.Node, len(r.dict.funcs))
- for i := range r.dict.funcs {
- objIdx := rdict.reloc(relocObj)
- targs := make([]typeInfo, rdict.len())
- for j := range targs {
- targs[j] = rdict.typInfo()
- }
- r.dict.funcs[i] = objInfo{idx: objIdx, explicits: targs}
- }
- }
+ dict := pr.objDictIdx(sym, idx, implicits, explicits)
+
+ r := pr.newReader(relocObj, idx, syncObject1)
+ r.ext = pr.newReader(relocObjExt, idx, syncObject1)
+
+ r.dict = dict
+ r.ext.dict = dict
sym = r.mangle(sym)
if !sym.IsBlank() && sym.Def != nil {
@@ -692,8 +673,10 @@ func (r *reader) mangle(sym *types.Sym) *types.Sym {
return sym.Pkg.Lookup(buf.String())
}
-func (r *reader) typeParamBounds(sym *types.Sym, implicits, explicits []*types.Type) {
- r.sync(syncTypeParamBounds)
+func (pr *pkgReader) objDictIdx(sym *types.Sym, idx int, implicits, explicits []*types.Type) *readerDict {
+ r := pr.newReader(relocObjDict, idx, syncObject1)
+
+ var dict readerDict
nimplicits := r.len()
nexplicits := r.len()
@@ -702,12 +685,11 @@ func (r *reader) typeParamBounds(sym *types.Sym, implicits, explicits []*types.T
base.Fatalf("%v has %v+%v params, but instantiated with %v+%v args", sym, nimplicits, nexplicits, len(implicits), len(explicits))
}
- r.dict.targs = append(implicits[:nimplicits:nimplicits], explicits...)
- r.dict.implicits = nimplicits
+ dict.targs = append(implicits[:nimplicits:nimplicits], explicits...)
+ dict.implicits = nimplicits
// For stenciling, we can just skip over the type parameters.
-
- for range r.dict.targs[r.dict.implicits:] {
+ for range dict.targs[dict.implicits:] {
// Skip past bounds without actually evaluating them.
r.sync(syncType)
if r.bool() {
@@ -716,6 +698,25 @@ func (r *reader) typeParamBounds(sym *types.Sym, implicits, explicits []*types.T
r.reloc(relocType)
}
}
+
+ dict.derived = make([]derivedInfo, r.len())
+ dict.derivedTypes = make([]*types.Type, len(dict.derived))
+ for i := range dict.derived {
+ dict.derived[i] = derivedInfo{r.reloc(relocType), r.bool()}
+ }
+
+ dict.funcs = make([]objInfo, r.len())
+ dict.funcsObj = make([]ir.Node, len(dict.funcs))
+ for i := range dict.funcs {
+ objIdx := r.reloc(relocObj)
+ targs := make([]typeInfo, r.len())
+ for j := range targs {
+ targs[j] = r.typInfo()
+ }
+ dict.funcs[i] = objInfo{idx: objIdx, explicits: targs}
+ }
+
+ return &dict
}
func (r *reader) typeParamNames() {
@@ -790,7 +791,11 @@ func (r *reader) selector() (origPkg *types.Pkg, sym *types.Sym) {
}
func (r *reader) hasTypeParams() bool {
- return r.dict != nil && len(r.dict.targs) != 0
+ return r.dict.hasTypeParams()
+}
+
+func (dict *readerDict) hasTypeParams() bool {
+ return dict != nil && len(dict.targs) != 0
}
// @@@ Compiler extensions