Skip to content

Commit

Permalink
Merge pull request #284 from ecmwf-ifs/naml-fix-masked-transformer-in…
Browse files Browse the repository at this point in the history
…place

MaskedTransformer: Fix in-place rebuilding of scoped nodes
  • Loading branch information
reuterbal authored Apr 11, 2024
2 parents 9aa9a37 + bb26c5c commit a594b44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit a594b44

Please sign in to comment.