Pull Request has been successfully merged by CANN-robot.
(Thank you for lidongsheng's contribution.)变更摘要
此 PR 将单体测试文件 test_merge_pass.py 拆分为 test_merge_pass/ 包下的多个独立测试文件,每个测试用例对应一个文件,同时将 golden IR 快照从外部 .pir 文件改为内联字符串,并提取公共辅助函数到新增的 test_common.py 模块中,以提升测试的可维护性和可读性。
主要改动
-
测试拆分与重组:将原
test_merge_pass.py中的 11 个测试函数(test_merge_pass1~test_merge_pass8、test_fillpad、test_oi_update、test_unroll_list)分别拆分到test_merge_pass/包下的独立文件中,每个文件包含一个测试函数及其对应的内联 golden IR。 -
快照验证方式变更:删除了
snapshot/目录下 4 个外部.pir快照文件,改为在每个测试文件中使用ir = """..."""内联字符串存储 golden IR,通过check_snapshot(func, ir)进行比对。 -
公共辅助函数抽取:新增
test_common.py,提取了check_snapshot、run_merge_pass(原_run_merge)和_ssa_verify等辅助函数,供所有拆分后的测试文件通过from ..test_common import check_snapshot, run_merge_pass复用。 -
移除旧的辅助逻辑:原文件中的
_collect_stmts辅助函数及_check_snapshot的文件读取逻辑被移除,断言方式从统计 IR 节点数量改为直接进行快照字符串比对。 -
新增包初始化文件:为
python/tests/ut/ir/和python/tests/ut/ir/test_merge_pass/分别添加了__init__.py使其成为正式的 Python 包。


代码审查
I've completed the full review of all 14 changed files. Here is my closing summary.
审查总结
按优先级统计
- P0: 0
- P1: 0
- P2: 1
- P3: 0
各文件审查结果
| 文件 | 结果 |
|---|---|
python/tests/ut/ir/__init__.py |
无问题(仅 License header) |
python/tests/ut/ir/test_common.py |
发现 1 个问题(bare raise) |
python/tests/ut/ir/test_merge_pass/__init__.py |
无问题(仅 License header) |
python/tests/ut/ir/test_merge_pass/test_fillpad.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_merge_pass1.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_merge_pass2.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_merge_pass3.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_merge_pass4.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_merge_pass5.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_merge_pass6.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_merge_pass7.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_merge_pass8.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_oi_update.py |
无问题 |
python/tests/ut/ir/test_merge_pass/test_unroll_list.py |
无问题 |
整体风险评估
低风险。 本次变更是一个纯粹的重构:将单体测试文件 test_merge_pass.py 拆分为独立的测试文件,用内联 IR 字符串替换基于文件的快照机制,并将共享辅助函数提取到 test_common.py。唯一的发现是 _ssa_verify 中一个已有问题的 bare raise,该问题源于原始代码,会掩盖 SSA 验证失败信息。除此之外,测试逻辑和覆盖范围保持不变,没有引入新的正确性、安全性或可靠性风险。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/pypto | ✅ gaoxiang618, DCGDDD (2/2) | ✅ gaoxiang618 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
tsungl4, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


流水线任务触发成功
任务链接 [31fd56dac2ee4357a8623d7c15dd3383][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| pre_comment | ✅ SUCCESS | >>>>> | |
| UT_Test_Py3_ninja_simulation | ✅ SUCCESS | ||
| UT_Test_Py3_ninja | ✅ SUCCESS | ||
| UT_Test_Cpp_make_gnu_part_1 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_gnu_part_2 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_gnu_part_3 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_clang_part1 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_clang_part2 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_clang_part3 | ✅ SUCCESS | ||
| UT_Test_kirinx90 | ✅ SUCCESS | ||
| UT_Test_kirin9030 | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> |
[2026-08-03 15:38:32] CI执行结束


流水线任务触发成功
任务链接 [666ea5c554cd4a71bbd0873797b28df1][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ⚠️ WARNING | >>>>> | |
| codecheck_precommit | ❌ FAILED | >>>>> | >>>>> |
| StaticCheck_md | ✅ SUCCESS |


🟡 Medium Priority
变更行:python/tests/ut/ir/test_common.py 第 34 行的 raise。
受影响的代码:_ssa_verify 函数(第 29–34 行)在 diagnostic 为真值时执行 raise,但该调用不在任何 except 块内,因此 Python 运行时会抛出 RuntimeError: No active exception to reraise,而非带有诊断信息的 AssertionError 或 RuntimeError。
失败模式:当 SSA 验证失败(diagnostic 为真值)时,之前的 print 语句会输出诊断报告,但紧接着的 raise 会抛出令人困惑的 RuntimeError: No active exception to reraise,掩盖了真正的失败原因,并使测试失败信息难以理解。
触发条件:IR pass(canonicalize / dce / merge_stmts_into_if)产生的 IR 程序未通过 SSA 验证时触发。
注意:该问题在旧文件 test_merge_pass.py(已删除)中已存在,但随本次重构被原样迁移至新增的 test_common.py 文件中。
建议:将 bare raise 替换为携带诊断信息的 raise AssertionError,例如:raise AssertionError(f"SSA verification failed for {name}") 或 raise RuntimeError(f"SSA verification failed for {name}")。


流水线任务触发成功
任务链接 [a61838bc621a420f9ece226f44656343][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| get_pr_file | ✅ SUCCESS | ||
| static-check | ❌ FAILED | ||
| compile | ✅ SUCCESS |


compile


流水线任务触发成功
任务链接 [e026e60a9efb4a59a5c4736d554cdd76][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| pre_comment | ✅ SUCCESS | >>>>> | |
| UT_Test_Py3_ninja_simulation | ✅ SUCCESS | ||
| UT_Test_Py3_ninja | ✅ SUCCESS | ||
| UT_Test_Cpp_make_gnu_part_1 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_gnu_part_2 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_gnu_part_3 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_clang_part1 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_clang_part2 | ✅ SUCCESS | ||
| UT_Test_Cpp_make_clang_part3 | ✅ SUCCESS | ||
| UT_Test_kirinx90 | ✅ SUCCESS | ||
| UT_Test_kirin9030 | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> |
[2026-08-03 17:40:08] CI执行结束


流水线任务触发成功
任务链接 [aab439ef597f4751855728b87ce93f85][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ⚠️ WARNING | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> | |
| StaticCheck_md | ✅ SUCCESS |
[2026-08-03 17:18:44] CI执行结束


流水线任务触发成功
任务链接 [0dd4a349891548b6b4f71c24137c38b6][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| get_pr_file | ✅ SUCCESS | ||
| static-check | ✅ SUCCESS | ||
| compile | ✅ SUCCESS |
[2026-08-03 17:40:54] CI执行结束


/lgtm
/approve


/lgtm


Pyhton object which can't translate to irnode, should be execlude from
iter_args and yield values
Related Issue: #2559