Skip to content

Commit a7c5baf

Browse files
committed
chore: isolate code from x/tools
1 parent b5bc828 commit a7c5baf

File tree

2 files changed

+50
-51
lines changed

2 files changed

+50
-51
lines changed

pkg/goanalysis/runner_base.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,56 @@ import (
1717
"golang.org/x/tools/go/analysis"
1818
)
1919

20+
// NOTE(ldez) altered: logger; serialize.
21+
// inheritFacts populates act.facts with
22+
// those it obtains from its dependency, dep.
23+
func inheritFacts(act, dep *action) {
24+
const serialize = false
25+
26+
for key, fact := range dep.objectFacts {
27+
// Filter out facts related to objects
28+
// that are irrelevant downstream
29+
// (equivalently: not in the compiler export data).
30+
if !exportedFrom(key.obj, dep.pkg.Types) {
31+
factsInheritDebugf("%v: discarding %T fact from %s for %s: %s", act, fact, dep, key.obj, fact)
32+
continue
33+
}
34+
35+
// Optionally serialize/deserialize fact
36+
// to verify that it works across address spaces.
37+
if serialize {
38+
var err error
39+
fact, err = codeFact(fact)
40+
if err != nil {
41+
act.r.log.Panicf("internal error: encoding of %T fact failed in %v", fact, act)
42+
}
43+
}
44+
45+
factsInheritDebugf("%v: inherited %T fact for %s: %s", act, fact, key.obj, fact)
46+
act.objectFacts[key] = fact
47+
}
48+
49+
for key, fact := range dep.packageFacts {
50+
// TODO: filter out facts that belong to
51+
// packages not mentioned in the export data
52+
// to prevent side channels.
53+
54+
// Optionally serialize/deserialize fact
55+
// to verify that it works across address spaces
56+
// and is deterministic.
57+
if serialize {
58+
var err error
59+
fact, err = codeFact(fact)
60+
if err != nil {
61+
act.r.log.Panicf("internal error: encoding of %T fact failed in %v", fact, act)
62+
}
63+
}
64+
65+
factsInheritDebugf("%v: inherited %T fact for %s: %s", act, fact, key.pkg.Path(), fact)
66+
act.packageFacts[key] = fact
67+
}
68+
}
69+
2070
// NOTE(ldez) no alteration.
2171
// codeFact encodes then decodes a fact,
2272
// just to exercise that logic.

pkg/goanalysis/runner_facts.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package goanalysis
33
import (
44
"go/types"
55
"reflect"
6-
7-
"golang.org/x/tools/go/analysis"
86
)
97

108
type objectFactKey struct {
@@ -16,52 +14,3 @@ type packageFactKey struct {
1614
pkg *types.Package
1715
typ reflect.Type
1816
}
19-
20-
// inheritFacts populates act.facts with
21-
// those it obtains from its dependency, dep.
22-
func inheritFacts(act, dep *action) {
23-
serialize := false
24-
25-
for key, fact := range dep.objectFacts {
26-
// Filter out facts related to objects
27-
// that are irrelevant downstream
28-
// (equivalently: not in the compiler export data).
29-
if !exportedFrom(key.obj, dep.pkg.Types) {
30-
factsInheritDebugf("%v: discarding %T fact from %s for %s: %s", act, fact, dep, key.obj, fact)
31-
continue
32-
}
33-
34-
// Optionally serialize/deserialize fact
35-
// to verify that it works across address spaces.
36-
if serialize {
37-
var err error
38-
fact, err = codeFact(fact)
39-
if err != nil {
40-
act.r.log.Panicf("internal error: encoding of %T fact failed in %v", fact, act)
41-
}
42-
}
43-
44-
factsInheritDebugf("%v: inherited %T fact for %s: %s", act, fact, key.obj, fact)
45-
act.objectFacts[key] = fact
46-
}
47-
48-
for key, fact := range dep.packageFacts {
49-
// TODO: filter out facts that belong to
50-
// packages not mentioned in the export data
51-
// to prevent side channels.
52-
53-
// Optionally serialize/deserialize fact
54-
// to verify that it works across address spaces
55-
// and is deterministic.
56-
if serialize {
57-
var err error
58-
fact, err = codeFact(fact)
59-
if err != nil {
60-
act.r.log.Panicf("internal error: encoding of %T fact failed in %v", fact, act)
61-
}
62-
}
63-
64-
factsInheritDebugf("%v: inherited %T fact for %s: %s", act, fact, key.pkg.Path(), fact)
65-
act.packageFacts[key] = fact
66-
}
67-
}

0 commit comments

Comments
 (0)