tqchen commented on a change in pull request #9533:
URL: https://github.com/apache/tvm/pull/9533#discussion_r752626980



##########
File path: src/relay/ir/expr.cc
##########
@@ -71,6 +71,29 @@ Tuple::Tuple(tvm::Array<relay::Expr> fields, Span span) {
   data_ = std::move(n);
 }
 
+Tuple Tuple::WithFields(Optional<Array<Expr>> opt_fields, Optional<Span> 
opt_span) {
+  Array<Expr> fields = opt_fields.value_or(get()->fields);

Review comment:
       I see, if it is a mution semantics, then we might want to rename it as 
SetXYZ, like `Array.Set`.
   
   It might be worth thinking a bit about the tradeoff since the original 
semantics on the python and c++ side is WithAttrs do not mutate the original 
value that is passed in(unless it is moved in and ensures that there is no 
followup). So it would be good to make it align with the WithAttrs semantics.
   
   Since a common usage pattern may ends up look like this:
   
   ```python
   x = PrimFunc(args, body)
   # y is a new copy that comes with a new attr
   # x remains as the original case
   y = x.with_attr("new_attr", value)
   
   record([x, y])
   ``` 
   
    So in the c++ API
   ```c++
   // y do not reuse x' sapce
   y = WithAttrs(x, attr)
   record([y, x])
   ```
   Instead if you do
   
   ```c++
   // compiler could decide that y can reuse x, because x is no longer used, 
the call becomes a move
   y = WithAttrs(x, attr)
   // x is not used as a followup work
   ```
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to