]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.unified] cmd/compile/internal/types2: remove package height
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 6 Jun 2022 03:52:12 +0000 (10:52 +0700)
committerGopher Robot <gobot@golang.org>
Mon, 27 Jun 2022 22:54:44 +0000 (22:54 +0000)
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>

src/cmd/compile/internal/importer/iimport.go
src/cmd/compile/internal/importer/ureader.go
src/cmd/compile/internal/types2/object.go
src/cmd/compile/internal/types2/package.go
src/cmd/compile/internal/types2/resolver.go
src/cmd/compile/internal/types2/sizeof_test.go

index 576036bdce37b1259b9e32f138d8113c842ef7cc..440f557a80da443a1859c23d261d4763805f4cde 100644 (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
index e5547b6d444c721040fb795525beda5b59fc860d..dc5614c8410760a64bf676302fb7ff72620d7a4a 100644 (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
index df080f071c3f44c7aaf325b687f3ab70a926a414..f37356180973abf86561321e093f6b22dfb5de3b 100644 (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
        }
 
index 8044e7e6a76ce25254bcacab3599d547698e64a6..26f10645d28be6eeba0ad5b1df4d1265e397a28f 100644 (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 }
 
index 5d498b6b2b1f48ba83723090704f42dabffc772b..77881f493f6749fd3bd93fccb6eae89423b559f8 100644 (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 {
index 17876d1f3c2354a1d9fc09cee096157424e99a78..af82b3fa7add821c952abca0347f94c9358327bb 100644 (file)
@@ -47,7 +47,7 @@ func TestSizeof(t *testing.T) {
 
                // Misc
                {Scope{}, 60, 104},
-               {Package{}, 40, 80},
+               {Package{}, 36, 72},
                {_TypeSet{}, 28, 56},
        }