Skip to content

Allow Swift to call objc_direct constructors #62183

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
Dec 8, 2022

Conversation

ellishg
Copy link
Contributor

@ellishg ellishg commented Nov 18, 2022

Import Objective-C constructors that are objc_direct in Swift.

In #40234 we stopped importing these objc_direct constructors to prevent a runtime error. This pull request fixes the codegen so that they can be used correctly.

@ellishg
Copy link
Contributor Author

ellishg commented Nov 21, 2022

CC @CodaFi @jckarter since y'all have been involved in #40234 and #60165.

@@ -47,14 +51,23 @@ markUsed(Bar.directClassMethod2())
markUsed(bar.directProtocolMethod())
// CHECK: function_ref @[[BYTE01]]-[Bar directProtocolMethod]

// CHECK: sil [clang Bar.directProtocolMethod] @[[BYTE01]]-[Bar directProtocolMethod] : $@convention(objc_method)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should add a syntax for quoting SIL symbol names with non-identifier characters, like LLVM's @"foo bar bas" syntax, so that the printed SIL here can still round-trip.

@jckarter
Copy link
Contributor

jckarter commented Dec 1, 2022

This looks great! It would be cool to also update the SIL printer/parser to round-trip the weird ObjC symbols, but I think it's fine to do that in a follow up.

@jckarter
Copy link
Contributor

jckarter commented Dec 1, 2022

@swift-ci Please test

@jckarter
Copy link
Contributor

jckarter commented Dec 8, 2022

@ellishg Any remaining concerns before I merge this?

@ellishg
Copy link
Contributor Author

ellishg commented Dec 8, 2022

This looks great! It would be cool to also update the SIL printer/parser to round-trip the weird ObjC symbols, but I think it's fine to do that in a follow up.

I agree, but I haven't looked at the SIL parser recently to know how difficult this is. If I find time I can try to follow this up.

@ellishg Any remaining concerns before I merge this?

That's all, please merge. Thanks!

@jckarter jckarter merged commit deab4cb into swiftlang:main Dec 8, 2022
@ellishg ellishg deleted the objc-direct-constructor branch December 8, 2022 23:20
@xymus
Copy link
Contributor

xymus commented Dec 14, 2022

The test IRGen/objc_direct.swift is failing on watchOS armv7k on something added by this PR:

/Users/ec2-user/jenkins/workspace/oss-swift_tools-RA_stdlib-DA_test-device-non_executable/swift/test/IRGen/objc_direct.swift:15:11: error: CHECK: expected string not found in input
// CHECK: call swiftcc i64 @"$sSo3BarC5valueABSgs5Int32V_tcfC"
          ^

See: https://ci.swift.org/job/oss-swift_tools-RA_stdlib-DA_test-device-non_executable/2480/

@ellishg Would you be available to fix it? We can disable the test for that platform for now if the fix is non-trivial.

@ellishg
Copy link
Contributor Author

ellishg commented Dec 14, 2022

The test IRGen/objc_direct.swift is failing on watchOS armv7k on something added by this PR:

/Users/ec2-user/jenkins/workspace/oss-swift_tools-RA_stdlib-DA_test-device-non_executable/swift/test/IRGen/objc_direct.swift:15:11: error: CHECK: expected string not found in input
// CHECK: call swiftcc i64 @"$sSo3BarC5valueABSgs5Int32V_tcfC"
          ^

See: https://ci.swift.org/job/oss-swift_tools-RA_stdlib-DA_test-device-non_executable/2480/

@ellishg Would you be available to fix it? We can disable the test for that platform for now if the fix is non-trivial.

I'm taking a look now. I assume the fix is simple, but I'll have to run locally to verify. Feel free to disable for that platform for now.

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.

3 participants