Skip to content

swift-frontend crashes in IRGen with SmallVector::grow_pod when Binding setter uses inline @MainActor adapter closure #88027

@Plightt

Description

@Plightt

Description

Hi Team,

I have hit a compiler crash that appears to be a Swift compiler bug. I have attached the evidence and a small standalone SwiftUI sample that reproduces it.

When a SwiftUI Binding setter uses a small inline @mainactor closure to pass a Bool value into another closure, the compiler crashes during code generation with a SmallVector::grow_pod failure.

Best,
Plight

Reproduction

import SwiftUI

@MainActor
struct Interactions {
    let onAllChanged: (Bool) -> Void

    var useAllBinding: Binding<Bool> {
        let handler = onAllChanged
        return Binding(
            get: { false },
            set: { @MainActor newValue in handler(newValue) }
        )
    }
}

@MainActor
struct ContentView: View {
    let onAllChanged: (Bool) -> Void

    var body: some View {
        Toggle("All", isOn: Interactions(onAllChanged: onAllChanged).useAllBinding)
    }
}

Reproduction Command

sdk=$(xcrun --sdk iphonesimulator --show-sdk-path)

xcrun swiftc /tmp/swift_bug_repro_small.swift \
  -target arm64-apple-ios18.6-simulator \
  -sdk "$sdk" \
  -swift-version 6 \
  -Onone \
  -Xfrontend -default-isolation=MainActor \
  -c \
  -o /tmp/swift_bug_repro_small.o

Result

The compiler aborts with:

  • fatal error encountered during compilation
  • SmallVector unable to grow. Requested capacity (4294967297) is larger than maximum value for size type (4294967295)

The stack includes:

  • llvm::SmallVectorBase<unsigned int>::grow_pod
  • (anonymous namespace)::SyncCallEmission::setArgs
  • IRGenRequest

In the app build, the failing generated function is reported as:

@$sSbScA_pSgIeAghyg_SbIeAghn_TR

That is a compiler-generated function rather than a user-defined function.

Stack dump

<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
<unknown>:0: note: SmallVector unable to grow. Requested capacity (4294967297) is larger than maximum value for size type (4294967295)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /tmp/swift_bug_repro_small.swift -target arm64-apple-ios18.6-simulator -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk -no-color-diagnostics -Xcc -fno-color-diagnostics -swift-version 6 -Onone -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -default-isolation=MainActor -empty-abi-descriptor -no-auto-bridging-header-chaining -module-name swift_bug_repro_small -disable-clang-spi -target-sdk-version 26.2 -target-sdk-name iphonesimulator26.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -in-process-plugin-server-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /tmp/swift_bug_repro_small.o
1.	Apple Swift version 6.2.4 (swiftlang-6.2.4.1.4 clang-1700.6.4.2)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for file "/tmp/swift_bug_repro_small.swift")
4.	While emitting IR SIL function "@$sSbScA_pSgIeAghyg_SbIeAghn_TR".
 for <<debugloc at "<compiler-generated>":0:0>>Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x000000010730b740 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001073090d0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010730bd6c SignalHandler(int, __siginfo*, void*) + 344
3  libsystem_platform.dylib 0x000000018f111764 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018f107888 pthread_kill + 296
5  libsystem_c.dylib        0x000000018f00c850 abort + 124
6  swift-frontend           0x000000010131b6a0 swift::DiagnosticHelper::~DiagnosticHelper() + 0
7  swift-frontend           0x0000000107279a38 llvm::report_fatal_error(llvm::Twine const&, bool) + 280
8  swift-frontend           0x00000001072ae174 report_at_maximum_capacity(unsigned long) + 0
9  swift-frontend           0x00000001072ade84 llvm::SmallVectorBase<unsigned int>::grow_pod(void*, unsigned long, unsigned long) + 384
10 swift-frontend           0x00000001013bf5ec (anonymous namespace)::SyncCallEmission::setArgs(swift::irgen::Explosion&, bool, swift::irgen::WitnessMetadata*) + 936
11 swift-frontend           0x000000010162ef70 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 5644
12 swift-frontend           0x00000001015ff3b0 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 2652
13 swift-frontend           0x00000001015fd284 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 15996
14 swift-frontend           0x00000001015f8fdc swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 2836
15 swift-frontend           0x0000000101411c08 swift::irgen::IRGenerator::emitLazyDefinitions() + 5204
16 swift-frontend           0x00000001015a9458 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 4528
17 swift-frontend           0x00000001015f7d88 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 180
18 swift-frontend           0x0000000100edf204 swift::IRGenRequest::OutputType swift::Evaluator::getResultUncached<swift::IRGenRequest, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()>(swift::IRGenRequest const&, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()) + 368
19 swift-frontend           0x00000001015ac07c swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 168
20 swift-frontend           0x0000000100f3ea74 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 156
21 swift-frontend           0x0000000100f3a088 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2108
22 swift-frontend           0x0000000100f39084 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1036
23 swift-frontend           0x0000000100f3c3b8 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
24 swift-frontend           0x0000000100f3afc8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3580
25 swift-frontend           0x0000000100eb8408 swift::mainEntry(int, char const**) + 5412
26 dyld                     0x000000018ed3dd54 start + 7184

Expected behavior

The compiler should either:

  1. produce an object file successfully, or
  2. produce a normal source diagnostic if the closure conversion is not allowed.

It should not abort.

Environment

  • Xcode 26.3 (17C529)
  • Apple Swift 6.2.4 (swiftlang-6.2.4.1.4, clang-1700.6.4.2)
  • macOS 26.3 (25D125)
  • Repro target: arm64-apple-ios18.6-simulator
  • SDK path from xcrun --sdk iphonesimulator --show-sdk-path
  • Compile flags used in the standalone repro:
    • -swift-version 6
    • -Onone
    • -Xfrontend -default-isolation=MainActor
    • -c

Additional information

The crash goes away if the setter closure type is made explicit and passed directly, for example:

import SwiftUI

@MainActor
struct Interactions {
    let onAllChanged: @isolated(any) @Sendable (Bool) -> Void

    var useAllBinding: Binding<Bool> {
        Binding(
            get: { false },
            set: onAllChanged
        )
    }
}

@MainActor
struct ContentView: View {
    let onAllChanged: @isolated(any) @Sendable (Bool) -> Void

    var body: some View {
        Toggle("All", isOn: Interactions(onAllChanged: onAllChanged).useAllBinding)
    }
}

This workaround compiled successfully in the standalone sample and restored the app build to:

  • BUILD SUCCEEDED (0 errors, 0 warnings)

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions