user defined types (#17314)
authorMichael Suo <suo@fb.com>
Tue, 26 Feb 2019 09:24:05 +0000 (01:24 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 26 Feb 2019 09:34:07 +0000 (01:34 -0800)
commit2cdbb140e62d80906c4a6b1944e7e36650ec54b1
treeaceacea80bff6bab81fb774e93da8e8d7c95622d
parent3ceeaae5e6fb0f5ab8c3e35a6051263add9becb7
user defined types (#17314)

Summary:
First pass at user defined types. The following is contained in this PR:
- `UserType` type, which contains a reference to a module with all methods for the type, and a separate namespace for data attributes (map of name -> TypePtr).
- `UserTypeRegistry`, similar to the operator registry
- `UserObject` which is the runtime representation of the user type (just a map of names -> IValues)
- `UserTypeValue` SugaredValue, to manage getattr and setattr while generating IR, plus compiler.cpp changes to make that work.
- Frontend changes to get `torch.jit.script` to work as a class decorator
- `ClassDef` node in our AST.
- primitive ops for object creation, setattr, and getattr, plus alias analysis changes to make mutation safe.

Things that definitely need to get done:
- Import/export, python_print support
- String frontend doesn't understand class definitions yet
- Python interop (using a user-defined type outside TorchScript) is completely broken
- Static methods (without `self`) don't work

Things that are nice but not essential:
- Method definition shouldn't matter (right now you can only reference a method that's already been defined)
- Class definitions can only contain defs, no other expressions are supported.

Things I definitely won't do initially:
- Polymorphism/inheritance
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17314

Differential Revision: D14194065

Pulled By: suo

fbshipit-source-id: c5434afdb9b39f84b7c85a9fdc2891f8250b5025
28 files changed:
aten/src/ATen/core/interned_strings.h
aten/src/ATen/core/ivalue.cpp
aten/src/ATen/core/ivalue.h
aten/src/ATen/core/jit_type.h
aten/src/ATen/core/type.cpp
test/test_jit.py
tools/build_variables.py
torch/CMakeLists.txt
torch/csrc/jit/import_method.cpp
torch/csrc/jit/ir.cpp
torch/csrc/jit/ir.h
torch/csrc/jit/passes/alias_analysis.cpp
torch/csrc/jit/passes/alias_analysis.h
torch/csrc/jit/passes/dead_code_elimination.cpp
torch/csrc/jit/passes/python_print.cpp
torch/csrc/jit/pybind_utils.h
torch/csrc/jit/register_prim_ops.cpp
torch/csrc/jit/script/compiler.cpp
torch/csrc/jit/script/init.cpp
torch/csrc/jit/script/lexer.h
torch/csrc/jit/script/python_tree_views.cpp
torch/csrc/jit/script/script_type_parser.cpp
torch/csrc/jit/script/sugared_value.cpp
torch/csrc/jit/script/sugared_value.h
torch/csrc/jit/script/tree_views.h
torch/csrc/jit/script/user_type.cpp [new file with mode: 0644]
torch/jit/__init__.py
torch/jit/frontend.py