Add implicit optional unwrapping (#15587)
authorElias Ellison <eellison@fb.com>
Fri, 18 Jan 2019 19:17:34 +0000 (11:17 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 18 Jan 2019 19:25:01 +0000 (11:25 -0800)
commitd4f6befc93938e5462b186f76405b544e50fab60
treeae89c058415b5d62c28ca56189a4d607d591b7c3
parentda578b7dcf43bab88a3f0d407cb8a31c10a79557
Add implicit optional unwrapping (#15587)

Summary:
Add support for type inference for optional type refinement.

If a conditional is of the form "x is None" or "x is not None", or is a boolean expression containing multiple none checks, the proper type refinements are inserted in each branch.

For example:
if optional_tensor is not None and len(optional_tensor) < 2:
# optional_tensor is a Tensor

if optional_tensor1 is not None and optional_tensor2 is not None:
# both optional_tensor1 and optional_tensor2 are Tensors

TODO:

- not run an op for unchecked unwrap optional in the interpreter

- potentially refine types to prim::None (omitted for now to simply things & because it's not an actual use cause).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15587

Differential Revision: D13733810

Pulled By: eellison

fbshipit-source-id: 57c32be9f5a09ab5542ba0144a6059b96de23d7a
aten/src/ATen/core/interned_strings.h
test/expect/TestScript.test_if_is_none_dispatch.expect
test/test_jit.py
torch/csrc/jit/passes/constant_propagation.cpp
torch/csrc/jit/register_prim_ops.cpp
torch/csrc/jit/script/compiler.cpp