Skip to content

Commit

Permalink
cmd/compile: deprecate has init and derived func instance
Browse files Browse the repository at this point in the history
Removes 'has init' and 'derived func instance' fields from unified IR
starting with V2.

This should be a no-op at the moment as the writer is hardwired to create V1.

Updates #68778

Change-Id: I84a606cbc27cd6d8bd6eee2aff44c89f4aa7413c
Reviewed-on: https://go-review.googlesource.com/c/go/+/606035
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
timothy-king committed Aug 20, 2024
1 parent 7dc1ee8 commit 24fd1a0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
13 changes: 10 additions & 3 deletions src/cmd/compile/internal/importer/ureader.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ func ReadPackage(ctxt *types2.Context, imports map[string]*types2.Package, input

r := pr.newReader(pkgbits.RelocMeta, pkgbits.PublicRootIdx, pkgbits.SyncPublic)
pkg := r.pkg()
r.Bool() // TODO(mdempsky): Remove; was "has init"

if r.Version().Has(pkgbits.HasInit) {
r.Bool()
}

for i, n := 0, r.Len(); i < n; i++ {
// As if r.obj(), but avoiding the Scope.Lookup call,
// to avoid eager loading of imports.
r.Sync(pkgbits.SyncObject)
assert(!r.Bool())
if r.Version().Has(pkgbits.DerivedFuncInstance) {
assert(!r.Bool())
}
r.p.objIdx(r.Reloc(pkgbits.RelocObj))
assert(r.Len() == 0)
}
Expand Down Expand Up @@ -366,7 +371,9 @@ func (r *reader) param() *types2.Var {
func (r *reader) obj() (types2.Object, []types2.Type) {
r.Sync(pkgbits.SyncObject)

assert(!r.Bool())
if r.Version().Has(pkgbits.DerivedFuncInstance) {
assert(!r.Bool())
}

pkg, name := r.p.objIdx(r.Reloc(pkgbits.RelocObj))
obj := pkg.Scope().Lookup(name)
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/compile/internal/noder/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,9 @@ func (r *reader) obj() ir.Node {
// and returns the encoded reference to it, without instantiating it.
func (r *reader) objInfo() objInfo {
r.Sync(pkgbits.SyncObject)
assert(!r.Bool()) // TODO(mdempsky): Remove; was derived func inst.
if r.Version().Has(pkgbits.DerivedFuncInstance) {
assert(!r.Bool())
}
idx := r.Reloc(pkgbits.RelocObj)

explicits := make([]typeInfo, r.Len())
Expand Down
30 changes: 23 additions & 7 deletions src/cmd/compile/internal/noder/unified.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ func writePkgStub(m posMap, noders []*noder) string {
{
w := publicRootWriter
w.pkg(pkg)
w.Bool(false) // TODO(mdempsky): Remove; was "has init"

if w.Version().Has(pkgbits.HasInit) {
w.Bool(false)
}

scope := pkg.Scope()
names := scope.Names()
Expand Down Expand Up @@ -410,11 +413,15 @@ func readPackage(pr *pkgReader, importpkg *types.Pkg, localStub bool) {
base.ErrorExit()
}

r.Bool() // TODO(mdempsky): Remove; was "has init"
if r.Version().Has(pkgbits.HasInit) {
r.Bool()
}

for i, n := 0, r.Len(); i < n; i++ {
r.Sync(pkgbits.SyncObject)
assert(!r.Bool())
if r.Version().Has(pkgbits.DerivedFuncInstance) {
assert(!r.Bool())
}
idx := r.Reloc(pkgbits.RelocObj)
assert(r.Len() == 0)

Expand Down Expand Up @@ -477,11 +484,15 @@ func writeUnifiedExport(out io.Writer) {
r.Sync(pkgbits.SyncPkg)
selfPkgIdx = l.relocIdx(pr, pkgbits.RelocPkg, r.Reloc(pkgbits.RelocPkg))

r.Bool() // TODO(mdempsky): Remove; was "has init"
if r.Version().Has(pkgbits.HasInit) {
r.Bool()
}

for i, n := 0, r.Len(); i < n; i++ {
r.Sync(pkgbits.SyncObject)
assert(!r.Bool())
if r.Version().Has(pkgbits.DerivedFuncInstance) {
assert(!r.Bool())
}
idx := r.Reloc(pkgbits.RelocObj)
assert(r.Len() == 0)

Expand All @@ -508,12 +519,17 @@ func writeUnifiedExport(out io.Writer) {

w.Sync(pkgbits.SyncPkg)
w.Reloc(pkgbits.RelocPkg, selfPkgIdx)
w.Bool(false) // TODO(mdempsky): Remove; was "has init"

if w.Version().Has(pkgbits.HasInit) {
w.Bool(false)
}

w.Len(len(idxs))
for _, idx := range idxs {
w.Sync(pkgbits.SyncObject)
w.Bool(false)
if w.Version().Has(pkgbits.DerivedFuncInstance) {
w.Bool(false)
}
w.Reloc(pkgbits.RelocObj, idx)
w.Len(0)
}
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/compile/internal/noder/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,9 @@ func (w *writer) obj(obj types2.Object, explicits *types2.TypeList) {
// bitstream.
func (w *writer) objInfo(info objInfo) {
w.Sync(pkgbits.SyncObject)
w.Bool(false) // TODO(mdempsky): Remove; was derived func inst.
if w.Version().Has(pkgbits.DerivedFuncInstance) {
w.Bool(false)
}
w.Reloc(pkgbits.RelocObj, info.idx)

w.Len(len(info.explicits))
Expand Down
12 changes: 9 additions & 3 deletions src/go/internal/gcimporter/ureader.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ func readUnifiedPackage(fset *token.FileSet, ctxt *types.Context, imports map[st

r := pr.newReader(pkgbits.RelocMeta, pkgbits.PublicRootIdx, pkgbits.SyncPublic)
pkg := r.pkg()
r.Bool() // TODO(mdempsky): Remove; was "has init"
if r.Version().Has(pkgbits.HasInit) {
r.Bool()
}

for i, n := 0, r.Len(); i < n; i++ {
// As if r.obj(), but avoiding the Scope.Lookup call,
// to avoid eager loading of imports.
r.Sync(pkgbits.SyncObject)
assert(!r.Bool())
if r.Version().Has(pkgbits.DerivedFuncInstance) {
assert(!r.Bool())
}
r.p.objIdx(r.Reloc(pkgbits.RelocObj))
assert(r.Len() == 0)
}
Expand Down Expand Up @@ -428,7 +432,9 @@ func (r *reader) param() *types.Var {
func (r *reader) obj() (types.Object, []types.Type) {
r.Sync(pkgbits.SyncObject)

assert(!r.Bool())
if r.Version().Has(pkgbits.DerivedFuncInstance) {
assert(!r.Bool())
}

pkg, name := r.p.objIdx(r.Reloc(pkgbits.RelocObj))
obj := pkgScope(pkg).Lookup(name)
Expand Down

0 comments on commit 24fd1a0

Please sign in to comment.