mirror of
https://github.com/golang/go
synced 2024-11-17 12:04:43 -07:00
cmd/compile/internal/typecheck: remove iexport assumption of LocalPkg.Path == ""
The indexed export data format encodes the local package's path as "", because that's historically how we've represented it within cmd/compile. The format also requires the local package to be first in the exported list of packages, and was implicitly relying on "" sorting before other, non-empty package paths. We can't change the format without breaking existing importers (e.g., go/internal/gcimporter), but we can at least remove the dependency on LocalPkg.Path being "". Prep refactoring for CL 393715. Updates #51734. Change-Id: I6dd4eafd2d538f4e81376948ef9e92fc44a5462a Reviewed-on: https://go-review.googlesource.com/c/go/+/406057 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
1973be519a
commit
e3661d5f08
@ -394,12 +394,15 @@ func (w *exportWriter) writeIndex(index map[*types.Sym]uint64, mainIndex bool) {
|
||||
pkgs = append(pkgs, pkg)
|
||||
}
|
||||
sort.Slice(pkgs, func(i, j int) bool {
|
||||
return pkgs[i].Path < pkgs[j].Path
|
||||
return exportPath(pkgs[i]) < exportPath(pkgs[j])
|
||||
})
|
||||
if mainIndex {
|
||||
base.Assertf(pkgs[0] == types.LocalPkg, "LocalPkg must be first")
|
||||
}
|
||||
|
||||
w.uint64(uint64(len(pkgs)))
|
||||
for _, pkg := range pkgs {
|
||||
w.string(pkg.Path)
|
||||
w.string(exportPath(pkg))
|
||||
if mainIndex {
|
||||
w.string(pkg.Name)
|
||||
w.uint64(uint64(pkg.Height))
|
||||
@ -714,7 +717,18 @@ func (w *exportWriter) pkg(pkg *types.Pkg) {
|
||||
// Ensure any referenced packages are declared in the main index.
|
||||
w.p.allPkgs[pkg] = true
|
||||
|
||||
w.string(pkg.Path)
|
||||
w.string(exportPath(pkg))
|
||||
}
|
||||
|
||||
// exportPath returns the path for pkg as it appears in the iexport
|
||||
// file format. For historical reasons (before cmd/compile required
|
||||
// the -p flag), the local package is represented as the empty string,
|
||||
// instead of its actual path.
|
||||
func exportPath(pkg *types.Pkg) string {
|
||||
if pkg == types.LocalPkg {
|
||||
return ""
|
||||
}
|
||||
return pkg.Path
|
||||
}
|
||||
|
||||
func (w *exportWriter) qualifiedIdent(n *ir.Name) {
|
||||
|
Loading…
Reference in New Issue
Block a user