Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JIT] Add support for del to TS classes #44352

Closed

Conversation

SplitInfinity
Copy link

@SplitInfinity SplitInfinity commented Sep 9, 2020

Stack from ghstack:

Summary
This commit adds support for del with class instances. If a class
implements __delitem__, then del class_instance[key] is syntactic
sugar for class_instance.__delitem__[key].

Test Plan
This commit adds a unit test to TestClassTypes to test this feature.

Differential Revision: D23603102

**Summary**
This commit adds support for `del` with class instances. If a class
implements `__delitem__`, then `del class_instance[key]` is syntactic
sugar for `class_instance.__delitem__[key]`.

**Test Plan**
This commit adds a unit test to TestClassTypes to test this feature.

[ghstack-poisoned]
SplitInfinity pushed a commit that referenced this pull request Sep 9, 2020
**Summary**
This commit adds support for `del` with class instances. If a class
implements `__delitem__`, then `del class_instance[key]` is syntactic
sugar for `class_instance.__delitem__[key]`.

**Test Plan**
This commit adds a unit test to TestClassTypes to test this feature.

ghstack-source-id: 840e127b58f312fe61c735826b88b01ef0ef74e6
Pull Request resolved: #44352
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Sep 9, 2020
@dr-ci
Copy link

dr-ci bot commented Sep 9, 2020

💊 CI failures summary and remediations

As of commit 7ed071e (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 1 time.

@yf225 yf225 self-requested a review September 9, 2020 03:24
@yf225
Copy link
Contributor

yf225 commented Sep 9, 2020

Super excited for this, thanks a lot @SplitInfinity!

@codecov
Copy link

codecov bot commented Sep 9, 2020

Codecov Report

Merging #44352 into gh/splitinfinity/42/base will increase coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@                    Coverage Diff                    @@
##           gh/splitinfinity/42/base   #44352   +/-   ##
=========================================================
  Coverage                     69.24%   69.24%           
=========================================================
  Files                           381      381           
  Lines                         47575    47575           
=========================================================
+ Hits                          32944    32945    +1     
+ Misses                        14631    14630    -1     
Impacted Files Coverage Δ
torch/testing/_internal/expecttest.py 78.57% <0.00%> (+1.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e0ac12...7ed071e. Read the comment docs.

Copy link
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one small change to match python semantics

// If val is a class instance, this is a method call to a type-specific
// implementation of del defined in a __delitem__ method.
if (auto cls = val->type()->cast<ClassType>()) {
if (!cls->findMethod("__delitem__")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a method doesn't define __delitem__, we should just defer to the normal environment_stack->removeVar(var.name(), /*check_if_removed=*/true); behavior

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I thought this code path is for Subscript expressions (e.g. del variable[key], where variable is a class, list or dict). If variable is a class but does not define __delitem__, this produces an error in Python too:

>>> class A:
...   def __init__(self):
...     pass
... 
>>> a = A()
>>> del a["key"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'A' object does not support item deletion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh word, yea i didn't realize this was within the subscript branch. Yea lgtm

Copy link
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVM, didnt realize this error was only when del was used with subscript, LGTM

@facebook-github-bot
Copy link
Contributor

@SplitInfinity merged this pull request in d3b6d5c.

@facebook-github-bot facebook-github-bot deleted the gh/splitinfinity/42/head branch September 13, 2020 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merged oncall: jit Add this issue/PR to JIT oncall triage queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants