mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
fe77a5413e
commit
07029254a0
6 changed files with 59 additions and 12 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue