[jit] Allow 'Any' to appear as a type argument.#26572
[jit] Allow 'Any' to appear as a type argument.#26572zdevito wants to merge 5 commits intogh/zdevito/113/basefrom
Conversation
| self.assertEqual(any_refinement(3, 4), 7) | ||
| self.assertEqual(any_refinement(3, "hi"), 0) | ||
|
|
||
| def test_any_in_class_fails(self): |
There was a problem hiding this comment.
Can we add tests that verify that Any is not allowed in Tuples, NamedTuples, or Interfaces as well?
| // static types in named types to reconstruct type tags of loaded | ||
| // values. Lifting this restriction requires solving the serialization | ||
| // problem first. | ||
| CAFFE2_API void checkNoAny( |
There was a problem hiding this comment.
I am a little wary of having this enforcement as opt-in. For example, if someone goes in and adds attributes to interfaces and forgets to include this check, we've very quickly produced the bug this comment describes.
There was a problem hiding this comment.
The specific example of interfaces will not actually cause this bug, but I agree in spirit. But how would we make it more likely to be called? There isn't a more common place to put it.
[jit] Allow 'Any' to appear as a type argument. Combined with isinstance specialization this allows a degree of polymorphic functions to work without needing to use our weirder overload hacks. We do not define any operators on Any, so the only thing you can do with it is to put it in containers or type refine it using an isinstance check. Any is restricted from appearing in non-argument position because we cannot restore type tags if it ends up as a field in a class. gh-metadata: pytorch pytorch 26572 gh/zdevito/113/head
[jit] Allow 'Any' to appear as a type argument. Combined with isinstance specialization this allows a degree of polymorphic functions to work without needing to use our weirder overload hacks. We do not define any operators on Any, so the only thing you can do with it is to put it in containers or type refine it using an isinstance check. Any is restricted from appearing in non-argument position because we cannot restore type tags if it ends up as a field in a class. gh-metadata: pytorch pytorch 26572 gh/zdevito/113/head
[jit] Allow 'Any' to appear as a type argument. Combined with isinstance specialization this allows a degree of polymorphic functions to work without needing to use our weirder overload hacks. We do not define any operators on Any, so the only thing you can do with it is to put it in containers or type refine it using an isinstance check. Any is restricted from appearing in non-argument position because we cannot restore type tags if it ends up as a field in a class. gh-metadata: pytorch pytorch 26572 gh/zdevito/113/head
[jit] Allow 'Any' to appear as a type argument. Combined with isinstance specialization this allows a degree of polymorphic functions to work without needing to use our weirder overload hacks. We do not define any operators on Any, so the only thing you can do with it is to put it in containers or type refine it using an isinstance check. Any is restricted from appearing in non-argument position because we cannot restore type tags if it ends up as a field in a class. gh-metadata: pytorch pytorch 26572 gh/zdevito/113/head
[jit] Allow 'Any' to appear as a type argument. Combined with isinstance specialization this allows a degree of polymorphic functions to work without needing to use our weirder overload hacks. We do not define any operators on Any, so the only thing you can do with it is to put it in containers or type refine it using an isinstance check. Any is restricted from appearing in non-argument position because we cannot restore type tags if it ends up as a field in a class. gh-metadata: pytorch pytorch 26572 gh/zdevito/113/head
Summary: Pull Request resolved: pytorch/pytorch#26572 Combined with isinstance specialization this allows a degree of polymorphic functions to work without needing to use our weirder overload hacks. We do not define any operators on Any, so the only thing you can do with it is to put it in containers or type refine it using an isinstance check. Any is restricted from appearing in non-argument position because we cannot restore type tags if it ends up as a field in a class. Test Plan: Imported from OSS Differential Revision: D17530643 Pulled By: zdevito fbshipit-source-id: f06f78ce84819f7773953a492f3d4c49219ee94c
Summary: Pull Request resolved: pytorch#26572 Combined with isinstance specialization this allows a degree of polymorphic functions to work without needing to use our weirder overload hacks. We do not define any operators on Any, so the only thing you can do with it is to put it in containers or type refine it using an isinstance check. Any is restricted from appearing in non-argument position because we cannot restore type tags if it ends up as a field in a class. Test Plan: Imported from OSS Differential Revision: D17530643 Pulled By: zdevito fbshipit-source-id: f06f78ce84819f7773953a492f3d4c49219ee94c
| inline Stack toTraceableStack(const py::tuple& inputs) { | ||
| auto info = toTypeInferredIValue(inputs); | ||
| AT_CHECK( | ||
| isTraceableType(info.type()), |
There was a problem hiding this comment.
Hi, @zdevito
May I know why we only support Tensors and (possibly nested) Lists, Dicts, and Tuples of Tensors?
What if we passed a None type of python, and what will happen that makes us not support it?
Stack from ghstack:
Combined with isinstance specialization this allows a degree of polymorphic
functions to work without needing to use our weirder overload hacks.
We do not define any operators on Any, so the only thing you can do with it
is to put it in containers or type refine it using an isinstance check.
Any is restricted from appearing in non-argument position because we
cannot restore type tags if it ends up as a field in a class.
Differential Revision: D17530643