From 562d05bd4d8f1c285b8f861f59edd6829721e0d7 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Fri, 13 Sep 2024 08:49:08 +1000 Subject: [PATCH] fix: don't setup extractors in init (#2664) fixes: #2660 --- go-runtime/schema/extract.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/go-runtime/schema/extract.go b/go-runtime/schema/extract.go index 56091af5e2..862de193d6 100644 --- a/go-runtime/schema/extract.go +++ b/go-runtime/schema/extract.go @@ -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, @@ -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. @@ -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)...) @@ -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)) }