diff options
author | Keith Randall <khr@golang.org> | 2021-03-07 23:48:02 -0800 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2021-03-09 18:35:29 +0000 |
commit | 48895d021bf631f15d68ecc10cab89ebd9cb28f6 (patch) | |
tree | 257a91659a7cfea887ffb1b2fc08abc35668fcec /src/cmd/compile/internal/typecheck/iexport.go | |
parent | b6df58bd1f3b2a05787f62bbec4267f7867d4bbd (diff) | |
download | go-48895d021bf631f15d68ecc10cab89ebd9cb28f6.tar.gz go-48895d021bf631f15d68ecc10cab89ebd9cb28f6.zip |
cmd/compile: remove skipping of implicit operations during export
We'll need to attach types to these operations, so we need to
represent them in the import/export data.
Some of the operations use a selector indicating a different package,
so we need to provide an option to encode the package of a selector.
The default selector() function can't encode that extra information,
as selector's exact encoding is used by go/types.
Change-Id: I4c110fe347b3d915f88a722834bc4058baea7854
Reviewed-on: https://go-review.googlesource.com/c/go/+/299771
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/iexport.go')
-rw-r--r-- | src/cmd/compile/internal/typecheck/iexport.go | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go index 6f33ca1597..fa16357066 100644 --- a/src/cmd/compile/internal/typecheck/iexport.go +++ b/src/cmd/compile/internal/typecheck/iexport.go @@ -617,6 +617,11 @@ func (w *exportWriter) selector(s *types.Sym) { base.Fatalf("missing currPkg") } + // If the selector being written is unexported, it comes with a package qualifier. + // If the selector being written is exported, it is not package-qualified. + // See the spec: https://golang.org/ref/spec#Uniqueness_of_identifiers + // As an optimization, we don't actually write the package every time - instead we + // call setPkg before a group of selectors (all of which must have the same package qualifier). pkg := w.currPkg if types.IsExported(s.Name) { pkg = types.LocalPkg @@ -628,6 +633,26 @@ func (w *exportWriter) selector(s *types.Sym) { w.string(s.Name) } +// Export a selector, but one whose package may not match +// the package being compiled. This is a separate function +// because the standard selector() serialization format is fixed +// by the go/types reader. This one can only be used during +// inline/generic body exporting. +func (w *exportWriter) exoticSelector(s *types.Sym) { + pkg := w.currPkg + if types.IsExported(s.Name) { + pkg = types.LocalPkg + } + + w.string(s.Name) + if s.Pkg == pkg { + w.uint64(0) + } else { + w.uint64(1) + w.pkg(s.Pkg) + } +} + func (w *exportWriter) typ(t *types.Type) { w.data.uint64(w.p.typOff(t)) } @@ -1299,21 +1324,6 @@ func simplifyForExport(n ir.Node) ir.Node { case ir.OPAREN: n := n.(*ir.ParenExpr) return simplifyForExport(n.X) - case ir.ODEREF: - n := n.(*ir.StarExpr) - if n.Implicit() { - return simplifyForExport(n.X) - } - case ir.OADDR: - n := n.(*ir.AddrExpr) - if n.Implicit() { - return simplifyForExport(n.X) - } - case ir.ODOT, ir.ODOTPTR: - n := n.(*ir.SelectorExpr) - if n.Implicit() { - return simplifyForExport(n.X) - } } return n } @@ -1437,7 +1447,7 @@ func (w *exportWriter) expr(n ir.Node) { w.op(ir.OXDOT) w.pos(n.Pos()) w.expr(n.X) - w.selector(n.Sel) + w.exoticSelector(n.Sel) case ir.ODOTTYPE, ir.ODOTTYPE2: n := n.(*ir.TypeAssertExpr) |