[llvm-branch-commits] [mlir] [mlir] mlir-opt-repl v2: save, bookmark, verify, pass-pipeline syntax, tab completion (PR #203803)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Jun 14 16:23:43 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r origin/main...HEAD mlir/test/mlir-opt-repl/conftest.py mlir/test/mlir-opt-repl/test_cli_and_edge_cases.py mlir/test/mlir-opt-repl/test_mcp.py mlir/test/mlir-opt-repl/test_repl.py mlir/tools/mlir-opt-repl/src/mlir_opt_repl/engine.py mlir/tools/mlir-opt-repl/src/mlir_opt_repl/mcp.py mlir/tools/mlir-opt-repl/src/mlir_opt_repl/repl.py
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- test/mlir-opt-repl/test_cli_and_edge_cases.py 2026-06-14 23:21:13.000000 +0000
+++ test/mlir-opt-repl/test_cli_and_edge_cases.py 2026-06-14 23:23:07.975876 +0000
@@ -121,41 +121,36 @@
assert "Loaded" in stdout.getvalue()
class TestCompleter:
def test_command_completion(self):
-
with patch("mlir_opt_repl.repl.readline") as mock_rl:
mock_rl.get_line_buffer.return_value = "lo"
result = _completer("lo", 0)
assert result == "load "
def test_pass_completion(self):
-
with patch("mlir_opt_repl.repl.readline") as mock_rl:
mock_rl.get_line_buffer.return_value = "run convert-arith"
result = _completer("convert-arith", 0)
assert result is not None
assert "convert-arith" in result
def test_no_match(self):
-
with patch("mlir_opt_repl.repl.readline") as mock_rl:
mock_rl.get_line_buffer.return_value = "zzz"
result = _completer("zzz", 0)
assert result is None
def test_bookmark_completion(self):
-
repl_module.bookmarks = {"mymark": 0}
with patch("mlir_opt_repl.repl.readline") as mock_rl:
mock_rl.get_line_buffer.return_value = "rewind my"
result = _completer("my", 0)
assert result == "mymark "
def test_state_out_of_range(self):
-
with patch("mlir_opt_repl.repl.readline") as mock_rl:
mock_rl.get_line_buffer.return_value = "lo"
result = _completer("lo", 99)
assert result is None
@@ -166,20 +161,18 @@
assert result is None
class TestBookmarkInvalidIndex:
def test_rewind_to_invalid_bookmark_mcp(self):
-
engine.ir_history = [("initial", "module {}")]
engine.current_ir = "module {}"
engine.bookmarks = {"stale": 99}
result = engine.handle_tool_call("rewind", {"target": "stale"})
assert result["isError"] is True
assert "invalid index" in result["content"][0]["text"]
def test_rewind_to_invalid_bookmark_repl(self):
-
engine.ir_history = [("initial", "module {}")]
engine.current_ir = "module {}"
repl_module.bookmarks = {"stale": 99}
output = run_repl("rewind stale\nquit\n")
assert "invalid index" in output
--- tools/mlir-opt-repl/src/mlir_opt_repl/repl.py 2026-06-14 23:21:13.000000 +0000
+++ tools/mlir-opt-repl/src/mlir_opt_repl/repl.py 2026-06-14 23:23:08.305284 +0000
@@ -292,11 +292,13 @@
print(f" {BOLD}--{p['name']}{RESET}: {DIM}{p['description']}{RESET}")
if not all_passes:
print(f"{DIM}(no passes matched){RESET}")
elif cmd == "help":
- print(dedent(f"""\
+ print(
+ dedent(
+ f"""\
{BOLD}Commands:{RESET}
{CYAN}load <file.mlir>{RESET} Load MLIR from a file
{CYAN}load -{RESET} Load MLIR from stdin (blank line to finish)
{CYAN}run <passes...>{RESET} Apply passes to current IR
{CYAN}run <pipeline>{RESET} Apply a pass-pipeline string (e.g. builtin.module(...))
@@ -309,9 +311,11 @@
{CYAN}save <file>{RESET} Save current IR to a file
{CYAN}verify{RESET} Verify current IR is valid
{CYAN}reset{RESET} Clear all state
{CYAN}passes [filter]{RESET} List available passes (tab-completable)
{CYAN}quit{RESET} Exit
- """))
+ """
+ )
+ )
else:
print(f"{RED}Unknown command: {cmd}. Type 'help' for usage.{RESET}")
``````````
</details>
https://github.com/llvm/llvm-project/pull/203803
More information about the llvm-branch-commits
mailing list