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>
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
}
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
//
// 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
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
}
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
// 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.
// 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 }
// 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
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 {
// Misc
{Scope{}, 60, 104},
- {Package{}, 40, 80},
+ {Package{}, 36, 72},
{_TypeSet{}, 28, 56},
}