Skip to content

SSA: Fix cycle in stack shuffler#16595

Merged
blishko merged 1 commit intodevelopfrom
fix-cycling-shuffler
Apr 15, 2026
Merged

SSA: Fix cycle in stack shuffler#16595
blishko merged 1 commit intodevelopfrom
fix-cycling-shuffler

Conversation

@blishko
Copy link
Copy Markdown
Contributor

@blishko blishko commented Apr 14, 2026

Previously, when we were trying to detect if all slots are reachable or final, we were checking only target slots that are filled at the current moment.
However, we need to check all the target slots, even those beoynd the current stack size.

Previous behaviour meant we were not shrinking the stack as much as was required in some situations and the shuffling went into a loop.

With this fix most of the examples that were looping previously are now successful.

Previously, when we were trying to detect if all slots are reachable or
final, we were checking only target slots that are filled at the current
moment.
However, we need to check *all* the target slots, even those beoynd the
current stack size.

Previous behaviour meant we were not shrinking the stack as much as was
required in some situations and the shuffling went into a loop.

With this fix most of the examples that were looping previously are now
successful.
{
// check that args are either in position or reachable
for (StackOffset const offset: _state.stackArgsRange())
for (StackOffset offset{_state.target().tailSize}; offset < _state.target().size; ++offset.value)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we need a helper method for this. This is the second occurrence where we need this kind of iteration, which means it is time to put it in a helper with a proper name. Just not sure what would a good name actually be.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what about argsRange in the State?
I.e. something along the lines of

auto argsRange() const
{
	return ranges::views::iota(m_target.tailSize, m_stackData.size()) | ranges::views::transform([](auto _i) { return StackOffset{_i}; });
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think this would work. The point is that the range cannot be limited by the current stack data.
The needs to cover the target arg slot offsets.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, sorry, I meant the iota range from tailSize to targetSize...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that should work. And we can call it targetArgsRange, maybe?

@blishko blishko requested a review from clonker April 14, 2026 22:20
@blishko blishko merged commit 28d6217 into develop Apr 15, 2026
84 checks passed
@blishko blishko deleted the fix-cycling-shuffler branch April 15, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants