Skip to content

Commit 3c8c9e1

Browse files
committed
go/types: don't print instance markers for type hashes
This is a port of CL 345891 to go/types. Change-Id: I5abcb9c9c5110923a743f0c47d9b34b2baabab68 Reviewed-on: https://go-review.googlesource.com/c/go/+/346555 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 2d98a4b commit 3c8c9e1

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/go/types/subst.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,28 +259,23 @@ func (subst *subster) typ(typ Type) Type {
259259
var instanceHashing = 0
260260

261261
func instantiatedHash(typ *Named, targs []Type) string {
262+
var buf bytes.Buffer
263+
262264
assert(instanceHashing == 0)
263265
instanceHashing++
264-
var buf bytes.Buffer
265266
w := newTypeWriter(&buf, nil)
266267
w.typeName(typ.obj)
267268
w.typeList(targs)
268269
instanceHashing--
269270

270-
// With respect to the represented type, whether a
271-
// type is fully expanded or stored as instance
272-
// does not matter - they are the same types.
273-
// Remove the instanceMarkers printed for instances.
274-
res := buf.Bytes()
275-
i := 0
276-
for _, b := range res {
277-
if b != instanceMarker {
278-
res[i] = b
279-
i++
271+
if debug {
272+
// there should be no instance markers in type hashes
273+
for _, b := range buf.Bytes() {
274+
assert(b != instanceMarker)
280275
}
281276
}
282277

283-
return string(res[:i])
278+
return buf.String()
284279
}
285280

286281
// typOrNil is like typ but if the argument is nil it is replaced with Typ[Invalid].

src/go/types/typestring.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ func (w *typeWriter) typ(typ Type) {
204204
}
205205

206206
case *Named:
207-
if t.instPos != nil {
207+
// Instance markers indicate unexpanded instantiated
208+
// types. Write them to aid debugging, but don't write
209+
// them when we need an instance hash: whether a type
210+
// is fully expanded or not doesn't matter for identity.
211+
if instanceHashing == 0 && t.instPos != nil {
208212
w.byte(instanceMarker)
209213
}
210214
w.typeName(t.obj)

0 commit comments

Comments
 (0)