Skip to content
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

Swift 6 Compiler Crash When Using Typed Throws in Function Declaration #78680

Open
nashysolutions opened this issue Jan 16, 2025 · 2 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@nashysolutions
Copy link

Description

The Swift 6 compiler crashes when compiling a function that uses typed throws with an error type. Removing the generic error type from the throws clause allows the code to compile successfully.

Reproduction

import Foundation

public struct FileStorage<Path: Codable> {
    
    public func savePath(_ path: Path, storageKey: String) throws(SaveError) {
    }
}

public extension FileStorage {
    
    enum SaveError: Error {
        case encodingFailed
    }
}

Error: Command SwiftCompile failed with nonzero exit code.

However, if I remove the generic error type from the throws clause, the code compiles successfully:

import Foundation

public struct FileStorage {
    
    public func savePath(_ path: String, storageKey: String) throws(SaveError) {
    }
}

public extension FileStorage {
    
    enum SaveError: Error {
        case encodingFailed
    }
}

Expected behavior

Expected behavior

The compiler should not crash. Instead, it should either:
1. Successfully compile the function, or
2. Provide a clear and helpful error message if the syntax is incorrect.

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

Xcode 16.2
Build version 16C5032a

ProductName: macOS
ProductVersion: 15.2
BuildVersion: 24C101

// swift-tools-version: 6.0

import PackageDescription

let package = Package(
    name: "Something",
    products: [
        .library(
            name: "Something",
            targets: ["Something"]),
    ],
    targets: [
        .target(
            name: "Something"
        )
    ]
)

Additional information

No response

@nashysolutions nashysolutions added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 16, 2025
@Lancelotbronner
Copy link

Lancelotbronner commented Jan 16, 2025

Providing a stack dump to help as this may be related to another crash I've encountered with parameter packs and typed throws.

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/lancelot/Downloads/test/Sources/main.swift -emit-dependencies-path /Users/lancelot/Downloads/test/.build/arm64-apple-macosx/debug/test.build/main.d -emit-reference-dependencies-path /Users/lancelot/Downloads/test/.build/arm64-apple-macosx/debug/test.build/main.swiftdeps -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -I /Users/lancelot/Downloads/test/.build/arm64-apple-macosx/debug/Modules -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/lancelot/Downloads/test/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -entry-point-function-name test_main -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/lancelot/Downloads/test -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name test -package-name test -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -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 /Users/lancelot/Downloads/test/.build/arm64-apple-macosx/debug/test.build/main.swift.o -index-store-path /Users/lancelot/Downloads/test/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.	Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for file "/Users/lancelot/Downloads/test/Sources/main.swift")
4.	While emitting IR SIL function "@$s4test11FileStorageV8savePath_10storageKeyyx_SStAC9SaveErrorOyx_GYKF".
 for 'savePath(_:storageKey:)' (at /Users/lancelot/Downloads/test/Sources/main.swift:4:2)
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           0x00000001063c6a9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001063c4cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001063c7068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x0000000191f1ee04 _sigtramp + 56
4  swift-frontend           0x00000001013ac4a8 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 6568
5  swift-frontend           0x00000001013ac4a8 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 6568
6  swift-frontend           0x00000001013aa65c swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 2088
7  swift-frontend           0x00000001011f5834 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) + 3364
8  swift-frontend           0x00000001013615a8 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 4700
9  swift-frontend           0x00000001013a9ba8 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 176
10 swift-frontend           0x000000010136a394 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'()) + 784
11 swift-frontend           0x0000000101363e90 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**) + 180
12 swift-frontend           0x0000000100d734bc 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
13 swift-frontend           0x0000000100d6ece4 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*) + 2176
14 swift-frontend           0x0000000100d6dbd0 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 984
15 swift-frontend           0x0000000100d70e88 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1684
16 swift-frontend           0x0000000100d6fbb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
17 swift-frontend           0x0000000100cf6a5c swift::mainEntry(int, char const**) + 3680
18 dyld                     0x0000000191b68274 start + 2840

@giginet
Copy link
Contributor

giginet commented Jan 17, 2025

It is already fixed on the current trunk. (6b2fb2e)

https://swiftfiddle.com/dqntwdewobbcxlzksnermyaqae

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

3 participants