Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ensure rule index not modified after indexing #1877

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions resolve/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type RuleIndex struct {
// The underlying state of rules. All indexing should be reproducible from this.
rules []*ruleRecord

// If indexing of rules has occurred already
indexed bool

// Rules indexed by label.
// Computed from `rules` when indexing.
labelMap map[label.Label]*ruleRecord
Expand Down Expand Up @@ -148,6 +151,10 @@ func NewRuleIndex(mrslv func(ruleKind, pkgRel string) Resolver, exts ...interfac
//
// AddRule may only be called before Finish.
func (ix *RuleIndex) AddRule(c *config.Config, r *rule.Rule, f *rule.File) {
if ix.indexed {
log.Fatal("AddRule called after Finish")
}

var lang string
var imps []ImportSpec
var embeds []label.Label
Expand Down Expand Up @@ -203,6 +210,8 @@ func (ix *RuleIndex) Finish() {

ix.collectEmbeds()
ix.buildImportIndex()

ix.indexed = true
}

func (ix *RuleIndex) collectEmbeds() {
Expand Down