已合并
【质量加固】补充 const 修饰、参数 const 修饰与 lambda 显式捕获 #4572
味蕾木柚创建于 12 天前
【质量加固】补充 const 修饰、参数 const 修饰与 lambda 显式捕获 #4572
已合并
味蕾木柚创建于 12 天前
味蕾木柚
味蕾木柚
12 天前

修改内容

共 16 处代码质量修复,覆盖 3 条编码规范规则,涉及 11 个文件。

规则1:成员函数 const 修饰(8处)

  • compiler/graph/passes/base_pass.h:6 个只读 getter 添加 const
  • compiler/graph/partition/base_cluster.h:GetPartitionedCallName() 添加 const
  • inc/.../graph_fusion_pass.h:GetName() 添加 const

规则2:参数 const 修饰(4处)

  • api/atc/omg.cc:CheckDigitStr/StringToInt 的 string 参数添加 const
  • compiler/.../te_file_utils.h/.cc:IsFileUsed 的 filePath 参数添加 const
  • parser/.../acl_graph_parser_util.cc:CheckDigitStr 的 string 参数添加 const

规则9:lambda 避免默认捕获模式(4处)

  • 3 处 call_once 中 [&] → [](静态成员无需捕获)
  • 1 处 [=] → [runnable](显式捕获所需变量)
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 味蕾木柚 的贡献)
味蕾木柚味蕾木柚
12 天前 创建了 pull request,commit 9a54f5c7
atomgit-bot
atomgit-bot
12 天前 评论:

变更摘要

本 PR 是针对编译与运行时模块的代码质量修复,共 16 处修改,覆盖 3 条编码规范规则,涉及 11 个文件:为只读 getter 与只读参数添加 const 修饰,并消除 lambda 的默认捕获模式,改用无捕获或显式捕获,以明确接口只读语义、提升代码规范性。

主要改动

  • 成员函数添加 const 修饰:为 BaseNodePass 的 6 个只读 getter(GetNodesNeedRePassGetNodesNeedRePassImmediatelyGetGlobalNodesNeedRePassImmediatelyGetNodesDeletedGetNodesSuspendGetNodesResume)以及 BaseCluster::GetPartitionedCallName()Pass::GetName() 添加 const 限定,明确这些方法不修改成员状态。
  • 参数添加 const 修饰:将 omg.cc 中的 CheckDigitStrStringToIntacl_graph_parser_util.cc 中的 CheckDigitStrstd::string 参数,以及 TeFileUtils::IsFileUsedfilePath 参数(te_file_utils.h/.cc)由非 const 引用改为 const 引用,声明参数只读语义。
  • call_once lambda 去除默认捕获AicpuKernelBuilder::Instance()AicpuKernelInfo::Instance()AicpuOptimizer::Instance()std::call_once 的 lambda 由 [&] 改为 [],因仅操作静态成员 instance_,无需捕获外部变量。
  • 线程 lambda 改为显式捕获TaskThread::Startstd::thread 的 lambda 由 [=] 改为 [runnable],仅显式捕获实际使用的 Runnable 对象,避免默认捕获整个作用域。
likedislike
不准确?
CANN-robot
CANN-robot成员
12 天前 评论:

Hi @m0_63918125, welcome to submitting your first PR to ge!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.

likedislike
atomgit-bot
atomgit-bot
12 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
12 天前 添加了label:cann-cla/no
此处折叠了141条消息 查看更多
ClarkXie成员
5 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
5 天前 添加了label:lgtm
yangyongqiang
yangyongqiang成员
4 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
4 天前 添加了label:approved
CANN-robotCANN-robot成员
4 天前 合入了pull request