Explicitly delete old logicModule entries from Context.moduleInfo

Creating variants has an optimization to reuse the logicModule of the
original variant as the logicModule of the first new variant.  Using
the same logicModule meant that updating the Context.moduleInfo map
from logicModules to *moduleInfo would overwrite the old entry for
the original variant with the new entry for the first variant.

TransitionMutators will need to keep the original logicModule for
later use, which will require disabling the optimization that reuses
it.  When the first variant is added to the map it no longer overwrites
the original variant.  Excplicitly track the original logicModule and
remove it from the map if necessary.

Bug: 319288033
Test: go test ./...
Change-Id: I05ffdf6d7ce60508f6d9e9657c21032f2c4f5d9c
This commit is contained in:
Colin Cross 2024-03-29 16:00:42 -07:00
parent 7b5888a4f6
commit 1d5e1a56fe

View file

@ -3086,6 +3086,11 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
deps []string
}
type newVariationPair struct {
newVariations modulesOrAliases
origLogicModule Module
}
reverseDeps := make(map[*moduleInfo][]depInfo)
var rename []rename
var replace []replace
@ -3093,7 +3098,7 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
errsCh := make(chan []error)
globalStateCh := make(chan globalStateChange)
newVariationsCh := make(chan modulesOrAliases)
newVariationsCh := make(chan newVariationPair)
done := make(chan bool)
c.depsModified = 0
@ -3113,6 +3118,8 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
pauseCh: pause,
}
origLogicModule := module.logicModule
module.startedMutator = mutator
func() {
@ -3138,7 +3145,7 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
}
if len(mctx.newVariations) > 0 {
newVariationsCh <- mctx.newVariations
newVariationsCh <- newVariationPair{mctx.newVariations, origLogicModule}
}
if len(mctx.reverseDeps) > 0 || len(mctx.replace) > 0 || len(mctx.rename) > 0 || len(mctx.newModules) > 0 || len(mctx.ninjaFileDeps) > 0 {
@ -3154,6 +3161,8 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
return false
}
var obsoleteLogicModules []Module
// Process errs and reverseDeps in a single goroutine
go func() {
for {
@ -3169,7 +3178,10 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
newModules = append(newModules, globalStateChange.newModules...)
deps = append(deps, globalStateChange.deps...)
case newVariations := <-newVariationsCh:
for _, moduleOrAlias := range newVariations {
if newVariations.origLogicModule != newVariations.newVariations[0].module().logicModule {
obsoleteLogicModules = append(obsoleteLogicModules, newVariations.origLogicModule)
}
for _, moduleOrAlias := range newVariations.newVariations {
if m := moduleOrAlias.module(); m != nil {
newModuleInfo[m.logicModule] = m
}
@ -3201,6 +3213,10 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
return nil, errs
}
for _, obsoleteLogicModule := range obsoleteLogicModules {
delete(newModuleInfo, obsoleteLogicModule)
}
c.moduleInfo = newModuleInfo
for _, group := range c.moduleGroups {