Skip to content
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

[Swift Language Features] Generate correct Dispose for non-frozen structs and generic types #2985

Open
Tracked by #2978
jkurdek opened this issue Feb 10, 2025 · 0 comments
Assignees
Labels
area-SwiftBindings Swift bindings for .NET

Comments

@jkurdek
Copy link
Member

jkurdek commented Feb 10, 2025

Non frozen structs and generic types are projected as classes. We need to manualy release all the resources in the dispose method. We need to learn what needs disposing and genearte an appropriate Dispose method.

By projecting non-frozen types and generics as classes, we allow them to have destructors. The problem is that without knowing their memory layout, we don’t know what needs to be released in the destructor.

For example, consider Swift.String:

  store ptr %2, ptr %str.debug._guts._object._object, align 8, !dbg !136
  call void @swift_bridgeObjectRelease(ptr %2) #5, !dbg !137

The value witness table might actually resolve this without requiring explicit knowledge of the layout:
https://github.com/swiftlang/swift/blob/b185bf9562f007c37acdfcdbe42eebfd96bd9973/include/swift/ABI/ValueWitness.def#L114

This is something we will investigate further.

Originally posted by @kotlarmilos in #2970

@jkurdek jkurdek changed the title Update projection tooling to generate canonical Dispose [Swift Language Features] Generate correct Dispose for non-frozen structs and generic types Feb 10, 2025
@jkurdek jkurdek added the area-SwiftBindings Swift bindings for .NET label Feb 10, 2025
@kotlarmilos kotlarmilos self-assigned this Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-SwiftBindings Swift bindings for .NET
Projects
None yet
Development

No branches or pull requests

2 participants