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:
parent
a104ecb69d
commit
87776913c6
|
@ -17,25 +17,15 @@ type nodeExpandModule struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ GraphNodeModuleInstance = (*nodeExpandModule)(nil)
|
_ RemovableIfNotTargeted = (*nodeExpandModule)(nil)
|
||||||
_ RemovableIfNotTargeted = (*nodeExpandModule)(nil)
|
_ GraphNodeEvalable = (*nodeExpandModule)(nil)
|
||||||
_ GraphNodeEvalable = (*nodeExpandModule)(nil)
|
_ GraphNodeReferencer = (*nodeExpandModule)(nil)
|
||||||
_ GraphNodeReferencer = (*nodeExpandModule)(nil)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (n *nodeExpandModule) Name() string {
|
func (n *nodeExpandModule) Name() string {
|
||||||
return n.Addr.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
|
// GraphNodeModulePath implementation
|
||||||
func (n *nodeExpandModule) ModulePath() addrs.Module {
|
func (n *nodeExpandModule) ModulePath() addrs.Module {
|
||||||
// This node represents the module call within a 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) {
|
func (n *evalPrepareModuleExpansion) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
path := ctx.Path()
|
|
||||||
eachMode := states.NoEach
|
eachMode := states.NoEach
|
||||||
expander := ctx.InstanceExpander()
|
expander := ctx.InstanceExpander()
|
||||||
|
|
||||||
|
@ -121,13 +110,18 @@ func (n *evalPrepareModuleExpansion) Eval(ctx EvalContext) (interface{}, error)
|
||||||
eachMode = states.EachMap
|
eachMode = states.EachMap
|
||||||
}
|
}
|
||||||
|
|
||||||
switch eachMode {
|
// nodeExpandModule itself does not have visibility into how it's ancestors
|
||||||
case states.EachList:
|
// were expended, so we use the expander here to provide all possible paths
|
||||||
expander.SetModuleCount(path, call, count)
|
// to our module, and register module instances with each of them.
|
||||||
case states.EachMap:
|
for _, path := range expander.ExpandModule(n.Addr.Parent()) {
|
||||||
expander.SetModuleForEach(path, call, forEach)
|
switch eachMode {
|
||||||
default:
|
case states.EachList:
|
||||||
expander.SetModuleSingle(path, call)
|
expander.SetModuleCount(path, call, count)
|
||||||
|
case states.EachMap:
|
||||||
|
expander.SetModuleForEach(path, call, forEach)
|
||||||
|
default:
|
||||||
|
expander.SetModuleSingle(path, call)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -359,12 +359,6 @@ func NewReferenceMap(vs []dag.Vertex) *ReferenceMap {
|
||||||
// Build the lookup table
|
// Build the lookup table
|
||||||
vertices := make(map[string][]dag.Vertex)
|
vertices := make(map[string][]dag.Vertex)
|
||||||
for _, v := range vs {
|
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
|
// We're only looking for referenceable nodes
|
||||||
rn, ok := v.(GraphNodeReferenceable)
|
rn, ok := v.(GraphNodeReferenceable)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue