Add named tuple's error message and workaround for RET failure (#46347)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/46347
Added the named tuple's error messages & workarounds when it returns from a function of a class in Pytorch Mobile.
To identify the error cases (returning NamedTuple type), I used the following coditions:
1) ins.op == RET (for returing)
2) type->kind() == TypeKind::TupleType (for pruning non-tuple types)
3) type->cast<TupleType>().name() (for pruning Tuple type)
- I could use the type's str (str() or repr_str()) directly, but I used whether it has the "name" attribute. Please give the comment for this.
[Information of Tuple and NamedTuple types]
1. Tuple
type->str(): (int, int)
type->repr_str(): Tuple[int, int]
type->kind(): TypeKind::TupleType # different with other types
type()->cast<NamedType>(): True
type()->cast<NamedType>()>name(): False # different with NamedTuple
2. NamedTuple
type->str(): __torch__.myNamedTuple
type->repr_str(): __torch__.myNamedTuple
type->kind(): TypeKind::TupleType # different with other types
type()->cast<NamedType>(): True
type->cast<TupleType>().name() = True # different with Tuple
(From the next diff, I will handle the other error cases: 1) returning List<module class>, Dict<module class> and 2) accessing Module class's member functions)
ghstack-source-id: 114361762
Test Plan:
[Added test results]
buck test mode/dev caffe2/test:mobile -- 'test_unsupported_return'
Summary
Pass: 2
ListingSuccess: 1
Finished test run: https://our.intern.facebook.com/intern/testinfra/testrun/7036874440497926
[Whole test results]
buck test mode/dev caffe2/test:mobile -- 'test'
Summary
Pass: 11
ListingSuccess: 1
Finished test run: https://our.intern.facebook.com/intern/testinfra/testrun/4503599664074084
Reviewed By: iseeyuan
Differential Revision: D24291962
fbshipit-source-id: a1a9e24e41a5f1e067738f59f1eae34d07cba31a