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

Compiler crash with SE-0430 "transferring" parameters and result values #73316

Open
groue opened this issue Apr 28, 2024 · 3 comments
Open

Compiler crash with SE-0430 "transferring" parameters and result values #73316

groue opened this issue Apr 28, 2024 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@groue
Copy link

groue commented Apr 28, 2024

Description

The compiler crashes when it compiles a code snippet that involves a transferring result value.

Reproduction

protocol IntBuilder {
    func makeInt() -> Int
}

struct Worker {
    func f(_ closure: @escaping @Sendable () -> [Int]) { }
}

struct HighLevel {
    let worker: Worker
    
    func f(_ closure: @escaping @Sendable () -> transferring [any IntBuilder]) {
        worker.f {
            return closure().map { $0.makeInt() }
        }
    }
}

Stack dump

$ /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift build

Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
Failed to reconstruct type for $sSay30InferSendableFromCapturesIssue10IntBuilder_pGIeghTo_D
Original type:
(sil_function_type type="@Sendable @callee_guaranteed () -> @sil_transferring @owned Array<any IntBuilder>"
  (result=bound_generic_struct_type decl="Swift.(file).Array"
    (existential_type
      (protocol_type decl="InferSendableFromCapturesIssue.(file).IntBuilder@/private/tmp/InferSendableFromCapturesIssue/Sources/InferSendableFromCapturesIssue/InferSendableFromCapturesIssue.swift:1:10")))
  (substitution_map null_generic_signature)
  (substitution_map null_generic_signature))
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Pass '-Xfrontend -disable-round-trip-debug-types' to disable this assertion.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /private/tmp/InferSendableFromCapturesIssue/Sources/InferSendableFromCapturesIssue/InferSendableFromCapturesIssue.swift -emit-dependencies-path /private/tmp/InferSendableFromCapturesIssue/.build/arm64-apple-macosx/debug/InferSendableFromCapturesIssue.build/InferSendableFromCapturesIssue.d -emit-reference-dependencies-path /private/tmp/InferSendableFromCapturesIssue/.build/arm64-apple-macosx/debug/InferSendableFromCapturesIssue.build/InferSendableFromCapturesIssue.swiftdeps -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -I /private/tmp/InferSendableFromCapturesIssue/.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 /private/tmp/InferSendableFromCapturesIssue/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -external-plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -enable-experimental-feature RegionBasedIsolation -enable-experimental-feature TransferringArgsAndResults -enable-upcoming-feature StrictConcurrency -empty-abi-descriptor -resource-dir /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /private/tmp/InferSendableFromCapturesIssue -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name InferSendableFromCapturesIssue -package-name infersendablefromcapturesissue -target-sdk-version 14.5 -target-sdk-name macosx14.5 -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 /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -o /private/tmp/InferSendableFromCapturesIssue/.build/arm64-apple-macosx/debug/InferSendableFromCapturesIssue.build/InferSendableFromCapturesIssue.swift.o -index-store-path /private/tmp/InferSendableFromCapturesIssue/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.	Apple Swift version 6.0-dev (LLVM 94447cf359772fc, Swift f36098a14a0d48b)
2.	Compiling with effective version 5.10
3.	While evaluating request IRGenRequest(IR Generation for file "/private/tmp/InferSendableFromCapturesIssue/Sources/InferSendableFromCapturesIssue/InferSendableFromCapturesIssue.swift")
4.	While emitting IR SIL function "@$s30InferSendableFromCapturesIssue9HighLevelV1fyySayAA10IntBuilder_pGyYbYTcF".
 for 'f(_:)' (at /private/tmp/InferSendableFromCapturesIssue/Sources/InferSendableFromCapturesIssue/InferSendableFromCapturesIssue.swift:12:5)
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           0x00000001062acadc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001062ab2a8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001062ad124 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x0000000197df3584 _sigtramp + 56
4  libsystem_pthread.dylib  0x0000000197dc2c20 pthread_kill + 288
5  libsystem_c.dylib        0x0000000197ccfa20 abort + 180
6  swift-frontend           0x0000000106362f50 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) (.cold.24) + 0
7  swift-frontend           0x00000001013568e0 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) + 3780
8  swift-frontend           0x0000000101356d34 (anonymous namespace)::IRGenDebugInfoImpl::createParameterTypes(swift::CanTypeWrapper<swift::SILFunctionType>) + 1004
9  swift-frontend           0x000000010134f644 (anonymous namespace)::IRGenDebugInfoImpl::emitFunction(swift::SILDebugScope const*, llvm::Function*, swift::SILFunctionTypeRepresentation, swift::SILType, swift::DeclContext*, llvm::StringRef) + 2172
10 swift-frontend           0x000000010138ff34 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 832
11 swift-frontend           0x000000010138f698 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1580
12 swift-frontend           0x0000000101232894 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&) + 740
13 swift-frontend           0x0000000101341eb8 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2172
14 swift-frontend           0x000000010138eb60 swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 200
15 swift-frontend           0x000000010134a558 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'()) + 212
16 swift-frontend           0x0000000101343f1c 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**) + 208
17 swift-frontend           0x0000000100e59cd8 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
18 swift-frontend           0x0000000100e55f90 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*) + 1416
19 swift-frontend           0x0000000100e55438 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
20 swift-frontend           0x0000000100e6666c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
21 swift-frontend           0x0000000100e57a48 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
22 swift-frontend           0x0000000100e569b4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
23 swift-frontend           0x0000000100c71240 swift::mainEntry(int, char const**) + 3096
24 dyld                     0x0000000197a3a0e0 start + 2360

Expected behavior

No crash.

Environment

$ /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift --version                                                                   

Apple Swift version 6.0-dev (LLVM 94447cf359772fc, Swift f36098a14a0d48b)
Target: arm64-apple-macosx14.0

Additional information

Removing the transferring keyword removes the crash. This compiles fine:

protocol IntBuilder {
    func makeInt() -> Int
}

struct Worker {
    func f(_ closure: @escaping @Sendable () -> [Int]) { }
}

struct HighLevel {
    let worker: Worker
    
    func f(_ closure: @escaping @Sendable () -> [any IntBuilder]) {
        worker.f {
            return closure().map { $0.makeInt() }
        }
    }
}

However I intend to let users provide IntBuilder instances that are not Sendable, hence my desire to use transferring (if I got SE-0430 right).

@groue groue added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Apr 28, 2024
@groue
Copy link
Author

groue commented Apr 28, 2024

Package that reproduces the crash: Issue73316.zip

@groue
Copy link
Author

groue commented Apr 28, 2024

A different snippet that crashes in a similar way:

struct Helper<T> {
    let resolve: @Sendable () throws -> transferring T
    
    init(_ resolve: @escaping @Sendable () throws -> transferring T) {
        self.resolve = resolve
    }
}

struct Worker {
    func f(_ closure: @escaping @Sendable () -> transferring [Int]) {
        Helper(closure)
    }
}
Crash log
$ /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift package clean && /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift build

Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
Failed to reconstruct type for $sSaySiGIeghTo_D
Original type:
(sil_function_type type="@Sendable @callee_guaranteed () -> @sil_transferring @owned Array<Int>"
  (result=bound_generic_struct_type decl="Swift.(file).Array"
    (struct_type decl="Swift.(file).Int"))
  (substitution_map null_generic_signature)
  (substitution_map null_generic_signature))
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Pass '-Xfrontend -disable-round-trip-debug-types' to disable this assertion.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/groue/Desktop/Issue73316-2/Sources/Issue73316-2/Issue73316_2.swift -emit-dependencies-path /Users/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/Issue73316_2.build/Issue73316_2.d -emit-reference-dependencies-path /Users/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/Issue73316_2.build/Issue73316_2.swiftdeps -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -I /Users/groue/Desktop/Issue73316-2/.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/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -external-plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -enable-experimental-feature RegionBasedIsolation -enable-experimental-feature TransferringArgsAndResults -enable-upcoming-feature StrictConcurrency -empty-abi-descriptor -resource-dir /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/groue/Desktop/Issue73316-2 -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name Issue73316_2 -package-name issue73316_2 -target-sdk-version 14.4 -target-sdk-name macosx14.4 -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 /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -o /Users/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/Issue73316_2.build/Issue73316_2.swift.o -index-store-path /Users/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.	Apple Swift version 6.0-dev (LLVM 94447cf359772fc, Swift f36098a14a0d48b)
2.	Compiling with effective version 5.10
3.	While evaluating request IRGenRequest(IR Generation for file "/Users/groue/Desktop/Issue73316-2/Sources/Issue73316-2/Issue73316_2.swift")
4.	While emitting IR SIL function "@$s12Issue73316_26WorkerV1fyySaySiGyYbYTcF".
 for 'f(_:)' (at /Users/groue/Desktop/Issue73316-2/Sources/Issue73316-2/Issue73316_2.swift:10:5)
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           0x000000010657cadc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010657b2a8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010657d124 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000019c417584 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000019c3e6c20 pthread_kill + 288
5  libsystem_c.dylib        0x000000019c2f3a20 abort + 180
6  swift-frontend           0x0000000106632f50 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) (.cold.24) + 0
7  swift-frontend           0x00000001016268e0 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) + 3780
8  swift-frontend           0x0000000101626d34 (anonymous namespace)::IRGenDebugInfoImpl::createParameterTypes(swift::CanTypeWrapper<swift::SILFunctionType>) + 1004
9  swift-frontend           0x000000010161f644 (anonymous namespace)::IRGenDebugInfoImpl::emitFunction(swift::SILDebugScope const*, llvm::Function*, swift::SILFunctionTypeRepresentation, swift::SILType, swift::DeclContext*, llvm::StringRef) + 2172
10 swift-frontend           0x000000010165ff34 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 832
11 swift-frontend           0x000000010165f698 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1580
12 swift-frontend           0x0000000101502894 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&) + 740
13 swift-frontend           0x0000000101611eb8 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2172
14 swift-frontend           0x000000010165eb60 swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 200
15 swift-frontend           0x000000010161a558 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'()) + 212
16 swift-frontend           0x0000000101613f1c 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**) + 208
17 swift-frontend           0x0000000101129cd8 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
18 swift-frontend           0x0000000101125f90 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*) + 1416
19 swift-frontend           0x0000000101125438 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
20 swift-frontend           0x000000010113666c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
21 swift-frontend           0x0000000101127a48 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
22 swift-frontend           0x00000001011269b4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
23 swift-frontend           0x0000000100f41240 swift::mainEntry(int, char const**) + 3096
24 dyld                     0x000000019c05e0e0 start + 2360

The snippet below crashes differently. Note that the code is invalid because there is an invalid closure conversion from non-transferring result to transferring result):

struct Helper<T> {
    let resolve: @Sendable () throws -> transferring T
    
    init(_ resolve: @escaping @Sendable () throws -> transferring T) {
        self.resolve = resolve
    }
}

struct InvalidWorker {
    func f(_ closure: @escaping @Sendable () -> [Int]) {
        Helper(closure)
    }
}
Crash log
% /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift package clean && /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift build

Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
Assertion failed: ((!params.empty() || type->isDifferentiable() || !type->getIsolation().isNonIsolated() || type->getThrownError()) && "0 parameter case should be specialized unless it is a " "differentiable function or has a global actor"), function emitFunctionTypeMetadataRef, file MetadataRequest.cpp, line 1667.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/groue/Desktop/Issue73316-2/Sources/Issue73316-2/Issue73316_2.swift -emit-dependencies-path /Users/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/Issue73316_2.build/Issue73316_2.d -emit-reference-dependencies-path /Users/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/Issue73316_2.build/Issue73316_2.swiftdeps -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -I /Users/groue/Desktop/Issue73316-2/.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/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -external-plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -enable-experimental-feature RegionBasedIsolation -enable-experimental-feature TransferringArgsAndResults -enable-upcoming-feature StrictConcurrency -empty-abi-descriptor -resource-dir /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/groue/Desktop/Issue73316-2 -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name Issue73316_2 -package-name issue73316_2 -target-sdk-version 14.4 -target-sdk-name macosx14.4 -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 /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-22-a.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -o /Users/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/Issue73316_2.build/Issue73316_2.swift.o -index-store-path /Users/groue/Desktop/Issue73316-2/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.	Apple Swift version 6.0-dev (LLVM 94447cf359772fc, Swift f36098a14a0d48b)
2.	Compiling with effective version 5.10
3.	While evaluating request IRGenRequest(IR Generation for file "/Users/groue/Desktop/Issue73316-2/Sources/Issue73316-2/Issue73316_2.swift")
4.	While emitting IR for source file /Users/groue/Desktop/Issue73316-2/Sources/Issue73316-2/Issue73316_2.swift
5.	While emitting field type metadata 'Helper' (at /Users/groue/Desktop/Issue73316-2/Sources/Issue73316-2/Issue73316_2.swift:1:1)
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           0x0000000105fb8adc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000105fb72a8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000105fb9124 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000019c417584 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000019c3e6c20 pthread_kill + 288
5  libsystem_c.dylib        0x000000019c2f3a20 abort + 180
6  libsystem_c.dylib        0x000000019c2f2d10 err + 0
7  swift-frontend           0x00000001060975d0 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) (.cold.111) + 0
8  swift-frontend           0x000000010110ed24 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 11220
9  swift-frontend           0x000000010110ba60 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 520
10 swift-frontend           0x000000010110bff8 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 32
11 swift-frontend           0x000000010100b4e0 clang::CodeGen::ConstantInitFuture llvm::function_ref<clang::CodeGen::ConstantInitFuture (swift::irgen::ConstantInitBuilder&)>::callback_fn<getTypeRefByFunction(swift::irgen::IRGenModule&, swift::CanGenericSignature, swift::CanType)::$_5>(long, swift::irgen::ConstantInitBuilder&) + 1412
12 swift-frontend           0x0000000101107778 swift::irgen::IRGenModule::getAddrOfStringForMetadataRef(llvm::StringRef, unsigned int, bool, llvm::function_ref<clang::CodeGen::ConstantInitFuture (swift::irgen::ConstantInitBuilder&)>) + 232
13 swift-frontend           0x000000010100ae50 getTypeRefByFunction(swift::irgen::IRGenModule&, swift::CanGenericSignature, swift::CanType) + 400
14 swift-frontend           0x000000010100800c getTypeRefImpl(swift::irgen::IRGenModule&, swift::CanType, swift::CanGenericSignature, swift::irgen::MangledTypeRefRole) + 220
15 swift-frontend           0x000000010100bab8 ReflectionMetadataBuilder::addTypeRef(swift::CanType, swift::CanGenericSignature, swift::irgen::MangledTypeRefRole) + 76
16 swift-frontend           0x000000010100e700 FieldTypeMetadataBuilder::addField(swift::reflection::FieldRecordFlags, swift::Type, llvm::StringRef) + 300
17 swift-frontend           0x000000010100e588 FieldTypeMetadataBuilder::addField(swift::irgen::Field) + 96
18 swift-frontend           0x000000010111d36c swift::irgen::forEachField(swift::irgen::IRGenModule&, swift::NominalTypeDecl const*, llvm::function_ref<void (swift::irgen::Field)>) + 128
19 swift-frontend           0x000000010100e268 FieldTypeMetadataBuilder::layoutRecord() + 256
20 swift-frontend           0x000000010100e10c FieldTypeMetadataBuilder::layout() + 468
21 swift-frontend           0x000000010100bd34 ReflectionMetadataBuilder::emit(std::__1::optional<llvm::function_ref<llvm::Constant* (swift::irgen::IRGenModule&, swift::irgen::ConstantInit)>>, char const*) + 44
22 swift-frontend           0x000000010100aa54 FieldTypeMetadataBuilder::emit() + 112
23 swift-frontend           0x000000010100a85c swift::irgen::IRGenModule::emitFieldDescriptor(swift::NominalTypeDecl const*) + 1068
24 swift-frontend           0x0000000101010178 swift::irgen::IRGenModule::emitStructDecl(swift::StructDecl*) + 128
25 swift-frontend           0x0000000100f39400 swift::irgen::IRGenModule::emitGlobalDecl(swift::Decl*) + 164
26 swift-frontend           0x0000000100f38dfc swift::irgen::IRGenModule::emitSourceFile(swift::SourceFile&) + 100
27 swift-frontend           0x000000010104e05c swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2592
28 swift-frontend           0x000000010109ab60 swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 200
29 swift-frontend           0x0000000101056558 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'()) + 212
30 swift-frontend           0x000000010104ff1c 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**) + 208
31 swift-frontend           0x0000000100b65cd8 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
32 swift-frontend           0x0000000100b61f90 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*) + 1416
33 swift-frontend           0x0000000100b61438 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
34 swift-frontend           0x0000000100b7266c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
35 swift-frontend           0x0000000100b63a48 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
36 swift-frontend           0x0000000100b629b4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
37 swift-frontend           0x000000010097d240 swift::mainEntry(int, char const**) + 3096
38 dyld                     0x000000019c05e0e0 start + 2360

@Azoy
Copy link
Member

Azoy commented May 8, 2024

cc: @gottesmm

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. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants