File tree Expand file tree Collapse file tree 2 files changed +32
-31
lines changed Expand file tree Collapse file tree 2 files changed +32
-31
lines changed Original file line number Diff line number Diff line change 8
8
package goanalysis
9
9
10
10
import (
11
+ "bytes"
12
+ "encoding/gob"
13
+ "fmt"
11
14
"go/types"
12
15
"reflect"
13
16
14
17
"golang.org/x/tools/go/analysis"
15
18
)
16
19
20
+ // NOTE(ldez) no alteration.
21
+ // codeFact encodes then decodes a fact,
22
+ // just to exercise that logic.
23
+ func codeFact (fact analysis.Fact ) (analysis.Fact , error ) {
24
+ // We encode facts one at a time.
25
+ // A real modular driver would emit all facts
26
+ // into one encoder to improve gob efficiency.
27
+ var buf bytes.Buffer
28
+ if err := gob .NewEncoder (& buf ).Encode (fact ); err != nil {
29
+ return nil , err
30
+ }
31
+
32
+ // Encode it twice and assert that we get the same bits.
33
+ // This helps detect nondeterministic Gob encoding (e.g. of maps).
34
+ var buf2 bytes.Buffer
35
+ if err := gob .NewEncoder (& buf2 ).Encode (fact ); err != nil {
36
+ return nil , err
37
+ }
38
+ if ! bytes .Equal (buf .Bytes (), buf2 .Bytes ()) {
39
+ return nil , fmt .Errorf ("encoding of %T fact is nondeterministic" , fact )
40
+ }
41
+
42
+ newFact := reflect .New (reflect .TypeOf (fact ).Elem ()).Interface ().(analysis.Fact )
43
+ if err := gob .NewDecoder (& buf ).Decode (newFact ); err != nil {
44
+ return nil , err
45
+ }
46
+ return newFact , nil
47
+ }
48
+
17
49
// NOTE(ldez) no alteration.
18
50
// exportedFrom reports whether obj may be visible to a package that imports pkg.
19
51
// This includes not just the exported members of pkg, but also unexported
Original file line number Diff line number Diff line change 1
1
package goanalysis
2
2
3
3
import (
4
- "bytes"
5
- "encoding/gob"
6
- "fmt"
7
4
"go/types"
8
5
"reflect"
9
6
@@ -68,31 +65,3 @@ func inheritFacts(act, dep *action) {
68
65
act .packageFacts [key ] = fact
69
66
}
70
67
}
71
-
72
- // codeFact encodes then decodes a fact,
73
- // just to exercise that logic.
74
- func codeFact (fact analysis.Fact ) (analysis.Fact , error ) {
75
- // We encode facts one at a time.
76
- // A real modular driver would emit all facts
77
- // into one encoder to improve gob efficiency.
78
- var buf bytes.Buffer
79
- if err := gob .NewEncoder (& buf ).Encode (fact ); err != nil {
80
- return nil , err
81
- }
82
-
83
- // Encode it twice and assert that we get the same bits.
84
- // This helps detect nondeterministic Gob encoding (e.g. of maps).
85
- var buf2 bytes.Buffer
86
- if err := gob .NewEncoder (& buf2 ).Encode (fact ); err != nil {
87
- return nil , err
88
- }
89
- if ! bytes .Equal (buf .Bytes (), buf2 .Bytes ()) {
90
- return nil , fmt .Errorf ("encoding of %T fact is nondeterministic" , fact )
91
- }
92
-
93
- newFact := reflect .New (reflect .TypeOf (fact ).Elem ()).Interface ().(analysis.Fact )
94
- if err := gob .NewDecoder (& buf ).Decode (newFact ); err != nil {
95
- return nil , err
96
- }
97
- return newFact , nil
98
- }
You can’t perform that action at this time.
0 commit comments