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

[TypedThrow] Generic Failure Protocol Crashes #74565

Open
pbk20191 opened this issue Jun 20, 2024 · 0 comments
Open

[TypedThrow] Generic Failure Protocol Crashes #74565

pbk20191 opened this issue Jun 20, 2024 · 0 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 typed throws Feature → error handling → throws & rethrows: Typed throws

Comments

@pbk20191
Copy link

Description

I was trying to merge TaskGroup API with generic Protocol. However code is not compiled.

Reproduction

Declare Generic Failure Protocol like below CompatDiscardingTaskGroup

@usableFromInline
package protocol CompatDiscardingTaskGroup<Failure> {
    
    
    associatedtype Failure:Error = any Error
    typealias Block = @Sendable @isolated(any) () async throws(Failure) -> Void
    
    @inlinable
    var isCancelled:Bool { get }
    
    @inlinable
    var isEmpty:Bool { get }
    
    @inlinable
    func cancelAll()
    
    @inlinable
    mutating func addTaskUnlessCancelled(
        priority: TaskPriority?,
        operation: @escaping Block
    ) -> Bool
    
    @inlinable
    mutating func addTask(
        priority: TaskPriority?,
        operation: @escaping Block
    )
    
    @inlinable
    @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
    mutating func addTask(executorPreference taskExecutor: (any TaskExecutor)?, priority: TaskPriority?, operation: @escaping Block)
    
    @inlinable
    @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
    mutating func addTaskUnlessCancelled(executorPreference taskExecutor: (any TaskExecutor)?, priority: TaskPriority?, operation: @escaping Block) -> Bool
    
}

Below code block is compiled which is expected

@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, macCatalyst 17.0, visionOS 1.0, *)
extension ThrowingDiscardingTaskGroup: CompatDiscardingTaskGroup {

}


extension ThrowingTaskGroup: CompatDiscardingTaskGroup where ChildTaskResult == Void {

}

However this code block is not compiled, and rather crash

@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, macCatalyst 17.0, visionOS 1.0, *)
extension DiscardingTaskGroup: CompatDiscardingTaskGroup {
    @usableFromInline
    package typealias Failure = Never
}

extension TaskGroup: CompatDiscardingTaskGroup where ChildTaskResult == Void {
    @usableFromInline
    package typealias Failure = Never

    
}

Stack dump

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/bagbyeong-gwan/IDE/XcodeWorkSpace/Tetra/Sources/BackportDiscardingTaskGroup/CompatDiscardingTaskGroup.swift /Users/bagbyeong-gwan/IDE/XcodeWorkSpace/Tetra/Sources/BackportDiscardingTaskGroup/SafetyRegion.swift /Users/bagbyeong-gwan/IDE/XcodeWorkSpace/Tetra/Sources/BackportDiscardingTaskGroup/Suppress.swift /Users/bagbyeong-gwan/IDE/XcodeWorkSpace/Tetra/Sources/BackportDiscardingTaskGroup/TaskGroup.swift /Users/bagbyeong-gwan/IDE/XcodeWorkSpace/Tetra/Sources/BackportDiscardingTaskGroup/ThrowingTaskGroup.swift /Users/bagbyeong-gwan/IDE/XcodeWorkSpace/Tetra/Sources/BackportDiscardingTaskGroup/imp.swift -target arm64-apple-macos10.15 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -I /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Products/Debug -I /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Products/Debug -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 6 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -enable-experimental-opaque-type-erasure -const-gather-protocols-file /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/Objects-normal/arm64/BackportDiscardingTaskGroup_const_extract_protocols.json -enable-experimental-feature IsolatedAny -enable-experimental-feature DebugDescriptionMacro -enable-upcoming-feature FullTypedThrows -empty-abi-descriptor -plugin-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing -validate-clang-modules-once -clang-build-session-file /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/bagbyeong-gwan/IDE/XcodeWorkSpace/Tetra/.swiftpm/xcode -resource-dir /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/bagbyeong-gwan/IDE/XcodeWorkSpace/Tetra/.swiftpm/xcode -Xcc -ivfsstatcache -Xcc /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.0-24A5264i-495167fbbdaa9fb73ea1f786c83da506.sdkstatcache -Xcc -I/Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/swift-overrides.hmap -Xcc -I/Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Products/Debug/include -Xcc -I/Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/DerivedSources-normal/arm64 -Xcc -I/Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/DerivedSources/arm64 -Xcc -I/Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name BackportDiscardingTaskGroup -package-name tetra -disable-clang-spi -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -emit-module-doc-path /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/Objects-normal/arm64/BackportDiscardingTaskGroup.swiftdoc -emit-module-source-info-path /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/Objects-normal/arm64/BackportDiscardingTaskGroup.swiftsourceinfo -emit-objc-header-path /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/Objects-normal/arm64/BackportDiscardingTaskGroup-Swift.h -serialize-diagnostics-path /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/Objects-normal/arm64/BackportDiscardingTaskGroup-master-emit-module.dia -emit-dependencies-path /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/Objects-normal/arm64/BackportDiscardingTaskGroup-master-emit-module.d -o /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/Objects-normal/arm64/BackportDiscardingTaskGroup.swiftmodule -emit-abi-descriptor-path /Users/bagbyeong-gwan/Library/Developer/Xcode/DerivedData/Tetra-eoeesywducengtdmcmtvnsxowdrs/Build/Intermediates.noindex/Tetra.build/Debug/BackportDiscardingTaskGroup.build/Objects-normal/arm64/BackportDiscardingTaskGroup.abi.json
1.	Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module BackportDiscardingTaskGroup)
4.	While generating SIL witness table protocol conformance TaskGroup<ChildTaskResult>: CompatDiscardingTaskGroup at extension of TaskGroup (at /Users/bagbyeong-gwan/IDE/XcodeWorkSpace/Tetra/Sources/BackportDiscardingTaskGroup/imp.swift:13:1)
5.	While generating protocol witness thunk SIL function "@$sScGyxG27BackportDiscardingTaskGroup06CompatbcD0ABytRszrlAbCP03addC15UnlessCancelled8priority9operationSbScPSg_yyYaYb7FailureQzYKYActFTW".
 for 'addTaskUnlessCancelled(priority:operation:)' (in module '_Concurrency')
6.	While emitting reabstraction thunk in SIL function "@$ss5NeverOIeAghHzr_ytIeAghHr_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           0x00000001084b2cd0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001084b0f44 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001084b32d8 SignalHandler(int) + 352
3  libsystem_platform.dylib 0x00000001a01d0184 _sigtramp + 56
4  swift-frontend           0x00000001038a30f0 swift::Lowering::SILGenFunction::emitApplyWithRethrow(swift::SILLocation, swift::SILValue, swift::SILType, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>) + 2268
5  swift-frontend           0x0000000103991334 buildThunkBody(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanType, llvm::function_ref<void (swift::Lowering::SILGenFunction&)>) + 1988
6  swift-frontend           0x00000001039930dc createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 3672
7  swift-frontend           0x00000001039886b8 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 1712
8  swift-frontend           0x00000001039960f0 (anonymous namespace)::TranslateArguments::processSingle(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::ManagedValue, (anonymous namespace)::ParamInfo) + 276
9  swift-frontend           0x0000000103993aa8 (anonymous namespace)::ExpanderBase<(anonymous namespace)::TranslateArguments, (anonymous namespace)::ParamInfo>::expand(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType) + 600
10 swift-frontend           0x000000010399c9a8 (anonymous namespace)::TranslateArguments::expandParam(swift::Lowering::AbstractionPattern, swift::AnyFunctionType::CanParam, swift::Lowering::AbstractionPattern, swift::AnyFunctionType::CanParam) + 352
11 swift-frontend           0x000000010398c808 (anonymous namespace)::TranslateArguments::process(swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, swift::Lowering::AbstractionPattern, swift::ArrayRefView<swift::AnyFunctionType::Param, swift::AnyFunctionType::CanParam, swift::AnyFunctionType::CanParam::getFromParam(swift::AnyFunctionType::Param const&), true>, bool) + 4724
12 swift-frontend           0x000000010398f5c0 swift::Lowering::SILGenFunction::emitProtocolWitness(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILDeclRef, swift::SubstitutionMap, swift::SILDeclRef, swift::SubstitutionMap, swift::Lowering::IsFreeFunctionWitness_t, bool, bool, std::__1::optional<swift::ActorIsolation>) + 3512
13 swift-frontend           0x00000001039c3e8c swift::Lowering::SILGenModule::emitProtocolWitness(swift::ProtocolConformanceRef, swift::SILLinkage, swift::IsSerialized_t, swift::SILDeclRef, swift::SILDeclRef, swift::Lowering::IsFreeFunctionWitness_t, swift::Witness) + 4272
14 swift-frontend           0x00000001039c6da4 (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethodImplementation(swift::SILDeclRef, swift::SILDeclRef, swift::Witness) + 376
15 swift-frontend           0x00000001039c67a8 (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethod(swift::SILDeclRef) + 780
16 swift-frontend           0x00000001039c62ac swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 1920
17 swift-frontend           0x00000001039c29e4 swift::Lowering::SILGenModule::getWitnessTable(swift::NormalProtocolConformance*) + 548
18 swift-frontend           0x00000001039c5a40 SILGenExtension::emitExtension(swift::ExtensionDecl*) + 880
19 swift-frontend           0x0000000103891118 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 264
20 swift-frontend           0x0000000103897200 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1804
21 swift-frontend           0x00000001039aee68 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 196
22 swift-frontend           0x000000010389c0f4 swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 524
23 swift-frontend           0x0000000102e7d6a8 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2484
24 swift-frontend           0x0000000102e81468 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1672
25 swift-frontend           0x0000000102e7f438 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4752
26 swift-frontend           0x0000000102e052d8 swift::mainEntry(int, char const**) + 2812
27 dyld                     0x000000019fe19298 start + 2876
Command SwiftEmitModule failed with a nonzero exit code

Expected behavior

Code should compile. Since Failure type is very obvious in this case( Never and any Error)

Environment

  • xcode beta swift 6
  • swift 6 2024-06-18

Additional information

No response

@pbk20191 pbk20191 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 Jun 20, 2024
@hborla hborla added typed throws Feature → error handling → throws & rethrows: Typed throws and removed triage needed This issue needs more specific labels labels Jul 14, 2024
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 typed throws Feature → error handling → throws & rethrows: Typed throws
Projects
None yet
Development

No branches or pull requests

2 participants