diff --git a/tests/pattern_rewriter/test_pattern_rewriter.py b/tests/pattern_rewriter/test_pattern_rewriter.py index 7528f9015b..4fb66e443e 100644 --- a/tests/pattern_rewriter/test_pattern_rewriter.py +++ b/tests/pattern_rewriter/test_pattern_rewriter.py @@ -1576,6 +1576,34 @@ def convert_type(self, typ: IntegerType) -> IndexType | None: op_modified=1, ) + prog = """\ +"builtin.module"() ({ + "test.op"() {"dict_nest" = {"hello" = i32}} : () -> () +}) : () -> () +""" + + expected_recursive = """ +"builtin.module"() ({ + "test.op"() {"dict_nest" = {"hello" = index}} : () -> () +}) : () -> () +""" + + rewrite_and_compare( + prog, + prog, + PatternRewriteWalker(Rewrite(recursive=False)), + expect_rewrite=False, + ) + + rewrite_and_compare( + prog, + expected_recursive, + PatternRewriteWalker(Rewrite(recursive=True)), + op_inserted=1, + op_removed=1, + op_replaced=1, + ) + def test_no_change(): """Test that doing nothing successfully does not report doing something.""" diff --git a/xdsl/pattern_rewriter.py b/xdsl/pattern_rewriter.py index f1a2ecddaf..8240e5e788 100644 --- a/xdsl/pattern_rewriter.py +++ b/xdsl/pattern_rewriter.py @@ -9,7 +9,7 @@ from typing import TypeVar, Union, final, get_args, get_origin from xdsl.builder import BuilderListener, InsertPoint -from xdsl.dialects.builtin import ArrayAttr, ModuleOp +from xdsl.dialects.builtin import ArrayAttr, DictionaryAttr, ModuleOp from xdsl.ir import ( Attribute, Block, @@ -441,6 +441,9 @@ def _convert_type_rec(self, typ: Attribute) -> Attribute | None: if isa(typ, ArrayAttr[Attribute]): parameters = tuple(self._convert_type_rec(p) or p for p in typ) inp = type(typ).new(parameters) + if isa(typ, DictionaryAttr): + parameters = {k: self._convert_type_rec(v) for k, v in typ.data.items()} + inp = type(typ).new(parameters) converted = self.convert_type(inp) return converted if converted is not None else inp