Skip to content

fix[next-dace]: return no successors for terminal blocks in find_successor_state - #2813

Merged
edopao merged 4 commits into
GridTools:mainfrom
edopao:dace-find-successor-terminal-state
Oct 8, 2026
Merged

edopao merged 4 commits into
GridTools:mainfrom
edopao:dace-find-successor-terminal-state

Conversation

@edopao

@edopao edopao commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Problem

find_successor_state (in gt4py.next.program_processors.runners.dace.transformations.utils) walks the outgoing region edges of a control-flow state, ascending into parent regions when a block has no successors locally. If the queried block and all its enclosing regions are terminal, the walk reached the SDFG root region and then recursed with the root region itself as state, so graph = state.parent_graph was None and the subsequent graph.nodes() call raised AttributeError: 'NoneType' object has no attribute 'nodes'.

This was hit via MultiStateGlobalSelfCopyElimination, which calls find_successor_state on transient-defining states (e.g. from OIR programs whose defining state is a terminal top-level block or inside a terminal LoopRegion).

Fix

Treat the root region as the termination point of the walk: the no-successors early-return condition in the inner _impl of find_successor_state now also triggers when graph.parent_graph is None (i.e. graph is the SDFG root region), returning an empty successor list instead of recursing into None.

Tests

New file tests/next_tests/unit_tests/program_processor_tests/runners_tests/dace_tests/transformation_tests/test_utils.py with two regression tests:

  • test_find_successor_state: a terminal top-level state returns [] (previously crashed with AttributeError), a non-terminal state returns its successor.
  • test_find_successor_state_terminal_loop_region: the last state of a LoopRegion body, where the loop itself is terminal at the top level, returns [] instead of crashing.

@philip-paul-mueller philip-paul-mueller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

It looks good, but while we are at it, we should also add a unit test that handles a nested SDFG.

Comment thread src/gt4py/next/program_processors/runners/dace/transformations/utils.py Outdated

@philip-paul-mueller philip-paul-mueller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@edopao
edopao merged commit 5995930 into GridTools:main Oct 8, 2026
24 checks passed
@edopao
edopao deleted the dace-find-successor-terminal-state branch October 8, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants