Skip to content

embedded: add swift_dynamicCastClass runtime function #74332

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
Jun 13, 2024

Conversation

eeckstein
Copy link
Contributor

To enable dynamic class casts

rdar://129672994

@eeckstein eeckstein requested a review from a team as a code owner June 12, 2024 12:52
@eeckstein eeckstein requested review from kubamracek and removed request for a team June 12, 2024 12:52
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@filip-sakel
Copy link
Contributor

Does this mean KeyPath could one day be supported in Embedded mode?

@eeckstein
Copy link
Contributor Author

Does this mean KeyPath could one day be supported in Embedded mode?

Yes, but unrelated to this change. The standard keypath runtime is probably too heavy for embedded swift. But we could support e.g. keypaths to stored properties only, which means that in embedded swift a keypath is just an integer offset.

@kubamracek
Copy link
Contributor

@swift-ci please test

@_cdecl("swift_dynamicCastClass")
public func swift_dynamicCastClass(object: UnsafeRawPointer, targetMetadata: UnsafeRawPointer) -> UnsafeRawPointer? {
let sourceObj = object.assumingMemoryBound(to: HeapObject.self)
var type = sourceObj.pointee.metadata.assumingMemoryBound(to: ClassMetadata.self)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might need to be a call to _swift_embedded_get_heap_object_metadata_pointer instead, to respect ptrauth correctly?

To enable dynamic class casts

rdar://129672994
@eeckstein eeckstein force-pushed the swift_dynamiccastclass branch from 0f6d8df to 13ecb51 Compare June 12, 2024 16:23
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein merged commit 6debc33 into swiftlang:main Jun 13, 2024
5 checks passed
@eeckstein eeckstein deleted the swift_dynamiccastclass branch June 13, 2024 05:34
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