Index resolution and origin membership

This commit is contained in:
2026-10-09 03:59:16 +00:00
parent c8546ae599
commit 799ebab5a6
5 changed files with 96 additions and 20 deletions

View File

@@ -26,6 +26,37 @@ type resolutionRecord struct {
reasons []string
dependencies []Path
helperExpected *document.Node
reasonSet map[string]struct{}
dependencySet map[string]struct{}
}
func (record *resolutionRecord) addReason(reason string) {
if record.reasonSet == nil {
record.reasonSet = make(map[string]struct{}, len(record.reasons)+1)
for _, existing := range record.reasons {
record.reasonSet[existing] = struct{}{}
}
}
if _, found := record.reasonSet[reason]; found {
return
}
record.reasonSet[reason] = struct{}{}
record.reasons = append(record.reasons, reason)
}
func (record *resolutionRecord) addDependency(path Path) {
pointer := path.String()
if record.dependencySet == nil {
record.dependencySet = make(map[string]struct{}, len(record.dependencies)+1)
for _, existing := range record.dependencies {
record.dependencySet[existing.String()] = struct{}{}
}
}
if _, found := record.dependencySet[pointer]; found {
return
}
record.dependencySet[pointer] = struct{}{}
record.dependencies = append(record.dependencies, path.clone())
}
type resolutionSnapshot struct {
@@ -207,9 +238,9 @@ func (state *resolutionState) addRecord(path Path, kind ChangeKind, reason strin
if kind == ChangeNormalization {
record.kind = ChangeNormalization
}
record.reasons = appendUniqueString(record.reasons, reason)
record.addReason(reason)
for _, dependency := range dependencies {
record.dependencies = appendUniquePath(record.dependencies, dependency)
record.addDependency(dependency)
}
if expected != nil {
record.helperExpected = document.Clone(expected)