Skip to content

Implement function bodies for lowered @_cdecl thunks#212

Merged
DougGregor merged 2 commits into
swiftlang:mainfrom
DougGregor:lowered-cdecl-function-bodies
Jan 30, 2025
Merged

Implement function bodies for lowered @_cdecl thunks#212
DougGregor merged 2 commits into
swiftlang:mainfrom
DougGregor:lowered-cdecl-function-bodies

Conversation

@DougGregor
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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