@@ -63,10 +63,15 @@ type typeWriter struct {
63
63
buf * bytes.Buffer
64
64
seen map [Type ]bool
65
65
qf Qualifier
66
+ hash bool
66
67
}
67
68
68
69
func newTypeWriter (buf * bytes.Buffer , qf Qualifier ) * typeWriter {
69
- return & typeWriter {buf , make (map [Type ]bool ), qf }
70
+ return & typeWriter {buf , make (map [Type ]bool ), qf , false }
71
+ }
72
+
73
+ func newTypeHasher (buf * bytes.Buffer ) * typeWriter {
74
+ return & typeWriter {buf , make (map [Type ]bool ), nil , true }
70
75
}
71
76
72
77
func (w * typeWriter ) byte (b byte ) { w .buf .WriteByte (b ) }
@@ -208,7 +213,7 @@ func (w *typeWriter) typ(typ Type) {
208
213
// types. Write them to aid debugging, but don't write
209
214
// them when we need an instance hash: whether a type
210
215
// is fully expanded or not doesn't matter for identity.
211
- if typeHashing == 0 && t .instPos != nil {
216
+ if ! w . hash && t .instPos != nil {
212
217
w .byte (instanceMarker )
213
218
}
214
219
w .typeName (t .obj )
@@ -292,7 +297,7 @@ func (w *typeWriter) tParamList(list []*TypeParam) {
292
297
293
298
func (w * typeWriter ) typeName (obj * TypeName ) {
294
299
if obj == nil {
295
- assert (typeHashing == 0 ) // we need an object for type hashing
300
+ assert (! w . hash ) // we need an object for type hashing
296
301
w .string ("<Named w/o object>" )
297
302
return
298
303
}
@@ -301,7 +306,7 @@ func (w *typeWriter) typeName(obj *TypeName) {
301
306
}
302
307
w .string (obj .name )
303
308
304
- if typeHashing != 0 {
309
+ if w . hash {
305
310
// For local defined types, use the (original!) TypeName's scope
306
311
// numbers to disambiguate.
307
312
if typ , _ := obj .typ .(* Named ); typ != nil {
@@ -335,7 +340,7 @@ func (w *typeWriter) tuple(tup *Tuple, variadic bool) {
335
340
w .string (", " )
336
341
}
337
342
// parameter names are ignored for type identity and thus type hashes
338
- if typeHashing == 0 && v .name != "" {
343
+ if ! w . hash && v .name != "" {
339
344
w .string (v .name )
340
345
w .byte (' ' )
341
346
}
@@ -383,8 +388,8 @@ func (w *typeWriter) signature(sig *Signature) {
383
388
}
384
389
385
390
w .byte (' ' )
386
- if n == 1 && (typeHashing != 0 || sig .results .vars [0 ].name == "" ) {
387
- // single unnamed result (if typeHashing , name must be ignored)
391
+ if n == 1 && (w . hash || sig .results .vars [0 ].name == "" ) {
392
+ // single unnamed result (if type hashing , name must be ignored)
388
393
w .typ (sig .results .vars [0 ].typ )
389
394
return
390
395
}
0 commit comments