Skip to content

[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

Merged
merged 1 commit into from
Oct 30, 2020
Merged

Conversation

ellishg
Copy link
Contributor

@ellishg ellishg commented Aug 7, 2020

When we encounter an Objective-C method with the objc_direct attribute we don't want to use objc_msgSend(). Instead we call the method directly.

@theblixguy theblixguy requested a review from rjmccall August 7, 2020 00:52
@ellishg
Copy link
Contributor Author

ellishg commented Aug 17, 2020

I've resolved most of the comments. Can I get a second review? @CodaFi @rjmccall

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

This looks great!

@ellishg ellishg force-pushed the master branch 3 times, most recently from a601f89 to 02d32ae Compare September 3, 2020 16:14
@ellishg ellishg force-pushed the master branch 2 times, most recently from 42720e1 to b4727f9 Compare September 10, 2020 18:39
if (objCProperty->isDirectProperty())
continue;
}
}
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@shahmishal
Copy link
Member

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

@ellishg ellishg changed the base branch from master to main October 1, 2020 13:57
@ellishg ellishg force-pushed the master branch 2 times, most recently from bef9734 to cfc6ed4 Compare October 19, 2020 15:50
Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

LGTM

@rjmccall
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - cfc6ed49098b42529e880b2cd926dc6bcfa79941

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - cfc6ed49098b42529e880b2cd926dc6bcfa79941

@ellishg
Copy link
Contributor Author

ellishg commented Oct 21, 2020

Hopefully I have fixed the ci tests

@ellishg
Copy link
Contributor Author

ellishg commented Oct 21, 2020

@swift-ci Please test

@rjmccall
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 31d12dc53ebb74b00c454f711cabeeaaf7306295

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 31d12dc53ebb74b00c454f711cabeeaaf7306295

@rjmccall
Copy link
Contributor

swiftlang/llvm-project#2028

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 31d12dc53ebb74b00c454f711cabeeaaf7306295

@ellishg
Copy link
Contributor Author

ellishg commented Oct 23, 2020

Sorry, I think I introduced some errors when I fixed the merge conflict. I’ll take a look tomorrow.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 31d12dc53ebb74b00c454f711cabeeaaf7306295

@@ -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]
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

@ellishg
Copy link
Contributor Author

ellishg commented Oct 23, 2020

I believe I have now fixed all the test failures.

@rjmccall
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3aa081c

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3aa081c

@ellishg
Copy link
Contributor Author

ellishg commented Oct 23, 2020

@rjmccall Oh yeah. You'll need to test with swiftlang/llvm-project#2028.

@rjmccall
Copy link
Contributor

swiftlang/llvm-project#2028

@swift-ci Please test

@rjmccall
Copy link
Contributor

@rjmccall Oh yeah. You'll need to test with apple/llvm-project#2028.

Argh, yes, I did it right earlier.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3aa081c

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3aa081c

@ellishg
Copy link
Contributor Author

ellishg commented Oct 26, 2020

@rjmccall The CI is failing to checkout llvm-project

fatal: Couldn't find remote ref pull/2028/merge

Shall we try again?

@rjmccall
Copy link
Contributor

@rjmccall The CI is failing to checkout llvm-project

fatal: Couldn't find remote ref pull/2028/merge

Shall we try again?

I'm just waiting until it merges into main; it should already be there, but the automerger is held up.

@rjmccall
Copy link
Contributor

@swift-ci Please test

@rjmccall
Copy link
Contributor

Alright, let's do it. Thanks for seeing this through!

@rjmccall rjmccall merged commit e35f077 into swiftlang:main Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants