diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-05-18 19:03:00 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-05-19 21:53:04 +0000 |
commit | eff66248ea242c2611a9a0e2be47a762073e81b2 (patch) | |
tree | 3259009953ffdb1c715797362f60c6c42a59266c /src/cmd/compile/internal/importer | |
parent | 3f6f12972b08d8559264971e8706efb3fbfd106a (diff) | |
download | go-eff66248ea242c2611a9a0e2be47a762073e81b2.tar.gz go-eff66248ea242c2611a9a0e2be47a762073e81b2.zip |
[dev.typeparams] cmd/compile/internal/types2: implement package height
This CL extends types2 with package height information, styled after
the way it works already in cmd/compile:
- A new NewPackageHeight entry point for constructing packages with
explicit height information, and a corresponding Height accessor
method.
- The types2 importer is updated to provide package height for
imported packages.
- The types2 type checker sets height based on imported packages.
- Adds an assertion to irgen to verify that types1 and types2
calculated the same height for the source package.
- Func.less's ordering incorporates package height to match
types.Sym.less and is generalized to object.less.
- sortTypes (used for sorting embedded types) now sorts defined types
using object.less as well.
Change-Id: Id4dbbb627aef405cc7438d611cbdd5a5bd97fc96
Reviewed-on: https://go-review.googlesource.com/c/go/+/321231
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/importer')
-rw-r--r-- | src/cmd/compile/internal/importer/iimport.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/importer/iimport.go b/src/cmd/compile/internal/importer/iimport.go index 5c02f837ef..b91b209d35 100644 --- a/src/cmd/compile/internal/importer/iimport.go +++ b/src/cmd/compile/internal/importer/iimport.go @@ -118,17 +118,22 @@ func iImportData(imports map[string]*types2.Package, data []byte, path string) ( pkgPathOff := r.uint64() pkgPath := p.stringAt(pkgPathOff) pkgName := p.stringAt(r.uint64()) - _ = r.uint64() // package height; unused by go/types + pkgHeight := int(r.uint64()) if pkgPath == "" { pkgPath = path } pkg := imports[pkgPath] if pkg == nil { - pkg = types2.NewPackage(pkgPath, pkgName) + pkg = types2.NewPackageHeight(pkgPath, pkgName, pkgHeight) imports[pkgPath] = pkg - } else if pkg.Name() != pkgName { - errorf("conflicting names %s and %s for package %q", pkg.Name(), pkgName, path) + } 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 |