mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] cmd/compile/internal/types2: remove unused gcCompatibilityMode flag (cleanup)
This flag is not needed by types2 (and possibly can also be removed from go/types). Removed some unnecessary comments along the way. Updates #46174. Change-Id: I1a7a99f724205a084d1c9850bce6f6f5d33f83ca Reviewed-on: https://go-review.googlesource.com/c/go/+/339831 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
bb5608dd5d
commit
f14908d01b
1 changed files with 13 additions and 85 deletions
|
|
@ -39,27 +39,6 @@ func RelativeTo(pkg *Package) Qualifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If gcCompatibilityMode is set, printing of types is modified
|
|
||||||
// to match the representation of some types in the gc compiler:
|
|
||||||
//
|
|
||||||
// - byte and rune lose their alias name and simply stand for
|
|
||||||
// uint8 and int32 respectively
|
|
||||||
// - embedded interfaces get flattened (the embedding info is lost,
|
|
||||||
// and certain recursive interface types cannot be printed anymore)
|
|
||||||
//
|
|
||||||
// This makes it easier to compare packages computed with the type-
|
|
||||||
// checker vs packages imported from gc export data.
|
|
||||||
//
|
|
||||||
// Caution: This flag affects all uses of WriteType, globally.
|
|
||||||
// It is only provided for testing in conjunction with
|
|
||||||
// gc-generated data.
|
|
||||||
//
|
|
||||||
// This flag is exported in the x/tools/go/types package. We don't
|
|
||||||
// need it at the moment in the std repo and so we don't export it
|
|
||||||
// anymore. We should eventually try to remove it altogether.
|
|
||||||
// TODO(gri) remove this
|
|
||||||
var gcCompatibilityMode bool
|
|
||||||
|
|
||||||
// TypeString returns the string representation of typ.
|
// TypeString returns the string representation of typ.
|
||||||
// The Qualifier controls the printing of
|
// The Qualifier controls the printing of
|
||||||
// package-level objects, and may be nil.
|
// package-level objects, and may be nil.
|
||||||
|
|
@ -106,16 +85,6 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if gcCompatibilityMode {
|
|
||||||
// forget the alias names
|
|
||||||
switch t.kind {
|
|
||||||
case Byte:
|
|
||||||
t = Typ[Uint8]
|
|
||||||
case Rune:
|
|
||||||
t = Typ[Int32]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buf.WriteString(t.name)
|
buf.WriteString(t.name)
|
||||||
|
|
||||||
case *Array:
|
case *Array:
|
||||||
|
|
@ -174,66 +143,25 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Interface:
|
case *Interface:
|
||||||
// We write the source-level methods and embedded types rather
|
|
||||||
// than the actual method set since resolved method signatures
|
|
||||||
// may have non-printable cycles if parameters have embedded
|
|
||||||
// interface types that (directly or indirectly) embed the
|
|
||||||
// current interface. For instance, consider the result type
|
|
||||||
// of m:
|
|
||||||
//
|
|
||||||
// type T interface{
|
|
||||||
// m() interface{ T }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
buf.WriteString("interface{")
|
buf.WriteString("interface{")
|
||||||
empty := true
|
empty := true
|
||||||
if gcCompatibilityMode {
|
for i, m := range t.methods {
|
||||||
// print flattened interface
|
if i > 0 {
|
||||||
// (useful to compare against gc-generated interfaces)
|
|
||||||
tset := t.typeSet()
|
|
||||||
for i, m := range tset.methods {
|
|
||||||
if i > 0 {
|
|
||||||
buf.WriteString("; ")
|
|
||||||
}
|
|
||||||
buf.WriteString(m.name)
|
|
||||||
writeSignature(buf, m.typ.(*Signature), qf, visited)
|
|
||||||
empty = false
|
|
||||||
}
|
|
||||||
if !empty && tset.hasTerms() {
|
|
||||||
buf.WriteString("; ")
|
buf.WriteString("; ")
|
||||||
}
|
}
|
||||||
first := true
|
buf.WriteString(m.name)
|
||||||
tset.is(func(t *term) bool {
|
writeSignature(buf, m.typ.(*Signature), qf, visited)
|
||||||
if !first {
|
empty = false
|
||||||
buf.WriteByte('|')
|
}
|
||||||
}
|
if !empty && len(t.embeddeds) > 0 {
|
||||||
first = false
|
buf.WriteString("; ")
|
||||||
if t.tilde {
|
}
|
||||||
buf.WriteByte('~')
|
for i, typ := range t.embeddeds {
|
||||||
}
|
if i > 0 {
|
||||||
writeType(buf, t.typ, qf, visited)
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// print explicit interface methods and embedded types
|
|
||||||
for i, m := range t.methods {
|
|
||||||
if i > 0 {
|
|
||||||
buf.WriteString("; ")
|
|
||||||
}
|
|
||||||
buf.WriteString(m.name)
|
|
||||||
writeSignature(buf, m.typ.(*Signature), qf, visited)
|
|
||||||
empty = false
|
|
||||||
}
|
|
||||||
if !empty && len(t.embeddeds) > 0 {
|
|
||||||
buf.WriteString("; ")
|
buf.WriteString("; ")
|
||||||
}
|
}
|
||||||
for i, typ := range t.embeddeds {
|
writeType(buf, typ, qf, visited)
|
||||||
if i > 0 {
|
empty = false
|
||||||
buf.WriteString("; ")
|
|
||||||
}
|
|
||||||
writeType(buf, typ, qf, visited)
|
|
||||||
empty = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// print /* incomplete */ if needed to satisfy existing tests
|
// print /* incomplete */ if needed to satisfy existing tests
|
||||||
// TODO(gri) get rid of this eventually
|
// TODO(gri) get rid of this eventually
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue