Skip to content

Conversation

DougGregor
Copy link
Member

swift_coroFrameAlloc was introduced in the Swift 6.2 runtime. Give it the appropriate availability in IRGen, so that it gets weak availability when needed (per the deployment target). Then, only create the stub function for calling into swift_coroFrameAlloc or malloc (when the former isn't available) when we're back-deploying to a runtime prior to Swift 6.2. This is a small code size/performance win when allocating coroutine frames on Swift 6.2-or-newer platforms.

This has a side effect of fixing a bug in Embedded Swift, where the swift_coroFrameAlloc was getting unconditionally set to have weak external linkage despite behind defined in the same LLVM module (because it comes from the standard library).

Fixes rdar://149695139 / issue #80947.

@DougGregor
Copy link
Member Author

@swift-ci please test

// REQUIRES: OS=macosx
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx26.0 -emit-irgen %S/yield_once_enable_emit_type_malloc_coro_frame.sil | %FileCheck %s

// CHECK-NOT: __swift_coroFrameAllocStub No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Missing newline.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, pushed with the fix

swift_coroFrameAlloc was introduced in the Swift 6.2 runtime. Give it
the appropriate availability in IRGen, so that it gets weak
availability when needed (per the deployment target). Then, only
create the stub function for calling into swift_coroFrameAlloc or
malloc (when the former isn't available) when we're back-deploying to
a runtime prior to Swift 6.2. This is a small code size/performance
win when allocating coroutine frames on Swift 6.2-or-newer platforms.

This has a side effect of fixing a bug in Embedded Swift, where the
swift_coroFrameAlloc was getting unconditionally set to have weak
external linkage despite behind defined in the same LLVM module
(because it comes from the standard library).

Fixes rdar://149695139 / issue swiftlang#80947.
@DougGregor DougGregor force-pushed the coroframealloc-backdeploy branch from ba214e4 to f7264e3 Compare September 16, 2025 17:51
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit 56f6063 into swiftlang:main Sep 17, 2025
5 checks passed
@DougGregor DougGregor deleted the coroframealloc-backdeploy branch September 17, 2025 03:15
@aschwaighofer
Copy link
Contributor

Thank you!

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