-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Description
Description
The Swift compiler crashes with signal 11 during SIL generation when calling a function from another module that takes a parameter pack expansion (repeat each T) as an argument.
The same code works correctly when the function is defined in the same module.
Environment
- Swift version: 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
- Target: arm64-apple-macosx26.0
- Crash location:
emitPackExpansionIntoPackin SILGenApply.cpp
Minimal Reproduction
https://github.com/coenttb/swift-issue-silgen-pack-expansion-cross-module
LibraryA (defines the function):
public enum Tuple {
public enum Append {}
}
extension Tuple.Append {
@inlinable
public static func apply<each T, U>(
_ tuple: (repeat each T),
_ element: U
) -> (repeat each T, U) {
(repeat each tuple, element)
}
}LibraryB (calls the function — CRASHES):
public import LibraryA
@inlinable
public func combine<each O1, O2>(
_ first: (repeat each O1),
_ second: O2
) -> (repeat each O1, O2) {
Tuple.Append.apply(first, second) // ❌ CRASHES
}To Reproduce
git clone https://github.com/coenttb/swift-issue-silgen-pack-expansion-cross-module
cd swift-issue-silgen-pack-expansion-cross-module
swift buildCrash Output
error: compile command failed due to signal 11 (use -v to see invocation)
Stack dump:
0. Program arguments: swift-frontend -frontend -emit-module ...
1. Apple Swift version 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
2. Compiling with the current language version
3. While evaluating request ASTLoweringRequest(Lowering AST to SIL for module LibraryB)
4. While silgen emitFunction SIL function "@$s8LibraryB7combine..."
for 'combine(_:_:)' (at .../Caller.swift:21:1)
4 swift-frontend emitPackExpansionIntoPack(...) + 492
5 swift-frontend emitPackExpansionIntoPack(...) + 492
6 swift-frontend emitDynamicPackLoop(...) + 1904
7 swift-frontend ArgEmitter::emitPackArg(...) + 3532
...
Key Stack Frames
| Frame | Function | File |
|---|---|---|
| 4-5 | emitPackExpansionIntoPack |
SILGenApply.cpp |
| 6 | emitDynamicPackLoop |
SILGenPack.cpp |
| 7 | ArgEmitter::emitPackArg |
SILGenApply.cpp |
Conditions Required
All three conditions must be present to trigger the crash:
| Condition | Description |
|---|---|
| 1. Cross-module call | Function defined in module A, called from module B |
| 2. Pack expansion argument | Passing (repeat each T) as function argument |
3. @inlinable |
Function must be inlinable (for cross-module inlining) |
Verified Test Results
| Test | Description | Result |
|---|---|---|
| Same module | Function and caller in same module | ✅ Compiles |
| Cross-module | Function in LibraryA, caller in LibraryB | ❌ Crashes |
| Inline expression | (repeat each tuple, element) directly |
✅ Compiles |
| Function call | Tuple.Append.apply(tuple, element) |
❌ Crashes |
Workaround
Inline the pack expansion expression instead of calling a cross-module function:
// Instead of:
Tuple.Append.apply(tuple, element) // ❌ Crashes
// Use:
(repeat each tuple, element) // ✅ WorksThis workaround prevents code reuse across modules for pack expansion operations.
Impact
This bug blocks:
- Creating reusable tuple/product utilities in shared libraries
- Result builder implementations that want to share pack manipulation code
- Any cross-module abstraction over parameter pack operations
Possibly Related Issues
- Crash in visitPackExpansionExpr, file SILGenExpr.cpp, line 1655 when writing variadically generic zip function #84568 - Crash in visitPackExpansionExpr
- Crash at compilation when calling variadic generic function using pack expansion as argument #67645 - Crash calling variadic generic function with pack expansion
- Parameter Pack Crashes within Generic Type #76391 - Parameter pack crashes within generic type
Metadata
Metadata
Assignees
Labels
No labels