Skip to content

Implement function bodies for lowered @_cdecl thunks #212

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 2 commits into from
Jan 30, 2025

Conversation

DougGregor
Copy link
Member

Improve the handling of lowering Swift declarations down to C thunks to more clearly model the mapping between the C parameters and the Swift parameters, and start generating code within the body of these C thunks. Provide tests and fixes for lowering of methods of structs and classes, including mutating methods, as well as inout parameters, direct and indirect returns, and so on.

Improve the handling of lowering Swift declarations down to C thunks to
more clearly model the mapping between the C parameters and the Swift
parameters, and start generating code within the body of these C
thunks. Provide tests and fixes for lowering of methods of structs and
classes, including mutating methods, as well as inout parameters,
direct and indirect returns, and so on.
case .enum, .struct, .protocol: loweringStep = .passIndirectly(parameterName)
case .actor, .class:
loweringStep =
.unsafeCastPointer(.passDirectly(parameterName), swiftType: type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh nice, I like this idea of constructing what we need to do like that

/// Produce the `@_cdecl` thunk for this lowered function signature that will
/// call into the original function.
@_spi(Testing)
public func cdeclThunk(cName: String, inputFunction: FunctionDeclSyntax) -> FunctionDeclSyntax {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very nice, thanks! 👍

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Really cool work here, looking good

@DougGregor DougGregor merged commit 98129ae into swiftlang:main Jan 30, 2025
12 checks passed
@DougGregor DougGregor deleted the lowered-cdecl-function-bodies branch January 30, 2025 17:26
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.

2 participants