Skip to content

Commit a8eb6d5

Browse files
committed
cmd/compile: simplify field/method export (internal cleanup)
Towards a fix for #15514. Change-Id: I62073e9fdcfe5ddda9b0a47fe8554b524191a77c Reviewed-on: https://go-review.googlesource.com/27638 Reviewed-by: Matthew Dempsky <[email protected]>
1 parent ec75230 commit a8eb6d5

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

src/cmd/compile/internal/gc/bexport.go

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,6 @@ func (p *exporter) typ(t *Type) {
810810
}
811811

812812
func (p *exporter) qualifiedName(sym *Sym) {
813-
if strings.Contains(sym.Name, ".") {
814-
Fatalf("exporter: invalid symbol name: %s", sym.Name)
815-
}
816813
p.string(sym.Name)
817814
p.pkg(sym.Pkg)
818815
}
@@ -834,7 +831,7 @@ func (p *exporter) fieldList(t *Type) {
834831

835832
func (p *exporter) field(f *Field) {
836833
p.pos(f.Nname)
837-
p.fieldName(f.Sym, f)
834+
p.fieldName(f)
838835
p.typ(f.Type)
839836
p.string(f.Note)
840837
}
@@ -856,37 +853,27 @@ func (p *exporter) methodList(t *Type) {
856853

857854
func (p *exporter) method(m *Field) {
858855
p.pos(m.Nname)
859-
p.fieldName(m.Sym, m)
856+
p.fieldName(m)
860857
p.paramList(m.Type.Params(), false)
861858
p.paramList(m.Type.Results(), false)
862859
}
863860

864861
// fieldName is like qualifiedName but it doesn't record the package
865862
// for blank (_) or exported names.
866-
func (p *exporter) fieldName(sym *Sym, t *Field) {
867-
if t != nil && sym != t.Sym {
868-
Fatalf("exporter: invalid fieldName parameters")
869-
}
870-
871-
name := sym.Name
872-
if t != nil {
873-
if t.Embedded == 0 {
874-
name = sym.Name
875-
} else if bname := basetypeName(t.Type); bname != "" && !exportname(bname) {
876-
// anonymous field with unexported base type name: use "?" as field name
877-
// (bname != "" per spec, but we are conservative in case of errors)
878-
name = "?"
879-
} else {
880-
name = ""
881-
}
882-
}
863+
func (p *exporter) fieldName(t *Field) {
864+
name := t.Sym.Name
883865

884-
if strings.Contains(name, ".") {
885-
Fatalf("exporter: invalid symbol name: %s", name)
866+
if t.Embedded != 0 {
867+
name = "" // anonymous field
868+
if bname := basetypeName(t.Type); bname != "" && !exportname(bname) {
869+
// anonymous field with unexported base type name
870+
name = "?" // unexported name to force export of package
871+
}
886872
}
887873
p.string(name)
888-
if name == "?" || name != "_" && name != "" && !exportname(name) {
889-
p.pkg(sym.Pkg)
874+
875+
if name != "_" && name != "" && !exportname(name) {
876+
p.pkg(t.Sym.Pkg)
890877
}
891878
}
892879

@@ -895,10 +882,8 @@ func basetypeName(t *Type) string {
895882
if s == nil && t.IsPtr() {
896883
s = t.Elem().Sym // deref
897884
}
885+
// s should exist, but be conservative
898886
if s != nil {
899-
if strings.Contains(s.Name, ".") {
900-
Fatalf("exporter: invalid symbol name: %s", s.Name)
901-
}
902887
return s.Name
903888
}
904889
return ""

src/cmd/compile/internal/gc/bimport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ func (p *importer) fieldName() *Sym {
595595
// (see parser.go:sym). The binary exporter only exports blank as a non-exported
596596
// identifier without qualification.
597597
pkg = builtinpkg
598-
} else if name == "?" || name != "" && !exportname(name) {
598+
} else if name != "" && !exportname(name) {
599599
if name == "?" {
600600
name = ""
601601
}

0 commit comments

Comments
 (0)