[JIT] Add property support for ScriptModules (#42390)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/42390

**Summary**
This commit extends support for properties to include
ScriptModules.

**Test Plan**
This commit adds a unit test that has a ScriptModule with
a user-defined property.

`python test/test_jit_py3.py TestScriptPy3.test_module_properties`

Test Plan: Imported from OSS

Reviewed By: eellison, mannatsingh

Differential Revision: D22880298

Pulled By: SplitInfinity

fbshipit-source-id: 74f6cb80f716084339e2151ca25092b6341a1560
This commit is contained in:
Meghan Lele
2020-09-14 18:41:17 -07:00
committed by Facebook GitHub Bot
parent 63105fd5b1
commit e7d782e724
9 changed files with 159 additions and 61 deletions

View File

@ -573,6 +573,14 @@ std::shared_ptr<SugaredValue> ModuleValue::attr(
return attr;
}
// Check if it's a property.
auto prop =
concreteType_->getJitType()->expect<ClassType>()->getProperty(field);
if (prop) {
return MethodValue(self_, prop->getter->name())
.call(loc, m, {}, {}, /*n_binders=*/1);
}
// We don't define this attr. Bailout with a hint to the user.
std::string hint;
if (auto failureReason = concreteType_->findFailedAttribute(field)) {