Make string serialization of C++ FunctionSchema consistent with torchgen.model.FunctionSchema#77926
Make string serialization of C++ FunctionSchema consistent with torchgen.model.FunctionSchema#77926shunting314 wants to merge 7 commits intogh/shunting314/20/basefrom
Conversation
…gen.model.FunctionSchema There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/) [ghstack-poisoned]
🔗 Helpful links
✅ No Failures (0 Pending)As of commit b7ef875 (more details on the Dr. CI page): Expand to see more💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
…gen.model.FunctionSchema There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/) ghstack-source-id: 156868252 Pull Request resolved: #77926
|
|
||
| const auto& returns = schema.returns(); | ||
| out << "("; | ||
| bool need_paren = returns.size() != 1 && !schema.is_varret(); |
There was a problem hiding this comment.
What does the is_varret() check do? (Can you paste a before/after?)
There was a problem hiding this comment.
I actually don't know. From the name and the string representation (...), I think it means variable number of return values. Also I don't see any occurrence of ... in native_functions.yaml. The Return.parse method in torchgen also does not handle ..., so I think FunctionSchema::is_varret is something specific to the C++ FunctionSchema.
Not sure what does pasting 'a before/after' means here since I don't change FunctionSchema::is_varret itself. But now the behavior is, if there is only a single return value and FunctionSchema.is_varret flag is not on, we skip the parenthesis around the return values. This will be consistent with torchgen function schema parser.
There was a problem hiding this comment.
I only find one example of using ... in return values here for prim ops: https://github.com/pytorch/pytorch/blob/master/torch/csrc/jit/runtime/register_prim_ops.cpp#L192 .
There was a problem hiding this comment.
oh thanks, that seems reasonable (not putting parens around ..., and also the fact that none of our native_functions.yaml ops care about it)
|
CI failure are not related but I'll rebase |
… with torchgen.model.FunctionSchema" There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/) [ghstack-poisoned]
…gen.model.FunctionSchema Pull Request resolved: #77926 There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. ghstack-source-id: 157089530 Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/)
… with torchgen.model.FunctionSchema" There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/) [ghstack-poisoned]
|
Fix unit test failure by updating .expect files to reflect the change. |
… with torchgen.model.FunctionSchema" There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/) [ghstack-poisoned]
…gen.model.FunctionSchema Pull Request resolved: #77926 There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. ghstack-source-id: 157127467 Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/)
… with torchgen.model.FunctionSchema" There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/) [ghstack-poisoned]
…gen.model.FunctionSchema Pull Request resolved: #77926 There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. ghstack-source-id: 157147958 Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/)
… with torchgen.model.FunctionSchema" There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/) [ghstack-poisoned]
… with torchgen.model.FunctionSchema" There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/) [ghstack-poisoned]
…gen.model.FunctionSchema Pull Request resolved: #77926 There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. ghstack-source-id: 157148340 Differential Revision: [D36535924](https://our.internmc.facebook.com/intern/diff/D36535924/)
|
@bdhirsh I changed the code a bit to make existing unit tests happy. Do you want to talk another look? Now we skip parenthesis around the return type if
According to the above rule some thing like There is one exception. If the return type is a single item but starts with left parenthesis, we still need add the extra prenthesis. There are 2 cases
|
|
@pytorchbot land this please |
|
@pytorchbot merge this please |
|
Hey @shunting314. |
|
cc @eellison for the change in case it affects TorchScript. |
…gen.model.FunctionSchema (#77926) Summary: Pull Request resolved: #77926 There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema. The latter will not add parenthesis around the returned types if that a single item, but the C++ FunctionSchema always add the parenthesis. Make them consistent so we can convert one type to the other via its string representation and parse method. Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/26d9386f6751b7c7b1cbc2861db9fcd99f64b8fa Reviewed By: bdhirsh Differential Revision: D36535924 Pulled By: shunting314 fbshipit-source-id: 1711a366ebcf44179a17a16fc5140458a1bd2780
Stack from ghstack (oldest at bottom):
There is a discrepency between the string representation of C++ FunctionSchema and torchgen.model.FunctionSchema.
The latter will not add parenthesis around the returned types if that a single item,
but the C++ FunctionSchema always add the parenthesis.
Make them consistent so we can convert one type to the other via its string representation and parse method.
Differential Revision: D36535924