Skip to content

Commit 09b503e

Browse files
touch ups
1 parent 51bb17e commit 09b503e

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

compiler/compiler_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,16 @@ func TestDeclSelection_RemoveUnusedNestedTypesInFunction(t *testing.T) {
380380

381381
srcFiles := []srctesting.Source{{Name: `main.go`, Contents: []byte(src)}}
382382
sel := declSelection(t, srcFiles, nil)
383+
sel.PrintDeclStatus()
383384
sel.IsAlive(`func:command-line-arguments.main`)
384385

385386
sel.IsAlive(`funcVar:command-line-arguments.Foo`)
386387
sel.IsAlive(`func:command-line-arguments.Foo<string>`)
387388
sel.IsDead(`func:command-line-arguments.Foo<int>`)
388389

389390
sel.IsAlive(`typeVar:command-line-arguments.Bar`)
390-
sel.IsAlive(`type:command-line-arguments.Bar<string;>@main.go:4:9`)
391-
sel.IsDead(`type:command-line-arguments.Bar<int;>@main.go:4:9`)
391+
sel.IsAlive(`type:nested:command-line-arguments.Bar<string;>@main.go:4:9`)
392+
sel.IsDead(`type:nested:command-line-arguments.Bar<int;>@main.go:4:9`)
392393

393394
sel.IsDead(`funcVar:command-line-arguments.deadCode`)
394395
sel.IsDead(`func:command-line-arguments.deadCode`)
@@ -413,6 +414,7 @@ func TestDeclSelection_RemoveUnusedNestedTypesInMethod(t *testing.T) {
413414

414415
srcFiles := []srctesting.Source{{Name: `main.go`, Contents: []byte(src)}}
415416
sel := declSelection(t, srcFiles, nil)
417+
sel.PrintDeclStatus()
416418
sel.IsAlive(`func:command-line-arguments.main`)
417419

418420
sel.IsAlive(`typeVar:command-line-arguments.Baz`)
@@ -423,8 +425,8 @@ func TestDeclSelection_RemoveUnusedNestedTypesInMethod(t *testing.T) {
423425
sel.IsAlive(`func:command-line-arguments.(*Baz).Foo<string>`)
424426

425427
sel.IsAlive(`typeVar:command-line-arguments.Bar`)
426-
sel.IsDead(`type:command-line-arguments.Bar<int;>@main.go:5:9`)
427-
sel.IsAlive(`type:command-line-arguments.Bar<string;>@main.go:5:9`)
428+
sel.IsDead(`type:nested:command-line-arguments.Bar<int;>@main.go:5:9`)
429+
sel.IsAlive(`type:nested:command-line-arguments.Bar<string;>@main.go:5:9`)
428430

429431
sel.IsDead(`funcVar:command-line-arguments.deadCode`)
430432
sel.IsDead(`func:command-line-arguments.deadCode`)
@@ -453,8 +455,8 @@ func TestDeclSelection_RemoveAllUnusedNestedTypes(t *testing.T) {
453455
sel.IsDead(`func:command-line-arguments.Foo<int>`)
454456

455457
sel.IsDead(`typeVar:command-line-arguments.Bar`)
456-
sel.IsDead(`type:command-line-arguments.Bar<string;>@main.go:4:9`)
457-
sel.IsDead(`type:command-line-arguments.Bar<int;>@main.go:4:9`)
458+
sel.IsDead(`type:nested:command-line-arguments.Bar<string;>@main.go:4:9`)
459+
sel.IsDead(`type:nested:command-line-arguments.Bar<int;>@main.go:4:9`)
458460

459461
sel.IsDead(`funcVar:command-line-arguments.deadCode`)
460462
sel.IsDead(`func:command-line-arguments.deadCode`)
@@ -482,7 +484,7 @@ func TestDeclSelection_CompletelyRemoveNestedType(t *testing.T) {
482484
sel.IsDead(`func:command-line-arguments.Foo<int>`)
483485

484486
sel.IsDead(`typeVar:command-line-arguments.Bar`)
485-
sel.IsDead(`type:command-line-arguments.Bar<int;>@main.go:4:9`)
487+
sel.IsDead(`type:nested:command-line-arguments.Bar<int;>@main.go:4:9`)
486488

487489
sel.IsDead(`funcVar:command-line-arguments.deadCode`)
488490
sel.IsDead(`func:command-line-arguments.deadCode`)

compiler/declCache.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func (dc *DeclCache) Read(decode func(any) error) error {
8383
if err := decode(decl); err != nil {
8484
return err
8585
}
86+
if decl.ForGeneric || isUnqueDeclFullName(decl.FullName) {
87+
// These declarations should not have been cached.
88+
continue
89+
}
8690
dc.decls[decl.FullName] = decl
8791
}
8892
return nil

compiler/sources/serializer.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
package sources
22

33
import (
4-
"bytes"
54
"encoding/gob"
65
"go/ast"
76
"go/token"
87
"sync"
98
)
109

11-
func (s *Sources) GobEncode() ([]byte, error) {
12-
buf := &bytes.Buffer{}
13-
err := s.Write(gob.NewEncoder(buf).Encode)
14-
return buf.Bytes(), err
15-
}
16-
17-
func (s *Sources) GobDecode(data []byte) error {
18-
return s.Read(gob.NewDecoder(bytes.NewReader(data)).Decode)
19-
}
20-
2110
// Write will call encode multiple times to write the various fields
2211
// of the sources. This is designed to be used with a gob.Encoder.
2312
//

0 commit comments

Comments
 (0)