Skip to content

Commit

Permalink
interactive: do not auto_expand passes_list (#3606)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexarice authored Dec 9, 2024
1 parent 8459f95 commit 1f276d3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tests/interactive/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
"""
)
1 change: 1 addition & 0 deletions xdsl/interactive/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 1f276d3

Please sign in to comment.