-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[IRGen] Call objc_direct methods correctly #33349
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
a601f89
to
02d32ae
Compare
42720e1
to
b4727f9
Compare
if (objCProperty->isDirectProperty()) | ||
continue; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an interesting question whether suppressing this in lookup is the right thing to do, as opposed to diagnosing the attempt during type-checking. I've asked @DougGregor and @brentdax to weigh in here. Naively I'd think we should diagnose during type-checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is effectively a choice between emitting a generic and slightly incorrect "no method found"-type diagnostic, and emitting a tailored "direct methods cannot be called through AnyObject dispatch"-type diagnostic.
I think it'd be better to emit a tailored diagnostic, but it could be left out if that would be very difficult, or it could be emitted based on a separate lookup performed while diagnosing the error. Please make sure you include a test case where one class has a direct method and another has a normal method by the same name—we'll want to make sure that the direct method doesn't stop you from using the normal one through AnyObject dispatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do agree that this is a very unhelpful error message for developers who might be surprised to see a "no method found"-type message after adding an objc_direct
attribute. I'm not very familiar with this part of the codebase, where would we put the lookup to diagnose the error?
And thanks for the test case, I'll add that.
bef9734
to
cfc6ed4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@swift-ci Please test |
Build failed |
Build failed |
Hopefully I have fixed the ci tests |
@swift-ci Please test |
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please test |
Build failed |
Sorry, I think I introduced some errors when I fixed the merge conflict. I’ll take a look tomorrow. |
Build failed |
@@ -6,7 +6,7 @@ @interface MyCls1(ext_in_objc) | |||
// CHECK: [[@LINE-1]]:12 | class/Swift | MyCls1 | [[MyCls1_USR]] | | |||
// CHECK: [[@LINE-2]]:19 | extension/ObjC | ext_in_objc | c:@M@cross_language@objc(cy)MyCls1@ext_in_objc | | |||
-(void)someMethFromObjC; | |||
// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | someMethFromObjC | [[someMethFromObjC_USR:.*]] | -[ext_in_objc someMethFromObjC] | |||
// CHECK: [[@LINE-1]]:8 | instance-method/ObjC | someMethFromObjC | [[someMethFromObjC_USR:.*]] | -[MyCls1(ext_in_objc) someMethFromObjC] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rjmccall I want to draw your attention to this test I fixed that breaks when using swiftlang/llvm-project#2028.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
I believe I have now fixed all the test failures. |
@swift-ci Please test |
Build failed |
Build failed |
@rjmccall Oh yeah. You'll need to test with swiftlang/llvm-project#2028. |
@swift-ci Please test |
Argh, yes, I did it right earlier. |
Build failed |
Build failed |
@rjmccall The CI is failing to checkout
Shall we try again? |
I'm just waiting until it merges into main; it should already be there, but the automerger is held up. |
@swift-ci Please test |
Alright, let's do it. Thanks for seeing this through! |
When we encounter an Objective-C method with the
objc_direct
attribute we don't want to useobjc_msgSend()
. Instead we call the method directly.