Skip to content

IRGen: Emit objc type encoding for ivars #81967

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 5 commits into from
Jun 25, 2025

Conversation

kastiglione
Copy link
Contributor

@kastiglione kastiglione commented Jun 4, 2025

ObjC ivar metadata has up to now emitted an empty string for the ivar's objc type encoding. Conversely, ObjC property metadata is emitted with an objc type encoding. This changes the compiler to also emit an objc type encoding for ivars.

The motivation for this change is for lldb to print ivars of classes declared in Objective-C but implemented in Swift, as defined in SE-0436. Without the presence of type encoding for ivars, lldb is unable to present to the user the ivars/properties of instances of such classes.

rdar://138569299

@kastiglione
Copy link
Contributor Author

@swift-ci test

2 similar comments
@kastiglione
Copy link
Contributor Author

@swift-ci test

@kastiglione
Copy link
Contributor Author

@swift-ci test

@kastiglione kastiglione marked this pull request as ready for review June 4, 2025 20:17
@kastiglione kastiglione requested a review from a team as a code owner June 4, 2025 20:17
Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

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

LGTM, although I'm not the one to judge IRGen style or logic.

@kastiglione
Copy link
Contributor Author

@swift-ci test macOS

@kastiglione kastiglione force-pushed the dl/IRGen-Emit-objc-type-encoding-for-ivars branch from d108509 to 2ddbb6b Compare June 5, 2025 14:20
@kastiglione
Copy link
Contributor Author

@swift-ci test

1 similar comment
@kastiglione
Copy link
Contributor Author

@swift-ci test

@kastiglione
Copy link
Contributor Author

@rjmccall the code I'm changing was authored by you, although that was 12 years ago. Tagging you in case you have feedback.

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.

Would you be interested in also fixing the TODOs about putting these in a proper section? I think this is just a matter of generalizing the useOSLogSection parameter on getAddrOfGlobalString to an enum.

Actually, there's an existing enum for this, ObjCLabelType. It probably ought to be renamed to StringLiteralKind and given an explicit CString enumerator, but it all looks pretty straightforward.

@kastiglione kastiglione marked this pull request as draft June 19, 2025 03:40
@kastiglione
Copy link
Contributor Author

kastiglione commented Jun 19, 2025

On further testing, this needs changes for bridged types. A property declared NSString and defined as String, cannot use an encoding of @, as a String is a struct and not a class.

My initial plan is to use ? as the encoding for the handful of classes which bridge to Swift structs.

@kastiglione
Copy link
Contributor Author

@swift-ci test

@kastiglione
Copy link
Contributor Author

@swift-ci test macOS

@kastiglione kastiglione requested a review from mikeash June 23, 2025 16:12
@kastiglione
Copy link
Contributor Author

@mikeash I've made a change here around bridged types such as String. See #81967 (comment) and 17499e4. Any thoughts?

@mikeash
Copy link
Contributor

mikeash commented Jun 24, 2025

Looks right to me. The type isn't representable in this form so ? is the right way to indicate that.

@kastiglione kastiglione force-pushed the dl/IRGen-Emit-objc-type-encoding-for-ivars branch from 17499e4 to a469626 Compare June 24, 2025 16:58
@kastiglione kastiglione changed the base branch from release/6.2 to main June 24, 2025 16:58
@kastiglione kastiglione force-pushed the dl/IRGen-Emit-objc-type-encoding-for-ivars branch from a469626 to bf2dd29 Compare June 24, 2025 16:59
@kastiglione
Copy link
Contributor Author

@swift-ci test

@kastiglione
Copy link
Contributor Author

@swift-ci test macOS

@kastiglione kastiglione merged commit ce7a3b3 into main Jun 25, 2025
5 checks passed
@kastiglione kastiglione deleted the dl/IRGen-Emit-objc-type-encoding-for-ivars branch June 25, 2025 22:39
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