nodeExpandModule doesn't need a Path() method

Unexpanded nodes can't implement GraphNodeModuleInstance (nee
GraphNodeSubPath), because they aren't aware how they have been
expanded, and may be in multiple distinct paths.

Since that means the EvalContext won't be in the correct path during the
walk, we just have to ensure that we don't use `ctx.Path()` inside Eval.
This commit is contained in:
James Bardin 2020-03-06 17:16:07 -05:00
parent a104ecb69d
commit 87776913c6
2 changed files with 15 additions and 27 deletions

View File

@ -17,25 +17,15 @@ type nodeExpandModule struct {
}
var (
_ GraphNodeModuleInstance = (*nodeExpandModule)(nil)
_ RemovableIfNotTargeted = (*nodeExpandModule)(nil)
_ GraphNodeEvalable = (*nodeExpandModule)(nil)
_ GraphNodeReferencer = (*nodeExpandModule)(nil)
_ RemovableIfNotTargeted = (*nodeExpandModule)(nil)
_ GraphNodeEvalable = (*nodeExpandModule)(nil)
_ GraphNodeReferencer = (*nodeExpandModule)(nil)
)
func (n *nodeExpandModule) Name() string {
return n.Addr.String()
}
// GraphNodeModuleInstance implementation
func (n *nodeExpandModule) Path() addrs.ModuleInstance {
// This node represents the module call within a module,
// so return the CallerAddr as the path as the module
// call may expand into multiple child instances
// FIXME:
return n.Addr.Parent().UnkeyedInstanceShim()
}
// GraphNodeModulePath implementation
func (n *nodeExpandModule) ModulePath() addrs.Module {
// This node represents the module call within a module,
@ -97,7 +87,6 @@ type evalPrepareModuleExpansion struct {
}
func (n *evalPrepareModuleExpansion) Eval(ctx EvalContext) (interface{}, error) {
path := ctx.Path()
eachMode := states.NoEach
expander := ctx.InstanceExpander()
@ -121,13 +110,18 @@ func (n *evalPrepareModuleExpansion) Eval(ctx EvalContext) (interface{}, error)
eachMode = states.EachMap
}
switch eachMode {
case states.EachList:
expander.SetModuleCount(path, call, count)
case states.EachMap:
expander.SetModuleForEach(path, call, forEach)
default:
expander.SetModuleSingle(path, call)
// nodeExpandModule itself does not have visibility into how it's ancestors
// were expended, so we use the expander here to provide all possible paths
// to our module, and register module instances with each of them.
for _, path := range expander.ExpandModule(n.Addr.Parent()) {
switch eachMode {
case states.EachList:
expander.SetModuleCount(path, call, count)
case states.EachMap:
expander.SetModuleForEach(path, call, forEach)
default:
expander.SetModuleSingle(path, call)
}
}
return nil, nil

View File

@ -359,12 +359,6 @@ func NewReferenceMap(vs []dag.Vertex) *ReferenceMap {
// Build the lookup table
vertices := make(map[string][]dag.Vertex)
for _, v := range vs {
_, ok := v.(GraphNodeModuleInstance)
if !ok {
// Only nodes with paths can participate in a reference map.
continue
}
// We're only looking for referenceable nodes
rn, ok := v.(GraphNodeReferenceable)
if !ok {