8000 [WIP] DO NOT MERGE - [core] Remove `@unchecked Sendable` from Lambda Runtime (depends on PR#508) by sebsto · Pull Request #526 · swift-server/swift-aws-lambda-runtime · GitHub
[go: up one dir, main page]

Skip to content

[WIP] DO NOT MERGE - [core] Remove @unchecked Sendable from Lambda Runtime (depends on PR#508) #526

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

Closed
wants to merge 3 commits into from

Conversation

sebsto
Copy link
Contributor
@sebsto sebsto commented Jul 2, 2025

This PR depends on #508

When removing the NIOLockedBox, we wanted to remove the last @unchecked Sendable in the code.

Motivation:

There is no good reason to bypass compiler verifications with @unchecked Sendable in this scenario. We would like to bring the extra verifications' benefit to the user of the library.

Modifications:

Lambda handlers and all depending structs and functions are tagged @sendable

Result:

This adds a requirement on user defined handlers (the public API of this library).
Code like

let handler:
    (Event, LambdaContext) async throws -> Response = {
        (request: Event, context: LambdaContext) in
    ...
    return Response() 
}
let runtime = LambdaRuntime(body: handler) 
try await runtime().run() 

is no longer accepted. The handler must marked @Sendable

let handler:
    @Sendable (Event, LambdaContext) async throws -> Response = {
        (request: Event, context: LambdaContext) in
    ...
    return Response() 
}

Fortunately, thanks to the compiler type inference, this does not affect handlers passed as a closure, such as

let runtime = LambdaRuntime {
    (event: HelloRequest, context: LambdaContext) in

    HelloResponse(
        greetings: "Hello \(event.name). You look \(event.age > 30 ? "younger" : "older") than your age."
    )
}

As we expect this is the preferred way to write a handler, we think the change in the public API is acceptable. Only more advanced users will have to explicitly add the @Sendable conformance to their standalone handler functions.

@sebsto sebsto changed the title [WIP] DO NOT MERGE - Remove @unchecked Sendable from Lambda Runtime [WIP] DO NOT MERGE - Remove @unchecked Sendable from Lambda Runtime (depends on PR#508) Jul 2, 2025
@sebsto sebsto self-assigned this Jul 2, 2025
@sebsto sebsto added the ⚠️ semver/major Breaks existing public API. label Jul 2, 2025
@sebsto sebsto changed the title [WIP] DO NOT MERGE - Remove @unchecked Sendable from Lambda Runtime (depends on PR#508) [WIP] DO NOT MERGE - [core] Remove @unchecked Sendable from Lambda Runtime (depends on PR#508) Jul 2, 2025
@sebsto
Copy link
Contributor Author
sebsto commented Jul 3, 2025

We decided to not force Sendable on Handler. This commit should allow that
7b50167

@sebsto sebsto closed this Jul 3, 2025
@sebsto sebsto deleted the sebsto/handler+sendable branch July 4, 2025 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ semver/major Breaks existing public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0