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

MaskedTransformer: Fix in-place rebuilding of scoped nodes #284

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion loki/ir/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def visit_ScopedNode(self, o, **kwargs):

# Update rebuilt node
if kwargs['parent_active']:
o._update(rebuilt)
o._update(*rebuilt)
return o
return tuple(i for i in rebuilt if i is not None) or None

Expand Down
8 changes: 8 additions & 0 deletions tests/test_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,14 @@ def test_masked_transformer_associates(frontend):
assert len(FindNodes(Assignment).visit(body)) == 3
assert not FindNodes(Associate).visit(body)

# Retains all nodes but the last, but check with ``inplace=True``
body = MaskedTransformer(start=None, stop=assignments[-1], active=True, inplace=True).visit(routine.body)
assert len(FindNodes(Assignment).visit(body)) == len(assignments) - 1
assocs = FindNodes(Associate).visit(body)
assert len(assocs) == 1
assert len(assocs[0].body) == len(assignments) - 1
assert all(isinstance(n, Assignment) for n in assocs[0].body)


@pytest.mark.parametrize('frontend', available_frontends())
def test_nested_masked_transformer(frontend):
Expand Down
Loading