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

Handle move blocks within a module which is changing the index #30232

Merged
merged 3 commits into from Dec 22, 2021

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Dec 21, 2021

When a move statement is only changing the index of a module, any moves within that module would result in cycles, because both the absolute From and To addresses would match both of the parent module's From and To address.

For example, changing the index of a module named count results in a a from->to of:

module.count->module.count[0]

And changing the count of a resource nested within module.count results in:

module.count[*].test.count->module.count[*].test.count[0]

Because module.count[*] matches both the From and To addresses of the parent, the edges would be added in both directions resulting in a cycle.

The graph we actually want in this case looks like

module.count->module.count[0]
module.count[*].test.count->module.count[*].test.count[0]
  module.count->module.count[0]

with a connection only from the inner move to the outer move, which matches the same order of operations when the outer module is changing the name entirely. We achieve this by checking if the dependent move statement is only changing the module index with a new from.MoveModuleReIndex(to) method, and skip adding the graph edge.

Fixes #30208

While not contributing to the cycle, it was noticed in #30208 that impliedMoveStatements was not correctly calling itself recursively, which is also fixed and tested by this PR.

@jbardin jbardin requested a review from a team December 21, 2021 21:43
Add a method for checking if the From and To addresses in a move
statement are only changing the indexes of modules relative to the
statement module.

This is needed because move statement nested within the module will be
able to match against both the From and To addresses, causing cycles in
the order of move operations.
Implied moves in nested modules were being skipped
@jbardin jbardin force-pushed the jbardin/module-move-re-index branch 2 times, most recently from 7587a28 to b23595f Compare December 21, 2021 23:09
@jbardin jbardin added the 1.1-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Dec 22, 2021
@jbardin jbardin force-pushed the jbardin/module-move-re-index branch 2 times, most recently from a4cba4d to 99704ee Compare December 22, 2021 14:49
Copy link
Member

@alisdair alisdair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me!

// ancestor module is only changing the index of a nested module, any
// nested move statements are going to match both the From and To address
// when the base name is not changing, causing a cycle in the order of
// operations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a bit of trouble understanding the previous block of code and its comment without the context of this paragraph here. I think it would have been easier to follow if this paragraph was before line 247, setting the scene for why we care about ancestor modules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I can move that around and group the checks together.

Changing only the index on a nested module will cause all nested moves
to create cycles, since their full addresses will match both the From
and To addresses. When building the dependency graph, check if the
parent is only changing the index of the containing module, and prevent
the backwards edge for the move.
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.1-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cyclic dependency error when both the parent and the child module have moved block.
3 participants