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 when returning a throwing closure with typed Error set to Never #78212

Open
martialln opened this issue Dec 16, 2024 · 1 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

Comments

@martialln
Copy link

Description

While I was playing with the memoization code seen in the forum to add support for typed error, I encountered a crash in the compiler.

I reduce it to the fact that the compiler crash when trying to return a throwing closure with typed error.

Reproduction

func bar<Err: Error>(
    _ f: @escaping () throws(Err) -> Void
) -> () throws(Err) -> Void {
    return {
        print("call f")
        return try f()
    }
}

let f = { print("hu?") }
let bared = bar(f)

Stack dump

0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types <PROJECT_PATH>/memoize/Sources/main.swift -target arm64-apple-macos14.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 <HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Products/Debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F <HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Products/Debug -F /Applications/Xcode.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 <HOME>/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 6 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -const-gather-protocols-file <HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/Objects-normal/arm64/memoize_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -enable-experimental-feature OpaqueTypeErasure -empty-abi-descriptor -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing -validate-clang-modules-once -clang-build-session-file <HOME>/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc <PROJECT_PATH>/memoize/.swiftpm/xcode -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir <PROJECT_PATH>/memoize/.swiftpm/xcode -Xcc -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -Xcc -ivfsstatcache -Xcc <HOME>/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.2-24C94-1dd28740b163f220e3e9b9fd2a542f53.sdkstatcache -Xcc -I<HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Products/Debug/include -Xcc -I<HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/DerivedSources-normal/arm64 -Xcc -I<HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/DerivedSources/arm64 -Xcc -I<HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name memoize -package-name memoize -frontend-parseable-output -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 -emit-module-doc-path <HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/Objects-normal/arm64/memoize.swiftdoc -emit-module-source-info-path <HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/Objects-normal/arm64/memoize.swiftsourceinfo -serialize-diagnostics-path <HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/Objects-normal/arm64/memoize-master-emit-module.dia -emit-dependencies-path <HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/Objects-normal/arm64/memoize-master-emit-module.d -o <HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/Objects-normal/arm64/memoize.swiftmodule -emit-abi-descriptor-path <HOME>/Library/Developer/Xcode/DerivedData/memoize-gsgovrbqeiyawbbpnzjqtjnokvkg/Build/Intermediates.noindex/memoize.build/Debug/memoize.build/Objects-normal/arm64/memoize.abi.json
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 ASTLoweringRequest(Lowering AST to SIL for module memoize)
4.	While emitting reabstraction thunk in SIL function "@$ss5NeverOIegzr_Ieg_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           0x000000010a94aa9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a948cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010a94b068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x0000000191dbae04 _sigtramp + 56
4  swift-frontend           0x0000000105d1f2a0 swift::Lowering::SILGenFunction::emitApplyWithRethrow(swift::SILLocation, swift::SILValue, swift::SILType, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>) + 2288
5  swift-frontend           0x0000000105e2b364 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           0x0000000105e2d1c4 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&) + 3840
7  swift-frontend           0x0000000105e228fc (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 1700
8  swift-frontend           0x0000000105d737a4 swift::Lowering::Conversion::emit(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::SGFContext) const + 472
9  swift-frontend           0x0000000105cfd5f8 (anonymous namespace)::ScalarResultPlan::finish(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::Initialization*, swift::SILFunctionTypeRepresentation) + 692
10 swift-frontend           0x0000000105cfd200 (anonymous namespace)::ScalarResultPlan::finish(swift::Lowering::SILGenFunction&, swift::SILLocation, llvm::ArrayRef<swift::Lowering::ManagedValue>&, swift::SILValue) + 440
11 swift-frontend           0x0000000105d1e29c swift::Lowering::SILGenFunction::emitApply(std::__1::unique_ptr<swift::Lowering::ResultPlan, std::__1::default_delete<swift::Lowering::ResultPlan>>&&, swift::Lowering::ArgumentScope&&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SubstitutionMap, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::CalleeTypeInfo const&, swift::optionset::OptionSet<swift::ApplyFlags, unsigned char>, swift::Lowering::SGFContext, std::__1::optional<swift::ActorIsolation>) + 3344
12 swift-frontend           0x0000000105d24f50 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2240
13 swift-frontend           0x0000000105d23408 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3116
14 swift-frontend           0x0000000105d9037c swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 128
15 swift-frontend           0x0000000105d7b90c swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 2016
16 swift-frontend           0x0000000105d82840 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 140
17 swift-frontend           0x0000000105e5b638 swift::ASTVisitor<swift::Lowering::SILGenTopLevel, void, void, void, void, void, void>::visit(swift::Decl*) + 2132
18 swift-frontend           0x0000000105e5895c swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*, swift::SILFunction*) + 1472
19 swift-frontend           0x0000000105d12ec0 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1428
20 swift-frontend           0x0000000105e4992c 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
21 swift-frontend           0x0000000105d17f14 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'()) + 528
22 swift-frontend           0x00000001052f2304 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2828
23 swift-frontend           0x00000001052f4e88 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1684
24 swift-frontend           0x00000001052f3bb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
25 swift-frontend           0x000000010527aa5c swift::mainEntry(int, char const**) + 3680
26 dyld                     0x0000000191a04274 start + 2840

Expected behavior

The compiler doesn't crash.

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

Additional information

Returning the same throwing closure with untyped error works.

@martialln martialln 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 Dec 16, 2024
@martialln
Copy link
Author

Maybe a duplicate of #74273

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

1 participant