Skip to content

Conversation

rconnell9
Copy link
Contributor

@rconnell9 rconnell9 commented Aug 13, 2025

Fix crash when running swift test for swift-build.

Was consistently able to cause the following crash prior to this change:
Thread 1 Crashed: 0 libswift_Concurrency.dylib 0x286d730b4 swift_task_alloc + 92 1 SwiftBuildPackageTests 0x1136b9c78 withExtendedLifetime<A, B, C>(_:_:) + 256 (Misc+Async.swift:124) 2 SwiftBuildPackageTests 0x113715c39 static NSTask.getOutput(url:arguments:currentDirectoryURL:environment:interruptible:) + 1 (Process.swift:86)

@rconnell9
Copy link
Contributor Author

@swift-ci test

@rconnell9 rconnell9 marked this pull request as ready for review August 13, 2025 04:59
Copy link

@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.

Lgtm!

Copy link
Collaborator

@jakepetroules jakepetroules left a comment

Choose a reason for hiding this comment

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

Ahh, nice catch. I think it's a compiler bug that withExtendedLifetime can contain async code despite its closure parameter not being annotated async?

Do we have a bug on the compiler to diagnose this as a compile-time error instead?

@jakepetroules
Copy link
Collaborator

@swift-ci test

@owenv owenv merged commit 35c3303 into swiftlang:main Aug 13, 2025
30 checks passed
@jakepetroules
Copy link
Collaborator

Ahh, nice catch. I think it's a compiler bug that withExtendedLifetime can contain async code despite its closure parameter not being annotated async?

Do we have a bug on the compiler to diagnose this as a compile-time error instead?

I mis-remembered, I was thinking of withoutActuallyEscaping. The async withExtendedLifetime is something coming from Swift Build's own codebase, in Misc+Async.swift:

@_alwaysEmitIntoClient
public func withExtendedLifetime<T: ~Copyable, E: Error, Result: ~Copyable>(
    _ x: borrowing T,
    _ body: (borrowing T) async throws(E) -> Result
) async throws(E) -> Result {
    defer { withExtendedLifetime(x) { } }
    return try await body(x)
}

(making this crash even more puzzling, since this patch is effectively just inlining the code)

@ktoso
Copy link

ktoso commented Aug 13, 2025

Yeah it's a bit puzzling but it seems something about this pattern was upsetting 🤔
Might be worth a follow up investigation in Swift itself

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.

4 participants