Skip to content

Commit

Permalink
fix: don't setup extractors in init (#2664)
Browse files Browse the repository at this point in the history
fixes: #2660
  • Loading branch information
stuartwdouglas authored Sep 12, 2024
1 parent ed06fbe commit 562d05b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions go-runtime/schema/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ import (
// It is a list of lists, where each list is a round of tasks dependent on the prior round's execution (e.g. an analyzer
// in Extractors[1] will only execute once all analyzers in Extractors[0] complete). Elements of the same list
// should be considered unordered and may run in parallel.
var Extractors [][]*analysis.Analyzer

func init() {
Extractors = [][]*analysis.Analyzer{
func Extractors() [][]*analysis.Analyzer {
ret := [][]*analysis.Analyzer{
{
initialize.Analyzer,
inspect.Analyzer,
Expand Down Expand Up @@ -82,6 +80,16 @@ func init() {
finalize.Analyzer,
},
}
for i := range ret {
for j := range ret[i] {
if ret[i][j] == nil {
// This should never happen, but we have seen something that looks like a go compiler bug
// If it happens again this should give us more information
panic(fmt.Sprintf("analyzer at Extractors[%d][%d] not yet initialized", i, j))
}
}
}
return ret
}

// NativeNames is a map of top-level declarations to their native Go names.
Expand Down Expand Up @@ -288,7 +296,8 @@ func analyzersWithDependencies() []*analysis.Analyzer {
// requirements to the analyzers
//
// flattens Extractors (a list of lists) into a single list to provide as input for the checker
for i, extractorRound := range Extractors {
extractors := Extractors()
for i, extractorRound := range extractors {
for _, extractor := range extractorRound {
extractor.RunDespiteErrors = true
extractor.Requires = append(extractor.Requires, dependenciesBeforeIndex(i)...)
Expand All @@ -301,7 +310,8 @@ func analyzersWithDependencies() []*analysis.Analyzer {
func dependenciesBeforeIndex(idx int) []*analysis.Analyzer {
var deps []*analysis.Analyzer
for i := range idx {
for _, extractor := range Extractors[i] {
extractors := Extractors()
for _, extractor := range extractors[i] {
if extractor == nil {
panic(fmt.Sprintf("analyzer at Extractors[%d] not yet initialized", i))
}
Expand Down

0 comments on commit 562d05b

Please sign in to comment.