cmd/compile: add package height to export data

A package's height is defined as the length of the longest import path
between itself and a leaf package (i.e., package with no imports).

We can't rely on knowing the path of the package being compiled, so
package height is useful for defining a package ordering.

Updates #24693.

Change-Id: I965162c440b6c5397db91b621ea0be7fa63881f1
Reviewed-on: https://go-review.googlesource.com/105038
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Matthew Dempsky 2018-04-05 14:29:32 -07:00
parent fe77a5413e
commit 07029254a0
6 changed files with 59 additions and 12 deletions

View file

@ -141,6 +141,11 @@ func Main(archInit func(*Arch)) {
localpkg = types.NewPkg("", "")
localpkg.Prefix = "\"\""
// We won't know localpkg's height until after import
// processing. In the mean time, set to MaxPkgHeight to ensure
// height comparisons at least work until then.
localpkg.Height = types.MaxPkgHeight
// pseudo-package, for scoping
builtinpkg = types.NewPkg("go.builtin", "") // TODO(gri) name this package go.builtin?
builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
@ -925,6 +930,10 @@ func loadsys() {
inimport = false
}
// myheight tracks the local package's height based on packages
// imported so far.
var myheight int
func importfile(f *Val) *types.Pkg {
path_, ok := f.U.(string)
if !ok {
@ -1117,6 +1126,10 @@ func importfile(f *Val) *types.Pkg {
errorexit()
}
if importpkg.Height >= myheight {
myheight = importpkg.Height + 1
}
return importpkg
}