From 1f276d367c08bcdead5e4a5f87f0323da7e6f9f1 Mon Sep 17 00:00:00 2001 From: Alex Rice Date: Mon, 9 Dec 2024 18:39:51 +0000 Subject: [PATCH] interactive: do not auto_expand passes_list (#3606) I was really struggling to debug this, but from what I can understand the `child_pass_pipeline` was ending up with duplicate passes because `self.pass_pipeline` shouldn't have been added. I'm not 100% this is the correct fix as I didn't manage to work out what everything did and why. --- tests/interactive/test_app.py | 82 +++++++++++++++++++++++++++++++++++ xdsl/interactive/app.py | 1 + 2 files changed, 83 insertions(+) diff --git a/tests/interactive/test_app.py b/tests/interactive/test_app.py index c70d029096..7eb11f86cb 100644 --- a/tests/interactive/test_app.py +++ b/tests/interactive/test_app.py @@ -537,3 +537,85 @@ async def test_dark_mode(): await pilot.press("d") assert app.theme == "textual-dark" + + +@pytest.mark.asyncio +async def test_apply_individual_rewrite(): + """Tests that using the tree to apply an individual rewrite works""" + + async with InputApp(tuple(get_all_dialects().items()), ()).run_test() as pilot: + app = cast(InputApp, pilot.app) + # clear preloaded code and unselect preselected pass + app.input_text_area.clear() + + await pilot.pause() + # Testing a pass + app.input_text_area.insert( + """ + func.func @hello(%n : i32) -> i32 { + %c0 = arith.constant 0 : i32 + %res = arith.addi %c0, %n : i32 + func.return %res : i32 +} + """ + ) + app.passes_tree.root.expand() + await pilot.pause() + + node = None + for n in app.passes_tree.root.children: + if ( + n.data is not None + and n.data[1] is not None + and str(n.data[1]) + == 'apply-individual-rewrite{matched_operation_index=3 operation_name="arith.addi" pattern_name="AddiConstantProp"}' + ): + node = n + + assert node is not None + + # manually trigger node selection + app.passes_tree.select_node(node) + + await pilot.pause() + + assert ( + app.output_text_area.text + == """builtin.module { + func.func @hello(%n : i32) -> i32 { + %c0 = arith.constant 0 : i32 + %res = arith.addi %n, %c0 : i32 + func.return %res : i32 + } +} +""" + ) + + # Apply second individual rewrite + node = None + for n in app.passes_tree.root.children: + if ( + n.data is not None + and n.data[1] is not None + and str(n.data[1]) + == 'apply-individual-rewrite{matched_operation_index=3 operation_name="arith.addi" pattern_name="AddiIdentityRight"}' + ): + node = n + + assert node is not None + + # manually trigger node selection + app.passes_tree.select_node(node) + + await pilot.pause() + + assert ( + app.output_text_area.text + == """builtin.module { + func.func @hello(%n : i32) -> i32 { + %c0 = arith.constant 0 : i32 + func.return %n : i32 + } +} +""" + ) diff --git a/xdsl/interactive/app.py b/xdsl/interactive/app.py index e6ef9794a7..dde8a6b7d4 100644 --- a/xdsl/interactive/app.py +++ b/xdsl/interactive/app.py @@ -179,6 +179,7 @@ def compose(self) -> ComposeResult: self.output_text_area = OutputTextArea(id="output") self.selected_passes_list_view = ListView(id="selected_passes_list_view") self.passes_tree = Tree(label=".", id="passes_tree") + self.passes_tree.auto_expand = False self.input_operation_count_datatable = DataTable( id="input_operation_count_datatable" )