1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:10:04 -07:00

[dev.unified] cmd/compile/internal/types2: remove package height

Same as CL 410342, but for types2.

Updates #51734

Change-Id: I6d6cb8fbb7567d3acf0b8cec0fa74f1344b56a1c
Reviewed-on: https://go-review.googlesource.com/c/go/+/410347
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Cuong Manh Le 2022-06-06 10:52:12 +07:00 committed by Gopher Robot
parent e7100adbca
commit 398d46d538
6 changed files with 7 additions and 33 deletions

View File

@ -139,22 +139,19 @@ func ImportData(imports map[string]*types2.Package, data, path string) (pkg *typ
pkgPathOff := r.uint64()
pkgPath := p.stringAt(pkgPathOff)
pkgName := p.stringAt(r.uint64())
pkgHeight := int(r.uint64())
_ = int(r.uint64()) // was package height, but not necessary anymore.
if pkgPath == "" {
pkgPath = path
}
pkg := imports[pkgPath]
if pkg == nil {
pkg = types2.NewPackageHeight(pkgPath, pkgName, pkgHeight)
pkg = types2.NewPackage(pkgPath, pkgName)
imports[pkgPath] = pkg
} else {
if pkg.Name() != pkgName {
errorf("conflicting names %s and %s for package %q", pkg.Name(), pkgName, path)
}
if pkg.Height() != pkgHeight {
errorf("conflicting heights %v and %v for package %q", pkg.Height(), pkgHeight, path)
}
}
p.pkgCache[pkgPathOff] = pkg

View File

@ -162,9 +162,9 @@ func (r *reader) doPkg() *types2.Package {
}
name := r.String()
height := r.Len()
_ = r.Len() // was package height, but not necessary anymore.
pkg := types2.NewPackageHeight(path, name, height)
pkg := types2.NewPackage(path, name)
r.p.imports[path] = pkg
// TODO(mdempsky): The list of imported packages is important for

View File

@ -189,7 +189,7 @@ func (obj *object) sameId(pkg *Package, name string) bool {
//
// Objects are ordered nil before non-nil, exported before
// non-exported, then by name, and finally (for non-exported
// functions) by package height and path.
// functions) by package path.
func (a *object) less(b *object) bool {
if a == b {
return false
@ -215,9 +215,6 @@ func (a *object) less(b *object) bool {
return a.name < b.name
}
if !ea {
if a.pkg.height != b.pkg.height {
return a.pkg.height < b.pkg.height
}
return a.pkg.path < b.pkg.path
}

View File

@ -14,7 +14,6 @@ type Package struct {
name string
scope *Scope
imports []*Package
height int
complete bool
fake bool // scope lookup errors are silently dropped if package is fake (internal use only)
cgo bool // uses of this package will be rewritten into uses of declarations from _cgo_gotypes.go
@ -23,14 +22,8 @@ type Package struct {
// NewPackage returns a new Package for the given package path and name.
// The package is not complete and contains no explicit imports.
func NewPackage(path, name string) *Package {
return NewPackageHeight(path, name, 0)
}
// NewPackageHeight is like NewPackage, but allows specifying the
// package's height.
func NewPackageHeight(path, name string, height int) *Package {
scope := NewScope(Universe, nopos, nopos, fmt.Sprintf("package %q", path))
return &Package{path: path, name: name, scope: scope, height: height}
return &Package{path: path, name: name, scope: scope}
}
// Path returns the package path.
@ -39,9 +32,6 @@ func (pkg *Package) Path() string { return pkg.path }
// Name returns the package name.
func (pkg *Package) Name() string { return pkg.name }
// Height returns the package height.
func (pkg *Package) Height() int { return pkg.height }
// SetName sets the package name.
func (pkg *Package) SetName(name string) { pkg.name = name }

View File

@ -197,7 +197,6 @@ func (check *Checker) importPackage(pos syntax.Pos, path, dir string) *Package {
// methods with receiver base type names.
func (check *Checker) collectObjects() {
pkg := check.pkg
pkg.height = 0
// pkgImports is the set of packages already imported by any package file seen
// so far. Used to avoid duplicate entries in pkg.imports. Allocate and populate
@ -255,15 +254,6 @@ func (check *Checker) collectObjects() {
continue
}
if imp == Unsafe {
// typecheck ignores imports of package unsafe for
// calculating height.
// TODO(mdempsky): Revisit this. This seems fine, but I
// don't remember explicitly considering this case.
} else if h := imp.height + 1; h > pkg.height {
pkg.height = h
}
// local name overrides imported package name
name := imp.name
if s.LocalPkgName != nil {

View File

@ -47,7 +47,7 @@ func TestSizeof(t *testing.T) {
// Misc
{Scope{}, 60, 104},
{Package{}, 40, 80},
{Package{}, 36, 72},
{_TypeSet{}, 28, 56},
}