-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NewIR]Refine IrPrinter and basic Concept Interface for const Object #55209
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
|
||
Block* block() { return module_.block(); } | ||
const Block* block() const { return module_op().block(); } | ||
|
||
Parameter* GetParameter(const std::string& name) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里返回Parameter* 也是不安全的,应该要返回const * 。否则是可以修改Parameter内容,就违背了Parameter的const调用语义。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这儿可以考虑加个非const重载。 一个返回const Parameter*, 一个返回Parameter*。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ir::OpBase的派生类(ModuleOp、GetParameterOp、SetParameterOp、CombineOp等等)的成员函数就没必要增加const限定符了。这些都是浅拷贝。增加const限定符和我们的设计理念是相悖的,后面人会参考内置op进行新op的定义。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall
|
||
void PrintValue(Value v); | ||
void PrintValue(const Value& v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@winter-wang 之前建议对于浅拷贝对象,要么统一用const&,要么就用临时对象。所以我之前统一成临时对象了,后面要统一改成const引用吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我的意见还是统一用临时对象。我记得const&的实现好像是指针方式,这儿用const&的话,相当于指针的指针,多了一次解引用。
…addlePaddle#55209) * [NewIR]Refine IrPrinter and basic Concept Interface for const Object
…addlePaddle#55209) * [NewIR]Refine IrPrinter and basic Concept Interface for const Object
PR types
Function optimization
PR changes
Others
Description
Pcard-67164
const*
,部分是const&
,有待统一为const &